@koobiq/react-primitives 0.0.1-beta.9 → 0.0.1
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/dist/behaviors/index.d.ts +9 -11
- package/dist/behaviors/useButton.d.ts +12 -10
- package/dist/behaviors/useButton.js +11 -22
- package/dist/behaviors/useCheckbox.d.ts +10 -45
- package/dist/behaviors/useCheckbox.js +15 -38
- package/dist/behaviors/useLink.d.ts +5 -9
- package/dist/behaviors/useLink.js +8 -17
- package/dist/behaviors/useNumberField.d.ts +1 -22
- package/dist/behaviors/useNumberField.js +2 -13
- package/dist/behaviors/useRadio.d.ts +8 -35
- package/dist/behaviors/useRadio.js +12 -16
- package/dist/behaviors/useRadioGroup.d.ts +2 -55
- package/dist/behaviors/useRadioGroup.js +1 -18
- package/dist/behaviors/useRadioGroupState.d.ts +2 -42
- package/dist/behaviors/useRadioGroupState.js +1 -16
- package/dist/behaviors/useSwitch.d.ts +316 -0
- package/dist/behaviors/useSwitch.js +33 -0
- package/dist/components/Button/Button.js +17 -13
- package/dist/components/Button/types.d.ts +10 -16
- package/dist/components/Checkbox/Checkbox.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.js +36 -19
- package/dist/components/Checkbox/types.d.ts +8 -8
- package/dist/components/Group/Group.js +7 -7
- package/dist/components/Group/types.d.ts +8 -8
- package/dist/components/Link/Link.js +21 -8
- package/dist/components/Link/types.d.ts +5 -5
- package/dist/components/NumberField/NumberField.d.ts +1 -1
- package/dist/components/NumberField/NumberField.js +9 -9
- package/dist/components/NumberField/types.d.ts +4 -4
- package/dist/components/Radio/Radio.d.ts +1 -1
- package/dist/components/Radio/Radio.js +20 -13
- package/dist/components/Radio/RadioContext.d.ts +2 -17
- package/dist/components/Radio/RadioGroup.d.ts +1 -1
- package/dist/components/Radio/RadioGroup.js +4 -4
- package/dist/components/Radio/types.d.ts +16 -14
- package/dist/components/Switch/Switch.d.ts +3 -0
- package/dist/components/{Toggle/Toggle.js → Switch/Switch.js} +19 -19
- package/dist/components/Switch/index.d.ts +2 -0
- package/dist/components/Switch/types.d.ts +18 -0
- package/dist/components/TextField/TextField.d.ts +2 -1
- package/dist/components/TextField/TextField.js +58 -57
- package/dist/components/TextField/types.d.ts +11 -8
- package/dist/components/Textarea/Textarea.d.ts +2 -4
- package/dist/components/Textarea/Textarea.js +6 -2
- package/dist/components/Textarea/types.d.ts +2 -1
- package/dist/components/index.d.ts +12 -12
- package/dist/index.d.ts +30 -15
- package/dist/index.js +38 -34
- package/package.json +32 -11
- package/dist/behaviors/useNumberFieldState.d.ts +0 -25
- package/dist/behaviors/useNumberFieldState.js +0 -13
- package/dist/behaviors/useTextField.d.ts +0 -19
- package/dist/behaviors/useTextField.js +0 -24
- package/dist/behaviors/useToggle.d.ts +0 -44
- package/dist/behaviors/useToggle.js +0 -54
- package/dist/components/Toggle/Toggle.d.ts +0 -3
- package/dist/components/Toggle/index.d.ts +0 -2
- package/dist/components/Toggle/types.d.ts +0 -18
- package/dist/types.d.ts +0 -8
|
@@ -2,17 +2,17 @@ import type { ComponentRef } from 'react';
|
|
|
2
2
|
import type { ExtendableComponentPropsWithRef, ExtendableProps } from '@koobiq/react-core';
|
|
3
3
|
import type { RenderProps } from '../../utils';
|
|
4
4
|
export type GroupBaseProps = ExtendableComponentPropsWithRef<{
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
isDisabled?: boolean;
|
|
6
|
+
isInvalid?: boolean;
|
|
7
7
|
}, 'div'>;
|
|
8
8
|
export type GroupRef = ComponentRef<'div'>;
|
|
9
9
|
export type GroupRenderProps = {
|
|
10
|
-
|
|
10
|
+
isIndeterminate?: boolean;
|
|
11
11
|
percentage?: number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
isHovered: boolean;
|
|
13
|
+
isFocusWithin: boolean;
|
|
14
|
+
isFocusVisible: boolean;
|
|
15
|
+
isDisabled: boolean;
|
|
16
|
+
isInvalid: boolean;
|
|
17
17
|
};
|
|
18
18
|
export type GroupProps = ExtendableProps<RenderProps<GroupRenderProps>, GroupBaseProps>;
|
|
@@ -4,18 +4,31 @@ import { polymorphicForwardRef, useDOMRef, mergeProps } from "@koobiq/react-core
|
|
|
4
4
|
import { useRenderProps } from "../../utils/index.js";
|
|
5
5
|
import { useLink } from "../../behaviors/useLink.js";
|
|
6
6
|
const Link = polymorphicForwardRef((props, ref) => {
|
|
7
|
-
const { as: Tag = "a", ...
|
|
7
|
+
const { as: Tag = "a", ...other } = props;
|
|
8
8
|
const domRef = useDOMRef(ref);
|
|
9
|
-
const {
|
|
10
|
-
|
|
9
|
+
const { isHovered, isPressed, isFocusVisible, isFocused, linkProps } = useLink(
|
|
10
|
+
{
|
|
11
|
+
...other,
|
|
12
|
+
...other.isDisabled && {
|
|
13
|
+
onPress: void 0,
|
|
14
|
+
onPressStart: void 0,
|
|
15
|
+
onPressEnd: void 0,
|
|
16
|
+
onPressChange: void 0,
|
|
17
|
+
onPressUp: void 0,
|
|
18
|
+
onKeyDown: void 0,
|
|
19
|
+
onKeyUp: void 0,
|
|
20
|
+
onClick: void 0,
|
|
21
|
+
href: void 0
|
|
22
|
+
}
|
|
23
|
+
},
|
|
11
24
|
domRef
|
|
12
25
|
);
|
|
13
26
|
const renderValues = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
isHovered,
|
|
28
|
+
isPressed,
|
|
29
|
+
isFocused,
|
|
30
|
+
isFocusVisible,
|
|
31
|
+
isDisabled: props.isDisabled || false
|
|
19
32
|
};
|
|
20
33
|
const renderProps = useRenderProps({
|
|
21
34
|
...props,
|
|
@@ -2,11 +2,11 @@ import type { ExtendableProps } from '@koobiq/react-core';
|
|
|
2
2
|
import type { UseLinkProps } from '../../behaviors';
|
|
3
3
|
import type { RenderProps } from '../../utils';
|
|
4
4
|
export type LinkRenderProps = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
isHovered: boolean;
|
|
6
|
+
isFocused: boolean;
|
|
7
|
+
isPressed: boolean;
|
|
8
|
+
isDisabled: boolean;
|
|
9
|
+
isFocusVisible: boolean;
|
|
10
10
|
};
|
|
11
11
|
export type LinkBaseProps = ExtendableProps<RenderProps<LinkRenderProps> & {
|
|
12
12
|
tabIndex?: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const NumberField: import("react").ForwardRefExoticComponent<Omit<import("
|
|
1
|
+
export declare const NumberField: import("react").ForwardRefExoticComponent<Omit<import("@react-types/numberfield").AriaNumberFieldProps, keyof import("../..").RenderProps<import("./types").NumberFieldRenderProps>> & import("../..").RenderProps<import("./types").NumberFieldRenderProps> & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -11,7 +11,7 @@ import { InputContext } from "../Input/InputContext.js";
|
|
|
11
11
|
import { TextContext } from "../Text/TextContext.js";
|
|
12
12
|
const NumberField = forwardRef(
|
|
13
13
|
(props, ref) => {
|
|
14
|
-
const {
|
|
14
|
+
const { isDisabled, isReadOnly, isRequired, isInvalid } = props;
|
|
15
15
|
const inputRef = useRef(null);
|
|
16
16
|
const {
|
|
17
17
|
labelProps,
|
|
@@ -27,10 +27,10 @@ const NumberField = forwardRef(
|
|
|
27
27
|
const renderProps = useRenderProps({
|
|
28
28
|
...props,
|
|
29
29
|
values: {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
isInvalid: isInvalid || false,
|
|
31
|
+
isDisabled: isDisabled || false,
|
|
32
|
+
isReadonly: isReadOnly || false,
|
|
33
|
+
isRequired: isRequired || false
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
return /* @__PURE__ */ jsx(
|
|
@@ -38,10 +38,10 @@ const NumberField = forwardRef(
|
|
|
38
38
|
{
|
|
39
39
|
...DOMProps,
|
|
40
40
|
...renderProps,
|
|
41
|
-
"data-
|
|
42
|
-
"data-readonly":
|
|
43
|
-
"data-required":
|
|
44
|
-
"data-disabled":
|
|
41
|
+
"data-invalid": isInvalid || void 0,
|
|
42
|
+
"data-readonly": isReadOnly || void 0,
|
|
43
|
+
"data-required": isRequired || void 0,
|
|
44
|
+
"data-disabled": isDisabled || void 0,
|
|
45
45
|
ref,
|
|
46
46
|
children: /* @__PURE__ */ jsx(
|
|
47
47
|
Provider,
|
|
@@ -7,22 +7,22 @@ export type NumberFieldRenderProps = {
|
|
|
7
7
|
* Whether the text field is disabled.
|
|
8
8
|
* @selector [data-disabled]
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
isDisabled: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Whether the value is invalid.
|
|
13
13
|
* @selector [data-error]
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
isInvalid: boolean;
|
|
16
16
|
/**
|
|
17
17
|
* Whether the text field is read only.
|
|
18
18
|
* @selector [data-readonly]
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
isReadonly: boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Whether the text field is required.
|
|
23
23
|
* @selector [data-required]
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
isRequired: boolean;
|
|
26
26
|
};
|
|
27
27
|
type NumberFieldBaseProps = RenderProps<NumberFieldRenderProps>;
|
|
28
28
|
export type NumberFieldProps = ExtendableProps<NumberFieldBaseProps, UseNumberFieldProps>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export declare const Radio: import("react").ForwardRefExoticComponent<Omit<import("
|
|
1
|
+
export declare const Radio: import("react").ForwardRefExoticComponent<Omit<import("@react-types/radio").AriaRadioProps, "inputRef" | keyof import("../..").RenderProps<import("./types").RadioRenderProps>> & import("../..").RenderProps<import("./types").RadioRenderProps> & {
|
|
2
2
|
inputRef?: import("react").RefObject<HTMLInputElement | null>;
|
|
3
3
|
} & import("react").RefAttributes<HTMLLabelElement>>;
|
|
@@ -8,13 +8,20 @@ import { RadioContext } from "./RadioContext.js";
|
|
|
8
8
|
import { useRadio } from "../../behaviors/useRadio.js";
|
|
9
9
|
const Radio = forwardRef(
|
|
10
10
|
(props, ref) => {
|
|
11
|
-
const { children, inputRef
|
|
11
|
+
const { children, inputRef } = props;
|
|
12
12
|
const state = useContext(RadioContext);
|
|
13
|
-
const {
|
|
14
|
-
const checked = selectedValue === props.value;
|
|
15
|
-
const disabled = disabledProp || disabledState;
|
|
13
|
+
const { isInvalid } = state;
|
|
16
14
|
const domRef = useDOMRef(inputRef);
|
|
17
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
isHovered,
|
|
17
|
+
isFocused,
|
|
18
|
+
isPressed,
|
|
19
|
+
isDisabled,
|
|
20
|
+
isSelected,
|
|
21
|
+
labelProps,
|
|
22
|
+
inputProps,
|
|
23
|
+
isFocusVisible
|
|
24
|
+
} = useRadio(
|
|
18
25
|
{
|
|
19
26
|
...removeDataAttributes(props),
|
|
20
27
|
children: typeof children === "function" ? true : children
|
|
@@ -23,13 +30,13 @@ const Radio = forwardRef(
|
|
|
23
30
|
domRef
|
|
24
31
|
);
|
|
25
32
|
const renderValues = {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
isInvalid,
|
|
34
|
+
isHovered,
|
|
35
|
+
isSelected,
|
|
36
|
+
isFocused,
|
|
37
|
+
isPressed,
|
|
38
|
+
isDisabled,
|
|
39
|
+
isFocusVisible
|
|
33
40
|
};
|
|
34
41
|
const renderProps = useRenderProps({
|
|
35
42
|
...props,
|
|
@@ -38,7 +45,7 @@ const Radio = forwardRef(
|
|
|
38
45
|
const DOMProps = filterDOMProps(props);
|
|
39
46
|
delete DOMProps.id;
|
|
40
47
|
return /* @__PURE__ */ jsxs("label", { ...mergeProps(DOMProps, labelProps, renderProps), ref, children: [
|
|
41
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", { ...inputProps, ref: domRef }) }),
|
|
48
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { elementType: "span", children: /* @__PURE__ */ jsx("input", { ...inputProps, ref: domRef }) }),
|
|
42
49
|
renderProps.children
|
|
43
50
|
] });
|
|
44
51
|
}
|
|
@@ -1,17 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
validationState: import("@react-types/shared").ValidationState | null;
|
|
4
|
-
selectedValue: string | null;
|
|
5
|
-
setSelectedValue(value: string | null): void;
|
|
6
|
-
lastFocusedValue: string | null;
|
|
7
|
-
setLastFocusedValue(value: string | null): void;
|
|
8
|
-
realtimeValidation: import("@react-types/shared").ValidationResult;
|
|
9
|
-
displayValidation: import("@react-types/shared").ValidationResult;
|
|
10
|
-
updateValidation(result: import("@react-types/shared").ValidationResult): void;
|
|
11
|
-
resetValidation(): void;
|
|
12
|
-
commitValidation(): void;
|
|
13
|
-
error: boolean;
|
|
14
|
-
readonly: boolean;
|
|
15
|
-
required: boolean;
|
|
16
|
-
disabled: boolean;
|
|
17
|
-
}>;
|
|
1
|
+
import type { RadioGroupState } from '@react-stately/radio';
|
|
2
|
+
export declare const RadioContext: import("react").Context<RadioGroupState>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const RadioGroup: import("react").ForwardRefExoticComponent<Omit<import("
|
|
1
|
+
export declare const RadioGroup: import("react").ForwardRefExoticComponent<Omit<import("@react-types/radio").AriaRadioGroupProps, keyof import("../..").RenderProps<import("./types").RadioGroupRenderProps>> & import("../..").RenderProps<import("./types").RadioGroupRenderProps> & import("react").RefAttributes<HTMLDivElement>>;
|
|
@@ -18,10 +18,10 @@ const RadioGroup = forwardRef(
|
|
|
18
18
|
...props,
|
|
19
19
|
values: {
|
|
20
20
|
orientation: props.orientation || "vertical",
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
isDisabled: state.isDisabled,
|
|
22
|
+
isReadOnly: state.isReadOnly,
|
|
23
|
+
isRequired: state.isRequired,
|
|
24
|
+
isInvalid: state.isInvalid,
|
|
25
25
|
state
|
|
26
26
|
}
|
|
27
27
|
});
|
|
@@ -1,22 +1,24 @@
|
|
|
1
1
|
import type { RefObject } from 'react';
|
|
2
2
|
import type { ExtendableProps } from '@koobiq/react-core';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AriaRadioGroupProps } from '@react-aria/radio';
|
|
4
|
+
import type { RadioGroupState } from '@react-stately/radio';
|
|
5
|
+
import type { UseRadioProps } from '../../behaviors';
|
|
4
6
|
import type { RenderProps } from '../../utils';
|
|
5
7
|
export type RadioRenderProps = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
isInvalid?: boolean;
|
|
9
|
+
isFocused?: boolean;
|
|
10
|
+
isHovered?: boolean;
|
|
11
|
+
isPressed?: boolean;
|
|
12
|
+
isSelected?: boolean;
|
|
13
|
+
isDisabled?: boolean;
|
|
14
|
+
isFocusVisible?: boolean;
|
|
15
|
+
isIndeterminate?: boolean;
|
|
14
16
|
};
|
|
15
17
|
export type RadioGroupRenderProps = {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
isInvalid: boolean;
|
|
19
|
+
isDisabled: boolean;
|
|
20
|
+
isReadOnly: boolean;
|
|
21
|
+
isRequired: boolean;
|
|
20
22
|
state: RadioGroupState;
|
|
21
23
|
orientation: 'horizontal' | 'vertical';
|
|
22
24
|
};
|
|
@@ -25,5 +27,5 @@ type RadioBaseProps = RenderProps<RadioRenderProps> & {
|
|
|
25
27
|
};
|
|
26
28
|
export type RadioProps = ExtendableProps<RadioBaseProps, UseRadioProps>;
|
|
27
29
|
type RadioGroupBaseProps = RenderProps<RadioGroupRenderProps>;
|
|
28
|
-
export type RadioGroupProps = ExtendableProps<RadioGroupBaseProps,
|
|
30
|
+
export type RadioGroupProps = ExtendableProps<RadioGroupBaseProps, AriaRadioGroupProps>;
|
|
29
31
|
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const Switch: import("react").ForwardRefExoticComponent<Omit<import("../..").UseSwitchProps, "inputRef" | keyof import("../..").RenderProps<import("./types").SwitchRenderProps>> & import("../..").RenderProps<import("./types").SwitchRenderProps> & {
|
|
2
|
+
inputRef?: import("react").RefObject<HTMLInputElement | null>;
|
|
3
|
+
} & import("react").RefAttributes<HTMLLabelElement>>;
|
|
@@ -4,21 +4,21 @@ import { forwardRef } from "react";
|
|
|
4
4
|
import { useDOMRef, filterDOMProps, mergeProps } from "@koobiq/react-core";
|
|
5
5
|
import { VisuallyHidden } from "@react-aria/visually-hidden";
|
|
6
6
|
import { removeDataAttributes, useRenderProps } from "../../utils/index.js";
|
|
7
|
-
import {
|
|
8
|
-
const
|
|
7
|
+
import { useSwitch } from "../../behaviors/useSwitch.js";
|
|
8
|
+
const Switch = forwardRef(
|
|
9
9
|
(props, ref) => {
|
|
10
10
|
const { children, inputRef } = props;
|
|
11
11
|
const domRef = useDOMRef(inputRef);
|
|
12
12
|
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
isHovered,
|
|
14
|
+
isInvalid,
|
|
15
|
+
isSelected,
|
|
16
|
+
isFocused,
|
|
17
|
+
isPressed,
|
|
18
|
+
isFocusVisible,
|
|
19
19
|
labelProps,
|
|
20
20
|
inputProps
|
|
21
|
-
} =
|
|
21
|
+
} = useSwitch(
|
|
22
22
|
{
|
|
23
23
|
...removeDataAttributes(props),
|
|
24
24
|
children: typeof children === "function" ? true : children
|
|
@@ -26,13 +26,13 @@ const Toggle = forwardRef(
|
|
|
26
26
|
domRef
|
|
27
27
|
);
|
|
28
28
|
const renderValues = {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
isHovered,
|
|
30
|
+
isInvalid,
|
|
31
|
+
isSelected,
|
|
32
|
+
isFocused,
|
|
33
|
+
isPressed,
|
|
34
|
+
isFocusVisible,
|
|
35
|
+
isDisabled: props.isDisabled || false
|
|
36
36
|
};
|
|
37
37
|
const renderProps = useRenderProps({
|
|
38
38
|
...props,
|
|
@@ -41,12 +41,12 @@ const Toggle = forwardRef(
|
|
|
41
41
|
const DOMProps = filterDOMProps(props);
|
|
42
42
|
delete DOMProps.id;
|
|
43
43
|
return /* @__PURE__ */ jsxs("label", { ...mergeProps(DOMProps, labelProps, renderProps), ref, children: [
|
|
44
|
-
/* @__PURE__ */ jsx(VisuallyHidden, { children: /* @__PURE__ */ jsx("input", { ...inputProps, ref: domRef }) }),
|
|
44
|
+
/* @__PURE__ */ jsx(VisuallyHidden, { elementType: "span", children: /* @__PURE__ */ jsx("input", { ...inputProps, ref: domRef }) }),
|
|
45
45
|
renderProps.children
|
|
46
46
|
] });
|
|
47
47
|
}
|
|
48
48
|
);
|
|
49
|
-
|
|
49
|
+
Switch.displayName = "Switch";
|
|
50
50
|
export {
|
|
51
|
-
|
|
51
|
+
Switch
|
|
52
52
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RefObject } from 'react';
|
|
2
|
+
import type { ExtendableProps } from '@koobiq/react-core';
|
|
3
|
+
import type { UseSwitchProps } from '../../behaviors';
|
|
4
|
+
import type { RenderProps } from '../../utils';
|
|
5
|
+
export type SwitchRenderProps = {
|
|
6
|
+
isInvalid?: boolean;
|
|
7
|
+
isPressed?: boolean;
|
|
8
|
+
isSelected?: boolean;
|
|
9
|
+
isHovered?: boolean;
|
|
10
|
+
isFocused?: boolean;
|
|
11
|
+
isDisabled?: boolean;
|
|
12
|
+
isFocusVisible?: boolean;
|
|
13
|
+
};
|
|
14
|
+
type SwitchBaseProps = RenderProps<SwitchRenderProps> & {
|
|
15
|
+
inputRef?: RefObject<HTMLInputElement | null>;
|
|
16
|
+
};
|
|
17
|
+
export type SwitchProps = ExtendableProps<SwitchBaseProps, UseSwitchProps>;
|
|
18
|
+
export {};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TextFieldComponentProps } from './index';
|
|
2
|
+
export declare const TextField: TextFieldComponentProps;
|
|
@@ -2,69 +2,70 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef, useRef } from "react";
|
|
4
4
|
import { filterDOMProps } from "@koobiq/react-core";
|
|
5
|
+
import { useTextField } from "@react-aria/textfield";
|
|
5
6
|
import { removeDataAttributes, useRenderProps, Provider } from "../../utils/index.js";
|
|
6
|
-
import { useTextField } from "../../behaviors/useTextField.js";
|
|
7
7
|
import { InputContext } from "../Input/InputContext.js";
|
|
8
8
|
import { TextareaContext } from "../Textarea/TextareaContext.js";
|
|
9
9
|
import { LabelContext } from "../Label/LabelContext.js";
|
|
10
10
|
import { TextContext } from "../Text/TextContext.js";
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
11
|
+
function TextFieldRender(props, ref) {
|
|
12
|
+
const { isDisabled, isReadOnly, isRequired } = props;
|
|
13
|
+
const inputRef = useRef(null);
|
|
14
|
+
const {
|
|
15
|
+
isInvalid,
|
|
16
|
+
labelProps,
|
|
17
|
+
inputProps,
|
|
18
|
+
descriptionProps,
|
|
19
|
+
errorMessageProps
|
|
20
|
+
} = useTextField(
|
|
21
|
+
{ ...removeDataAttributes(props) },
|
|
22
|
+
inputRef
|
|
23
|
+
);
|
|
24
|
+
const DOMProps = filterDOMProps(props);
|
|
25
|
+
delete DOMProps.id;
|
|
26
|
+
const renderProps = useRenderProps({
|
|
27
|
+
...props,
|
|
28
|
+
values: {
|
|
29
|
+
isInvalid: isInvalid || false,
|
|
30
|
+
isDisabled: isDisabled || false,
|
|
31
|
+
isReadOnly: isReadOnly || false,
|
|
32
|
+
isRequired: isRequired || false
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
return /* @__PURE__ */ jsx(
|
|
36
|
+
"div",
|
|
37
|
+
{
|
|
38
|
+
...DOMProps,
|
|
39
|
+
...renderProps,
|
|
40
|
+
"data-invalid": isInvalid || void 0,
|
|
41
|
+
"data-readonly": isReadOnly || void 0,
|
|
42
|
+
"data-required": isRequired || void 0,
|
|
43
|
+
"data-disabled": isDisabled || void 0,
|
|
44
|
+
ref,
|
|
45
|
+
children: /* @__PURE__ */ jsx(
|
|
46
|
+
Provider,
|
|
47
|
+
{
|
|
48
|
+
values: [
|
|
49
|
+
[LabelContext, labelProps],
|
|
50
|
+
[InputContext, { ...inputProps, ref: inputRef }],
|
|
51
|
+
[TextareaContext, { ...inputProps, ref: inputRef }],
|
|
52
|
+
[
|
|
53
|
+
TextContext,
|
|
54
|
+
{
|
|
55
|
+
slots: {
|
|
56
|
+
description: descriptionProps,
|
|
57
|
+
errorMessage: errorMessageProps
|
|
57
58
|
}
|
|
58
|
-
|
|
59
|
-
]
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
TextField
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
],
|
|
62
|
+
children: renderProps.children
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
const TextField = forwardRef(TextFieldRender);
|
|
68
69
|
export {
|
|
69
70
|
TextField
|
|
70
71
|
};
|
|
@@ -1,30 +1,33 @@
|
|
|
1
|
-
import type { ComponentRef } from 'react';
|
|
1
|
+
import type { ComponentRef, ReactElement } from 'react';
|
|
2
2
|
import type { ExtendableProps } from '@koobiq/react-core';
|
|
3
|
-
import type {
|
|
3
|
+
import type { AriaTextFieldProps } from '@react-aria/textfield';
|
|
4
4
|
import type { RenderProps } from '../../utils';
|
|
5
5
|
export type TextFieldRenderProps = {
|
|
6
6
|
/**
|
|
7
7
|
* Whether the text field is disabled.
|
|
8
8
|
* @selector [data-disabled]
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
isDisabled: boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Whether the value is invalid.
|
|
13
13
|
* @selector [data-error]
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
isInvalid: boolean;
|
|
16
16
|
/**
|
|
17
17
|
* Whether the text field is read only.
|
|
18
18
|
* @selector [data-readonly]
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
isReadOnly: boolean;
|
|
21
21
|
/**
|
|
22
22
|
* Whether the text field is required.
|
|
23
23
|
* @selector [data-required]
|
|
24
24
|
*/
|
|
25
|
-
|
|
25
|
+
isRequired: boolean;
|
|
26
26
|
};
|
|
27
|
-
type TextFieldBaseProps = RenderProps<TextFieldRenderProps
|
|
28
|
-
|
|
27
|
+
type TextFieldBaseProps = RenderProps<TextFieldRenderProps> & {
|
|
28
|
+
inputElementType?: 'input' | 'textarea';
|
|
29
|
+
};
|
|
30
|
+
export type TextFieldProps<T = HTMLInputElement> = ExtendableProps<TextFieldBaseProps, AriaTextFieldProps<T>>;
|
|
31
|
+
export type TextFieldComponentProps = <T = HTMLInputElement>(props: TextFieldProps<T>) => ReactElement | null;
|
|
29
32
|
export type TextFieldRef = ComponentRef<'div'>;
|
|
30
33
|
export {};
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
value?: string | number | readonly string[];
|
|
4
|
-
} & import("react").HTMLAttributes<HTMLInputElement | HTMLTextAreaElement> & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
1
|
+
import { type TextareaProps } from './index';
|
|
2
|
+
export declare const Textarea: import("react").ForwardRefExoticComponent<Omit<TextareaProps, "ref"> & import("react").RefAttributes<HTMLTextAreaElement>>;
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { forwardRef } from "react";
|
|
4
|
-
import { mergeProps } from "@koobiq/react-core";
|
|
4
|
+
import { mergeProps, useMultiRef } from "@koobiq/react-core";
|
|
5
5
|
import { useTextareaContext } from "./TextareaContext.js";
|
|
6
6
|
const Textarea = forwardRef((props, ref) => {
|
|
7
7
|
const { children, ...other } = props;
|
|
8
8
|
const defaultProps = useTextareaContext();
|
|
9
9
|
const commonProps = mergeProps(defaultProps, other);
|
|
10
|
-
|
|
10
|
+
const innerRef = useMultiRef([
|
|
11
|
+
ref,
|
|
12
|
+
...defaultProps.ref ? [defaultProps.ref] : []
|
|
13
|
+
]);
|
|
14
|
+
return /* @__PURE__ */ jsx("textarea", { ...commonProps, ref: innerRef, children });
|
|
11
15
|
});
|
|
12
16
|
Textarea.displayName = "Textarea";
|
|
13
17
|
export {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { ComponentRef, HTMLAttributes, ReactNode } from 'react';
|
|
1
|
+
import type { ComponentRef, HTMLAttributes, ReactNode, Ref } from 'react';
|
|
2
2
|
export type TextareaProps = {
|
|
3
3
|
children?: ReactNode;
|
|
4
4
|
value?: string | number | readonly string[];
|
|
5
|
+
ref?: Ref<HTMLTextAreaElement>;
|
|
5
6
|
} & HTMLAttributes<HTMLInputElement | HTMLTextAreaElement>;
|
|
6
7
|
export type TextareaRef = ComponentRef<'textarea'>;
|