@cdx-ui/primitives 0.0.1-alpha.2 → 0.0.1-alpha.21
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/lib/commonjs/avatar/context.js +11 -0
- package/lib/commonjs/avatar/context.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarBadge.js +20 -0
- package/lib/commonjs/avatar/createAvatarBadge.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarIcon.js +30 -0
- package/lib/commonjs/avatar/createAvatarIcon.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarImage.js +51 -0
- package/lib/commonjs/avatar/createAvatarImage.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarRoot.js +34 -0
- package/lib/commonjs/avatar/createAvatarRoot.js.map +1 -0
- package/lib/commonjs/avatar/createAvatarText.js +42 -0
- package/lib/commonjs/avatar/createAvatarText.js.map +1 -0
- package/lib/commonjs/avatar/index.js +30 -0
- package/lib/commonjs/avatar/index.js.map +1 -0
- package/lib/commonjs/avatar/types.js +6 -0
- package/lib/commonjs/avatar/types.js.map +1 -0
- package/lib/commonjs/button/createButtonRoot.js +3 -3
- package/lib/commonjs/button/createButtonRoot.js.map +1 -1
- package/lib/commonjs/button/index.js +18 -19
- package/lib/commonjs/button/index.js.map +1 -1
- package/lib/commonjs/checkbox/context.js +14 -0
- package/lib/commonjs/checkbox/context.js.map +1 -0
- package/lib/commonjs/checkbox/createCheckboxGroup.js +44 -0
- package/lib/commonjs/checkbox/createCheckboxGroup.js.map +1 -0
- package/lib/commonjs/checkbox/createCheckboxIcon.js +29 -0
- package/lib/commonjs/checkbox/createCheckboxIcon.js.map +1 -0
- package/lib/commonjs/checkbox/createCheckboxIndicator.js +47 -0
- package/lib/commonjs/checkbox/createCheckboxIndicator.js.map +1 -0
- package/lib/commonjs/checkbox/createCheckboxLabel.js +46 -0
- package/lib/commonjs/checkbox/createCheckboxLabel.js.map +1 -0
- package/lib/commonjs/checkbox/createCheckboxRoot.js +99 -0
- package/lib/commonjs/checkbox/createCheckboxRoot.js.map +1 -0
- package/lib/commonjs/checkbox/createCheckboxRoot.web.js +90 -0
- package/lib/commonjs/checkbox/createCheckboxRoot.web.js.map +1 -0
- package/lib/commonjs/checkbox/index.js +30 -0
- package/lib/commonjs/checkbox/index.js.map +1 -0
- package/lib/commonjs/checkbox/types.js +6 -0
- package/lib/commonjs/checkbox/types.js.map +1 -0
- package/lib/commonjs/checkbox/useCheckboxRoot.js +82 -0
- package/lib/commonjs/checkbox/useCheckboxRoot.js.map +1 -0
- package/lib/commonjs/index.js +49 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/input/index.js +13 -19
- package/lib/commonjs/input/index.js.map +1 -1
- package/lib/commonjs/link/LinkProvider.js +28 -0
- package/lib/commonjs/link/LinkProvider.js.map +1 -0
- package/lib/commonjs/link/createLink.js +74 -0
- package/lib/commonjs/link/createLink.js.map +1 -0
- package/lib/commonjs/link/index.js +27 -0
- package/lib/commonjs/link/index.js.map +1 -0
- package/lib/commonjs/link/types.js +6 -0
- package/lib/commonjs/link/types.js.map +1 -0
- package/lib/commonjs/link/useLink.js +56 -0
- package/lib/commonjs/link/useLink.js.map +1 -0
- package/lib/commonjs/overlay/OverlayContainer.js +6 -4
- package/lib/commonjs/overlay/OverlayContainer.js.map +1 -1
- package/lib/commonjs/select/context.js +8 -43
- package/lib/commonjs/select/context.js.map +1 -1
- package/lib/commonjs/select/createSelectItem.js +1 -1
- package/lib/commonjs/select/createSelectItem.js.map +1 -1
- package/lib/commonjs/select/createSelectRoot.js +1 -1
- package/lib/commonjs/select/createSelectRoot.js.map +1 -1
- package/lib/commonjs/select/createSelectTrigger.js +2 -8
- package/lib/commonjs/select/createSelectTrigger.js.map +1 -1
- package/lib/commonjs/switch/createSwitchRoot.js +73 -0
- package/lib/commonjs/switch/createSwitchRoot.js.map +1 -0
- package/lib/commonjs/switch/index.js +15 -0
- package/lib/commonjs/switch/index.js.map +1 -0
- package/lib/commonjs/switch/types.js +6 -0
- package/lib/commonjs/switch/types.js.map +1 -0
- package/lib/commonjs/types.js +2 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/dataAttributes.web.js +1 -4
- package/lib/commonjs/utils/dataAttributes.web.js.map +1 -1
- package/lib/module/avatar/context.js +5 -0
- package/lib/module/avatar/context.js.map +1 -0
- package/lib/module/{input/createInputIcon.js → avatar/createAvatarBadge.js} +3 -3
- package/lib/module/avatar/createAvatarBadge.js.map +1 -0
- package/lib/module/avatar/createAvatarIcon.js +25 -0
- package/lib/module/avatar/createAvatarIcon.js.map +1 -0
- package/lib/module/avatar/createAvatarImage.js +46 -0
- package/lib/module/avatar/createAvatarImage.js.map +1 -0
- package/lib/module/avatar/createAvatarRoot.js +29 -0
- package/lib/module/avatar/createAvatarRoot.js.map +1 -0
- package/lib/module/avatar/createAvatarText.js +37 -0
- package/lib/module/avatar/createAvatarText.js.map +1 -0
- package/lib/module/avatar/index.js +26 -0
- package/lib/module/avatar/index.js.map +1 -0
- package/lib/module/avatar/types.js +4 -0
- package/lib/module/avatar/types.js.map +1 -0
- package/lib/module/button/createButtonRoot.js +3 -3
- package/lib/module/button/createButtonRoot.js.map +1 -1
- package/lib/module/button/index.js +18 -19
- package/lib/module/button/index.js.map +1 -1
- package/lib/module/checkbox/context.js +7 -0
- package/lib/module/checkbox/context.js.map +1 -0
- package/lib/module/checkbox/createCheckboxGroup.js +39 -0
- package/lib/module/checkbox/createCheckboxGroup.js.map +1 -0
- package/lib/module/checkbox/createCheckboxIcon.js +24 -0
- package/lib/module/checkbox/createCheckboxIcon.js.map +1 -0
- package/lib/module/checkbox/createCheckboxIndicator.js +42 -0
- package/lib/module/checkbox/createCheckboxIndicator.js.map +1 -0
- package/lib/module/checkbox/createCheckboxLabel.js +41 -0
- package/lib/module/checkbox/createCheckboxLabel.js.map +1 -0
- package/lib/module/checkbox/createCheckboxRoot.js +94 -0
- package/lib/module/checkbox/createCheckboxRoot.js.map +1 -0
- package/lib/module/checkbox/createCheckboxRoot.web.js +85 -0
- package/lib/module/checkbox/createCheckboxRoot.web.js.map +1 -0
- package/lib/module/checkbox/index.js +26 -0
- package/lib/module/checkbox/index.js.map +1 -0
- package/lib/module/checkbox/types.js +4 -0
- package/lib/module/checkbox/types.js.map +1 -0
- package/lib/module/checkbox/useCheckboxRoot.js +78 -0
- package/lib/module/checkbox/useCheckboxRoot.js.map +1 -0
- package/lib/module/index.js +5 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/input/index.js +12 -17
- package/lib/module/input/index.js.map +1 -1
- package/lib/module/link/LinkProvider.js +23 -0
- package/lib/module/link/LinkProvider.js.map +1 -0
- package/lib/module/link/createLink.js +68 -0
- package/lib/module/link/createLink.js.map +1 -0
- package/lib/module/link/index.js +6 -0
- package/lib/module/link/index.js.map +1 -0
- package/lib/module/link/types.js +4 -0
- package/lib/module/link/types.js.map +1 -0
- package/lib/module/link/useLink.js +52 -0
- package/lib/module/link/useLink.js.map +1 -0
- package/lib/module/overlay/OverlayContainer.js +7 -5
- package/lib/module/overlay/OverlayContainer.js.map +1 -1
- package/lib/module/select/context.js +4 -42
- package/lib/module/select/context.js.map +1 -1
- package/lib/module/select/createSelectItem.js +2 -2
- package/lib/module/select/createSelectItem.js.map +1 -1
- package/lib/module/select/createSelectRoot.js +2 -2
- package/lib/module/select/createSelectRoot.js.map +1 -1
- package/lib/module/select/createSelectTrigger.js +3 -9
- package/lib/module/select/createSelectTrigger.js.map +1 -1
- package/lib/module/switch/createSwitchRoot.js +67 -0
- package/lib/module/switch/createSwitchRoot.js.map +1 -0
- package/lib/module/switch/index.js +11 -0
- package/lib/module/switch/index.js.map +1 -0
- package/lib/module/switch/types.js +4 -0
- package/lib/module/switch/types.js.map +1 -0
- package/lib/module/types.js +2 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/dataAttributes.web.js +1 -4
- package/lib/module/utils/dataAttributes.web.js.map +1 -1
- package/lib/typescript/avatar/context.d.ts +6 -0
- package/lib/typescript/avatar/context.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarBadge.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarBadge.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarIcon.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarIcon.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarImage.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarImage.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarRoot.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarRoot.d.ts.map +1 -0
- package/lib/typescript/avatar/createAvatarText.d.ts +4 -0
- package/lib/typescript/avatar/createAvatarText.d.ts.map +1 -0
- package/lib/typescript/avatar/index.d.ts +11 -0
- package/lib/typescript/avatar/index.d.ts.map +1 -0
- package/lib/typescript/avatar/types.d.ts +33 -0
- package/lib/typescript/avatar/types.d.ts.map +1 -0
- package/lib/typescript/button/context.d.ts +1 -1
- package/lib/typescript/button/context.d.ts.map +1 -1
- package/lib/typescript/button/createButtonRoot.d.ts +1 -1
- package/lib/typescript/button/createButtonRoot.d.ts.map +1 -1
- package/lib/typescript/button/index.d.ts +1 -1
- package/lib/typescript/button/index.d.ts.map +1 -1
- package/lib/typescript/button/types.d.ts +0 -7
- package/lib/typescript/button/types.d.ts.map +1 -1
- package/lib/typescript/checkbox/context.d.ts +18 -0
- package/lib/typescript/checkbox/context.d.ts.map +1 -0
- package/lib/typescript/checkbox/createCheckboxGroup.d.ts +3 -0
- package/lib/typescript/checkbox/createCheckboxGroup.d.ts.map +1 -0
- package/lib/typescript/checkbox/createCheckboxIcon.d.ts +3 -0
- package/lib/typescript/checkbox/createCheckboxIcon.d.ts.map +1 -0
- package/lib/typescript/checkbox/createCheckboxIndicator.d.ts +5 -0
- package/lib/typescript/checkbox/createCheckboxIndicator.d.ts.map +1 -0
- package/lib/typescript/checkbox/createCheckboxLabel.d.ts +5 -0
- package/lib/typescript/checkbox/createCheckboxLabel.d.ts.map +1 -0
- package/lib/typescript/checkbox/createCheckboxRoot.d.ts +2 -0
- package/lib/typescript/checkbox/createCheckboxRoot.d.ts.map +1 -0
- package/lib/typescript/checkbox/createCheckboxRoot.web.d.ts +2 -0
- package/lib/typescript/checkbox/createCheckboxRoot.web.d.ts.map +1 -0
- package/lib/typescript/checkbox/index.d.ts +11 -0
- package/lib/typescript/checkbox/index.d.ts.map +1 -0
- package/lib/typescript/checkbox/types.d.ts +57 -0
- package/lib/typescript/checkbox/types.d.ts.map +1 -0
- package/lib/typescript/checkbox/useCheckboxRoot.d.ts +147 -0
- package/lib/typescript/checkbox/useCheckboxRoot.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/input/index.d.ts +3 -3
- package/lib/typescript/input/index.d.ts.map +1 -1
- package/lib/typescript/input/types.d.ts +1 -2
- package/lib/typescript/input/types.d.ts.map +1 -1
- package/lib/typescript/link/LinkProvider.d.ts +36 -0
- package/lib/typescript/link/LinkProvider.d.ts.map +1 -0
- package/lib/typescript/link/createLink.d.ts +6 -0
- package/lib/typescript/link/createLink.d.ts.map +1 -0
- package/lib/typescript/link/index.d.ts +6 -0
- package/lib/typescript/link/index.d.ts.map +1 -0
- package/lib/typescript/link/types.d.ts +45 -0
- package/lib/typescript/link/types.d.ts.map +1 -0
- package/lib/typescript/link/useLink.d.ts +9 -0
- package/lib/typescript/link/useLink.d.ts.map +1 -0
- package/lib/typescript/overlay/OverlayContainer.d.ts +5 -1
- package/lib/typescript/overlay/OverlayContainer.d.ts.map +1 -1
- package/lib/typescript/select/context.d.ts +14 -7
- package/lib/typescript/select/context.d.ts.map +1 -1
- package/lib/typescript/select/createSelectTrigger.d.ts +2 -7
- package/lib/typescript/select/createSelectTrigger.d.ts.map +1 -1
- package/lib/typescript/select/types.d.ts +1 -7
- package/lib/typescript/select/types.d.ts.map +1 -1
- package/lib/typescript/switch/createSwitchRoot.d.ts +3 -0
- package/lib/typescript/switch/createSwitchRoot.d.ts.map +1 -0
- package/lib/typescript/switch/index.d.ts +7 -0
- package/lib/typescript/switch/index.d.ts.map +1 -0
- package/lib/typescript/switch/types.d.ts +38 -0
- package/lib/typescript/switch/types.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +8 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils/dataAttributes.web.d.ts.map +1 -1
- package/package.json +12 -8
- package/src/avatar/context.tsx +5 -0
- package/src/avatar/createAvatarBadge.tsx +12 -0
- package/src/avatar/createAvatarIcon.tsx +16 -0
- package/src/avatar/createAvatarImage.tsx +40 -0
- package/src/avatar/createAvatarRoot.tsx +23 -0
- package/src/avatar/createAvatarText.tsx +30 -0
- package/src/avatar/index.ts +43 -0
- package/src/avatar/types.ts +77 -0
- package/src/button/context.tsx +1 -1
- package/src/button/createButtonRoot.tsx +5 -4
- package/src/button/index.tsx +18 -19
- package/src/button/types.ts +0 -8
- package/src/checkbox/context.tsx +18 -0
- package/src/checkbox/createCheckboxGroup.tsx +32 -0
- package/src/checkbox/createCheckboxIcon.tsx +18 -0
- package/src/checkbox/createCheckboxIndicator.tsx +43 -0
- package/src/checkbox/createCheckboxLabel.tsx +42 -0
- package/src/checkbox/createCheckboxRoot.tsx +100 -0
- package/src/checkbox/createCheckboxRoot.web.tsx +79 -0
- package/src/checkbox/index.ts +43 -0
- package/src/checkbox/types.ts +74 -0
- package/src/checkbox/useCheckboxRoot.ts +85 -0
- package/src/index.ts +6 -1
- package/src/input/index.tsx +15 -28
- package/src/input/types.ts +0 -4
- package/src/link/LinkProvider.tsx +50 -0
- package/src/link/createLink.tsx +71 -0
- package/src/link/index.tsx +5 -0
- package/src/link/types.ts +47 -0
- package/src/link/useLink.ts +54 -0
- package/src/overlay/OverlayContainer.tsx +7 -8
- package/src/select/context.tsx +9 -44
- package/src/select/createSelectItem.tsx +3 -3
- package/src/select/createSelectRoot.tsx +3 -3
- package/src/select/createSelectTrigger.tsx +6 -31
- package/src/select/types.ts +1 -10
- package/src/switch/createSwitchRoot.tsx +72 -0
- package/src/switch/index.ts +16 -0
- package/src/switch/types.ts +42 -0
- package/src/types.ts +7 -0
- package/src/utils/dataAttributes.web.ts +2 -4
- package/lib/commonjs/input/createInputIcon.js +0 -20
- package/lib/commonjs/input/createInputIcon.js.map +0 -1
- package/lib/module/input/createInputIcon.js.map +0 -1
- package/lib/typescript/input/createInputIcon.d.ts +0 -4
- package/lib/typescript/input/createInputIcon.d.ts.map +0 -1
- package/src/input/createInputIcon.tsx +0 -12
package/src/select/context.tsx
CHANGED
|
@@ -1,56 +1,21 @@
|
|
|
1
|
-
import { createContext
|
|
2
|
-
import type { InteractionState
|
|
1
|
+
import { createContext } from '@cdx-ui/utils';
|
|
2
|
+
import type { InteractionState } from '../types';
|
|
3
|
+
import type { SelectContextValue, SelectItemInteractionState } from './types';
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
items: [],
|
|
7
|
-
setOpen: () => {},
|
|
8
|
-
value: undefined,
|
|
9
|
-
onValueChange: () => {},
|
|
10
|
-
disabled: false,
|
|
11
|
-
required: false,
|
|
12
|
-
invalid: false,
|
|
13
|
-
readOnly: false,
|
|
14
|
-
native: false,
|
|
15
|
-
triggerRef: { current: null },
|
|
16
|
-
contentId: '',
|
|
17
|
-
triggerId: '',
|
|
18
|
-
activeValue: undefined,
|
|
19
|
-
setActiveValue: () => {}, // TODO: Is this needed? At the very least it could be moved to SelectContent
|
|
20
|
-
accessibilityLabel: undefined,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export const SelectContext = createContext<SelectContextValue>(defaultContextValue);
|
|
24
|
-
|
|
25
|
-
export const useSelectContext = () => useContext(SelectContext);
|
|
5
|
+
export const [SelectProvider, useSelectContext] =
|
|
6
|
+
createContext<SelectContextValue>('SelectContext');
|
|
26
7
|
|
|
27
8
|
/**
|
|
28
9
|
* Propagates the trigger's interaction state (hover, focus, active, etc.) to
|
|
29
10
|
* child components like SelectValue and SelectIcon so they can apply matching
|
|
30
11
|
* data-attribute styles.
|
|
31
12
|
*/
|
|
32
|
-
export const
|
|
33
|
-
|
|
34
|
-
focus: false,
|
|
35
|
-
active: false,
|
|
36
|
-
disabled: false,
|
|
37
|
-
focusVisible: false,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
export const useSelectTriggerContext = () => useContext(SelectTriggerContext);
|
|
13
|
+
export const [SelectTriggerProvider, useSelectTriggerContext] =
|
|
14
|
+
createContext<InteractionState>('SelectTriggerContext');
|
|
41
15
|
|
|
42
16
|
/**
|
|
43
17
|
* Propagates the item's interaction and selection state (hover, focus, active,
|
|
44
18
|
* highlighted, checked, etc.) to child components like SelectItemLabel.
|
|
45
19
|
*/
|
|
46
|
-
export const
|
|
47
|
-
|
|
48
|
-
focus: false,
|
|
49
|
-
active: false,
|
|
50
|
-
disabled: false,
|
|
51
|
-
focusVisible: false,
|
|
52
|
-
highlighted: false,
|
|
53
|
-
checked: false,
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
export const useSelectItemContext = () => useContext(SelectItemContext);
|
|
20
|
+
export const [SelectItemProvider, useSelectItemContext] =
|
|
21
|
+
createContext<SelectItemInteractionState>('SelectItemContext');
|
|
@@ -4,7 +4,7 @@ import { composeEventHandlers } from '@cdx-ui/utils';
|
|
|
4
4
|
import { useFocus, useFocusRing } from '@react-native-aria/focus';
|
|
5
5
|
import { useHover, usePress } from '@react-native-aria/interactions';
|
|
6
6
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
7
|
-
import {
|
|
7
|
+
import { SelectItemProvider, useSelectContext } from './context';
|
|
8
8
|
import type { ISelectItemProps } from './types';
|
|
9
9
|
|
|
10
10
|
export const createSelectItem = <T,>(BaseItem: React.ComponentType<T>) =>
|
|
@@ -74,7 +74,7 @@ export const createSelectItem = <T,>(BaseItem: React.ComponentType<T>) =>
|
|
|
74
74
|
);
|
|
75
75
|
|
|
76
76
|
return (
|
|
77
|
-
<
|
|
77
|
+
<SelectItemProvider value={interactionState}>
|
|
78
78
|
<BaseItem
|
|
79
79
|
ref={ref}
|
|
80
80
|
role="option"
|
|
@@ -115,7 +115,7 @@ export const createSelectItem = <T,>(BaseItem: React.ComponentType<T>) =>
|
|
|
115
115
|
>
|
|
116
116
|
{children}
|
|
117
117
|
</BaseItem>
|
|
118
|
-
</
|
|
118
|
+
</SelectItemProvider>
|
|
119
119
|
);
|
|
120
120
|
},
|
|
121
121
|
);
|
|
@@ -2,7 +2,7 @@ import type React from 'react';
|
|
|
2
2
|
import { forwardRef, useCallback, useId, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { useControllableState, useFormControl } from '@cdx-ui/utils';
|
|
4
4
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
5
|
-
import {
|
|
5
|
+
import { SelectProvider } from './context';
|
|
6
6
|
import type { ISelectProps } from './types';
|
|
7
7
|
|
|
8
8
|
export const createSelectRoot = <T,>(BaseRoot: React.ComponentType<T>) =>
|
|
@@ -110,7 +110,7 @@ export const createSelectRoot = <T,>(BaseRoot: React.ComponentType<T>) =>
|
|
|
110
110
|
);
|
|
111
111
|
|
|
112
112
|
return (
|
|
113
|
-
<
|
|
113
|
+
<SelectProvider value={contextValue}>
|
|
114
114
|
<BaseRoot
|
|
115
115
|
ref={ref}
|
|
116
116
|
{...(props as T)}
|
|
@@ -124,7 +124,7 @@ export const createSelectRoot = <T,>(BaseRoot: React.ComponentType<T>) =>
|
|
|
124
124
|
>
|
|
125
125
|
{children}
|
|
126
126
|
</BaseRoot>
|
|
127
|
-
</
|
|
127
|
+
</SelectProvider>
|
|
128
128
|
);
|
|
129
129
|
},
|
|
130
130
|
);
|
|
@@ -4,8 +4,9 @@ import { type GestureResponderEvent, Platform } from 'react-native';
|
|
|
4
4
|
import { composeEventHandlers, mergeRefs } from '@cdx-ui/utils';
|
|
5
5
|
import { useFocus, useFocusRing } from '@react-native-aria/focus';
|
|
6
6
|
import { useHover, usePress } from '@react-native-aria/interactions';
|
|
7
|
+
import type { InteractionState } from '../types';
|
|
7
8
|
import { dataAttributes } from '../utils/dataAttributes';
|
|
8
|
-
import {
|
|
9
|
+
import { SelectTriggerProvider, useSelectContext } from './context';
|
|
9
10
|
import type { ISelectTriggerProps } from './types';
|
|
10
11
|
|
|
11
12
|
export const createSelectTrigger = <T,>(BaseTrigger: React.ComponentType<T>) =>
|
|
@@ -20,21 +21,7 @@ export const createSelectTrigger = <T,>(BaseTrigger: React.ComponentType<T>) =>
|
|
|
20
21
|
isDisabled: isDisabledProp,
|
|
21
22
|
...props
|
|
22
23
|
}: Omit<ISelectTriggerProps, 'children'> & {
|
|
23
|
-
children?:
|
|
24
|
-
| (({
|
|
25
|
-
hovered,
|
|
26
|
-
pressed,
|
|
27
|
-
focused,
|
|
28
|
-
focusVisible,
|
|
29
|
-
disabled,
|
|
30
|
-
}: {
|
|
31
|
-
hovered?: boolean;
|
|
32
|
-
pressed?: boolean;
|
|
33
|
-
focused?: boolean;
|
|
34
|
-
focusVisible?: boolean;
|
|
35
|
-
disabled?: boolean;
|
|
36
|
-
}) => React.ReactNode)
|
|
37
|
-
| React.ReactNode;
|
|
24
|
+
children?: ((state: InteractionState) => React.ReactNode) | React.ReactNode;
|
|
38
25
|
},
|
|
39
26
|
ref?: any,
|
|
40
27
|
) => {
|
|
@@ -122,7 +109,7 @@ export const createSelectTrigger = <T,>(BaseTrigger: React.ComponentType<T>) =>
|
|
|
122
109
|
: {};
|
|
123
110
|
|
|
124
111
|
return (
|
|
125
|
-
<
|
|
112
|
+
<SelectTriggerProvider value={interactionState}>
|
|
126
113
|
<BaseTrigger
|
|
127
114
|
ref={mergedRef}
|
|
128
115
|
role="combobox"
|
|
@@ -172,21 +159,9 @@ export const createSelectTrigger = <T,>(BaseTrigger: React.ComponentType<T>) =>
|
|
|
172
159
|
)}
|
|
173
160
|
{...webKeyboardProps}
|
|
174
161
|
>
|
|
175
|
-
{
|
|
176
|
-
passes raw hook values (isHovered, isFocused, etc.) while this
|
|
177
|
-
passes merged interaction state (isHoveredProp || isHovered). Pick
|
|
178
|
-
one convention and apply to both. */}
|
|
179
|
-
{typeof children === 'function'
|
|
180
|
-
? children({
|
|
181
|
-
hovered: interactionState.hover,
|
|
182
|
-
focused: interactionState.focus,
|
|
183
|
-
pressed: interactionState.active,
|
|
184
|
-
disabled: interactionState.disabled,
|
|
185
|
-
focusVisible: interactionState.focusVisible,
|
|
186
|
-
})
|
|
187
|
-
: children}
|
|
162
|
+
{typeof children === 'function' ? children(interactionState) : children}
|
|
188
163
|
</BaseTrigger>
|
|
189
|
-
</
|
|
164
|
+
</SelectTriggerProvider>
|
|
190
165
|
);
|
|
191
166
|
},
|
|
192
167
|
);
|
package/src/select/types.ts
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import type { PropsWithoutRef, ReactNode, RefAttributes, RefObject } from 'react';
|
|
2
2
|
import type { PressableProps, ViewProps } from 'react-native';
|
|
3
3
|
import type { EntryOrExitLayoutType } from 'react-native-reanimated';
|
|
4
|
-
|
|
5
|
-
// TODO: Consolidate with button/types.ts
|
|
6
|
-
|
|
7
|
-
export interface InteractionState {
|
|
8
|
-
hover: boolean;
|
|
9
|
-
focus: boolean;
|
|
10
|
-
active: boolean;
|
|
11
|
-
disabled: boolean;
|
|
12
|
-
focusVisible: boolean;
|
|
13
|
-
}
|
|
4
|
+
import type { InteractionState } from '../types';
|
|
14
5
|
|
|
15
6
|
export interface SelectItemInteractionState extends InteractionState {
|
|
16
7
|
highlighted: boolean;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import React, { forwardRef } from 'react';
|
|
2
|
+
import { useFocusRing } from '@react-native-aria/focus';
|
|
3
|
+
import { useHover } from '@react-native-aria/interactions';
|
|
4
|
+
import { useToggleState } from '@react-stately/toggle';
|
|
5
|
+
import { useFormControlContext, mergeRefs } from '@cdx-ui/utils';
|
|
6
|
+
import type { ISwitchProps } from './types';
|
|
7
|
+
|
|
8
|
+
type MergeableRef = Parameters<typeof mergeRefs>[0];
|
|
9
|
+
|
|
10
|
+
export const createSwitchRoot = <T, R = unknown>(BaseSwitch: React.ComponentType<T>) =>
|
|
11
|
+
forwardRef<R, ISwitchProps>(
|
|
12
|
+
(
|
|
13
|
+
{
|
|
14
|
+
disabled,
|
|
15
|
+
isDisabled,
|
|
16
|
+
isChecked,
|
|
17
|
+
isInvalid,
|
|
18
|
+
defaultValue,
|
|
19
|
+
value,
|
|
20
|
+
onValueChange,
|
|
21
|
+
...props
|
|
22
|
+
}: ISwitchProps,
|
|
23
|
+
ref: React.ForwardedRef<R>,
|
|
24
|
+
) => {
|
|
25
|
+
const formControlContext = useFormControlContext();
|
|
26
|
+
const combinedProps = { ...formControlContext, ...props };
|
|
27
|
+
const controlledValue = value ?? isChecked;
|
|
28
|
+
const state = useToggleState({
|
|
29
|
+
defaultSelected: defaultValue ?? false,
|
|
30
|
+
isSelected: controlledValue,
|
|
31
|
+
onChange: onValueChange,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const checked = controlledValue ?? state.isSelected;
|
|
35
|
+
|
|
36
|
+
const _ref = React.useRef(null);
|
|
37
|
+
const { isHovered } = useHover({}, _ref);
|
|
38
|
+
const { isFocusVisible, focusProps } = useFocusRing();
|
|
39
|
+
|
|
40
|
+
const mergedRef = mergeRefs(ref as MergeableRef, _ref);
|
|
41
|
+
|
|
42
|
+
const isDisabledResolved = disabled || isDisabled || combinedProps.isDisabled;
|
|
43
|
+
const isInvalidResolved = isInvalid || combinedProps.isInvalid;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<BaseSwitch
|
|
47
|
+
states={{
|
|
48
|
+
hover: isHovered,
|
|
49
|
+
disabled: isDisabledResolved,
|
|
50
|
+
invalid: isInvalidResolved,
|
|
51
|
+
checked,
|
|
52
|
+
focusVisible: isFocusVisible,
|
|
53
|
+
}}
|
|
54
|
+
dataSet={{
|
|
55
|
+
hover: isHovered ? 'true' : 'false',
|
|
56
|
+
disabled: isDisabledResolved ? 'true' : 'false',
|
|
57
|
+
invalid: isInvalidResolved ? 'true' : 'false',
|
|
58
|
+
checked: checked ? 'true' : 'false',
|
|
59
|
+
'focus-visible': isFocusVisible ? 'true' : 'false',
|
|
60
|
+
}}
|
|
61
|
+
disabled={isDisabledResolved}
|
|
62
|
+
{...focusProps}
|
|
63
|
+
onValueChange={(val: boolean) => {
|
|
64
|
+
state.setSelected(val);
|
|
65
|
+
}}
|
|
66
|
+
value={checked}
|
|
67
|
+
{...(combinedProps as T)}
|
|
68
|
+
ref={mergedRef as React.Ref<R>}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
},
|
|
72
|
+
);
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { createSwitchRoot } from './createSwitchRoot';
|
|
3
|
+
import type { ISwitchComponentType } from './types';
|
|
4
|
+
|
|
5
|
+
export type { ISwitchProps, ISwitchComponentType, IInterfaceSwitchProps } from './types';
|
|
6
|
+
|
|
7
|
+
export function createSwitch<T, R = unknown>({
|
|
8
|
+
Root,
|
|
9
|
+
}: {
|
|
10
|
+
Root: React.ComponentType<T>;
|
|
11
|
+
}): ISwitchComponentType<T, R> {
|
|
12
|
+
const Switch = createSwitchRoot(Root);
|
|
13
|
+
|
|
14
|
+
Switch.displayName = 'Switch';
|
|
15
|
+
return Switch as ISwitchComponentType<T, R>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
|
|
3
|
+
export interface IInterfaceSwitchProps {
|
|
4
|
+
/**
|
|
5
|
+
* Callback invoked when the switch value changes.
|
|
6
|
+
*/
|
|
7
|
+
onValueChange?: (value: boolean) => void;
|
|
8
|
+
/**
|
|
9
|
+
* If true, set the Switch to the checked state.
|
|
10
|
+
*/
|
|
11
|
+
isChecked?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* The current value of the switch.
|
|
14
|
+
*/
|
|
15
|
+
value?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* If true, the switch will be disabled.
|
|
18
|
+
*/
|
|
19
|
+
isDisabled?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* If true, the switch will be disabled.
|
|
22
|
+
*/
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* If true, the checkbox will be initially checked.
|
|
26
|
+
*/
|
|
27
|
+
defaultValue?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* If true, set the switch to the invalid state.
|
|
30
|
+
*/
|
|
31
|
+
isInvalid?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* If true, the switch will be hovered.
|
|
34
|
+
*/
|
|
35
|
+
isHovered?: boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type ISwitchComponentType<T, R = unknown> = React.ForwardRefExoticComponent<
|
|
39
|
+
React.PropsWithoutRef<T & IInterfaceSwitchProps> & React.RefAttributes<R>
|
|
40
|
+
>;
|
|
41
|
+
|
|
42
|
+
export type ISwitchProps = IInterfaceSwitchProps;
|
package/src/types.ts
ADDED
|
@@ -17,10 +17,8 @@ export function dataAttributes(attrs: Record<string, DataAttributeValue>): {
|
|
|
17
17
|
const dataSet: Record<string, boolean | string> = {};
|
|
18
18
|
for (const key in attrs) {
|
|
19
19
|
const value = attrs[key];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
dataSet[key] = value;
|
|
20
|
+
|
|
21
|
+
dataSet[key] = value ?? false;
|
|
24
22
|
}
|
|
25
23
|
return { dataSet };
|
|
26
24
|
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createInputIcon = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
-
const createInputIcon = BaseInputIcon => /*#__PURE__*/(0, _react.forwardRef)(({
|
|
10
|
-
children,
|
|
11
|
-
...props
|
|
12
|
-
}, ref) => {
|
|
13
|
-
return /*#__PURE__*/(0, _jsxRuntime.jsx)(BaseInputIcon, {
|
|
14
|
-
ref: ref,
|
|
15
|
-
...props,
|
|
16
|
-
children: children
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
exports.createInputIcon = createInputIcon;
|
|
20
|
-
//# sourceMappingURL=createInputIcon.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_react","require","_jsxRuntime","createInputIcon","BaseInputIcon","forwardRef","children","props","ref","jsx","exports"],"sourceRoot":"../../../src","sources":["input/createInputIcon.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAAmC,IAAAC,WAAA,GAAAD,OAAA;AAG5B,MAAME,eAAe,GAAQC,aAAqC,iBACvE,IAAAC,iBAAU,EAA2B,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACpE,oBACE,IAAAN,WAAA,CAAAO,GAAA,EAACL,aAAa;IAACI,GAAG,EAAEA,GAAI;IAAA,GAAMD,KAAK;IAAAD,QAAA,EAChCA;EAAQ,CACI,CAAC;AAEpB,CAAC,CAAC;AAACI,OAAA,CAAAP,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","jsx","_jsx","createInputIcon","BaseInputIcon","children","props","ref"],"sourceRoot":"../../../src","sources":["input/createInputIcon.tsx"],"mappings":";;AACA,SAASA,UAAU,QAAQ,OAAO;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAGnC,OAAO,MAAMC,eAAe,GAAQC,aAAqC,iBACvEJ,UAAU,CAA2B,CAAC;EAAEK,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,GAAG,KAAK;EACpE,oBACEL,IAAA,CAACE,aAAa;IAACG,GAAG,EAAEA,GAAI;IAAA,GAAMD,KAAK;IAAAD,QAAA,EAChCA;EAAQ,CACI,CAAC;AAEpB,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
import type { IInputIconProps } from './types';
|
|
3
|
-
export declare const createInputIcon: <T>(BaseInputIcon: React.ComponentType<T>) => React.ForwardRefExoticComponent<IInputIconProps & React.RefAttributes<unknown>>;
|
|
4
|
-
//# sourceMappingURL=createInputIcon.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createInputIcon.d.ts","sourceRoot":"","sources":["../../../src/input/createInputIcon.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/C,eAAO,MAAM,eAAe,GAAI,CAAC,EAAG,eAAe,KAAK,CAAC,aAAa,CAAC,CAAC,CAAC,oFAOrE,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
import { forwardRef } from 'react';
|
|
3
|
-
import type { IInputIconProps } from './types';
|
|
4
|
-
|
|
5
|
-
export const createInputIcon = <T,>(BaseInputIcon: React.ComponentType<T>) =>
|
|
6
|
-
forwardRef<unknown, IInputIconProps>(({ children, ...props }, ref) => {
|
|
7
|
-
return (
|
|
8
|
-
<BaseInputIcon ref={ref} {...(props as T)}>
|
|
9
|
-
{children}
|
|
10
|
-
</BaseInputIcon>
|
|
11
|
-
);
|
|
12
|
-
});
|