@cdx-ui/primitives 0.0.1-alpha.1 → 0.0.1-alpha.11
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/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 +28 -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 +25 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/input/index.js +16 -18
- package/lib/commonjs/input/index.js.map +1 -1
- package/lib/commonjs/select/context.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/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 +23 -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 +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/input/index.js +15 -16
- package/lib/module/input/index.js.map +1 -1
- package/lib/module/select/context.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/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 +4 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/input/index.d.ts +3 -2
- package/lib/typescript/input/index.d.ts.map +1 -1
- package/lib/typescript/select/context.d.ts +2 -1
- package/lib/typescript/select/context.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 -9
- 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 +4 -1
- package/src/input/index.tsx +18 -25
- package/src/select/context.tsx +2 -1
- 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/src/input/index.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
import { createInputField } from './createInputField';
|
|
2
3
|
import { createInputIcon } from './createInputIcon';
|
|
3
4
|
import { createInputRoot } from './createInputRoot';
|
|
@@ -12,40 +13,32 @@ export type {
|
|
|
12
13
|
IInputSlotProps,
|
|
13
14
|
} from './types';
|
|
14
15
|
|
|
15
|
-
export
|
|
16
|
+
export function createInput<
|
|
16
17
|
RootProps,
|
|
17
18
|
IconProps,
|
|
18
19
|
SlotProps,
|
|
19
20
|
FieldProps,
|
|
20
21
|
RootRef = unknown,
|
|
21
22
|
FieldRef = unknown,
|
|
22
|
-
>({
|
|
23
|
-
Root,
|
|
24
|
-
Icon,
|
|
25
|
-
Slot,
|
|
26
|
-
Field,
|
|
27
|
-
}: {
|
|
23
|
+
>(BaseComponents: {
|
|
28
24
|
Root: React.ComponentType<RootProps>;
|
|
29
25
|
Icon: React.ComponentType<IconProps>;
|
|
30
26
|
Slot: React.ComponentType<SlotProps>;
|
|
31
27
|
Field: React.ComponentType<FieldProps>;
|
|
32
|
-
})
|
|
33
|
-
const Input = createInputRoot(Root)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
}) {
|
|
29
|
+
const Input = createInputRoot(BaseComponents.Root);
|
|
30
|
+
const Icon = createInputIcon(BaseComponents.Icon);
|
|
31
|
+
const Slot = createInputSlot(BaseComponents.Slot);
|
|
32
|
+
const Field = createInputField(BaseComponents.Field);
|
|
37
33
|
|
|
38
|
-
Input.displayName = '
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
Input.displayName = 'InputPrimitive';
|
|
35
|
+
Icon.displayName = 'InputPrimitive.Icon';
|
|
36
|
+
Slot.displayName = 'InputPrimitive.Slot';
|
|
37
|
+
Field.displayName = 'InputPrimitive.Field';
|
|
42
38
|
|
|
43
|
-
return Input
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
FieldRef
|
|
50
|
-
>;
|
|
51
|
-
};
|
|
39
|
+
return Object.assign(Input, {
|
|
40
|
+
Icon,
|
|
41
|
+
Slot,
|
|
42
|
+
Field,
|
|
43
|
+
}) as IInputComponentType<RootProps, IconProps, SlotProps, FieldProps, RootRef, FieldRef>;
|
|
44
|
+
}
|
package/src/select/context.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createContext, useContext } from 'react';
|
|
2
|
-
import type { InteractionState
|
|
2
|
+
import type { InteractionState } from '../types';
|
|
3
|
+
import type { SelectContextValue, SelectItemInteractionState } from './types';
|
|
3
4
|
|
|
4
5
|
const defaultContextValue: SelectContextValue = {
|
|
5
6
|
open: false,
|
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
|
}
|