-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Segment Group
- Loading branch information
Showing
10 changed files
with
202 additions
and
59 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
'@tszhong0411/ui': patch | ||
--- | ||
|
||
Add Segment Group component |
This file contains 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,31 @@ | ||
--- | ||
title: Segment Group | ||
description: Organizes and navigates between sections in a view. | ||
link: | ||
doc: https://ark-ui.com/react/docs/components/segment-group | ||
api: https://ark-ui.com/react/docs/components/segment-group#api-reference | ||
--- | ||
|
||
<ComponentPreview name='segment-group/segment-group' /> | ||
|
||
## Usage | ||
|
||
```tsx | ||
import { SegmentGroup, SegmentGroupItem } from '@tszhong0411/ui' | ||
``` | ||
|
||
```tsx | ||
<SegmentGroup> | ||
<SegmentGroupItem value='Next.js'>Next.js</SegmentGroupItem> | ||
</SegmentGroup> | ||
``` | ||
|
||
## Examples | ||
|
||
### Disabled | ||
|
||
<ComponentPreview name='segment-group/disabled' /> | ||
|
||
### Vertical | ||
|
||
<ComponentPreview name='segment-group/vertical' /> |
This file contains 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,26 @@ | ||
import { SegmentGroup, SegmentGroupItem } from '@tszhong0411/ui' | ||
|
||
const frameworks = [ | ||
{ label: 'React', value: 'react' }, | ||
{ label: 'Solid', value: 'solid' }, | ||
{ label: 'Svelte', value: 'svelte', disabled: true }, | ||
{ label: 'Vue', value: 'vue' } | ||
] | ||
|
||
const SegmentGroupDisabledDemo = () => { | ||
return ( | ||
<SegmentGroup defaultValue='react'> | ||
{frameworks.map((framework) => ( | ||
<SegmentGroupItem | ||
key={framework.value} | ||
value={framework.value} | ||
disabled={framework.disabled} | ||
> | ||
{framework.label} | ||
</SegmentGroupItem> | ||
))} | ||
</SegmentGroup> | ||
) | ||
} | ||
|
||
export default SegmentGroupDisabledDemo |
22 changes: 22 additions & 0 deletions
22
apps/docs/src/components/demos/segment-group/segment-group.tsx
This file contains 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,22 @@ | ||
import { SegmentGroup, SegmentGroupItem } from '@tszhong0411/ui' | ||
|
||
const frameworks = [ | ||
{ label: 'React', value: 'react' }, | ||
{ label: 'Solid', value: 'solid' }, | ||
{ label: 'Svelte', value: 'svelte' }, | ||
{ label: 'Vue', value: 'vue' } | ||
] | ||
|
||
const SegmentGroupDemo = () => { | ||
return ( | ||
<SegmentGroup defaultValue='react'> | ||
{frameworks.map((framework) => ( | ||
<SegmentGroupItem key={framework.value} value={framework.value}> | ||
{framework.label} | ||
</SegmentGroupItem> | ||
))} | ||
</SegmentGroup> | ||
) | ||
} | ||
|
||
export default SegmentGroupDemo |
This file contains 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,22 @@ | ||
import { SegmentGroup, SegmentGroupItem } from '@tszhong0411/ui' | ||
|
||
const frameworks = [ | ||
{ label: 'React', value: 'react' }, | ||
{ label: 'Solid', value: 'solid' }, | ||
{ label: 'Svelte', value: 'svelte' }, | ||
{ label: 'Vue', value: 'vue' } | ||
] | ||
|
||
const SegmentGroupVerticalDemo = () => { | ||
return ( | ||
<SegmentGroup orientation='vertical' defaultValue='react'> | ||
{frameworks.map((framework) => ( | ||
<SegmentGroupItem key={framework.value} value={framework.value}> | ||
{framework.label} | ||
</SegmentGroupItem> | ||
))} | ||
</SegmentGroup> | ||
) | ||
} | ||
|
||
export default SegmentGroupVerticalDemo |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,67 @@ | ||
import { SegmentGroup as SegmentGroupPrimitive } from '@ark-ui/react' | ||
import { cn } from '@tszhong0411/utils' | ||
|
||
type SegmentGroupProps = React.ComponentProps<typeof SegmentGroupPrimitive.Root> | ||
|
||
const SegmentGroup = (props: SegmentGroupProps) => { | ||
const { className, children, orientation = 'horizontal', ...rest } = props | ||
|
||
return ( | ||
<SegmentGroupPrimitive.Root | ||
orientation={orientation} | ||
className={cn( | ||
'flex items-start', | ||
orientation === 'horizontal' ? 'gap-4 border-b' : 'flex-col gap-1 border-l', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
<SegmentGroupIndicator /> | ||
{children} | ||
</SegmentGroupPrimitive.Root> | ||
) | ||
} | ||
|
||
type SegmentGroupIndicatorProps = React.ComponentProps<typeof SegmentGroupPrimitive.Indicator> | ||
|
||
const SegmentGroupIndicator = (props: SegmentGroupIndicatorProps) => { | ||
const { className, ...rest } = props | ||
|
||
return ( | ||
<SegmentGroupPrimitive.Indicator | ||
className={cn( | ||
'border-foreground', | ||
'data-[orientation=horizontal]:bottom-0 data-[orientation=horizontal]:w-[var(--width)] data-[orientation=horizontal]:translate-y-px data-[orientation=horizontal]:border-b-2', | ||
'data-[orientation=vertical]:h-[var(--height)] data-[orientation=vertical]:-translate-x-px data-[orientation=vertical]:border-l-2', | ||
className | ||
)} | ||
{...rest} | ||
/> | ||
) | ||
} | ||
|
||
type SegmentGroupItemProps = React.ComponentProps<typeof SegmentGroupPrimitive.Item> | ||
|
||
const SegmentGroupItem = (props: SegmentGroupItemProps) => { | ||
const { className, children, ...rest } = props | ||
|
||
return ( | ||
<SegmentGroupPrimitive.Item | ||
className={cn( | ||
'text-muted-foreground hover:text-accent-foreground cursor-pointer font-medium transition-colors', | ||
'data-[orientation=horizontal]:px-1 data-[orientation=horizontal]:pb-3', | ||
'data-[orientation=vertical]:px-3 data-[orientation=vertical]:py-1.5', | ||
'data-[state=checked]:text-foreground', | ||
'data-[disabled]:text-muted-foreground data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50', | ||
className | ||
)} | ||
{...rest} | ||
> | ||
{children} | ||
<SegmentGroupPrimitive.ItemControl /> | ||
<SegmentGroupPrimitive.ItemHiddenInput /> | ||
</SegmentGroupPrimitive.Item> | ||
) | ||
} | ||
|
||
export { SegmentGroup, SegmentGroupIndicator, SegmentGroupItem } |
Oops, something went wrong.