Skip to content

Commit 3d66cb3

Browse files
committed
feat(ui): add Segment component with types and update component index
1 parent 33fcbd8 commit 3d66cb3

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import type { Root } from '@radix-ui/react-tabs';
2+
import { forwardRef } from 'react';
3+
4+
import SegmentList from '../tabs/TabsList';
5+
import SegmentRoot from '../tabs/TabsRoot';
6+
import SegmentTrigger from '../tabs/TabsTrigger';
7+
8+
import type { SegmentOptionData, SegmentProps } from './types';
9+
10+
const Segment = forwardRef<React.ComponentRef<typeof Root>, SegmentProps<SegmentOptionData>>((props, ref) => {
11+
const {
12+
className,
13+
classNames,
14+
dir,
15+
enableIndicator = true,
16+
items,
17+
loop,
18+
orientation = 'horizontal',
19+
size,
20+
value,
21+
...rest
22+
} = props;
23+
24+
return (
25+
<SegmentRoot
26+
className={[className, classNames?.root]}
27+
dir={dir}
28+
ref={ref}
29+
size={size}
30+
value={value}
31+
{...rest}
32+
>
33+
<SegmentList
34+
className={classNames?.list}
35+
dir={dir}
36+
enableIndicator={enableIndicator}
37+
loop={loop}
38+
orientation={orientation}
39+
size={size}
40+
value={value}
41+
classNames={{
42+
indicator: classNames?.indicator,
43+
indicatorRoot: classNames?.indicatorRoot
44+
}}
45+
>
46+
{items.map(item => (
47+
<SegmentTrigger
48+
className={classNames?.trigger}
49+
dir={dir}
50+
disabled={item.disabled}
51+
enableIndicator={enableIndicator}
52+
key={item.value}
53+
size={size}
54+
value={item.value}
55+
>
56+
{item.label}
57+
</SegmentTrigger>
58+
))}
59+
</SegmentList>
60+
</SegmentRoot>
61+
);
62+
});
63+
64+
Segment.displayName = 'Segment';
65+
66+
export default Segment;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as Segment } from './Segment';
2+
3+
export type { SegmentOptionData, SegmentProps } from './types';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { TabsOptionData, TabsProps } from '../tabs/types';
2+
3+
export type SegmentOptionData = Omit<TabsOptionData, 'children'>;
4+
5+
export type SegmentProps<T extends SegmentOptionData> = Omit<TabsProps<TabsOptionData>, 'items'> & {
6+
items: T[];
7+
};

packages/ui/src/components/tabs/TabsRoot.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { cn } from '@/lib/utils';
66
import { tabsVariants } from './tabs-variants';
77
import type { TabsRootProps } from './types';
88

9-
const TabRoot = forwardRef<React.ElementRef<typeof Root>, TabsRootProps>((props, ref) => {
9+
const TabRoot = forwardRef<React.ComponentRef<typeof Root>, TabsRootProps>((props, ref) => {
1010
const { className, fill, orientation, size, ...rest } = props;
1111

1212
const { root } = tabsVariants({ fill, orientation, size });

packages/ui/src/components/tabs/TabsTrigger.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { cn } from '@/lib/utils';
66
import { tabsVariants } from './tabs-variants';
77
import type { TabsTriggerProps } from './types';
88

9-
const TabsTrigger = forwardRef<React.ElementRef<typeof Trigger>, TabsTriggerProps>((props, ref) => {
9+
const TabsTrigger = forwardRef<React.ComponentRef<typeof Trigger>, TabsTriggerProps>((props, ref) => {
1010
const { className, enableIndicator = true, size, ...rest } = props;
1111

1212
const { trigger } = tabsVariants({ enableIndicator, size });

packages/ui/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export * from './components/resizable';
6262

6363
export * from './components/scroll-area';
6464

65+
export * from './components/segment';
66+
6567
export * from './components/select';
6668

6769
export * from './components/sheet';

0 commit comments

Comments
 (0)