Skip to content

Commit b5a9529

Browse files
committed
[shadcn] Add missing PopoverTrigger and PopoverContent to ThemeComponents type
1 parent bcd8f95 commit b5a9529

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

.changeset/red-avocados-suffer.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sjsf/shadcn-theme": minor
3+
---
4+
5+
Add missing `PopoverTrigger` and `PopoverContent` to `ThemeComponents` type.

packages/shadcn-theme/src/lib/default-ui/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Checkbox } from './checkbox';
66
import { Input } from './input';
77
import { FilesInput } from './files-input';
88
import { Label } from './label';
9-
import { Popover } from './popover';
9+
import { Popover, PopoverTrigger, PopoverContent } from './popover';
1010
import { RadioGroup, RadioGroupItem } from './radio-group';
1111
import { Select, SelectContent, SelectItem, SelectTrigger } from './select';
1212
import { Slider } from './slider';
@@ -21,6 +21,8 @@ export const components: ThemeComponents = {
2121
FilesInput,
2222
Label,
2323
Popover,
24+
PopoverTrigger,
25+
PopoverContent,
2426
RadioGroup,
2527
RadioGroupItem,
2628
Select,

packages/shadcn-theme/src/lib/new-york-ui/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Checkbox } from './checkbox';
66
import { Input } from './input';
77
import { FilesInput } from './files-input';
88
import { Label } from './label';
9-
import { Popover } from './popover';
9+
import { Popover, PopoverTrigger, PopoverContent } from './popover';
1010
import { RadioGroup, RadioGroupItem } from './radio-group';
1111
import { Select, SelectContent, SelectItem, SelectTrigger } from './select';
1212
import { Slider } from './slider';
@@ -21,6 +21,8 @@ export const components: ThemeComponents = {
2121
FilesInput,
2222
Label,
2323
Popover,
24+
PopoverTrigger,
25+
PopoverContent,
2426
RadioGroup,
2527
RadioGroupItem,
2628
Select,

packages/shadcn-theme/src/lib/theme/context.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import type {
99
Calendar,
1010
Checkbox,
1111
Label,
12-
Popover,
1312
RadioGroup,
1413
Select,
1514
Slider,
@@ -18,6 +17,7 @@ import type {
1817
WithoutChild,
1918
WithoutChildrenOrChild
2019
} from 'bits-ui';
20+
import { Popover } from 'bits-ui';
2121

2222
type CalendarProps = WithoutChildrenOrChild<Calendar.RootProps>;
2323

@@ -36,6 +36,10 @@ export interface ThemeComponents {
3636
>;
3737
Label: Component<Label.RootProps>;
3838
Popover: Component<Popover.ContentProps>;
39+
// @deprecate (for search reasons)
40+
// TODO: Make this components required in next major
41+
PopoverTrigger?: Component<Popover.TriggerProps>;
42+
PopoverContent?: Component<Popover.ContentProps>;
3943
RadioGroup: Component<RadioGroup.RootProps, {}, 'value' | 'ref'>;
4044
RadioGroupItem: Component<WithoutChildrenOrChild<RadioGroup.ItemProps>>;
4145
Select: Component<Select.RootProps, {}, 'value' | 'open'>;
@@ -53,10 +57,28 @@ export interface ThemeContext {
5357

5458
const THEME_CONTEXT = Symbol('theme-context');
5559

56-
export function getThemeContext(): ThemeContext {
60+
export function getThemeContext(): Required<ThemeContext> {
5761
return getContext(THEME_CONTEXT);
5862
}
5963

6064
export function setThemeContext(ctx: ThemeContext) {
61-
setContext(THEME_CONTEXT, ctx);
65+
// TODO: Remove Proxy in next major
66+
setContext(THEME_CONTEXT, {
67+
get components() {
68+
return new Proxy(ctx.components, {
69+
get(target, prop, receiver) {
70+
switch (prop as keyof ThemeComponents) {
71+
case 'PopoverContent': {
72+
return target.PopoverContent ?? Popover.Content;
73+
}
74+
case 'PopoverTrigger': {
75+
return target.PopoverTrigger ?? Popover.Trigger;
76+
}
77+
default:
78+
return Reflect.get(target, prop, receiver);
79+
}
80+
}
81+
});
82+
}
83+
});
6284
}

0 commit comments

Comments
 (0)