@brand-map/primitives 0.0.0-broken.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/README.md +8 -0
- package/.changeset/config.json +11 -0
- package/.oxfmtrc.json +35 -0
- package/.oxlintrc.json +166 -0
- package/README.md +78 -0
- package/bun.lock +904 -0
- package/mise.toml +3 -0
- package/package.json +61 -0
- package/src/accordion/accordion.tsx +189 -0
- package/src/accordion/accordion.web.tsx +282 -0
- package/src/accordion/index.ts +2 -0
- package/src/accordion/types.ts +44 -0
- package/src/alert-dialog/alert-dialog.tsx +238 -0
- package/src/alert-dialog/alert-dialog.web.tsx +260 -0
- package/src/alert-dialog/index.ts +2 -0
- package/src/alert-dialog/types.ts +81 -0
- package/src/aspect-ratio/aspect-ratio.tsx +27 -0
- package/src/aspect-ratio/index.ts +1 -0
- package/src/avatar/avatar.tsx +122 -0
- package/src/avatar/index.ts +2 -0
- package/src/avatar/types.ts +20 -0
- package/src/checkbox/checkbox.tsx +95 -0
- package/src/checkbox/checkbox.web.tsx +111 -0
- package/src/checkbox/index.ts +2 -0
- package/src/checkbox/types.ts +14 -0
- package/src/collapsible/collapsible.tsx +98 -0
- package/src/collapsible/collapsible.web.tsx +149 -0
- package/src/collapsible/index.ts +2 -0
- package/src/collapsible/types.ts +23 -0
- package/src/context-menu/context-menu.tsx +616 -0
- package/src/context-menu/context-menu.web.tsx +560 -0
- package/src/context-menu/index.ts +2 -0
- package/src/context-menu/types.ts +136 -0
- package/src/dialog/dialog.tsx +286 -0
- package/src/dialog/dialog.web.tsx +215 -0
- package/src/dialog/index.ts +2 -0
- package/src/dialog/types.ts +92 -0
- package/src/dropdown-menu/dropdown-menu.tsx +575 -0
- package/src/dropdown-menu/dropdown-menu.web.tsx +565 -0
- package/src/dropdown-menu/index.ts +2 -0
- package/src/dropdown-menu/types.ts +121 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/use-Isomorphic-layout-effect.tsx +12 -0
- package/src/hooks/use-augmented-ref.tsx +25 -0
- package/src/hooks/use-controllable-state.tsx +70 -0
- package/src/hooks/use-relative-position.tsx +175 -0
- package/src/hover-card/hover-card.tsx +255 -0
- package/src/hover-card/hover-card.web.tsx +161 -0
- package/src/hover-card/index.ts +2 -0
- package/src/hover-card/types.ts +56 -0
- package/src/label/index.ts +2 -0
- package/src/label/label.tsx +36 -0
- package/src/label/label.web.tsx +38 -0
- package/src/label/types.ts +24 -0
- package/src/menubar/index.ts +2 -0
- package/src/menubar/menubar.tsx +602 -0
- package/src/menubar/menubar.web.tsx +575 -0
- package/src/menubar/types.ts +126 -0
- package/src/navigation-menu/index.ts +2 -0
- package/src/navigation-menu/navigation-menu.tsx +302 -0
- package/src/navigation-menu/navigation-menu.web.tsx +259 -0
- package/src/navigation-menu/types.ts +85 -0
- package/src/popover/index.ts +2 -0
- package/src/popover/popover.tsx +279 -0
- package/src/popover/popover.web.tsx +217 -0
- package/src/popover/types.ts +44 -0
- package/src/portal/index.ts +1 -0
- package/src/portal/portal.tsx +56 -0
- package/src/progress/index.ts +2 -0
- package/src/progress/progress.tsx +59 -0
- package/src/progress/progress.web.tsx +46 -0
- package/src/progress/types.ts +14 -0
- package/src/radio-group/index.ts +2 -0
- package/src/radio-group/radio-group.tsx +106 -0
- package/src/radio-group/radio-group.web.tsx +85 -0
- package/src/radio-group/types.ts +24 -0
- package/src/select/index.ts +2 -0
- package/src/select/select.tsx +447 -0
- package/src/select/select.web.tsx +368 -0
- package/src/select/types.ts +145 -0
- package/src/separator/index.ts +2 -0
- package/src/separator/separator.tsx +21 -0
- package/src/separator/types.ts +10 -0
- package/src/slider/index.ts +2 -0
- package/src/slider/slider.tsx +77 -0
- package/src/slider/slider.web.tsx +75 -0
- package/src/slider/types.ts +39 -0
- package/src/slot/index.ts +1 -0
- package/src/slot/slot.tsx +224 -0
- package/src/switch/index.ts +2 -0
- package/src/switch/switch.tsx +49 -0
- package/src/switch/switch.web.tsx +60 -0
- package/src/switch/types.ts +19 -0
- package/src/table/index.ts +1 -0
- package/src/table/table.tsx +121 -0
- package/src/tabs/index.ts +2 -0
- package/src/tabs/tabs.tsx +120 -0
- package/src/tabs/tabs.web.tsx +106 -0
- package/src/tabs/types.ts +37 -0
- package/src/toast/index.ts +2 -0
- package/src/toast/toast.tsx +124 -0
- package/src/toast/types.ts +20 -0
- package/src/toggle/index.ts +2 -0
- package/src/toggle/toggle.tsx +35 -0
- package/src/toggle/toggle.web.tsx +36 -0
- package/src/toggle/types.ts +11 -0
- package/src/toggle-group/index.ts +2 -0
- package/src/toggle-group/toggle-group.tsx +100 -0
- package/src/toggle-group/toggle-group.web.tsx +103 -0
- package/src/toggle-group/types.ts +46 -0
- package/src/toolbar/index.ts +2 -0
- package/src/toolbar/toolbar.tsx +141 -0
- package/src/toolbar/toolbar.web.tsx +158 -0
- package/src/toolbar/types.ts +64 -0
- package/src/tooltip/index.ts +2 -0
- package/src/tooltip/tooltip.tsx +261 -0
- package/src/tooltip/tooltip.web.tsx +175 -0
- package/src/tooltip/types.ts +61 -0
- package/src/types/index.ts +141 -0
- package/src/utils/index.ts +69 -0
- package/tsconfig.json +23 -0
package/mise.toml
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brand-map/primitives",
|
|
3
|
+
"version": "0.0.0-broken.0",
|
|
4
|
+
"exports": {
|
|
5
|
+
"./accordion": "./src/accordion/index.ts",
|
|
6
|
+
"./alert-dialog": "./src/alert-dialog/index.ts",
|
|
7
|
+
"./aspect-ratio": "./src/aspect-ratio/index.ts",
|
|
8
|
+
"./avatar": "./src/avatar/index.ts",
|
|
9
|
+
"./checkbox": "./src/checkbox/index.ts",
|
|
10
|
+
"./collapsible": "./src/collapsible/index.ts",
|
|
11
|
+
"./context-menu": "./src/context-menu/index.ts",
|
|
12
|
+
"./dialog": "./src/dialog/index.ts",
|
|
13
|
+
"./dropdown-menu": "./src/dropdown-menu/index.ts",
|
|
14
|
+
"./hooks": "./src/hooks/index.ts",
|
|
15
|
+
"./hover-card": "./src/hover-card/index.ts",
|
|
16
|
+
"./label": "./src/label/index.ts",
|
|
17
|
+
"./menubar": "./src/menubar/index.ts",
|
|
18
|
+
"./navigation-menu": "./src/navigation-menu/index.ts",
|
|
19
|
+
"./popover": "./src/popover/index.ts",
|
|
20
|
+
"./portal": "./src/portal/index.ts",
|
|
21
|
+
"./progress": "./src/progress/index.ts",
|
|
22
|
+
"./radio-group": "./src/radio-group/index.ts",
|
|
23
|
+
"./select": "./src/select/index.ts",
|
|
24
|
+
"./separator": "./src/separator/index.ts",
|
|
25
|
+
"./slider": "./src/slider/index.ts",
|
|
26
|
+
"./slot": "./src/slot/index.ts",
|
|
27
|
+
"./switch": "./src/switch/index.ts",
|
|
28
|
+
"./table": "./src/table/index.ts",
|
|
29
|
+
"./tabs": "./src/tabs/index.ts",
|
|
30
|
+
"./toast": "./src/toast/index.ts",
|
|
31
|
+
"./toggle": "./src/toggle/index.ts",
|
|
32
|
+
"./toggle-group": "./src/toggle-group/index.ts",
|
|
33
|
+
"./toolbar": "./src/toolbar/index.ts",
|
|
34
|
+
"./tooltip": "./src/tooltip/index.ts",
|
|
35
|
+
"./types": "./src/types/index.ts",
|
|
36
|
+
"./utils": "./src/utils/index.ts"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"version-bump": "npx changeset && npx changeset version"
|
|
43
|
+
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"react": "^19.2.4",
|
|
46
|
+
"react-native": "^0.83.1",
|
|
47
|
+
"zustand": "^5.0.10"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@changesets/cli": "^2.29.8",
|
|
51
|
+
"@tsconfig/react-native": "^3.0.9",
|
|
52
|
+
"@types/jest": "^30.0.0",
|
|
53
|
+
"@types/react": "^19.2.10",
|
|
54
|
+
"oxfmt": "^0.27.0",
|
|
55
|
+
"oxlint": "^1.42.0",
|
|
56
|
+
"typescript": "^5.9.3"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">=20.11.0"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { type GestureResponderEvent } from "react-native";
|
|
3
|
+
|
|
4
|
+
import { useControllableState } from "../hooks";
|
|
5
|
+
import * as Slot from "../slot";
|
|
6
|
+
|
|
7
|
+
import type { ContentProps, ContentRef, HeaderProps, HeaderRef, ItemProps, ItemRef, RootContext, RootProps, RootRef, TriggerProps, TriggerRef } from "./types";
|
|
8
|
+
|
|
9
|
+
const AccordionContext = React.createContext<RootContext | null>(null);
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @xample
|
|
13
|
+
* ```tsx
|
|
14
|
+
* <Root
|
|
15
|
+
* multiple
|
|
16
|
+
* onValueChange={(val) => {}}
|
|
17
|
+
* value={["some"]}
|
|
18
|
+
* render={(props, state) => <>{state.multiple ? <>multiple</> : <>single</>}</>}
|
|
19
|
+
* >
|
|
20
|
+
* ...
|
|
21
|
+
* </Root>
|
|
22
|
+
*/
|
|
23
|
+
const Root = React.forwardRef<RootRef, RootProps>(
|
|
24
|
+
({ render, multiple = false, disabled = false, collapsible = true, value: valueProp, onValueChange: onValueChangeProps, defaultValue, ...props }, ref) => {
|
|
25
|
+
const [value = [], onValueChange] = useControllableState({
|
|
26
|
+
prop: valueProp,
|
|
27
|
+
defaultProp: defaultValue ?? [],
|
|
28
|
+
onChange: onValueChangeProps,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<AccordionContext.Provider
|
|
33
|
+
value={{
|
|
34
|
+
multiple,
|
|
35
|
+
disabled,
|
|
36
|
+
collapsible,
|
|
37
|
+
value,
|
|
38
|
+
onValueChange,
|
|
39
|
+
}}
|
|
40
|
+
>
|
|
41
|
+
{typeof render === "function" ? (
|
|
42
|
+
<>{render(props, { disabled: disabled, multiple, value })}</>
|
|
43
|
+
) : (
|
|
44
|
+
<Slot.View
|
|
45
|
+
ref={ref}
|
|
46
|
+
render={render}
|
|
47
|
+
{...props}
|
|
48
|
+
/>
|
|
49
|
+
)}
|
|
50
|
+
</AccordionContext.Provider>
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
);
|
|
54
|
+
Root.displayName = "RootNativeAccordion";
|
|
55
|
+
|
|
56
|
+
function useRootContext() {
|
|
57
|
+
const context = React.useContext(AccordionContext);
|
|
58
|
+
if (!context) {
|
|
59
|
+
throw new Error("Accordion compound components cannot be rendered outside the Accordion component");
|
|
60
|
+
}
|
|
61
|
+
return context;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const AccordionItemContext = React.createContext<(ItemProps & { nativeID: string; open: boolean }) | null>(null);
|
|
65
|
+
|
|
66
|
+
const Item = React.forwardRef<ItemRef, ItemProps>(({ render, value, disabled, ...props }, ref) => {
|
|
67
|
+
const { value: rootValue } = useRootContext();
|
|
68
|
+
const nativeID = React.useId();
|
|
69
|
+
const open = isItemExpanded(rootValue, value);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<AccordionItemContext.Provider value={{ value, disabled, nativeID, open }}>
|
|
73
|
+
{typeof render === "function" ? (
|
|
74
|
+
<>{render(props, { open })}</>
|
|
75
|
+
) : (
|
|
76
|
+
<Slot.View
|
|
77
|
+
ref={ref}
|
|
78
|
+
{...props}
|
|
79
|
+
/>
|
|
80
|
+
)}
|
|
81
|
+
</AccordionItemContext.Provider>
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
Item.displayName = "ItemNativeAccordion";
|
|
85
|
+
|
|
86
|
+
function useItemContext() {
|
|
87
|
+
const context = React.useContext(AccordionItemContext);
|
|
88
|
+
if (!context) {
|
|
89
|
+
throw new Error("AccordionItem compound components cannot be rendered outside the AccordionItem component");
|
|
90
|
+
}
|
|
91
|
+
return context;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const Header = React.forwardRef<HeaderRef, HeaderProps>(({ ...props }, ref) => {
|
|
95
|
+
const { disabled: rootDisabled } = useRootContext();
|
|
96
|
+
const { disabled: itemDisabled, open } = useItemContext();
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Slot.View
|
|
100
|
+
ref={ref}
|
|
101
|
+
role="heading"
|
|
102
|
+
aria-expanded={open}
|
|
103
|
+
aria-disabled={rootDisabled ?? itemDisabled}
|
|
104
|
+
{...props}
|
|
105
|
+
/>
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
Header.displayName = "HeaderNativeAccordion";
|
|
109
|
+
|
|
110
|
+
const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ render, onPress: onPressProp, disabled: disabledProp, ...props }, ref) => {
|
|
111
|
+
const { disabled: rootDisabled, multiple, onValueChange, value: rootValue, collapsible } = useRootContext();
|
|
112
|
+
const { nativeID, disabled: itemDisabled, value, open } = useItemContext();
|
|
113
|
+
|
|
114
|
+
function onPress(event: GestureResponderEvent) {
|
|
115
|
+
if (rootDisabled || itemDisabled) return;
|
|
116
|
+
|
|
117
|
+
if (!multiple) {
|
|
118
|
+
const newValue = collapsible ? (rootValue.includes(value) ? ([] as string[]) : [value]) : [value];
|
|
119
|
+
onValueChange?.(newValue);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (multiple) {
|
|
123
|
+
const rootToArray = toStringArray(rootValue);
|
|
124
|
+
const newValue = collapsible
|
|
125
|
+
? rootToArray.includes(value)
|
|
126
|
+
? rootToArray.filter((val) => val !== value)
|
|
127
|
+
: rootToArray.concat(value)
|
|
128
|
+
: Array.from(new Set(rootToArray.concat(value)));
|
|
129
|
+
onValueChange(newValue);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
onPressProp?.(event);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const isDisabled = disabledProp || rootDisabled || itemDisabled;
|
|
136
|
+
|
|
137
|
+
if (typeof render === "function") {
|
|
138
|
+
return render(props, { open: isItemExpanded(rootValue, value) });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<Slot.Pressable
|
|
143
|
+
ref={ref}
|
|
144
|
+
nativeID={nativeID}
|
|
145
|
+
aria-disabled={isDisabled}
|
|
146
|
+
role="button"
|
|
147
|
+
onPress={onPress}
|
|
148
|
+
accessibilityState={{
|
|
149
|
+
expanded: open,
|
|
150
|
+
disabled: isDisabled,
|
|
151
|
+
}}
|
|
152
|
+
disabled={isDisabled}
|
|
153
|
+
{...props}
|
|
154
|
+
/>
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
Trigger.displayName = "TriggerNativeAccordion";
|
|
158
|
+
|
|
159
|
+
const Content = React.forwardRef<ContentRef, ContentProps>(({ keepMounted, ...props }, ref) => {
|
|
160
|
+
const { multiple } = useRootContext();
|
|
161
|
+
const { nativeID, open } = useItemContext();
|
|
162
|
+
|
|
163
|
+
if (!keepMounted) {
|
|
164
|
+
if (!open) {
|
|
165
|
+
return null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Slot.View
|
|
171
|
+
ref={ref}
|
|
172
|
+
aria-hidden={!(keepMounted || open)}
|
|
173
|
+
aria-labelledby={nativeID}
|
|
174
|
+
role={!multiple ? "region" : "summary"}
|
|
175
|
+
{...props}
|
|
176
|
+
/>
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
Content.displayName = "ContentNativeAccordion";
|
|
180
|
+
|
|
181
|
+
export { Content, Header, Item, Root, Trigger, useItemContext, useRootContext };
|
|
182
|
+
|
|
183
|
+
function toStringArray(value?: string | string[]) {
|
|
184
|
+
return Array.isArray(value) ? value : value ? [value] : [];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function isItemExpanded(rootValue: string | string[] | undefined, value: string) {
|
|
188
|
+
return Array.isArray(rootValue) ? rootValue.includes(value) : rootValue === value;
|
|
189
|
+
}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
// import { useAugmentedRef, useControllableState, useIsomorphicLayoutEffect } from "../hooks";
|
|
2
|
+
// import * as Slot from "../slot";
|
|
3
|
+
// import * as Accordion from "@radix-ui/react-accordion";
|
|
4
|
+
// import * as React from "react";
|
|
5
|
+
// import { Pressable, View } from "react-native";
|
|
6
|
+
|
|
7
|
+
// import type { ContentProps, ContentRef, HeaderProps, HeaderRef, ItemProps, ItemRef, RootProps, RootRef, TriggerProps, TriggerRef } from "./types";
|
|
8
|
+
|
|
9
|
+
// const AccordionContext = React.createContext<RootProps | null>(null);
|
|
10
|
+
|
|
11
|
+
// const Root = React.forwardRef<RootRef, RootProps>(
|
|
12
|
+
// (
|
|
13
|
+
// { render, value: valueProp, onValueChange: onValueChangeProps, defaultValue, type, disabled, dir, orientation = "vertical", collapsible, ...props },
|
|
14
|
+
// ref,
|
|
15
|
+
// ) => {
|
|
16
|
+
// const [value = type === "multiple" ? [] : undefined, onValueChange] = useControllableState<(string | undefined) | string[]>({
|
|
17
|
+
// prop: valueProp,
|
|
18
|
+
// defaultProp: defaultValue,
|
|
19
|
+
// onChange: onValueChangeProps as (state: string | string[] | undefined) => void,
|
|
20
|
+
// });
|
|
21
|
+
|
|
22
|
+
//
|
|
23
|
+
// return (
|
|
24
|
+
// <AccordionContext.Provider
|
|
25
|
+
// value={
|
|
26
|
+
// {
|
|
27
|
+
// value,
|
|
28
|
+
// onValueChange,
|
|
29
|
+
// type,
|
|
30
|
+
// disabled,
|
|
31
|
+
// dir,
|
|
32
|
+
// orientation,
|
|
33
|
+
// } as RootProps
|
|
34
|
+
// }
|
|
35
|
+
// >
|
|
36
|
+
// <Accordion.Root
|
|
37
|
+
// render
|
|
38
|
+
// value={value as any}
|
|
39
|
+
// onValueChange={onValueChange as any}
|
|
40
|
+
// type={type as any}
|
|
41
|
+
// disabled={disabled}
|
|
42
|
+
// dir={dir}
|
|
43
|
+
// orientation={orientation}
|
|
44
|
+
// collapsible={collapsible}
|
|
45
|
+
// >
|
|
46
|
+
// <Component
|
|
47
|
+
// ref={ref}
|
|
48
|
+
// {...props}
|
|
49
|
+
// />
|
|
50
|
+
// </Accordion.Root>
|
|
51
|
+
// </AccordionContext.Provider>
|
|
52
|
+
// );
|
|
53
|
+
// },
|
|
54
|
+
// );
|
|
55
|
+
|
|
56
|
+
// Root.displayName = "RootWebAccordion";
|
|
57
|
+
|
|
58
|
+
// function useRootContext() {
|
|
59
|
+
// const context = React.useContext(AccordionContext);
|
|
60
|
+
// if (!context) {
|
|
61
|
+
// throw new Error("Accordion compound components cannot be rendered outside the Accordion component");
|
|
62
|
+
// }
|
|
63
|
+
// return context;
|
|
64
|
+
// }
|
|
65
|
+
|
|
66
|
+
// const AccordionItemContext = React.createContext<(ItemProps & { isExpanded: boolean }) | null>(null);
|
|
67
|
+
|
|
68
|
+
// const Item = React.forwardRef<ItemRef, ItemProps>(({ value: itemValue, disabled, ...props }, ref) => {
|
|
69
|
+
// const augmentedRef = useAugmentedRef({ ref });
|
|
70
|
+
// const { value, orientation, disabled: disabledRoot } = useRootContext();
|
|
71
|
+
|
|
72
|
+
// useIsomorphicLayoutEffect(() => {
|
|
73
|
+
// if (augmentedRef.current) {
|
|
74
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
75
|
+
// const isExpanded = Array.isArray(value) ? value.includes(itemValue) : value === itemValue;
|
|
76
|
+
// augRef.dataset.state = isExpanded ? "open" : "closed";
|
|
77
|
+
// }
|
|
78
|
+
// }, [value, itemValue]);
|
|
79
|
+
|
|
80
|
+
// useIsomorphicLayoutEffect(() => {
|
|
81
|
+
// if (augmentedRef.current) {
|
|
82
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
83
|
+
// augRef.dataset.orientation = orientation;
|
|
84
|
+
// if (disabled || disabledRoot) {
|
|
85
|
+
// augRef.dataset.disabled = "true";
|
|
86
|
+
// } else {
|
|
87
|
+
// augRef.dataset.disabled = undefined;
|
|
88
|
+
// }
|
|
89
|
+
// }
|
|
90
|
+
// }, [orientation, disabled, disabledRoot]);
|
|
91
|
+
|
|
92
|
+
//
|
|
93
|
+
// return (
|
|
94
|
+
// <AccordionItemContext.Provider
|
|
95
|
+
// value={{
|
|
96
|
+
// value: itemValue,
|
|
97
|
+
// disabled,
|
|
98
|
+
// isExpanded: isItemExpanded(value, itemValue),
|
|
99
|
+
// }}
|
|
100
|
+
// >
|
|
101
|
+
// <Accordion.Item
|
|
102
|
+
// value={itemValue}
|
|
103
|
+
// disabled={disabled}
|
|
104
|
+
// render
|
|
105
|
+
// >
|
|
106
|
+
// <Component
|
|
107
|
+
// ref={augmentedRef}
|
|
108
|
+
// {...props}
|
|
109
|
+
// />
|
|
110
|
+
// </Accordion.Item>
|
|
111
|
+
// </AccordionItemContext.Provider>
|
|
112
|
+
// );
|
|
113
|
+
// });
|
|
114
|
+
|
|
115
|
+
// Item.displayName = "ItemWebAccordion";
|
|
116
|
+
|
|
117
|
+
// function useItemContext() {
|
|
118
|
+
// const context = React.useContext(AccordionItemContext);
|
|
119
|
+
// if (!context) {
|
|
120
|
+
// throw new Error("AccordionItem compound components cannot be rendered outside the AccordionItem component");
|
|
121
|
+
// }
|
|
122
|
+
// return context;
|
|
123
|
+
// }
|
|
124
|
+
|
|
125
|
+
// const Header = React.forwardRef<HeaderRef, HeaderProps>(({ ...props }, ref) => {
|
|
126
|
+
// const augmentedRef = useAugmentedRef({ ref });
|
|
127
|
+
// const { disabled, isExpanded } = useItemContext();
|
|
128
|
+
// const { orientation, disabled: disabledRoot } = useRootContext();
|
|
129
|
+
|
|
130
|
+
// useIsomorphicLayoutEffect(() => {
|
|
131
|
+
// if (augmentedRef.current) {
|
|
132
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
133
|
+
// augRef.dataset.state = isExpanded ? "open" : "closed";
|
|
134
|
+
// }
|
|
135
|
+
// }, [isExpanded]);
|
|
136
|
+
|
|
137
|
+
// useIsomorphicLayoutEffect(() => {
|
|
138
|
+
// if (augmentedRef.current) {
|
|
139
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
140
|
+
// augRef.dataset.orientation = orientation;
|
|
141
|
+
// if (disabled || disabledRoot) {
|
|
142
|
+
// augRef.dataset.disabled = "true";
|
|
143
|
+
// } else {
|
|
144
|
+
// augRef.dataset.disabled = undefined;
|
|
145
|
+
// }
|
|
146
|
+
// }
|
|
147
|
+
// }, [orientation, disabled, disabledRoot]);
|
|
148
|
+
|
|
149
|
+
//
|
|
150
|
+
// return (
|
|
151
|
+
// <Accordion.Header render>
|
|
152
|
+
// <Component
|
|
153
|
+
// ref={augmentedRef}
|
|
154
|
+
// {...props}
|
|
155
|
+
// />
|
|
156
|
+
// </Accordion.Header>
|
|
157
|
+
// );
|
|
158
|
+
// });
|
|
159
|
+
|
|
160
|
+
// Header.displayName = "HeaderWebAccordion";
|
|
161
|
+
|
|
162
|
+
// const HIDDEN_STYLE: React.CSSProperties = {
|
|
163
|
+
// position: "absolute",
|
|
164
|
+
// top: 0,
|
|
165
|
+
// left: 0,
|
|
166
|
+
// zIndex: -999999,
|
|
167
|
+
// opacity: 0,
|
|
168
|
+
// };
|
|
169
|
+
|
|
170
|
+
// const Trigger = React.forwardRef<TriggerRef, TriggerProps>(({ disabled: disabledProp, ...props }, ref) => {
|
|
171
|
+
// const { disabled: disabledRoot } = useRootContext();
|
|
172
|
+
// const { disabled, isExpanded } = useItemContext();
|
|
173
|
+
// const triggerRef = React.useRef<HTMLButtonElement>(null);
|
|
174
|
+
// const augmentedRef = useAugmentedRef({ ref });
|
|
175
|
+
|
|
176
|
+
// useIsomorphicLayoutEffect(() => {
|
|
177
|
+
// if (augmentedRef.current) {
|
|
178
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
179
|
+
|
|
180
|
+
// augRef.dataset.state = isExpanded ? "expanded" : "closed";
|
|
181
|
+
// }
|
|
182
|
+
// }, [isExpanded]);
|
|
183
|
+
|
|
184
|
+
// useIsomorphicLayoutEffect(() => {
|
|
185
|
+
// if (augmentedRef.current) {
|
|
186
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
187
|
+
|
|
188
|
+
// if (disabled || disabledRoot || disabledProp) {
|
|
189
|
+
// augRef.dataset.disabled = "true";
|
|
190
|
+
// } else {
|
|
191
|
+
// augRef.dataset.disabled = undefined;
|
|
192
|
+
// }
|
|
193
|
+
// }
|
|
194
|
+
// }, [disabled, disabledRoot, disabledProp]);
|
|
195
|
+
|
|
196
|
+
// useIsomorphicLayoutEffect(() => {
|
|
197
|
+
// if (triggerRef.current) {
|
|
198
|
+
// triggerRef.current.disabled = true;
|
|
199
|
+
// }
|
|
200
|
+
// }, []);
|
|
201
|
+
|
|
202
|
+
// const isDisabled = disabledProp ?? disabledRoot ?? disabled;
|
|
203
|
+
//
|
|
204
|
+
// return (
|
|
205
|
+
// <>
|
|
206
|
+
// <Accordion.Trigger
|
|
207
|
+
// ref={triggerRef}
|
|
208
|
+
// aria-hidden
|
|
209
|
+
// tabIndex={-1}
|
|
210
|
+
// style={HIDDEN_STYLE}
|
|
211
|
+
// />
|
|
212
|
+
// <Accordion.Trigger
|
|
213
|
+
// disabled={isDisabled}
|
|
214
|
+
// render
|
|
215
|
+
// >
|
|
216
|
+
// <Component
|
|
217
|
+
// ref={augmentedRef}
|
|
218
|
+
// role="button"
|
|
219
|
+
// disabled={isDisabled}
|
|
220
|
+
// {...props}
|
|
221
|
+
// onPress={(ev) => {
|
|
222
|
+
// if (triggerRef.current && !isDisabled) {
|
|
223
|
+
// triggerRef.current.disabled = false;
|
|
224
|
+
// triggerRef.current.click();
|
|
225
|
+
// triggerRef.current.disabled = true;
|
|
226
|
+
// }
|
|
227
|
+
// props.onPress?.(ev);
|
|
228
|
+
// }}
|
|
229
|
+
// />
|
|
230
|
+
// </Accordion.Trigger>
|
|
231
|
+
// </>
|
|
232
|
+
// );
|
|
233
|
+
// });
|
|
234
|
+
|
|
235
|
+
// Trigger.displayName = "TriggerWebAccordion";
|
|
236
|
+
|
|
237
|
+
// const Content = React.forwardRef<ContentRef, ContentProps>(({ keepMounted, ...props }, ref) => {
|
|
238
|
+
// const augmentedRef = useAugmentedRef({ ref });
|
|
239
|
+
|
|
240
|
+
// const { orientation, disabled: disabledRoot } = useRootContext();
|
|
241
|
+
// const { disabled, isExpanded } = useItemContext();
|
|
242
|
+
// useIsomorphicLayoutEffect(() => {
|
|
243
|
+
// if (augmentedRef.current) {
|
|
244
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
245
|
+
// augRef.dataset.state = isExpanded ? "expanded" : "closed";
|
|
246
|
+
// }
|
|
247
|
+
// }, [isExpanded]);
|
|
248
|
+
|
|
249
|
+
// useIsomorphicLayoutEffect(() => {
|
|
250
|
+
// if (augmentedRef.current) {
|
|
251
|
+
// const augRef = augmentedRef.current as unknown as HTMLDivElement;
|
|
252
|
+
// augRef.dataset.orientation = orientation;
|
|
253
|
+
|
|
254
|
+
// if (disabled || disabledRoot) {
|
|
255
|
+
// augRef.dataset.disabled = "true";
|
|
256
|
+
// } else {
|
|
257
|
+
// augRef.dataset.disabled = undefined;
|
|
258
|
+
// }
|
|
259
|
+
// }
|
|
260
|
+
// }, [orientation, disabled, disabledRoot]);
|
|
261
|
+
|
|
262
|
+
//
|
|
263
|
+
// return (
|
|
264
|
+
// <Accordion.Content
|
|
265
|
+
// keepMounted={keepMounted}
|
|
266
|
+
// render
|
|
267
|
+
// >
|
|
268
|
+
// <Component
|
|
269
|
+
// ref={augmentedRef}
|
|
270
|
+
// {...props}
|
|
271
|
+
// />
|
|
272
|
+
// </Accordion.Content>
|
|
273
|
+
// );
|
|
274
|
+
// });
|
|
275
|
+
|
|
276
|
+
// Content.displayName = "ContentWebAccordion";
|
|
277
|
+
|
|
278
|
+
// export { Content, Header, Item, Root, Trigger, useItemContext, useRootContext };
|
|
279
|
+
|
|
280
|
+
// function isItemExpanded(rootValue: string | string[] | undefined, value: string) {
|
|
281
|
+
// return Array.isArray(rootValue) ? rootValue.includes(value) : rootValue === value;
|
|
282
|
+
// }
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { KeepMountable, PressableRef, RenderPressableProps, RenderViewProps, ViewRef } from "../types";
|
|
2
|
+
|
|
3
|
+
type Root = {
|
|
4
|
+
value?: string[];
|
|
5
|
+
onValueChange?: (value: string[]) => void;
|
|
6
|
+
|
|
7
|
+
multiple?: boolean | undefined;
|
|
8
|
+
defaultValue?: string[];
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
type RootContext = Omit<Root, "value"> & {
|
|
12
|
+
value: string[];
|
|
13
|
+
onValueChange: (value: string[]) => void;
|
|
14
|
+
|
|
15
|
+
collapsible: boolean;
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type RootRef = ViewRef;
|
|
20
|
+
type ItemRef = ViewRef;
|
|
21
|
+
type ContentRef = ViewRef;
|
|
22
|
+
type HeaderRef = ViewRef;
|
|
23
|
+
type TriggerRef = PressableRef;
|
|
24
|
+
|
|
25
|
+
type RootProps = (Root & RenderViewProps<Required<Pick<Root, "multiple" | "value"> & Pick<RootContext, "disabled">>>) & {
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
collapsible?: boolean;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @platform: WEB ONLY
|
|
31
|
+
*/
|
|
32
|
+
dir?: "ltr" | "rtl";
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @platform: WEB ONLY
|
|
36
|
+
*/
|
|
37
|
+
orientation?: "vertical" | "horizontal";
|
|
38
|
+
};
|
|
39
|
+
type ItemProps = RenderViewProps<{ open: boolean }> & { value: string; disabled?: boolean };
|
|
40
|
+
type ContentProps = KeepMountable & RenderViewProps;
|
|
41
|
+
type HeaderProps = RenderViewProps;
|
|
42
|
+
type TriggerProps = RenderPressableProps<{ open: boolean }>;
|
|
43
|
+
|
|
44
|
+
export type { ContentProps, ContentRef, HeaderProps, HeaderRef, ItemProps, ItemRef, RootContext, RootProps, RootRef, TriggerProps, TriggerRef };
|