Skip to content

Commit 425e7c9

Browse files
committed
refactor(ui): update InputGroup and related components to use InputGroupAddon
1 parent d434032 commit 425e7c9

File tree

10 files changed

+64
-75
lines changed

10 files changed

+64
-75
lines changed

apps/storybook/stories/InputGroup.stories.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { Meta, StoryObj } from '@storybook/react-vite';
22
import {
33
InputGroup,
4+
InputGroupAddon,
45
InputGroupButton,
56
InputGroupInput,
6-
InputGroupText,
77
Label,
88
Stack,
99
} from '@trycompai/ui-shadcn';
@@ -25,9 +25,9 @@ export const WithIconLeft: Story = {
2525
render: () => (
2626
<div className="w-[300px]">
2727
<InputGroup>
28-
<InputGroupText>
29-
<Search className="h-4 w-4" />
30-
</InputGroupText>
28+
<InputGroupAddon align="inline-start">
29+
<Search />
30+
</InputGroupAddon>
3131
<InputGroupInput placeholder="Search..." />
3232
</InputGroup>
3333
</div>
@@ -39,9 +39,9 @@ export const WithIconRight: Story = {
3939
<div className="w-[300px]">
4040
<InputGroup>
4141
<InputGroupInput placeholder="Enter email" />
42-
<InputGroupText>
43-
<Mail className="h-4 w-4" />
44-
</InputGroupText>
42+
<InputGroupAddon align="inline-end">
43+
<Mail />
44+
</InputGroupAddon>
4545
</InputGroup>
4646
</div>
4747
),
@@ -51,7 +51,7 @@ export const WithPrefix: Story = {
5151
render: () => (
5252
<div className="w-[300px]">
5353
<InputGroup>
54-
<InputGroupText>https://</InputGroupText>
54+
<InputGroupAddon align="inline-start">https://</InputGroupAddon>
5555
<InputGroupInput placeholder="example.com" />
5656
</InputGroup>
5757
</div>
@@ -63,7 +63,7 @@ export const WithSuffix: Story = {
6363
<div className="w-[300px]">
6464
<InputGroup>
6565
<InputGroupInput placeholder="Username" />
66-
<InputGroupText>@company.com</InputGroupText>
66+
<InputGroupAddon align="inline-end">@company.com</InputGroupAddon>
6767
</InputGroup>
6868
</div>
6969
),
@@ -73,11 +73,11 @@ export const Currency: Story = {
7373
render: () => (
7474
<div className="w-[200px]">
7575
<InputGroup>
76-
<InputGroupText>
77-
<DollarSign className="h-4 w-4" />
78-
</InputGroupText>
76+
<InputGroupAddon align="inline-start">
77+
<DollarSign />
78+
</InputGroupAddon>
7979
<InputGroupInput type="number" placeholder="0.00" />
80-
<InputGroupText>USD</InputGroupText>
80+
<InputGroupAddon align="inline-end">USD</InputGroupAddon>
8181
</InputGroup>
8282
</div>
8383
),
@@ -89,7 +89,7 @@ export const WithButton: Story = {
8989
<InputGroup>
9090
<InputGroupInput defaultValue="https://example.com/share/abc123" readOnly />
9191
<InputGroupButton>
92-
<Copy className="h-4 w-4 mr-2" />
92+
<Copy />
9393
Copy
9494
</InputGroupButton>
9595
</InputGroup>
@@ -104,27 +104,27 @@ export const AllExamples: Story = {
104104
<Stack gap="2">
105105
<Label>Search</Label>
106106
<InputGroup>
107-
<InputGroupText>
108-
<Search className="h-4 w-4" />
109-
</InputGroupText>
107+
<InputGroupAddon align="inline-start">
108+
<Search />
109+
</InputGroupAddon>
110110
<InputGroupInput placeholder="Search..." />
111111
</InputGroup>
112112
</Stack>
113113

114114
<Stack gap="2">
115115
<Label>Website</Label>
116116
<InputGroup>
117-
<InputGroupText>https://</InputGroupText>
117+
<InputGroupAddon align="inline-start">https://</InputGroupAddon>
118118
<InputGroupInput placeholder="example.com" />
119119
</InputGroup>
120120
</Stack>
121121

122122
<Stack gap="2">
123123
<Label>Price</Label>
124124
<InputGroup>
125-
<InputGroupText>$</InputGroupText>
125+
<InputGroupAddon align="inline-start">$</InputGroupAddon>
126126
<InputGroupInput type="number" placeholder="0.00" />
127-
<InputGroupText>USD</InputGroupText>
127+
<InputGroupAddon align="inline-end">USD</InputGroupAddon>
128128
</InputGroup>
129129
</Stack>
130130
</Stack>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"docker:down": "bun run -F @comp/db docker:down",
7777
"docker:up": "bun run -F @comp/db docker:up",
7878
"format": "prettier --write .",
79-
"lint": "turbo lint --filter=@comp/portal --filter=@trycompai/ui-v2",
79+
"lint": "turbo lint --filter=@comp/portal --filter=@comp/storybook --filter=@trycompai/ui-shadcn",
8080
"prepare": "husky",
8181
"test": "turbo test --parallel",
8282
"test:release": "node scripts/test-release.js",

packages/ui-shadcn/src/components/ui/alert.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const variantIcons = {
3434
type AlertVariant = NonNullable<VariantProps<typeof alertVariants>['variant']>;
3535

3636
interface AlertProps
37-
extends Omit<React.ComponentProps<'div'>, 'className' | 'title'>,
37+
extends
38+
Omit<React.ComponentProps<'div'>, 'className' | 'title'>,
3839
VariantProps<typeof alertVariants> {
3940
/** Alert title - renders AlertTitle component */
4041
title?: React.ReactNode;

packages/ui-shadcn/src/components/ui/command.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { Command as CommandPrimitive } from 'cmdk';
44
import * as React from 'react';
55

66
import { Dialog as DialogPrimitive } from '@base-ui/react/dialog';
7-
import { CheckIcon, SearchIcon } from 'lucide-react';
87
import { cva, type VariantProps } from 'class-variance-authority';
8+
import { CheckIcon, SearchIcon } from 'lucide-react';
99

1010
const commandVariants = cva(
1111
'bg-popover text-popover-foreground rounded-xl p-1 flex size-full flex-col overflow-hidden',
@@ -25,17 +25,12 @@ const commandVariants = cva(
2525
);
2626

2727
interface CommandProps
28-
extends Omit<React.ComponentProps<typeof CommandPrimitive>, 'className'>,
28+
extends
29+
Omit<React.ComponentProps<typeof CommandPrimitive>, 'className'>,
2930
VariantProps<typeof commandVariants> {}
3031

3132
function Command({ width, ...props }: CommandProps) {
32-
return (
33-
<CommandPrimitive
34-
data-slot="command"
35-
className={commandVariants({ width })}
36-
{...props}
37-
/>
38-
);
33+
return <CommandPrimitive data-slot="command" className={commandVariants({ width })} {...props} />;
3934
}
4035

4136
function CommandDialog({

packages/ui-shadcn/src/components/ui/grid.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,6 @@ import { cn } from '../../../lib/utils';
55

66
const gridVariants = cva('grid', {
77
variants: {
8-
cols: {
9-
'1': 'grid-cols-1',
10-
'2': 'grid-cols-2',
11-
'3': 'grid-cols-3',
12-
'4': 'grid-cols-4',
13-
'5': 'grid-cols-5',
14-
'6': 'grid-cols-6',
15-
'12': 'grid-cols-12',
16-
},
178
gap: {
189
'0': 'gap-0',
1910
'1': 'gap-1',
@@ -34,12 +25,28 @@ const gridVariants = cva('grid', {
3425
},
3526
},
3627
defaultVariants: {
37-
cols: '1',
3828
gap: '4',
3929
align: 'stretch',
4030
},
4131
});
4232

33+
const gridColsVariants = cva('', {
34+
variants: {
35+
cols: {
36+
'1': 'grid-cols-1',
37+
'2': 'grid-cols-2',
38+
'3': 'grid-cols-3',
39+
'4': 'grid-cols-4',
40+
'5': 'grid-cols-5',
41+
'6': 'grid-cols-6',
42+
'12': 'grid-cols-12',
43+
},
44+
},
45+
defaultVariants: {
46+
cols: '1',
47+
},
48+
});
49+
4350
type ResponsiveCols = {
4451
base?: '1' | '2' | '3' | '4' | '5' | '6' | '12';
4552
sm?: '1' | '2' | '3' | '4' | '5' | '6' | '12';
@@ -98,8 +105,9 @@ const responsiveColsMap: Record<string, Record<string, string>> = {
98105

99106
const getResponsiveClasses = (cols: ResponsiveCols): string => {
100107
const classes: string[] = [];
108+
const withBase: ResponsiveCols = cols.base ? cols : { base: '1', ...cols };
101109

102-
for (const [breakpoint, value] of Object.entries(cols)) {
110+
for (const [breakpoint, value] of Object.entries(withBase)) {
103111
if (value && responsiveColsMap[breakpoint]?.[value]) {
104112
classes.push(responsiveColsMap[breakpoint][value]);
105113
}
@@ -111,20 +119,16 @@ const getResponsiveClasses = (cols: ResponsiveCols): string => {
111119
interface GridProps
112120
extends
113121
Omit<React.ComponentProps<'div'>, 'cols' | 'className'>,
114-
Omit<VariantProps<typeof gridVariants>, 'cols'> {
122+
VariantProps<typeof gridVariants> {
115123
cols?: '1' | '2' | '3' | '4' | '5' | '6' | '12' | ResponsiveCols;
116124
}
117125

118126
function Grid({ cols = '1', gap, align, ...props }: GridProps) {
119127
const colsClasses =
120-
typeof cols === 'object' ? getResponsiveClasses(cols) : gridVariants({ cols });
128+
typeof cols === 'object' ? getResponsiveClasses(cols) : gridColsVariants({ cols });
121129

122130
return (
123-
<div
124-
data-slot="grid"
125-
className={cn('grid', colsClasses, gridVariants({ gap, align, cols: undefined }))}
126-
{...props}
127-
/>
131+
<div data-slot="grid" className={cn(gridVariants({ gap, align }), colsClasses)} {...props} />
128132
);
129133
}
130134

packages/ui-shadcn/src/components/ui/input-group.tsx

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@ import * as React from 'react';
66
import { cn } from '../../../lib/utils';
77
import { buttonVariants } from './button';
88

9-
function InputGroup({ className, ...props }: React.ComponentProps<'div'>) {
9+
function InputGroup({ ...props }: Omit<React.ComponentProps<'div'>, 'className'>) {
1010
return (
1111
<div
1212
data-slot="input-group"
1313
role="group"
14-
className={cn(
15-
'border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 h-9 rounded-md border shadow-xs transition-[color,box-shadow] has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot][aria-invalid=true]]:ring-[3px] has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5 [[data-slot=combobox-content]_&]:focus-within:border-inherit [[data-slot=combobox-content]_&]:focus-within:ring-0 group/input-group relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto',
16-
className,
17-
)}
14+
className="border-input dark:bg-input/30 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 h-9 rounded-md border shadow-xs transition-[color,box-shadow] has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot][aria-invalid=true]]:ring-[3px] has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5 [[data-slot=combobox-content]_&]:focus-within:border-inherit [[data-slot=combobox-content]_&]:focus-within:ring-0 group/input-group relative flex w-full min-w-0 items-center outline-none has-[>textarea]:h-auto"
1815
{...props}
1916
/>
2017
);
@@ -40,16 +37,15 @@ const inputGroupAddonVariants = cva(
4037
);
4138

4239
function InputGroupAddon({
43-
className,
4440
align = 'inline-start',
4541
...props
46-
}: React.ComponentProps<'div'> & VariantProps<typeof inputGroupAddonVariants>) {
42+
}: Omit<React.ComponentProps<'div'>, 'className'> & VariantProps<typeof inputGroupAddonVariants>) {
4743
return (
4844
<div
4945
role="group"
5046
data-slot="input-group-addon"
5147
data-align={align}
52-
className={cn(inputGroupAddonVariants({ align }), className)}
48+
className={inputGroupAddonVariants({ align })}
5349
onClick={(e) => {
5450
if ((e.target as HTMLElement).closest('button')) {
5551
return;
@@ -95,16 +91,11 @@ function InputGroupButton({
9591
);
9692
}
9793

98-
function InputGroupText({ className, ...props }: React.ComponentProps<'span'>) {
99-
return (
100-
<span
101-
className={cn(
102-
"text-muted-foreground gap-2 text-sm [&_svg:not([class*='size-'])]:size-4 flex items-center [&_svg]:pointer-events-none",
103-
className,
104-
)}
105-
{...props}
106-
/>
107-
);
94+
function InputGroupText({
95+
align = 'inline-start',
96+
...props
97+
}: Omit<React.ComponentProps<'div'>, 'className'> & VariantProps<typeof inputGroupAddonVariants>) {
98+
return <InputGroupAddon align={align} {...props} />;
10899
}
109100

110101
function InputGroupInput({ ...props }: Omit<React.ComponentProps<'input'>, 'className'>) {

packages/ui-shadcn/src/components/ui/select.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ function SelectLabel({ ...props }: Omit<SelectPrimitive.GroupLabel.Props, 'class
9393
);
9494
}
9595

96-
function SelectItem({
97-
children,
98-
...props
99-
}: Omit<SelectPrimitive.Item.Props, 'className'>) {
96+
function SelectItem({ children, ...props }: Omit<SelectPrimitive.Item.Props, 'className'>) {
10097
return (
10198
<SelectPrimitive.Item
10299
data-slot="select-item"

packages/ui-shadcn/src/components/ui/table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ function TableCell({ ...props }: Omit<React.ComponentProps<'td'>, 'className'>)
5757
}
5858

5959
function TableCaption({ ...props }: Omit<React.ComponentProps<'caption'>, 'className'>) {
60-
return <caption data-slot="table-caption" className="text-muted-foreground mt-4 text-sm" {...props} />;
60+
return (
61+
<caption data-slot="table-caption" className="text-muted-foreground mt-4 text-sm" {...props} />
62+
);
6163
}
6264

6365
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow };

packages/ui-shadcn/src/components/ui/text.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ const textVariants = cva('', {
4242
});
4343

4444
interface TextProps
45-
extends Omit<React.HTMLAttributes<HTMLElement>, 'className'>,
46-
VariantProps<typeof textVariants> {
45+
extends Omit<React.HTMLAttributes<HTMLElement>, 'className'>, VariantProps<typeof textVariants> {
4746
as?: 'p' | 'span' | 'div';
4847
}
4948

packages/ui-shadcn/src/components/ui/toggle-group.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ function ToggleGroupItem({
8484
}
8585

8686
export { ToggleGroup, ToggleGroupItem };
87-
export type { ToggleGroupProps, ToggleGroupItemProps };
87+
export type { ToggleGroupItemProps, ToggleGroupProps };

0 commit comments

Comments
 (0)