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

Segmented Control #591

Merged
merged 14 commits into from
Oct 17, 2024
Merged

Conversation

marcelines
Copy link
Collaborator

Changes

  • Adds Segmented Control component to components package along with its story.

@marcelines marcelines added the feature New feature or request label Oct 4, 2024
@marcelines marcelines self-assigned this Oct 4, 2024
Copy link

changeset-bot bot commented Oct 4, 2024

🦋 Changeset detected

Latest commit: 34855e1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@status-im/components Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Oct 4, 2024

@marcelines is attempting to deploy a commit to the Status Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Oct 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
status-components ✅ Ready (Inspect) Visit Preview 💬 2 unresolved
✅ 4 resolved
Oct 14, 2024 9:13am

@prichodko
Copy link
Collaborator

This should be implemented using https://www.radix-ui.com/primitives/docs/components/toggle-group#examples, don't you think?

Comment on lines 268 to 269
size,
type,
Copy link
Collaborator

Choose a reason for hiding this comment

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

passing this shouldn't be necessary, with context

ref: (el: HTMLButtonElement | null) => {
segmentRefs.current[index] = el
},
active: child.props.value === props.value,
Copy link
Collaborator

Choose a reason for hiding this comment

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

i am sure radix has a data-attribute for active toggle


const TabsContext = createContext<Pick<RootProps, 'size' | 'type'>>({})

export const Root = (props: RootProps) => {
Copy link
Collaborator

@prichodko prichodko Oct 10, 2024

Choose a reason for hiding this comment

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

please follow structure of other components (see Tabs, DropdownMenu), e.g.

  1. Root at the top
  2. styles close to the used components instead of all at the top

}
>(
(
{ children, emoji, active, size = '32', type = 'grey', ...itemProps },
Copy link
Collaborator

Choose a reason for hiding this comment

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

consume type and size from context, that's why you added it, no?

}
>(
(
{ icon, children, active, size = '32', type = 'grey', ...itemProps },
Copy link
Collaborator

Choose a reason for hiding this comment

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

consume type and size from context, that's why you added it, no?

@prichodko
Copy link
Collaborator

Next time you update the composition (like adding context), think it through. Adding React Context eliminates the need for these cloning gymnastics.

@marcelines
Copy link
Collaborator Author

Next time you update the composition (like adding context), think it through. Adding React Context eliminates the need for these cloning gymnastics.

You're absolutely right. I'm tired and i missed it. But i still need it to be cloned so that i can pass the ref to have the animated selector.

Copy link
Collaborator

@jkbktl jkbktl left a comment

Choose a reason for hiding this comment

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

✅ needs couple of things to fix regarding colors, other than that looks good to me

@@ -42,7 +52,7 @@ export const List = forwardRef<
React.ElementRef<typeof Tabs.List>,
React.ComponentPropsWithoutRef<typeof Tabs.List>
>((props, ref) => {
const { size } = useContext(TabsContext)!
const { size } = useTabsContext()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

🤦

Comment on lines +109 to +113
// Ensuring there is always a value
// @see https://www.radix-ui.com/primitives/docs/components/toggle-group#ensuring-there-is-always-a-value
if (value) {
onValueChange(value)
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@status-im-auto
Copy link
Member

status-im-auto commented Oct 17, 2024

Jenkins Builds

Click to see older builds (1)
Commit #️⃣ Finished (UTC) Duration Platform Result
e4e2372 #1 2024-10-17 11:05:30 ~17 sec chrome 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
c99d7d9 #2 2024-10-17 12:41:28 ~14 sec chrome 📄log
34855e1 #3 2024-10-17 13:04:29 ~14 sec chrome 📄log

@prichodko
Copy link
Collaborator

prichodko commented Oct 17, 2024

I see you've already checked the changes @marcelines 👍.

I made a few cosmetic changes to align with other components in the library. Reordering, renaming from "tab" to "segment"...

I removed the distinction between icon and emoji because we a) currently don't have a defined approach to handling emojis and b) we don't support them in <Tabs /> either. However, I hope that when the time comes, we can reuse the icon prop for emojis (e.g. `icon={ because they seem identical.

Added hook to consume context to this component and <Tabs />.

Copy link
Collaborator

Choose a reason for hiding this comment

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

non-blocking: this story appears to have a lot of copy-pasting instead of doing a better abstraction.

image

There are three identical columns, each contained within a different background. Why not extract the column consisting of 10 components into a single "variant" and render the "variant" three times with different backgrounds?

Copy link
Collaborator

Choose a reason for hiding this comment

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

updated at 34855e1

Copy link
Collaborator

@prichodko prichodko Oct 17, 2024

Choose a reason for hiding this comment

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

image

🥳

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes. Much better. 👍

@prichodko prichodko merged commit 4953fe7 into status-im:main Oct 17, 2024
1 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants