-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add Tabs compound component #284
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6cb097b
feat: add Tabs compound component backed by Base UI
IzumiSy cd85bdf
Update variants and tests
IzumiSy 01780cd
fix: update tabs snapshot to match bg-muted change
IzumiSy 7f6efc1
Add tabs component in primitive demos
IzumiSy d8c521b
Remove orientation prop
IzumiSy dc6b436
Add capsule variant
IzumiSy 7bc3d2d
Add examples: badges and icons
IzumiSy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| --- | ||
| "@tailor-platform/app-shell": minor | ||
| --- | ||
|
|
||
| Add `Tabs` compound component for tab-based navigation, backed by Base UI's Tabs primitive. | ||
|
|
||
| ```tsx | ||
| import { Tabs } from "@tailor-platform/app-shell"; | ||
|
|
||
| <Tabs.Root defaultValue="overview"> | ||
| <Tabs.List> | ||
| <Tabs.Tab value="overview">Overview</Tabs.Tab> | ||
| <Tabs.Tab value="projects">Projects</Tabs.Tab> | ||
| </Tabs.List> | ||
| <Tabs.Panel value="overview">Overview content</Tabs.Panel> | ||
| <Tabs.Panel value="projects">Projects content</Tabs.Panel> | ||
| </Tabs.Root>; | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| --- | ||
| title: Tabs | ||
| description: Tab navigation with a compound component API | ||
| --- | ||
|
|
||
| # Tabs | ||
|
|
||
| The `Tabs` component provides tab-based navigation for toggling between related panels on the same page. It is backed by Base UI's Tabs primitive. | ||
|
|
||
| ## Import | ||
|
|
||
| ```tsx | ||
| import { Tabs } from "@tailor-platform/app-shell"; | ||
| ``` | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ```tsx | ||
| <Tabs.Root defaultValue="overview"> | ||
| <Tabs.List> | ||
| <Tabs.Tab value="overview">Overview</Tabs.Tab> | ||
| <Tabs.Tab value="projects">Projects</Tabs.Tab> | ||
| <Tabs.Tab value="account">Account</Tabs.Tab> | ||
| </Tabs.List> | ||
| <Tabs.Panel value="overview">Overview content</Tabs.Panel> | ||
| <Tabs.Panel value="projects">Projects content</Tabs.Panel> | ||
| <Tabs.Panel value="account">Account content</Tabs.Panel> | ||
| </Tabs.Root> | ||
| ``` | ||
|
|
||
| ## Sub-components | ||
|
|
||
| | Sub-component | Description | | ||
| | ------------- | -------------------------------------------------------------- | | ||
| | `Tabs.Root` | Manages tab selection state | | ||
| | `Tabs.List` | Groups the individual tab buttons | | ||
| | `Tabs.Tab` | An interactive tab button that toggles the corresponding panel | | ||
| | `Tabs.Panel` | A panel displayed when the corresponding tab is active | | ||
|
|
||
| ## Props | ||
|
|
||
| ### Tabs.Root Props | ||
|
|
||
| | Prop | Type | Default | Description | | ||
| | --------------- | ---------------------------------- | ----------- | --------------------------------------- | | ||
| | `defaultValue` | `Tabs.Tab.Value` | `0` | Initial active tab value (uncontrolled) | | ||
| | `value` | `Tabs.Tab.Value` | - | Controlled active tab value | | ||
| | `onValueChange` | `(value: any) => void` | - | Callback when the active tab changes | | ||
| | `variant` | `'default' \| 'line' \| 'capsule'` | `'default'` | Visual style of the tabs | | ||
| | `className` | `string` | - | Additional CSS classes for root | | ||
| | `children` | `React.ReactNode` | - | Tabs sub-components | | ||
|
|
||
| ### Tabs.List Props | ||
|
|
||
| Accepts `className` and all standard HTML `<div>` props. | ||
|
|
||
| ### Tabs.Tab Props | ||
|
|
||
| | Prop | Type | Default | Description | | ||
| | ---------- | ---------------- | ------- | ---------------------------------- | | ||
| | `value` | `Tabs.Tab.Value` | - | **Required.** The value of the tab | | ||
| | `disabled` | `boolean` | - | Whether the tab is disabled | | ||
|
|
||
| Also accepts `className` and all standard HTML `<button>` props. | ||
|
|
||
| ### Tabs.Panel Props | ||
|
|
||
| | Prop | Type | Default | Description | | ||
| | ------------- | ---------------- | ------- | ------------------------------------------------------ | | ||
| | `value` | `Tabs.Tab.Value` | - | **Required.** The value matching the corresponding tab | | ||
| | `keepMounted` | `boolean` | `false` | Whether to keep the panel in the DOM when hidden | | ||
|
|
||
| Also accepts `className` and all standard HTML `<div>` props. | ||
|
|
||
| ## Controlled Usage | ||
|
|
||
| ```tsx | ||
| const [activeTab, setActiveTab] = useState("overview"); | ||
|
|
||
| <Tabs.Root value={activeTab} onValueChange={setActiveTab}> | ||
| <Tabs.List> | ||
| <Tabs.Tab value="overview">Overview</Tabs.Tab> | ||
| <Tabs.Tab value="details">Details</Tabs.Tab> | ||
| </Tabs.List> | ||
| <Tabs.Panel value="overview">Overview content</Tabs.Panel> | ||
| <Tabs.Panel value="details">Details content</Tabs.Panel> | ||
| </Tabs.Root>; | ||
| ``` | ||
|
|
||
| ## Examples | ||
|
|
||
| ### With Disabled Tab | ||
|
|
||
| ```tsx | ||
| <Tabs.Root defaultValue="active"> | ||
| <Tabs.List> | ||
| <Tabs.Tab value="active">Active</Tabs.Tab> | ||
| <Tabs.Tab value="pending">Pending</Tabs.Tab> | ||
| <Tabs.Tab value="archived" disabled> | ||
| Archived | ||
| </Tabs.Tab> | ||
| </Tabs.List> | ||
| <Tabs.Panel value="active">Active items</Tabs.Panel> | ||
| <Tabs.Panel value="pending">Pending items</Tabs.Panel> | ||
| <Tabs.Panel value="archived">Archived items</Tabs.Panel> | ||
| </Tabs.Root> | ||
| ``` | ||
|
|
||
| ### Use Icons in Tab | ||
|
|
||
| ```tsx | ||
| <Tabs.Root defaultValue="overview" variant="capsule"> | ||
| <Tabs.List> | ||
| <Tabs.Tab value="overview"> | ||
| <LayoutDashboardIcon /> | ||
| </Tabs.Tab> | ||
| <Tabs.Tab value="projects"> | ||
| <FolderKanbanIcon /> | ||
| </Tabs.Tab> | ||
| <Tabs.Tab value="settings"> | ||
| <SettingsIcon /> | ||
| </Tabs.Tab> | ||
| </Tabs.List> | ||
| <Tabs.Panel value="overview">Overview content</Tabs.Panel> | ||
| <Tabs.Panel value="projects">Projects content</Tabs.Panel> | ||
| <Tabs.Panel value="settings">Settings content</Tabs.Panel> | ||
| </Tabs.Root> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Super minor, but you can probably just pull the example icons from lucide instead for a more "realistic" example
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.
Ah, right. Let me quickly updated that before merging this PR. It won't need the extra review again.
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.
Found the other examples are using SVG icons too, so will work in a different PR to eradicate those things with lucide-react all at once.