@koobiq/react-primitives 0.0.1-beta.22 → 0.0.1-beta.24
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.
|
@@ -1,56 +1,21 @@
|
|
|
1
1
|
import type { RefObject } from 'react';
|
|
2
|
-
import type { ExtendableProps } from '@koobiq/react-core';
|
|
3
2
|
import type { AriaCheckboxProps } from '@react-aria/checkbox';
|
|
4
|
-
export type UseCheckboxProps =
|
|
5
|
-
/**
|
|
6
|
-
* If `true`, the component will indicate an error.
|
|
7
|
-
* @default false
|
|
8
|
-
* */
|
|
9
|
-
error?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* If `true`, the component is checked.
|
|
12
|
-
* @default false
|
|
13
|
-
* */
|
|
14
|
-
checked?: boolean;
|
|
15
|
-
/** It prevents the user from changing the value of the checkbox.
|
|
16
|
-
* @default false
|
|
17
|
-
*/
|
|
18
|
-
readonly?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* If `true`, the component is disabled.
|
|
21
|
-
* @default false
|
|
22
|
-
* */
|
|
23
|
-
disabled?: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* If `true`, the input element is required.
|
|
26
|
-
* @default false
|
|
27
|
-
* */
|
|
28
|
-
required?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* If `true`, the component appears indeterminate.
|
|
31
|
-
* @default false
|
|
32
|
-
* */
|
|
33
|
-
indeterminate?: boolean;
|
|
34
|
-
/** The default checked state. Use when the component is not controlled. */
|
|
35
|
-
defaultChecked?: boolean;
|
|
36
|
-
/** Callback fired when the state is changed. */
|
|
37
|
-
onChange?: (checked: boolean) => void;
|
|
38
|
-
}, Omit<AriaCheckboxProps, 'onChange' | 'isRequired' | 'isInvalid' | 'isReadOnly' | 'isSelected' | 'isDisabled' | 'isIndeterminate' | 'defaultSelected'>>;
|
|
3
|
+
export type UseCheckboxProps = AriaCheckboxProps;
|
|
39
4
|
export declare function useCheckbox(props: UseCheckboxProps, inputRef: RefObject<HTMLInputElement | null>): {
|
|
40
5
|
validationErrors: string[];
|
|
41
6
|
validationDetails: ValidityState;
|
|
7
|
+
isInvalid: boolean;
|
|
8
|
+
isPressed: boolean;
|
|
9
|
+
isHovered: boolean;
|
|
10
|
+
isFocused: boolean;
|
|
11
|
+
isSelected: boolean;
|
|
12
|
+
isDisabled: boolean;
|
|
13
|
+
isReadOnly: boolean;
|
|
42
14
|
labelProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & import("react").LabelHTMLAttributes<HTMLLabelElement>;
|
|
43
15
|
inputProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & import("react").InputHTMLAttributes<HTMLInputElement> & {
|
|
44
16
|
ref: RefObject<HTMLInputElement | null>;
|
|
45
17
|
};
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pressed: boolean;
|
|
49
|
-
hovered: boolean;
|
|
50
|
-
focused: boolean;
|
|
51
|
-
checked: boolean;
|
|
52
|
-
disabled: boolean;
|
|
53
|
-
readonly: boolean;
|
|
54
|
-
focusVisible: boolean;
|
|
18
|
+
isFocusVisible: boolean;
|
|
19
|
+
isIndeterminate: boolean | undefined;
|
|
55
20
|
};
|
|
56
21
|
export type UseCheckboxReturn = ReturnType<typeof useCheckbox>;
|
|
@@ -2,23 +2,10 @@
|
|
|
2
2
|
import { useToggleState, useHover, useFocusRing, mergeProps } from "@koobiq/react-core";
|
|
3
3
|
import { useCheckbox as useCheckbox$1 } from "@react-aria/checkbox";
|
|
4
4
|
function useCheckbox(props, inputRef) {
|
|
5
|
-
const {
|
|
6
|
-
|
|
7
|
-
checked,
|
|
8
|
-
disabled,
|
|
9
|
-
readonly,
|
|
10
|
-
required,
|
|
11
|
-
indeterminate,
|
|
12
|
-
defaultChecked,
|
|
13
|
-
onChange
|
|
14
|
-
} = props;
|
|
15
|
-
const state = useToggleState({
|
|
16
|
-
isSelected: checked,
|
|
17
|
-
defaultSelected: defaultChecked,
|
|
18
|
-
onChange
|
|
19
|
-
});
|
|
5
|
+
const { isDisabled: isDisabledProp, isIndeterminate: isIndeterminateProp } = props;
|
|
6
|
+
const state = useToggleState(props);
|
|
20
7
|
const { hoverProps, isHovered } = useHover({
|
|
21
|
-
isDisabled:
|
|
8
|
+
isDisabled: isDisabledProp
|
|
22
9
|
});
|
|
23
10
|
const { focusProps, isFocused, isFocusVisible } = useFocusRing();
|
|
24
11
|
const {
|
|
@@ -30,34 +17,23 @@ function useCheckbox(props, inputRef) {
|
|
|
30
17
|
isReadOnly,
|
|
31
18
|
isPressed,
|
|
32
19
|
...other
|
|
33
|
-
} = useCheckbox$1(
|
|
34
|
-
{
|
|
35
|
-
...props,
|
|
36
|
-
isInvalid: error,
|
|
37
|
-
isDisabled: disabled,
|
|
38
|
-
isIndeterminate: indeterminate,
|
|
39
|
-
isReadOnly: readonly,
|
|
40
|
-
isRequired: required
|
|
41
|
-
},
|
|
42
|
-
state,
|
|
43
|
-
inputRef
|
|
44
|
-
);
|
|
20
|
+
} = useCheckbox$1(props, state, inputRef);
|
|
45
21
|
const labelProps = mergeProps(hoverProps, commonLabelProps);
|
|
46
22
|
const inputProps = mergeProps(focusProps, commonInputProps, {
|
|
47
23
|
ref: inputRef
|
|
48
24
|
});
|
|
49
25
|
return {
|
|
26
|
+
isInvalid,
|
|
27
|
+
isPressed,
|
|
28
|
+
isHovered,
|
|
29
|
+
isFocused,
|
|
30
|
+
isSelected,
|
|
31
|
+
isDisabled,
|
|
32
|
+
isReadOnly,
|
|
50
33
|
labelProps,
|
|
51
34
|
inputProps,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
pressed: isPressed,
|
|
55
|
-
hovered: isHovered,
|
|
56
|
-
focused: isFocused,
|
|
57
|
-
checked: isSelected,
|
|
58
|
-
disabled: isDisabled,
|
|
59
|
-
readonly: isReadOnly,
|
|
60
|
-
focusVisible: isFocusVisible,
|
|
35
|
+
isFocusVisible,
|
|
36
|
+
isIndeterminate: isIndeterminateProp,
|
|
61
37
|
...other
|
|
62
38
|
};
|
|
63
39
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const Checkbox: import("react").ForwardRefExoticComponent<Omit<import("
|
|
1
|
+
export declare const Checkbox: import("react").ForwardRefExoticComponent<Omit<import("@react-types/checkbox").AriaCheckboxProps, keyof import("../..").RenderProps<import("./types").CheckboxRenderProps> | "inputRef"> & import("../..").RenderProps<import("./types").CheckboxRenderProps> & {
|
|
2
2
|
inputRef?: import("react").RefObject<HTMLInputElement | null>;
|
|
3
3
|
} & import("react").RefAttributes<HTMLLabelElement>>;
|
|
@@ -10,13 +10,15 @@ const Checkbox = forwardRef(
|
|
|
10
10
|
const { children, inputRef } = props;
|
|
11
11
|
const domRef = useDOMRef(inputRef);
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
isHovered,
|
|
14
|
+
isInvalid,
|
|
15
|
+
isSelected,
|
|
16
|
+
isFocused,
|
|
17
|
+
isPressed,
|
|
18
|
+
isReadOnly,
|
|
19
|
+
isDisabled,
|
|
20
|
+
isFocusVisible,
|
|
21
|
+
isIndeterminate,
|
|
20
22
|
labelProps,
|
|
21
23
|
inputProps
|
|
22
24
|
} = useCheckbox(
|
|
@@ -27,14 +29,14 @@ const Checkbox = forwardRef(
|
|
|
27
29
|
domRef
|
|
28
30
|
);
|
|
29
31
|
const renderValues = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
isHovered,
|
|
33
|
+
isInvalid,
|
|
34
|
+
isSelected,
|
|
35
|
+
isFocused,
|
|
36
|
+
isPressed,
|
|
37
|
+
isFocusVisible,
|
|
38
|
+
isIndeterminate,
|
|
39
|
+
isDisabled: props.isDisabled || false
|
|
38
40
|
};
|
|
39
41
|
const renderProps = useRenderProps({
|
|
40
42
|
...props,
|
|
@@ -42,10 +44,25 @@ const Checkbox = forwardRef(
|
|
|
42
44
|
});
|
|
43
45
|
const DOMProps = filterDOMProps(props);
|
|
44
46
|
delete DOMProps.id;
|
|
45
|
-
return /* @__PURE__ */ jsxs(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
return /* @__PURE__ */ jsxs(
|
|
48
|
+
"label",
|
|
49
|
+
{
|
|
50
|
+
"data-hovered": isHovered,
|
|
51
|
+
"data-pressed": isPressed,
|
|
52
|
+
"data-focused": isFocused,
|
|
53
|
+
"data-invalid": isInvalid,
|
|
54
|
+
"data-selected": isSelected,
|
|
55
|
+
"data-disabled": isDisabled,
|
|
56
|
+
"data-read-only": isReadOnly,
|
|
57
|
+
"data-focus-visible": isFocusVisible,
|
|
58
|
+
...mergeProps(DOMProps, labelProps, renderProps),
|
|
59
|
+
ref,
|
|
60
|
+
children: [
|
|
61
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { elementType: "span", children: /* @__PURE__ */ jsx("input", { ...inputProps, ref: domRef }) }),
|
|
62
|
+
renderProps.children
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
);
|
|
49
66
|
}
|
|
50
67
|
);
|
|
51
68
|
Checkbox.displayName = "Checkbox";
|
|
@@ -3,14 +3,14 @@ import type { ExtendableProps } from '@koobiq/react-core';
|
|
|
3
3
|
import type { UseCheckboxProps } from '../../behaviors';
|
|
4
4
|
import type { RenderProps } from '../../utils';
|
|
5
5
|
export type CheckboxRenderProps = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
isInvalid?: boolean;
|
|
7
|
+
isPressed?: boolean;
|
|
8
|
+
isSelected?: boolean;
|
|
9
|
+
isHovered?: boolean;
|
|
10
|
+
isFocused?: boolean;
|
|
11
|
+
isDisabled?: boolean;
|
|
12
|
+
isFocusVisible?: boolean;
|
|
13
|
+
isIndeterminate?: boolean;
|
|
14
14
|
};
|
|
15
15
|
type CheckboxBaseProps = RenderProps<CheckboxRenderProps> & {
|
|
16
16
|
inputRef?: RefObject<HTMLInputElement | null>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koobiq/react-primitives",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.24",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"@react-stately/toggle": "^3.7.0",
|
|
53
53
|
"@react-stately/tooltip": "^3.4.13",
|
|
54
54
|
"@react-stately/tree": "^3.8.9",
|
|
55
|
-
"@koobiq/logger": "0.0.1-beta.
|
|
56
|
-
"@koobiq/react-core": "0.0.1-beta.
|
|
55
|
+
"@koobiq/logger": "0.0.1-beta.24",
|
|
56
|
+
"@koobiq/react-core": "0.0.1-beta.24"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"react": "18.x || 19.x",
|