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

feat: ui items #4881

Merged
merged 1 commit into from
Feb 3, 2024
Merged

feat: ui items #4881

merged 1 commit into from
Feb 3, 2024

Conversation

fbwoolf
Copy link
Contributor

@fbwoolf fbwoolf commented Jan 30, 2024

Try out this version of Leather — Extension build, Test report

This PR builds/shares a reusable Item component.

Assets
Screenshot 2024-01-30 at 10 47 45 AM

Activity
Screenshot 2024-01-30 at 10 47 11 AM

Accounts
Screenshot 2024-01-30 at 10 48 26 AM

Send
Screenshot 2024-01-30 at 10 47 21 AM

Receive
Screenshot 2024-01-30 at 10 47 59 AM

Swap
Screenshot 2024-01-30 at 10 48 13 AM

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Jan 30, 2024

@mica000 @fabric-8 use the Storybook link to check over the Item component here when you can.

Copy link
Contributor

@pete-watters pete-watters left a comment

Choose a reason for hiding this comment

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

Great work here Fara! 👏 🚀

@mica000
Copy link

mica000 commented Jan 31, 2024

This is great @fbwoolf! Thank you so much!
Was looking very much forward for this component as it will be used in many places!

  1. On Storybooks the item seems broken, so not sure what is happening there?
  2. In relation to the "arrow right", that appears on send, account and activity, let's use the variant without the arrow. For now we are only using the "arrow right" on the Approval UX redesign views as a way to move the user to a page such as Account or Fee.
  3. Corner radius: 2px on the item
  4. Token and status: Will create a ticket to handle token and status

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Great work Fara.

Please forgive the many questions on how this works, and some of the decisions. Also curious if we're going to use this with Radix primitive components as well.

bg: 'accent.background-primary',
height: 'auto',
userSelect: 'none',
p: 'space.03',
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if padding should not be defined here? @fabric-8 @mica000 are we absolutely sure we only ever use one padding unit inside them?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah for now that what we do indeed, so far we didn't run into cases where we'd need to go differently about that 🤷

src/app/ui/components/items/item-with-buttons.layout.tsx Outdated Show resolved Hide resolved
src/app/components/account/account-list-item-layout.tsx Outdated Show resolved Hide resolved
src/app/ui/components/items/item-default.layout.tsx Outdated Show resolved Hide resolved
src/app/ui/components/items/item.stories.tsx Outdated Show resolved Hide resolved
src/app/ui/components/items/item.tsx Outdated Show resolved Hide resolved
src/app/ui/components/items/item.tsx Outdated Show resolved Hide resolved
src/app/ui/components/items/item.tsx Outdated Show resolved Hide resolved
src/app/pages/receive/components/receive-item.tsx Outdated Show resolved Hide resolved
Comment on lines 108 to 114
function onKeyDown(e: KeyboardEvent<HTMLInputElement>) {
if (!isRoleButton) return;
if (e.key === 'enter' || e.key === ' ') {
e.preventDefault();
onClick();
}
}
Copy link
Collaborator

@kyranjamie kyranjamie Jan 31, 2024

Choose a reason for hiding this comment

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

Why is this needed? If the element's a button it should behave this way by default.

I'm always cautious of code which tries to replicate how browser elements. There's always way more to them than you think. Reminds me of https://remysharp.com/2016/12/11/how-tabs-should-work as an example. If there's a way we can just use the browser behaviour than recreating, that's preferable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not always a button. I am adding this here after referencing how to add accessibility to a div so that it can be either a div or a button.

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Jan 31, 2024

@mica000 why do you say the storybook items are broken? 🤔 https://65982789c7e2278518f189e7-vbbtozlkvb.chromatic.com/?path=/story/item--default ...they seem fine to me?

@mica000
Copy link

mica000 commented Jan 31, 2024

@mica000 why do you say the storybook items are broken? 🤔 https://65982789c7e2278518f189e7-vbbtozlkvb.chromatic.com/?path=/story/item--default ...they seem fine to me?

I see them like this:
image

Seems like the padding is off?
Here is how it is in desgins:
image

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Jan 31, 2024

@mica000 why do you say the storybook items are broken? 🤔 https://65982789c7e2278518f189e7-vbbtozlkvb.chromatic.com/?path=/story/item--default ...they seem fine to me?

Strange, not what I see ...will double check code bc I'm not used to working with Grids.
Screenshot 2024-01-31 at 9 34 34 AM

@fabric-8
Copy link
Contributor

It look fine to me a bit earlier but now I'm also getting this:
CleanShot 2024-01-31 at 21 59 27@2x

Wanted to call out that we changed the height of text elements to 20px after removing the link elements in figma, gonna look at it later when it's maybe rendered correctly again :)

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 2, 2024

Moving this into draft mode until I'm done refactoring.

@fbwoolf fbwoolf marked this pull request as draft February 2, 2024 01:05
@fbwoolf fbwoolf marked this pull request as ready for review February 2, 2024 02:26
@fbwoolf fbwoolf requested a review from kyranjamie February 2, 2024 02:26
@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 2, 2024

@kyranjamie let me know what you think of this version in your AM if you have time, thx.

EDIT: There is likely more refactoring we can do to simplify the sharing of the asset list items, but this might be a good step until we have new designs. Also, quite a few components typically pass components as props, so I used isValidElement to render the passed jsx. Styling isn't perfect with the interaction yet, but wanted to get feedback on this direction.

Copy link
Collaborator

@kyranjamie kyranjamie left a comment

Choose a reason for hiding this comment

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

Thanks for trying some different solutions @fbwoolf

import { ItemLayout } from '@app/ui/components/item/item.layout';
import { Spinner } from '@app/ui/components/spinner';

interface AccountListItemLayoutProps extends ComponentProps<'div'> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't spread the additional props, so either remove type, or spread props

Comment on lines 30 to 106
interface RootProps {
isDisabled?: boolean;
isInteractive?: boolean;
onClickItem?(): void;
}
function Root({ children, isDisabled, isInteractive, onClickItem }: RootProps & HasChildren) {
return isInteractive ? (
<ItemInteractive disabled={isDisabled} onClick={onClickItem}>
{children}
</ItemInteractive>
) : (
<ItemBase>{children}</ItemBase>
);
}
Copy link
Collaborator

@kyranjamie kyranjamie Feb 2, 2024

Choose a reason for hiding this comment

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

There's no value in using a slot component if we just had a single one. Recommend changing to a single component.

On isInteractive, this could just be inferred from whether there's a onClick defined or not? The redundancy creates the possibility for illogical props isInteractive={false} onClick={() => {...}}

I reckon that, as the behaviours of ItemInteractive and ItemBase are different, they don't belong tied together in a single component. It's only because of past use of isPressable that they are in this solution. If this is too complex to remove, I think it's okay to leave as this, I just question whether this ternary logic should belong in the component itself.

For instance, what if we were to remove isPressable, and in all the places where it's used we just use ItemInteractive and disable it if there isn't an action? That would make more sense I think?

Copy link
Contributor Author

@fbwoolf fbwoolf Feb 2, 2024

Choose a reason for hiding this comment

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

I'm not using a slot component, but did use the naming of Root so that is prob confusing. I am just using a config recipe, not a slot recipe in this refactor.

I am using isDefined(onClick) in the component to set the isInteractive prop, but I can move to handle it in the item, np ...just thought it was more explicit with our use atm.

We can't really remove the isPressable situation w/out a bigger refactor here, and I don't think we should take the time to do it rn with new designs coming anyway for most of these features? I thought about, and tried, just disabling the ItemInteractive when not pressable, but a disabled state/styling is really different than this. That is why I chose to use the shared base styling and applying the variant of interactive to a different component. Also, we do get the console error of a button in a button in some cases (with the Connect Ledger button) when it is embedded in the asset list.


const ItemInteractive = forwardRef<HTMLButtonElement, HTMLStyledProps<'button'> & ItemVariantProps>(
(props, ref) => (
<styled.button className={`group ${itemRecipe({ interactive: true })}`} ref={ref} {...props} />
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the group class about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

group selectors in panda are pretty cool. This is how I'm handling the isDisabled state of children. You then apply groupDisabled to the children and they will inherit that state.

https://panda-css.com/docs/concepts/conditional-styles#group-selectors

@kyranjamie
Copy link
Collaborator

kyranjamie commented Feb 2, 2024

The disabled state is the more complex requirement here. We need a way to communicate the state of the button to child content.

image

A component API that optionally allows a render component would work well I think.

<InteractiveItem>Simple use-case</InteractiveItem>

<InteractiveItem isDisabled>
  {({ isDisabled }) => (<ItemContent isDisabled={isDisabled} /> )}
</InteractiveItem>

That, or we just duplicate the isDisabled prop? Wonder if necessary.

How/where is this handled in the current implementation?

@kyranjamie
Copy link
Collaborator

As far of this effort, I wonder if you can look into how we could best apply these same InteractiveItem styles to the dropdown item

Figma link https://www.figma.com/file/2MLHeIeL6XPVi3Tc2DfFCr/%E2%9D%96-Leather-%E2%80%93-Design-System?type=design&node-id=8945-105536&mode=design&t=1tV8WbAOcIewYOVX-4

Practically all the styles are shared

@mica000
Copy link

mica000 commented Feb 2, 2024

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 2, 2024

The disabled state is the more complex requirement here. We need a way to communicate the state of the button to child content.

How/where is this handled in the current implementation?

There is a isDisabled variant being used. Ref the deployed storybook and look at the stories I built. The group selector is handling changing the styles of children.

I actually don't think the render prop pattern is suggested anymore by React. The docs say it is deprecated for using custom hooks?

https://legacy.reactjs.org/docs/render-props.html

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 2, 2024

As far of this effort, I wonder if you can look into how we could best apply these same InteractiveItem styles to the dropdown item

Practically all the styles are shared

After working on these, I'm not sure it is nec, is it? Thestyles are pretty simple.

@kyranjamie
Copy link
Collaborator

kyranjamie commented Feb 2, 2024

There is a isDisabled variant being used. Ref the deployed storybook and look at the stories I built. The group selector is handling changing the styles of children.

Nice, didn't know this.

I actually don't think the render prop pattern is suggested anymore by React. The docs say it is deprecated for using custom hooks?

Because of group, no need to add the render prop here then. Though, I think we still have legit cases for render props, eg the loader pattern. We're using it exclusively because we can't do what we want with hooks (handling conditionality).

After working on these, I'm not sure it is nec, is it? Thestyles are pretty simple.

Would still be nice not to repeat them however simple, if they're exactly the same?

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 2, 2024

Would still be nice not to repeat them however simple, if they're exactly the same?

Yeah, was looking at them again. Seems like a good idea to share the different state styling b/w them.

@fbwoolf fbwoolf force-pushed the feat/ui-items branch 3 times, most recently from a6edc2d to 290c5cc Compare February 3, 2024 02:29
@fbwoolf fbwoolf linked an issue Feb 3, 2024 that may be closed by this pull request
@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 3, 2024

@kyranjamie maybe look this over if get a sec, I was able to refactor to one ItemInteractive with this version and I'm sharing item styles with the Select and DropdownMenu items.

@fbwoolf fbwoolf requested a review from kyranjamie February 3, 2024 02:35
@kyranjamie
Copy link
Collaborator

@kyranjamie maybe look this over if get a sec, I was able to refactor to one ItemInteractive with this version and I'm sharing item styles with the Select and DropdownMenu items.

Yeah looks great Fara. Super tidy 💯

@fbwoolf
Copy link
Contributor Author

fbwoolf commented Feb 3, 2024

Added the ItemLayout story here...

Screenshot 2024-02-03 at 4 52 23 PM

@fbwoolf fbwoolf added this pull request to the merge queue Feb 3, 2024
Merged via the queue into dev with commit 4e6cd7d Feb 3, 2024
28 checks passed
@fbwoolf fbwoolf deleted the feat/ui-items branch February 3, 2024 22:59
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.

Design System: Layout Design System: InteractiveItem
5 participants