-
Notifications
You must be signed in to change notification settings - Fork 146
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
feat: ui items #4881
Conversation
c2d9fc9
to
db9c29d
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.
Great work here Fara! 👏 🚀
This is great @fbwoolf! Thank you so much!
|
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.
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.
src/app/ui/components/items/item.tsx
Outdated
bg: 'accent.background-primary', | ||
height: 'auto', | ||
userSelect: 'none', | ||
p: 'space.03', |
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.
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.
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.tsx
Outdated
function onKeyDown(e: KeyboardEvent<HTMLInputElement>) { | ||
if (!isRoleButton) return; | ||
if (e.key === 'enter' || e.key === ' ') { | ||
e.preventDefault(); | ||
onClick(); | ||
} | ||
} |
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.
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.
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.
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.
@mica000 why do you say the storybook items are broken? 🤔 https://65982789c7e2278518f189e7-vbbtozlkvb.chromatic.com/?path=/story/item--default ...they seem fine to me? |
Seems like the padding is off? |
Strange, not what I see ...will double check code bc I'm not used to working with Grids. |
409490c
to
af7a229
Compare
|
10921e2
to
d20245f
Compare
@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 |
d20245f
to
149b760
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.
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'> { |
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 don't spread the additional props, so either remove type, or spread props
src/app/ui/components/item/item.tsx
Outdated
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> | ||
); | ||
} |
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.
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?
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'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.
src/app/ui/components/item/item.tsx
Outdated
|
||
const ItemInteractive = forwardRef<HTMLButtonElement, HTMLStyledProps<'button'> & ItemVariantProps>( | ||
(props, ref) => ( | ||
<styled.button className={`group ${itemRecipe({ interactive: true })}`} ref={ref} {...props} /> |
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.
What's the group class about?
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.
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
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 |
There is a I actually don't think the render prop pattern is suggested anymore by React. The docs say it is deprecated for using custom hooks? |
After working on these, I'm not sure it is nec, is it? The |
Nice, didn't know this.
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).
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. |
a6edc2d
to
290c5cc
Compare
@kyranjamie maybe look this over if get a sec, I was able to refactor to one |
Yeah looks great Fara. Super tidy 💯 |
290c5cc
to
4382352
Compare
This PR builds/shares a reusable
Item
component.Assets
Activity
Accounts
Send
Receive
Swap