Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: APP-2612 - Implement Avatar component #49

Closed
wants to merge 9 commits into from

Conversation

Fabricevladimir
Copy link
Contributor

@Fabricevladimir Fabricevladimir commented Nov 23, 2023

Description

  • adds the avatar component

Task: APP-2612

Type of change

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have selected the correct base branch.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • Any dependent changes have been merged and published in downstream modules.
  • I ran all tests with success and extended them if necessary.
  • I have updated the CHANGELOG.md file in the root folder of the package after the [UPCOMING] title and before the latest version.
  • I have tested my code on the test network.

@Fabricevladimir Fabricevladimir marked this pull request as ready for review November 28, 2023 11:37
@Fabricevladimir Fabricevladimir changed the title WIP - Feature: APP-2612 - Implement Avatar component Feature: APP-2612 - Implement Avatar component Nov 28, 2023
Comment on lines +72 to +83
--ods-gradient-tl-primary-500-to-800: linear-gradient(
135deg,
var(--ods-color-primary-500),
var(--ods-color-primary-800)
);

--ods-gradient-neutral-900: 31 41 51;
--ods-gradient-tl-neutral-900: linear-gradient(
135deg,
rgb(var(--ods-gradient-neutral-900) / 0.24),
rgb(var(--ods-gradient-neutral-900) / 0.96)
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RuggeroCino, I ran into an interesting little issue where you can either define color stops for the gradients or go all the way and define the whole gradient as a background image. I went for the latter option because it made more sense in terms of on the fly styling, but it does have its drawbacks. Here, for example, I was unable to find a way to add the transparency using the custom ODS color variable as long as that variable was defined as a hex code (no string concatenation in normal css 🤷🏾‍♂️). I'm not at all happy with this solution; what are your thoughts? Right now it's either we define the colors as RGB values or hardcode the gradient stops. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, CSS custom properties are hard to use with opacity :/
I would discuss this with Selim and see if we really need to use opacity for this gradient, if not we could use a lighter neutral color and have something similar to the primary 500 to 800. Otherwise let's discuss about the alternatives

Copy link
Member

@cgero-eth cgero-eth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done @Fabricevladimir! I left some comments

@@ -45,6 +45,7 @@
"@radix-ui/react-progress": "^1.0.0",
"classnames": "^2.3.0",
"react": "^18.2.0",
"react-blockies": "^1.4.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's relax the version of the react-blockies dependency to ^1.0.0

import type React from 'react';
import { useEffect, useState, type HTMLAttributes } from 'react';
import Blockies from 'react-blockies';

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would either enforce this new space between the third party imports and the relative ones through a eslint rule or just remove this new line to be aligned across all components

Comment on lines +14 to +15
render(createTestComponent());
expect(screen.getByTestId(IconType.ADD)).toBeInTheDocument();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not rely on the properties defined on the createTestComponent function, the ones set there are only used to be able to render a functional component. If we do so, we will end with having multiple tests coupled with each other. Instead let's specify them on the tests like:

const icon = IconType.ADD;
render(createTestComponent({ icon });
expect(screen.getByTestId(icon)).toBeInTheDocument();

@@ -0,0 +1,13 @@
import { type HTMLAttributes } from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the component doesn't really have some specific logic, I would just combine this with the Avatar component. What do you think?


import { Avatar, type IAvatarProps } from './avatar';

const etherIcon = 'https://assets.coingecko.com/coins/images/279/large/ethereum.png';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to the test using it to avoid shared variables between tests. Also, right now the test might randomly fail if for some reason the asset url is not valid anymore. I'd suggest to try the solution posted here to fire the load and error events on the test instead

* // Results in the fallback 'Al' due to a single-word copy.
* 'Alice'
*/
src?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are delegating the logic of checking if a dao/user has a valid image/profile-image set to the components using this component. Let's sync if we can improve this by adding for instance a fallback property.

private addressRegex = /^0x[a-fA-F0-9]{40}$/;

isAddress(value: string | null | undefined): boolean {
if (!value || typeof value !== 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we already specify that value is either string or null/undefined, we don't need to check that it is actually a string, we can simply write:

Suggested change
if (!value || typeof value !== 'string') {
if (value == null) {

);
};

Avatar.displayName = 'Avatar';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The component display name is set automatically, right?

@Fabricevladimir Fabricevladimir marked this pull request as draft November 30, 2023 11:10
@Fabricevladimir
Copy link
Contributor Author

Reopening new PR to make use of radix-ui's avatar primitive

@cgero-eth cgero-eth deleted the f/avatars branch July 23, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants