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
14 changes: 12 additions & 2 deletions packages/components/src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ type RootProps = React.ComponentProps<typeof Tabs.Root> & {

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

function useTabsContext() {
const context = useContext(TabsContext)

if (!context) {
throw new Error('useTabsContext must be used within a <Tabs.Root />')
}

return context
}

export const Root = (props: RootProps) => {
const { size = '32', variant = 'grey', ...rootProps } = props

Expand All @@ -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.

🤦


return (
<Tabs.List
Expand Down Expand Up @@ -74,7 +84,7 @@ export const Trigger = forwardRef<
>((props, ref) => {
const { children, ...rest } = props

const { size, variant } = useContext(TabsContext)!
const { size, variant } = useTabsContext()

return (
<Tabs.Trigger {...rest} ref={ref} className={tabStyles({ variant, size })}>
Expand Down