-
Notifications
You must be signed in to change notification settings - Fork 7
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
Conversation
--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) | ||
); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
b835005
to
6e2912c
Compare
There was a problem hiding this 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", |
There was a problem hiding this comment.
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'; | ||
|
There was a problem hiding this comment.
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
render(createTestComponent()); | ||
expect(screen.getByTestId(IconType.ADD)).toBeInTheDocument(); |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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') { |
There was a problem hiding this comment.
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:
if (!value || typeof value !== 'string') { | |
if (value == null) { |
); | ||
}; | ||
|
||
Avatar.displayName = 'Avatar'; |
There was a problem hiding this comment.
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?
Reopening new PR to make use of radix-ui's avatar primitive |
Description
Task: APP-2612
Type of change
Checklist:
CHANGELOG.md
file in the root folder of the package after the [UPCOMING] title and before the latest version.