@koobiq/react-primitives 0.0.1-beta.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.
Files changed (102) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/behaviors/index.d.ts +11 -0
  4. package/dist/behaviors/useButton.d.ts +12 -0
  5. package/dist/behaviors/useButton.js +37 -0
  6. package/dist/behaviors/useCheckbox.d.ts +56 -0
  7. package/dist/behaviors/useCheckbox.js +66 -0
  8. package/dist/behaviors/useLink.d.ts +15 -0
  9. package/dist/behaviors/useLink.js +35 -0
  10. package/dist/behaviors/useNumberField.d.ts +26 -0
  11. package/dist/behaviors/useNumberField.js +22 -0
  12. package/dist/behaviors/useNumberFieldState.d.ts +25 -0
  13. package/dist/behaviors/useNumberFieldState.js +13 -0
  14. package/dist/behaviors/useProgressBar.d.ts +7 -0
  15. package/dist/behaviors/useProgressBar.js +9 -0
  16. package/dist/behaviors/useRadio.d.ts +45 -0
  17. package/dist/behaviors/useRadio.js +46 -0
  18. package/dist/behaviors/useRadioGroup.d.ts +55 -0
  19. package/dist/behaviors/useRadioGroup.js +22 -0
  20. package/dist/behaviors/useRadioGroupState.d.ts +42 -0
  21. package/dist/behaviors/useRadioGroupState.js +20 -0
  22. package/dist/behaviors/useTextField.d.ts +19 -0
  23. package/dist/behaviors/useTextField.js +24 -0
  24. package/dist/behaviors/useToggle.d.ts +44 -0
  25. package/dist/behaviors/useToggle.js +54 -0
  26. package/dist/components/Button/Button.d.ts +4 -0
  27. package/dist/components/Button/Button.js +84 -0
  28. package/dist/components/Button/ButtonContext.d.ts +5 -0
  29. package/dist/components/Button/ButtonContext.js +5 -0
  30. package/dist/components/Button/index.d.ts +3 -0
  31. package/dist/components/Button/types.d.ts +43 -0
  32. package/dist/components/Checkbox/Checkbox.d.ts +3 -0
  33. package/dist/components/Checkbox/Checkbox.js +54 -0
  34. package/dist/components/Checkbox/index.d.ts +2 -0
  35. package/dist/components/Checkbox/types.d.ts +19 -0
  36. package/dist/components/Group/Group.d.ts +2 -0
  37. package/dist/components/Group/Group.js +43 -0
  38. package/dist/components/Group/GroupContext.d.ts +3 -0
  39. package/dist/components/Group/GroupContext.js +7 -0
  40. package/dist/components/Group/index.d.ts +3 -0
  41. package/dist/components/Group/types.d.ts +18 -0
  42. package/dist/components/Input/Input.d.ts +2 -0
  43. package/dist/components/Input/Input.js +19 -0
  44. package/dist/components/Input/InputContext.d.ts +3 -0
  45. package/dist/components/Input/InputContext.js +7 -0
  46. package/dist/components/Input/index.d.ts +3 -0
  47. package/dist/components/Input/types.d.ts +7 -0
  48. package/dist/components/Label/Label.d.ts +4 -0
  49. package/dist/components/Label/Label.js +17 -0
  50. package/dist/components/Label/LabelContext.d.ts +5 -0
  51. package/dist/components/Label/LabelContext.js +5 -0
  52. package/dist/components/Label/index.d.ts +3 -0
  53. package/dist/components/Label/types.d.ts +4 -0
  54. package/dist/components/Link/Link.d.ts +2 -0
  55. package/dist/components/Link/Link.js +29 -0
  56. package/dist/components/Link/index.d.ts +2 -0
  57. package/dist/components/Link/types.d.ts +11 -0
  58. package/dist/components/NumberField/NumberField.d.ts +1 -0
  59. package/dist/components/NumberField/NumberField.js +88 -0
  60. package/dist/components/NumberField/index.d.ts +2 -0
  61. package/dist/components/NumberField/types.d.ts +30 -0
  62. package/dist/components/ProgressBar/ProgressBar.d.ts +2 -0
  63. package/dist/components/ProgressBar/ProgressBar.js +33 -0
  64. package/dist/components/ProgressBar/index.d.ts +2 -0
  65. package/dist/components/ProgressBar/types.d.ts +8 -0
  66. package/dist/components/Radio/Radio.d.ts +3 -0
  67. package/dist/components/Radio/Radio.js +49 -0
  68. package/dist/components/Radio/RadioContext.d.ts +17 -0
  69. package/dist/components/Radio/RadioContext.js +7 -0
  70. package/dist/components/Radio/RadioGroup.d.ts +1 -0
  71. package/dist/components/Radio/RadioGroup.js +51 -0
  72. package/dist/components/Radio/index.d.ts +4 -0
  73. package/dist/components/Radio/types.d.ts +29 -0
  74. package/dist/components/Text/Text.d.ts +5 -0
  75. package/dist/components/Text/Text.js +14 -0
  76. package/dist/components/Text/TextContext.d.ts +5 -0
  77. package/dist/components/Text/TextContext.js +5 -0
  78. package/dist/components/Text/index.d.ts +3 -0
  79. package/dist/components/Text/types.d.ts +6 -0
  80. package/dist/components/TextField/TextField.d.ts +1 -0
  81. package/dist/components/TextField/TextField.js +70 -0
  82. package/dist/components/TextField/index.d.ts +2 -0
  83. package/dist/components/TextField/types.d.ts +30 -0
  84. package/dist/components/Textarea/Textarea.d.ts +4 -0
  85. package/dist/components/Textarea/Textarea.js +15 -0
  86. package/dist/components/Textarea/TextareaContext.d.ts +3 -0
  87. package/dist/components/Textarea/TextareaContext.js +7 -0
  88. package/dist/components/Textarea/index.d.ts +3 -0
  89. package/dist/components/Textarea/types.d.ts +6 -0
  90. package/dist/components/Toggle/Toggle.d.ts +3 -0
  91. package/dist/components/Toggle/Toggle.js +52 -0
  92. package/dist/components/Toggle/index.d.ts +2 -0
  93. package/dist/components/Toggle/types.d.ts +18 -0
  94. package/dist/components/index.d.ts +13 -0
  95. package/dist/index.d.ts +12 -0
  96. package/dist/index.js +88 -0
  97. package/dist/types.d.ts +8 -0
  98. package/dist/utils/index.d.ts +41 -0
  99. package/dist/utils/index.js +72 -0
  100. package/dist/utils/useSlottedContext.d.ts +4 -0
  101. package/dist/utils/useSlottedContext.js +11 -0
  102. package/package.json +52 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Koobiq
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @koobiq/react-primitives
@@ -0,0 +1,11 @@
1
+ export * from './useButton.js';
2
+ export * from './useCheckbox.js';
3
+ export * from './useLink.js';
4
+ export * from './useTextField.js';
5
+ export * from './useToggle.js';
6
+ export * from './useRadio.js';
7
+ export * from './useRadioGroup.js';
8
+ export * from './useRadioGroupState.js';
9
+ export * from './useProgressBar.js';
10
+ export * from './useNumberField.js';
11
+ export * from './useNumberFieldState.js';
@@ -0,0 +1,12 @@
1
+ import type { RefObject } from 'react';
2
+ import type { ButtonOptions } from '../types';
3
+ export type UseButtonProps = ButtonOptions;
4
+ export declare function useButton(props: UseButtonProps, ref: RefObject<Element | null>): {
5
+ pressed: boolean;
6
+ hovered: boolean;
7
+ focused: boolean;
8
+ disabled: boolean | undefined;
9
+ buttonProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement>;
10
+ focusVisible: boolean;
11
+ };
12
+ export type UseButtonReturn = ReturnType<typeof useButton>;
@@ -0,0 +1,37 @@
1
+ "use client";
2
+ import { useFocusRing, useHover, mergeProps } from "@koobiq/react-core";
3
+ import { useButton as useButton$1 } from "@react-aria/button";
4
+ function useButton(props, ref) {
5
+ const { onClick, onPress, disabled, ...otherProps } = props;
6
+ const {
7
+ focusProps,
8
+ isFocused: focused,
9
+ isFocusVisible: focusVisible
10
+ } = useFocusRing({
11
+ within: true
12
+ });
13
+ const { hoverProps, isHovered: hovered } = useHover({
14
+ ...props,
15
+ isDisabled: disabled
16
+ });
17
+ const { buttonProps: commonButtonProps, isPressed: pressed } = useButton$1(
18
+ {
19
+ ...otherProps,
20
+ onPress: onPress || onClick,
21
+ isDisabled: disabled
22
+ },
23
+ ref
24
+ );
25
+ const buttonProps = mergeProps(commonButtonProps, focusProps, hoverProps);
26
+ return {
27
+ pressed,
28
+ hovered,
29
+ focused,
30
+ disabled,
31
+ buttonProps,
32
+ focusVisible
33
+ };
34
+ }
35
+ export {
36
+ useButton
37
+ };
@@ -0,0 +1,56 @@
1
+ import type { RefObject } from 'react';
2
+ import type { ExtendableProps } from '@koobiq/react-core';
3
+ import type { AriaCheckboxProps } from '@react-aria/checkbox';
4
+ export type UseCheckboxProps = ExtendableProps<{
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'>>;
39
+ export declare function useCheckbox(props: UseCheckboxProps, inputRef: RefObject<HTMLInputElement | null>): {
40
+ validationErrors: string[];
41
+ validationDetails: ValidityState;
42
+ labelProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & import("react").LabelHTMLAttributes<HTMLLabelElement>;
43
+ inputProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & import("react").InputHTMLAttributes<HTMLInputElement> & {
44
+ ref: RefObject<HTMLInputElement | null>;
45
+ };
46
+ indeterminate: boolean | undefined;
47
+ error: boolean;
48
+ pressed: boolean;
49
+ hovered: boolean;
50
+ focused: boolean;
51
+ checked: boolean;
52
+ disabled: boolean;
53
+ readonly: boolean;
54
+ focusVisible: boolean;
55
+ };
56
+ export type UseCheckboxReturn = ReturnType<typeof useCheckbox>;
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import { useToggleState, useHover, useFocusRing, mergeProps } from "@koobiq/react-core";
3
+ import { useCheckbox as useCheckbox$1 } from "@react-aria/checkbox";
4
+ function useCheckbox(props, inputRef) {
5
+ const {
6
+ error,
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
+ });
20
+ const { hoverProps, isHovered } = useHover({
21
+ isDisabled: disabled
22
+ });
23
+ const { focusProps, isFocused, isFocusVisible } = useFocusRing();
24
+ const {
25
+ labelProps: commonLabelProps,
26
+ inputProps: commonInputProps,
27
+ isInvalid,
28
+ isDisabled,
29
+ isSelected,
30
+ isReadOnly,
31
+ isPressed,
32
+ ...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
+ );
45
+ const labelProps = mergeProps(hoverProps, commonLabelProps);
46
+ const inputProps = mergeProps(focusProps, commonInputProps, {
47
+ ref: inputRef
48
+ });
49
+ return {
50
+ labelProps,
51
+ inputProps,
52
+ indeterminate,
53
+ error: isInvalid,
54
+ pressed: isPressed,
55
+ hovered: isHovered,
56
+ focused: isFocused,
57
+ checked: isSelected,
58
+ disabled: isDisabled,
59
+ readonly: isReadOnly,
60
+ focusVisible: isFocusVisible,
61
+ ...other
62
+ };
63
+ }
64
+ export {
65
+ useCheckbox
66
+ };
@@ -0,0 +1,15 @@
1
+ import type { RefObject } from 'react';
2
+ import type { ExtendableProps } from '@koobiq/react-core';
3
+ import type { AriaLinkOptions } from '@react-aria/link';
4
+ export type UseLinkProps = ExtendableProps<{
5
+ disabled?: boolean;
6
+ onClick?: AriaLinkOptions['onPress'];
7
+ }, Omit<AriaLinkOptions, 'isDisabled'>>;
8
+ export declare function useLink(props: UseLinkProps, ref: RefObject<HTMLElement | null>): {
9
+ linkProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement>;
10
+ pressed: boolean;
11
+ hovered: boolean;
12
+ focused: boolean;
13
+ focusVisible: boolean;
14
+ };
15
+ export type UseLinkReturn = ReturnType<typeof useLink>;
@@ -0,0 +1,35 @@
1
+ "use client";
2
+ import { useHover, useFocusRing, mergeProps } from "@koobiq/react-core";
3
+ import { useLink as useLink$1 } from "@react-aria/link";
4
+ function useLink(props, ref) {
5
+ const { disabled, onClick, ...otherProps } = props;
6
+ const { hoverProps, isHovered } = useHover({
7
+ ...otherProps,
8
+ isDisabled: disabled
9
+ });
10
+ const { focusProps, isFocused, isFocusVisible } = useFocusRing();
11
+ const { linkProps: commonLinkProps, isPressed } = useLink$1(
12
+ {
13
+ ...otherProps,
14
+ onPress: onClick,
15
+ isDisabled: disabled
16
+ },
17
+ ref
18
+ );
19
+ const linkProps = mergeProps(
20
+ { disabled },
21
+ focusProps,
22
+ hoverProps,
23
+ commonLinkProps
24
+ );
25
+ return {
26
+ linkProps,
27
+ pressed: isPressed,
28
+ hovered: isHovered,
29
+ focused: isFocused,
30
+ focusVisible: isFocusVisible
31
+ };
32
+ }
33
+ export {
34
+ useLink
35
+ };
@@ -0,0 +1,26 @@
1
+ import type { RefObject } from 'react';
2
+ import type { ExtendableProps } from '@koobiq/react-core';
3
+ import type { AriaNumberFieldProps } from '@react-aria/numberfield';
4
+ export type UseNumberFieldProps = ExtendableProps<{
5
+ /**
6
+ * If `true`, the component is disabled.
7
+ * @default false
8
+ * */
9
+ disabled?: boolean;
10
+ /** It prevents the user from changing the value of the checkbox.
11
+ * @default false
12
+ */
13
+ readonly?: boolean;
14
+ /**
15
+ * If `true`, the input element is required.
16
+ * @default false
17
+ * */
18
+ required?: boolean;
19
+ /**
20
+ * If `true`, the component will indicate an error.
21
+ * @default false
22
+ * */
23
+ error?: boolean;
24
+ }, Omit<AriaNumberFieldProps, 'isDisabled' | 'isInvalid' | 'isRequired' | 'isReadOnly' | 'isWheelDisabled'>>;
25
+ export declare function useNumberField(props: UseNumberFieldProps, ref: RefObject<HTMLInputElement | null>): import("@react-aria/numberfield").NumberFieldAria;
26
+ export type UseNumberFieldReturn = ReturnType<typeof useNumberField>;
@@ -0,0 +1,22 @@
1
+ import { useLocale } from "@react-aria/i18n";
2
+ import { useNumberField as useNumberField$1 } from "@react-aria/numberfield";
3
+ import { useNumberFieldState } from "./useNumberFieldState.js";
4
+ function useNumberField(props, ref) {
5
+ const { disabled, error, readonly, required, ...other } = props;
6
+ const { locale } = useLocale();
7
+ const state = useNumberFieldState({ ...props, locale });
8
+ return useNumberField$1(
9
+ {
10
+ isDisabled: disabled,
11
+ isReadOnly: readonly,
12
+ isRequired: required,
13
+ isInvalid: error,
14
+ ...other
15
+ },
16
+ state,
17
+ ref
18
+ );
19
+ }
20
+ export {
21
+ useNumberField
22
+ };
@@ -0,0 +1,25 @@
1
+ import type { ExtendableProps } from '@koobiq/react-core';
2
+ import type { NumberFieldStateOptions } from '@react-stately/numberfield';
3
+ export type UseNumberFieldStateProps = ExtendableProps<{
4
+ /**
5
+ * If `true`, the component is disabled.
6
+ * @default false
7
+ * */
8
+ disabled?: boolean;
9
+ /** It prevents the user from changing the value of the checkbox.
10
+ * @default false
11
+ */
12
+ readonly?: boolean;
13
+ /**
14
+ * If `true`, the input element is required.
15
+ * @default false
16
+ * */
17
+ required?: boolean;
18
+ /**
19
+ * If `true`, the component will indicate an error.
20
+ * @default false
21
+ * */
22
+ error?: boolean;
23
+ }, Omit<NumberFieldStateOptions, 'isDisabled' | 'isReadOnly' | 'isRequired' | 'isInvalid'>>;
24
+ export declare function useNumberFieldState(props: UseNumberFieldStateProps): import("@react-stately/numberfield").NumberFieldState;
25
+ export type UseNumberFieldStateReturn = ReturnType<typeof useNumberFieldState>;
@@ -0,0 +1,13 @@
1
+ import { useNumberFieldState as useNumberFieldState$1 } from "@react-stately/numberfield";
2
+ function useNumberFieldState(props) {
3
+ return useNumberFieldState$1({
4
+ ...props,
5
+ isInvalid: props.error || false,
6
+ isReadOnly: props.readonly || false,
7
+ isDisabled: props.disabled || false,
8
+ isRequired: props.required || false
9
+ });
10
+ }
11
+ export {
12
+ useNumberFieldState
13
+ };
@@ -0,0 +1,7 @@
1
+ import type { ExtendableProps } from '@koobiq/react-core';
2
+ import type { AriaProgressBarProps } from '@react-aria/progress';
3
+ export type UseProgressBarProps = ExtendableProps<Omit<AriaProgressBarProps, 'isIndeterminate'>, {
4
+ indeterminate?: boolean;
5
+ }>;
6
+ export declare function useProgressBar(props: UseProgressBarProps): import("@react-aria/progress").ProgressBarAria;
7
+ export type UseProgressBarReturn = ReturnType<typeof useProgressBar>;
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import { useProgressBar as useProgressBar$1 } from "@react-aria/progress";
3
+ function useProgressBar(props) {
4
+ const { indeterminate, ...other } = props;
5
+ return useProgressBar$1({ ...other, isIndeterminate: indeterminate });
6
+ }
7
+ export {
8
+ useProgressBar
9
+ };
@@ -0,0 +1,45 @@
1
+ import type { RefObject } from 'react';
2
+ import type { ExtendableProps } from '@koobiq/react-core';
3
+ import type { AriaRadioProps } from '@react-aria/radio';
4
+ import type { RadioGroupState } from '@react-stately/radio';
5
+ export type UseRadioProps = ExtendableProps<{
6
+ /**
7
+ * If `true`, the component is disabled.
8
+ * @default false
9
+ * */
10
+ disabled?: boolean;
11
+ }, Omit<AriaRadioProps, 'isDisabled'>>;
12
+ export type UseRadioState = ExtendableProps<{
13
+ /**
14
+ * If `true`, the component is disabled.
15
+ * @default false
16
+ * */
17
+ disabled?: boolean;
18
+ /** It prevents the user from changing the value of the checkbox.
19
+ * @default false
20
+ */
21
+ readonly?: boolean;
22
+ /**
23
+ * If `true`, the input element is required.
24
+ * @default false
25
+ * */
26
+ required?: boolean;
27
+ /**
28
+ * If `true`, the component will indicate an error.
29
+ * @default false
30
+ * */
31
+ error?: boolean;
32
+ }, Omit<RadioGroupState, 'isDisabled' | 'isReadOnly' | 'isRequired' | 'isInvalid'>>;
33
+ export declare function useRadio(props: UseRadioProps, state: UseRadioState, ref: RefObject<HTMLInputElement | null>): {
34
+ labelProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & import("react").LabelHTMLAttributes<HTMLLabelElement>;
35
+ inputProps: import("@react-types/shared").DOMAttributes<import("@react-types/shared").FocusableElement> & import("react").InputHTMLAttributes<HTMLInputElement> & {
36
+ ref: RefObject<HTMLInputElement | null>;
37
+ };
38
+ pressed: boolean;
39
+ hovered: boolean;
40
+ focused: boolean;
41
+ checked: boolean;
42
+ disabled: boolean;
43
+ focusVisible: boolean;
44
+ };
45
+ export type UseRadioReturn = ReturnType<typeof useRadio>;
@@ -0,0 +1,46 @@
1
+ "use client";
2
+ import { useHover, mergeProps, useFocusRing } from "@koobiq/react-core";
3
+ import { useRadio as useRadio$1 } from "@react-aria/radio";
4
+ function useRadio(props, state, ref) {
5
+ const { disabled } = props;
6
+ const {
7
+ inputProps: commonInputProps,
8
+ labelProps: commonLabelProps,
9
+ isDisabled,
10
+ isSelected,
11
+ isPressed
12
+ } = useRadio$1(
13
+ {
14
+ ...props,
15
+ isDisabled: disabled
16
+ },
17
+ Object.assign(state, {
18
+ isInvalid: state.error || false,
19
+ isReadOnly: state.readonly || false,
20
+ isDisabled: state.disabled || false,
21
+ isRequired: state.required || false
22
+ }),
23
+ ref
24
+ );
25
+ const { hoverProps, isHovered } = useHover({
26
+ isDisabled: disabled
27
+ });
28
+ const labelProps = mergeProps(hoverProps, commonLabelProps);
29
+ const { focusProps, isFocused, isFocusVisible } = useFocusRing();
30
+ const inputProps = mergeProps(focusProps, commonInputProps, {
31
+ ref
32
+ });
33
+ return {
34
+ labelProps,
35
+ inputProps,
36
+ pressed: isPressed,
37
+ hovered: isHovered,
38
+ focused: isFocused,
39
+ checked: isSelected,
40
+ disabled: isDisabled,
41
+ focusVisible: isFocusVisible
42
+ };
43
+ }
44
+ export {
45
+ useRadio
46
+ };
@@ -0,0 +1,55 @@
1
+ import type { ExtendableProps } from '@koobiq/react-core';
2
+ import { type AriaRadioGroupProps } from '@react-aria/radio';
3
+ import type { RadioGroupState } from '@react-stately/radio';
4
+ export type UseRadioGroupProps = ExtendableProps<{
5
+ /**
6
+ * If `true`, the component is disabled.
7
+ * @default false
8
+ * */
9
+ disabled?: boolean;
10
+ /** It prevents the user from changing the value of the checkbox.
11
+ * @default false
12
+ */
13
+ readonly?: boolean;
14
+ /**
15
+ * If `true`, the input element is required.
16
+ * @default false
17
+ * */
18
+ required?: boolean;
19
+ /**
20
+ * If `true`, the component will indicate an error.
21
+ * @default false
22
+ * */
23
+ error?: boolean;
24
+ }, Omit<AriaRadioGroupProps, 'isDisabled' | 'isReadOnly' | 'isRequired' | 'isInvalid'>>;
25
+ export type UseRadioGroupState = ExtendableProps<{
26
+ /**
27
+ * If `true`, the component is disabled.
28
+ * @default false
29
+ * */
30
+ disabled?: boolean;
31
+ /** It prevents the user from changing the value of the checkbox.
32
+ * @default false
33
+ */
34
+ readonly?: boolean;
35
+ /**
36
+ * If `true`, the input element is required.
37
+ * @default false
38
+ * */
39
+ required?: boolean;
40
+ /**
41
+ * If `true`, the component will indicate an error.
42
+ * @default false
43
+ * */
44
+ error?: boolean;
45
+ }, Omit<RadioGroupState, 'isDisabled' | 'isReadOnly' | 'isRequired' | 'isInvalid'>>;
46
+ export declare function useRadioGroup(props: UseRadioGroupProps, state: UseRadioGroupState): {
47
+ radioGroupProps: import("@react-types/shared").DOMAttributes;
48
+ labelProps: import("@react-types/shared").DOMAttributes;
49
+ descriptionProps: import("@react-types/shared").DOMAttributes;
50
+ errorMessageProps: import("@react-types/shared").DOMAttributes;
51
+ validationErrors: string[];
52
+ validationDetails: ValidityState;
53
+ error: boolean;
54
+ };
55
+ export type UseRadioGroupReturn = ReturnType<typeof useRadioGroup>;
@@ -0,0 +1,22 @@
1
+ import { useRadioGroup as useRadioGroup$1 } from "@react-aria/radio";
2
+ function useRadioGroup(props, state) {
3
+ const { isInvalid, ...other } = useRadioGroup$1(
4
+ {
5
+ ...props,
6
+ isInvalid: props.error || false,
7
+ isReadOnly: props.readonly || false,
8
+ isDisabled: props.disabled || false,
9
+ isRequired: props.required || false
10
+ },
11
+ Object.assign(state, {
12
+ isInvalid: state.error || false,
13
+ isReadOnly: state.readonly || false,
14
+ isDisabled: state.disabled || false,
15
+ isRequired: state.required || false
16
+ })
17
+ );
18
+ return { error: isInvalid, ...other };
19
+ }
20
+ export {
21
+ useRadioGroup
22
+ };
@@ -0,0 +1,42 @@
1
+ import type { ExtendableProps } from '@koobiq/react-core';
2
+ import type { RadioGroupProps } from '@react-stately/radio';
3
+ export type UseRadioGroupStateProps = ExtendableProps<{
4
+ /**
5
+ * If `true`, the component is disabled.
6
+ * @default false
7
+ * */
8
+ disabled?: boolean;
9
+ /** It prevents the user from changing the value of the checkbox.
10
+ * @default false
11
+ */
12
+ readonly?: boolean;
13
+ /**
14
+ * If `true`, the input element is required.
15
+ * @default false
16
+ * */
17
+ required?: boolean;
18
+ /**
19
+ * If `true`, the component will indicate an error.
20
+ * @default false
21
+ * */
22
+ error?: boolean;
23
+ }, Omit<RadioGroupProps, 'isDisabled' | 'isReadOnly' | 'isRequired' | 'isInvalid'>>;
24
+ export declare function useRadioGroupState(props: UseRadioGroupStateProps): {
25
+ name: string;
26
+ validationState: import("@react-types/shared").ValidationState | null;
27
+ selectedValue: string | null;
28
+ setSelectedValue(value: string | null): void;
29
+ lastFocusedValue: string | null;
30
+ setLastFocusedValue(value: string | null): void;
31
+ realtimeValidation: import("@react-types/shared").ValidationResult;
32
+ displayValidation: import("@react-types/shared").ValidationResult;
33
+ updateValidation(result: import("@react-types/shared").ValidationResult): void;
34
+ resetValidation(): void;
35
+ commitValidation(): void;
36
+ error: boolean;
37
+ readonly: boolean;
38
+ required: boolean;
39
+ disabled: boolean;
40
+ };
41
+ export type UseRadioGroupStateReturn = ReturnType<typeof useRadioGroupState>;
42
+ export type RadioGroupState = UseRadioGroupStateReturn;
@@ -0,0 +1,20 @@
1
+ import { useRadioGroupState as useRadioGroupState$1 } from "@react-stately/radio";
2
+ function useRadioGroupState(props) {
3
+ const { isDisabled, isInvalid, isReadOnly, isRequired, ...other } = useRadioGroupState$1({
4
+ ...props,
5
+ isInvalid: props.error || false,
6
+ isReadOnly: props.readonly || false,
7
+ isDisabled: props.disabled || false,
8
+ isRequired: props.required || false
9
+ });
10
+ return {
11
+ error: isInvalid,
12
+ readonly: isReadOnly,
13
+ required: isRequired,
14
+ disabled: isDisabled,
15
+ ...other
16
+ };
17
+ }
18
+ export {
19
+ useRadioGroupState
20
+ };
@@ -0,0 +1,19 @@
1
+ import type { RefObject } from 'react';
2
+ import type { AriaTextFieldOptions } from '@react-aria/textfield';
3
+ export type UseTextFieldProps = {
4
+ error?: boolean;
5
+ readonly?: boolean;
6
+ required?: boolean;
7
+ disabled?: boolean;
8
+ inputElementType?: 'input' | 'textarea';
9
+ } & Omit<AriaTextFieldOptions<'input' | 'textarea'>, 'isDisabled' | 'isInvalid' | 'isRequired' | 'isReadOnly'>;
10
+ export declare function useTextField(props: UseTextFieldProps, ref: RefObject<HTMLInputElement | HTMLTextAreaElement | null>): {
11
+ inputProps: import("react").DetailedHTMLProps<import("react").InputHTMLAttributes<HTMLInputElement>, HTMLInputElement> | import("react").DetailedHTMLProps<import("react").TextareaHTMLAttributes<HTMLTextAreaElement>, HTMLTextAreaElement>;
12
+ labelProps: import("@react-types/shared").DOMAttributes | import("react").LabelHTMLAttributes<HTMLLabelElement>;
13
+ descriptionProps: import("@react-types/shared").DOMAttributes;
14
+ errorMessageProps: import("@react-types/shared").DOMAttributes;
15
+ validationErrors: string[];
16
+ validationDetails: ValidityState;
17
+ error: boolean;
18
+ };
19
+ export type UseTextFieldReturn = ReturnType<typeof useTextField>;
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import { useTextField as useTextField$1 } from "@react-aria/textfield";
3
+ function useTextField(props, ref) {
4
+ const { disabled, error, label, readonly, required, ...other } = props;
5
+ const { isInvalid, ...textFieldProps } = useTextField$1(
6
+ {
7
+ isDisabled: disabled,
8
+ isReadOnly: readonly,
9
+ isRequired: required,
10
+ isInvalid: error,
11
+ label,
12
+ errorMessage: error ? label : void 0,
13
+ ...other
14
+ },
15
+ ref
16
+ );
17
+ return {
18
+ error: isInvalid,
19
+ ...textFieldProps
20
+ };
21
+ }
22
+ export {
23
+ useTextField
24
+ };