Skip to content

Commit ed65a6b

Browse files
committed
feat: add component label
1 parent 90bb37d commit ed65a6b

File tree

8 files changed

+142
-0
lines changed

8 files changed

+142
-0
lines changed

packages/ui-variants/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export * from './variants/button-group';
1313
export * from './variants/card';
1414
export * from './variants/carousel';
1515
export * from './variants/divider';
16+
export * from './variants/label';
1617
export * from './variants/scroll-area';
1718
export * from './variants/tabs';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { tv } from 'tailwind-variants';
2+
3+
export const labelVariants = tv({
4+
base: 'font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70',
5+
defaultVariants: {
6+
size: 'md'
7+
},
8+
variants: {
9+
size: {
10+
'2xl': 'text-xl',
11+
lg: 'text-base',
12+
md: 'text-sm',
13+
sm: 'text-xs',
14+
xl: 'text-lg',
15+
xs: 'text-2xs'
16+
}
17+
}
18+
});

packages/ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"@radix-ui/react-alert-dialog": "^1.1.14",
1616
"@radix-ui/react-aspect-ratio": "^1.1.7",
1717
"@radix-ui/react-avatar": "^1.1.10",
18+
"@radix-ui/react-checkbox": "^1.3.2",
1819
"@radix-ui/react-compose-refs": "1.1.2",
20+
"@radix-ui/react-label": "^2.1.7",
1921
"@radix-ui/react-scroll-area": "^1.2.9",
2022
"@radix-ui/react-separator": "^1.1.7",
2123
"@radix-ui/react-slot": "1.2.3",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as Label } from './source/Label';
2+
3+
export type { LabelProps } from './types';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Root } from '@radix-ui/react-label';
2+
import { cn, labelVariants } from '@soybean-react-ui/variants';
3+
import { forwardRef } from 'react';
4+
5+
import type { LabelProps } from '../types';
6+
7+
const Label = forwardRef<React.ComponentRef<typeof Root>, LabelProps>((props, ref) => {
8+
const { className, size, ...rest } = props;
9+
10+
const mergedCls = cn(labelVariants({ size }), className);
11+
12+
return (
13+
<Root
14+
className={mergedCls}
15+
ref={ref}
16+
{...rest}
17+
/>
18+
);
19+
});
20+
21+
Label.displayName = Root.displayName;
22+
23+
export default Label;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { LabelProps as _LabelProps } from '@radix-ui/react-label';
2+
3+
import type { BaseNodeProps } from '../../types';
4+
5+
export type LabelProps = BaseNodeProps<_LabelProps>;

packages/ui/src/index.ts

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

2121
export * from './components/divider';
2222

23+
export * from './components/label';
24+
2325
export * from './components/scroll-area';
2426

2527
export * from './components/sonner';

pnpm-lock.yaml

Lines changed: 88 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)