From 887e2283798e94ce1252fcb3f5801d4bce8b048a Mon Sep 17 00:00:00 2001 From: Jesse Pinho Date: Fri, 26 Jul 2024 09:03:17 -0700 Subject: [PATCH] ``: Use Radix UI's Tabs component under the hood, and rename to `` (#1543) * Use Radix UI's Tabs component under the hood * Tweak types * Tweak style utils * Remove unneeded code for now * Rename to Tabs --- .../index.stories.tsx | 11 ++- .../{SegmentedPicker => Tabs}/index.test.tsx | 8 +- .../src/{SegmentedPicker => Tabs}/index.tsx | 84 +++++++++---------- packages/ui/src/utils/button.ts | 7 +- 4 files changed, 56 insertions(+), 54 deletions(-) rename packages/ui/src/{SegmentedPicker => Tabs}/index.stories.tsx (75%) rename packages/ui/src/{SegmentedPicker => Tabs}/index.test.tsx (89%) rename packages/ui/src/{SegmentedPicker => Tabs}/index.tsx (55%) diff --git a/packages/ui/src/SegmentedPicker/index.stories.tsx b/packages/ui/src/Tabs/index.stories.tsx similarity index 75% rename from packages/ui/src/SegmentedPicker/index.stories.tsx rename to packages/ui/src/Tabs/index.stories.tsx index feeadeabe1..055c3d0d4c 100644 --- a/packages/ui/src/SegmentedPicker/index.stories.tsx +++ b/packages/ui/src/Tabs/index.stories.tsx @@ -1,11 +1,10 @@ import type { Meta, StoryObj } from '@storybook/react'; import { useArgs } from '@storybook/preview-api'; -import { SegmentedPicker } from '.'; +import { Tabs } from '.'; -const meta: Meta = { - component: SegmentedPicker, - title: 'SegmentedPicker', +const meta: Meta = { + component: Tabs, tags: ['autodocs', '!dev'], argTypes: { value: { control: false }, @@ -15,7 +14,7 @@ const meta: Meta = { }; export default meta; -type Story = StoryObj; +type Story = StoryObj; export const Basic: Story = { args: { @@ -34,6 +33,6 @@ export const Basic: Story = { const onChange = (value: { toString: () => string }) => updateArgs({ value }); - return ; + return ; }, }; diff --git a/packages/ui/src/SegmentedPicker/index.test.tsx b/packages/ui/src/Tabs/index.test.tsx similarity index 89% rename from packages/ui/src/SegmentedPicker/index.test.tsx rename to packages/ui/src/Tabs/index.test.tsx index d62cd34ddc..dbc82ea583 100644 --- a/packages/ui/src/SegmentedPicker/index.test.tsx +++ b/packages/ui/src/Tabs/index.test.tsx @@ -1,12 +1,12 @@ import { describe, expect, it, vi } from 'vitest'; -import { SegmentedPicker } from '.'; +import { Tabs } from '.'; import { fireEvent, render } from '@testing-library/react'; import { ThemeProvider } from '../ThemeProvider'; -describe('', () => { +describe('', () => { it('renders a button for each of the `options`', () => { const { queryByText } = render( - ', () => { it("calls the `onChange` handler with the clicked option's value when clicked", () => { const onChange = vi.fn(); const { getByText } = render( - string; $getBorderRadius: (theme: DefaultTheme) => string; @@ -68,37 +69,27 @@ const SelectedIndicator = styled(motion.div)` z-index: -1; `; -export interface SegmentedPickerOption { - /** - * The value to pass to the `onChange` handler when clicked. Must be unique - * across all segments, and must be either a string, number, or an object with - * a `.toString()` method so that it can be used as a React key. - */ - value: ValueType; +export interface TabsTab { + value: string; label: string; disabled?: boolean; } -export interface SegmentedPickerProps string }> { - /** - * The currently selected value. Will be compared to the `options`' `value` - * property using `===` to determine which segment is selected. - */ - value: ValueType; - onChange: (value: ValueType) => void; - options: SegmentedPickerOption[]; +export interface TabsProps { + value: string; + onChange: (value: string) => void; + options: TabsTab[]; actionType?: ActionType; } /** - * Renders a segmented picker where only one option can be selected at a time. - * Functionally equivalent to a `