@seed-design/react 1.0.6 → 1.1.0
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/components/ActionButton/ActionButton.cjs +7 -1
- package/lib/components/ActionButton/ActionButton.d.ts +7 -1
- package/lib/components/ActionButton/ActionButton.d.ts.map +1 -1
- package/lib/components/ActionButton/ActionButton.js +7 -1
- package/lib/components/BottomSheet/BottomSheet.cjs +14 -18
- package/lib/components/BottomSheet/BottomSheet.d.ts +12 -19
- package/lib/components/BottomSheet/BottomSheet.d.ts.map +1 -1
- package/lib/components/BottomSheet/BottomSheet.js +14 -18
- package/lib/components/BottomSheet/BottomSheet.namespace.cjs +2 -0
- package/lib/components/BottomSheet/BottomSheet.namespace.d.ts +1 -0
- package/lib/components/BottomSheet/BottomSheet.namespace.d.ts.map +1 -1
- package/lib/components/BottomSheet/BottomSheet.namespace.js +1 -0
- package/lib/components/BottomSheetHandle/BottomSheetHandle.cjs +20 -0
- package/lib/components/BottomSheetHandle/BottomSheetHandle.d.ts +6 -0
- package/lib/components/BottomSheetHandle/BottomSheetHandle.d.ts.map +1 -0
- package/lib/components/BottomSheetHandle/BottomSheetHandle.js +16 -0
- package/lib/components/BottomSheetHandle/index.cjs +9 -0
- package/lib/components/BottomSheetHandle/index.d.ts +2 -0
- package/lib/components/BottomSheetHandle/index.d.ts.map +1 -0
- package/lib/components/BottomSheetHandle/index.js +1 -0
- package/lib/components/Chip/Chip.cjs +4 -3
- package/lib/components/Chip/Chip.d.ts.map +1 -1
- package/lib/components/Chip/Chip.js +4 -3
- package/lib/components/Field/Field.cjs +108 -0
- package/lib/components/Field/Field.d.ts +41 -0
- package/lib/components/Field/Field.d.ts.map +1 -0
- package/lib/components/Field/Field.js +96 -0
- package/lib/components/Field/Field.namespace.cjs +17 -0
- package/lib/components/Field/Field.namespace.d.ts +2 -0
- package/lib/components/Field/Field.namespace.d.ts.map +1 -0
- package/lib/components/Field/Field.namespace.js +1 -0
- package/lib/components/Field/index.cjs +19 -0
- package/lib/components/Field/index.d.ts +3 -0
- package/lib/components/Field/index.d.ts.map +1 -0
- package/lib/components/Field/index.js +3 -0
- package/lib/components/FieldButton/FieldButton.cjs +201 -0
- package/lib/components/FieldButton/FieldButton.d.ts +61 -0
- package/lib/components/FieldButton/FieldButton.d.ts.map +1 -0
- package/lib/components/FieldButton/FieldButton.js +161 -0
- package/lib/components/FieldButton/FieldButton.namespace.cjs +26 -0
- package/lib/components/FieldButton/FieldButton.namespace.d.ts +2 -0
- package/lib/components/FieldButton/FieldButton.namespace.d.ts.map +1 -0
- package/lib/components/FieldButton/FieldButton.namespace.js +1 -0
- package/lib/components/FieldButton/index.cjs +28 -0
- package/lib/components/FieldButton/index.d.ts +3 -0
- package/lib/components/FieldButton/index.d.ts.map +1 -0
- package/lib/components/FieldButton/index.js +3 -0
- package/lib/components/HelpBubble/HelpBubble.d.ts +1 -1
- package/lib/components/List/List.cjs +5 -4
- package/lib/components/List/List.d.ts.map +1 -1
- package/lib/components/List/List.js +5 -4
- package/lib/components/PageBanner/PageBanner.cjs +8 -3
- package/lib/components/PageBanner/PageBanner.d.ts +5 -2
- package/lib/components/PageBanner/PageBanner.d.ts.map +1 -1
- package/lib/components/PageBanner/PageBanner.js +7 -3
- package/lib/components/PageBanner/PageBanner.namespace.cjs +2 -1
- package/lib/components/PageBanner/PageBanner.namespace.d.ts +1 -1
- package/lib/components/PageBanner/PageBanner.namespace.d.ts.map +1 -1
- package/lib/components/PageBanner/PageBanner.namespace.js +1 -1
- package/lib/components/PageBanner/index.cjs +2 -1
- package/lib/components/PageBanner/index.d.ts +1 -1
- package/lib/components/PageBanner/index.d.ts.map +1 -1
- package/lib/components/PageBanner/index.js +1 -1
- package/lib/components/Slider/Slider.cjs +110 -0
- package/lib/components/Slider/Slider.d.ts +51 -0
- package/lib/components/Slider/Slider.d.ts.map +1 -0
- package/lib/components/Slider/Slider.js +94 -0
- package/lib/components/Slider/Slider.namespace.cjs +21 -0
- package/lib/components/Slider/Slider.namespace.d.ts +2 -0
- package/lib/components/Slider/Slider.namespace.d.ts.map +1 -0
- package/lib/components/Slider/Slider.namespace.js +1 -0
- package/lib/components/Slider/index.cjs +23 -0
- package/lib/components/Slider/index.d.ts +3 -0
- package/lib/components/Slider/index.d.ts.map +1 -0
- package/lib/components/Slider/index.js +3 -0
- package/lib/components/TextField/TextField.cjs +54 -74
- package/lib/components/TextField/TextField.d.ts +2 -35
- package/lib/components/TextField/TextField.d.ts.map +1 -1
- package/lib/components/TextField/TextField.js +56 -65
- package/lib/components/TextField/TextField.namespace.cjs +0 -11
- package/lib/components/TextField/TextField.namespace.d.ts +1 -1
- package/lib/components/TextField/TextField.namespace.d.ts.map +1 -1
- package/lib/components/TextField/TextField.namespace.js +1 -1
- package/lib/components/TextField/TextField.test.d.ts +1 -0
- package/lib/components/TextField/TextField.test.d.ts.map +1 -0
- package/lib/components/TextField/index.cjs +2 -11
- package/lib/components/TextField/index.d.ts +2 -1
- package/lib/components/TextField/index.d.ts.map +1 -1
- package/lib/components/TextField/index.js +2 -1
- package/lib/components/TextField/memoize.cjs +18 -0
- package/lib/components/TextField/memoize.d.ts +2 -0
- package/lib/components/TextField/memoize.d.ts.map +1 -0
- package/lib/components/TextField/memoize.js +14 -0
- package/lib/components/TextField/useTextFieldWithGraphemes.cjs +52 -0
- package/lib/components/TextField/useTextFieldWithGraphemes.d.ts +23 -0
- package/lib/components/TextField/useTextFieldWithGraphemes.d.ts.map +1 -0
- package/lib/components/TextField/useTextFieldWithGraphemes.js +48 -0
- package/lib/components/TextField/useTextFieldWithGraphemes.test.d.ts +1 -0
- package/lib/components/TextField/useTextFieldWithGraphemes.test.d.ts.map +1 -0
- package/lib/components/index.cjs +53 -12
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.d.ts.map +1 -1
- package/lib/components/index.js +12 -2
- package/lib/index.cjs +53 -12
- package/lib/index.js +12 -2
- package/lib/node_modules/unicode-segmenter/_grapheme_data.cjs +23 -0
- package/lib/node_modules/unicode-segmenter/_grapheme_data.js +19 -0
- package/lib/node_modules/unicode-segmenter/_incb_data.cjs +29 -0
- package/lib/node_modules/unicode-segmenter/_incb_data.js +25 -0
- package/lib/node_modules/unicode-segmenter/core.cjs +83 -0
- package/lib/node_modules/unicode-segmenter/core.js +78 -0
- package/lib/node_modules/unicode-segmenter/grapheme.cjs +312 -0
- package/lib/node_modules/unicode-segmenter/grapheme.js +307 -0
- package/lib/primitive.cjs +7 -0
- package/lib/primitive.d.ts +1 -0
- package/lib/primitive.d.ts.map +1 -1
- package/lib/primitive.js +1 -0
- package/lib/utils/createWithStateProps.cjs +8 -4
- package/lib/utils/createWithStateProps.d.ts +6 -3
- package/lib/utils/createWithStateProps.d.ts.map +1 -1
- package/lib/utils/createWithStateProps.js +8 -4
- package/package.json +9 -6
- package/src/components/ActionButton/ActionButton.tsx +21 -2
- package/src/components/BottomSheet/BottomSheet.namespace.ts +5 -0
- package/src/components/BottomSheet/BottomSheet.tsx +24 -38
- package/src/components/BottomSheetHandle/BottomSheetHandle.tsx +22 -0
- package/src/components/BottomSheetHandle/index.ts +1 -0
- package/src/components/Chip/Chip.tsx +4 -3
- package/src/components/Field/Field.namespace.ts +19 -0
- package/src/components/Field/Field.tsx +136 -0
- package/src/components/Field/index.ts +21 -0
- package/src/components/FieldButton/FieldButton.namespace.ts +38 -0
- package/src/components/FieldButton/FieldButton.tsx +249 -0
- package/src/components/FieldButton/index.ts +40 -0
- package/src/components/HelpBubble/HelpBubble.tsx +1 -1
- package/src/components/List/List.tsx +5 -4
- package/src/components/PageBanner/PageBanner.namespace.ts +4 -2
- package/src/components/PageBanner/PageBanner.tsx +10 -3
- package/src/components/PageBanner/index.ts +4 -2
- package/src/components/Slider/Slider.namespace.ts +28 -0
- package/src/components/Slider/Slider.tsx +154 -0
- package/src/components/Slider/index.ts +30 -0
- package/src/components/TextField/TextField.namespace.ts +2 -24
- package/src/components/TextField/TextField.test.tsx +260 -0
- package/src/components/TextField/TextField.tsx +67 -143
- package/src/components/TextField/index.ts +7 -24
- package/src/components/TextField/memoize.ts +14 -0
- package/src/components/TextField/useTextFieldWithGraphemes.test.tsx +301 -0
- package/src/components/TextField/useTextFieldWithGraphemes.ts +65 -0
- package/src/components/index.ts +3 -0
- package/src/primitive.ts +1 -0
- package/src/utils/createWithStateProps.tsx +14 -9
- package/lib/components/List/ListHeader.namespace.d.ts +0 -2
- package/lib/components/List/ListHeader.namespace.d.ts.map +0 -1
- package/src/components/List/ListHeader.namespace.ts +0 -0
|
@@ -7,49 +7,26 @@ const jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
const reactUseLayoutEffect = require('@radix-ui/react-use-layout-effect');
|
|
8
8
|
const reactPrimitive = require('@seed-design/react-primitive');
|
|
9
9
|
const reactTextField = require('@seed-design/react-text-field');
|
|
10
|
-
const
|
|
10
|
+
const reactField = require('@seed-design/react-field');
|
|
11
|
+
const textInput = require('@seed-design/css/recipes/text-input');
|
|
11
12
|
const clsx = require('clsx');
|
|
12
13
|
const React = require('react');
|
|
13
14
|
const createSlotRecipeContext = require('../../utils/createSlotRecipeContext.cjs');
|
|
14
15
|
const createWithStateProps = require('../../utils/createWithStateProps.cjs');
|
|
15
16
|
const Icon = require('../private/Icon.cjs');
|
|
16
17
|
const reactComposeRefs = require('@radix-ui/react-compose-refs');
|
|
18
|
+
const domUtils = require('@seed-design/dom-utils');
|
|
17
19
|
|
|
18
|
-
const { withProvider, withContext, useClassNames } = createSlotRecipeContext.createSlotRecipeContext(
|
|
19
|
-
const
|
|
20
|
+
const { withProvider, withContext, useClassNames } = createSlotRecipeContext.createSlotRecipeContext(textInput.textInput);
|
|
21
|
+
const withFieldStateProps = createWithStateProps.createWithStateProps([{ useContext: reactField.useFieldContext, strict: false }]);
|
|
22
|
+
const withStateProps = createWithStateProps.createWithStateProps([
|
|
23
|
+
reactTextField.useTextFieldContext,
|
|
24
|
+
{ useContext: reactField.useFieldContext, strict: false }
|
|
25
|
+
]);
|
|
20
26
|
const TextFieldRoot = withProvider(
|
|
21
|
-
reactTextField.TextField.Root,
|
|
27
|
+
withFieldStateProps(reactTextField.TextField.Root),
|
|
22
28
|
"root"
|
|
23
29
|
);
|
|
24
|
-
const TextFieldHeader = withContext(
|
|
25
|
-
withStateProps(reactPrimitive.Primitive.div),
|
|
26
|
-
"header"
|
|
27
|
-
);
|
|
28
|
-
const TextFieldLabel = withContext(
|
|
29
|
-
reactTextField.TextField.Label,
|
|
30
|
-
"label"
|
|
31
|
-
);
|
|
32
|
-
const TextFieldIndicator = React.forwardRef(
|
|
33
|
-
(props, ref) => {
|
|
34
|
-
const { className, ...otherProps } = props;
|
|
35
|
-
const classNames = useClassNames();
|
|
36
|
-
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
37
|
-
/* @__PURE__ */ jsxRuntime.jsx(reactPrimitive.Primitive.span, { children: " " }),
|
|
38
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
39
|
-
reactPrimitive.Primitive.span,
|
|
40
|
-
{
|
|
41
|
-
ref,
|
|
42
|
-
className: clsx(classNames.indicator, className),
|
|
43
|
-
...otherProps
|
|
44
|
-
}
|
|
45
|
-
)
|
|
46
|
-
] });
|
|
47
|
-
}
|
|
48
|
-
);
|
|
49
|
-
const TextFieldField = withContext(
|
|
50
|
-
withStateProps(reactPrimitive.Primitive.div),
|
|
51
|
-
"field"
|
|
52
|
-
);
|
|
53
30
|
const TextFieldPrefixIcon = withContext(
|
|
54
31
|
withStateProps(Icon.InternalIcon),
|
|
55
32
|
"prefixIcon"
|
|
@@ -66,15 +43,50 @@ const TextFieldSuffixText = withContext(
|
|
|
66
43
|
withStateProps(reactPrimitive.Primitive.span),
|
|
67
44
|
"suffixText"
|
|
68
45
|
);
|
|
69
|
-
const TextFieldInput =
|
|
70
|
-
|
|
71
|
-
|
|
46
|
+
const TextFieldInput = React.forwardRef(
|
|
47
|
+
({ className, ...otherProps }, ref) => {
|
|
48
|
+
const classNames = useClassNames();
|
|
49
|
+
const textFieldContext = reactTextField.useTextFieldContext();
|
|
50
|
+
const fieldContext = reactField.useFieldContext({ strict: false });
|
|
51
|
+
const mergedProps = domUtils.mergeProps(
|
|
52
|
+
fieldContext ? fieldContext.stateProps : {},
|
|
53
|
+
fieldContext ? fieldContext.inputAriaAttributes : {},
|
|
54
|
+
textFieldContext.inputProps,
|
|
55
|
+
fieldContext ? fieldContext.inputProps : {},
|
|
56
|
+
otherProps
|
|
57
|
+
);
|
|
58
|
+
if (
|
|
59
|
+
// if not in field, then must have aria-label or aria-labelledby
|
|
60
|
+
!fieldContext && !otherProps["aria-label"] && !otherProps["aria-labelledby"]
|
|
61
|
+
) {
|
|
62
|
+
console.warn(
|
|
63
|
+
"TextFieldInput: Please provide `aria-label` or `aria-labelledby` for accessibility, or put `TextFieldInput` inside a `Field` where a `FieldLabel` is provided."
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return /* @__PURE__ */ jsxRuntime.jsx(reactTextField.TextField.Input, { ref, ...mergedProps, className: clsx(classNames.value, className) });
|
|
67
|
+
}
|
|
72
68
|
);
|
|
69
|
+
TextFieldInput.displayName = "TextFieldInput";
|
|
73
70
|
const TextFieldTextarea = React.forwardRef(
|
|
74
|
-
(
|
|
75
|
-
const { className, autoresize = true, ...otherProps } = props;
|
|
71
|
+
({ className, autoresize = true, ...otherProps }, ref) => {
|
|
76
72
|
const classNames = useClassNames();
|
|
77
|
-
const
|
|
73
|
+
const textFieldContext = reactTextField.useTextFieldContext();
|
|
74
|
+
const fieldContext = reactField.useFieldContext({ strict: false });
|
|
75
|
+
const mergedProps = domUtils.mergeProps(
|
|
76
|
+
fieldContext ? fieldContext.stateProps : {},
|
|
77
|
+
fieldContext ? fieldContext.inputAriaAttributes : {},
|
|
78
|
+
textFieldContext.inputProps,
|
|
79
|
+
fieldContext ? fieldContext.inputProps : {},
|
|
80
|
+
otherProps
|
|
81
|
+
);
|
|
82
|
+
if (
|
|
83
|
+
// if not in field, then must have aria-label or aria-labelledby
|
|
84
|
+
!fieldContext && !otherProps["aria-label"] && !otherProps["aria-labelledby"]
|
|
85
|
+
) {
|
|
86
|
+
console.warn(
|
|
87
|
+
"TextFieldTextarea: Please provide `aria-label` or `aria-labelledby` for accessibility, or put `TextFieldTextarea` inside a `Field` where a `FieldLabel` is provided."
|
|
88
|
+
);
|
|
89
|
+
}
|
|
78
90
|
const inputRef = React.useRef(null);
|
|
79
91
|
const onHeightChange = React.useCallback(() => {
|
|
80
92
|
if (!inputRef.current) return;
|
|
@@ -97,52 +109,20 @@ const TextFieldTextarea = React.forwardRef(
|
|
|
97
109
|
if (inputRef.current) {
|
|
98
110
|
onHeightChange();
|
|
99
111
|
}
|
|
100
|
-
}, [onHeightChange, value, inputRef]);
|
|
112
|
+
}, [onHeightChange, textFieldContext.value, inputRef]);
|
|
101
113
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
102
114
|
reactTextField.TextField.Textarea,
|
|
103
115
|
{
|
|
104
116
|
ref: reactComposeRefs.composeRefs(inputRef, ref),
|
|
105
|
-
...
|
|
117
|
+
...mergedProps,
|
|
106
118
|
className: clsx(classNames.value, className)
|
|
107
119
|
}
|
|
108
120
|
);
|
|
109
121
|
}
|
|
110
122
|
);
|
|
111
|
-
|
|
112
|
-
withStateProps(reactPrimitive.Primitive.div),
|
|
113
|
-
"footer"
|
|
114
|
-
);
|
|
115
|
-
const TextFieldDescription = withContext(
|
|
116
|
-
reactTextField.TextField.Description,
|
|
117
|
-
"description"
|
|
118
|
-
);
|
|
119
|
-
const TextFieldErrorMessage = withContext(
|
|
120
|
-
reactTextField.TextField.ErrorMessage,
|
|
121
|
-
"errorMessage"
|
|
122
|
-
);
|
|
123
|
-
const TextFieldErrorIcon = withContext(
|
|
124
|
-
withStateProps(Icon.InternalIcon),
|
|
125
|
-
"errorIcon"
|
|
126
|
-
);
|
|
127
|
-
const TextFieldCharacterCountArea = withContext(withStateProps(reactPrimitive.Primitive.div), "characterCountArea");
|
|
128
|
-
const TextFieldCharacterCount = withContext(
|
|
129
|
-
reactTextField.TextField.GraphemeCount,
|
|
130
|
-
"characterCount"
|
|
131
|
-
);
|
|
132
|
-
const TextFieldMaxCharacterCount = withContext(withStateProps(reactPrimitive.Primitive.span), "maxCharacterCount");
|
|
123
|
+
TextFieldTextarea.displayName = "TextFieldTextarea";
|
|
133
124
|
|
|
134
|
-
exports.TextFieldCharacterCount = TextFieldCharacterCount;
|
|
135
|
-
exports.TextFieldCharacterCountArea = TextFieldCharacterCountArea;
|
|
136
|
-
exports.TextFieldDescription = TextFieldDescription;
|
|
137
|
-
exports.TextFieldErrorIcon = TextFieldErrorIcon;
|
|
138
|
-
exports.TextFieldErrorMessage = TextFieldErrorMessage;
|
|
139
|
-
exports.TextFieldField = TextFieldField;
|
|
140
|
-
exports.TextFieldFooter = TextFieldFooter;
|
|
141
|
-
exports.TextFieldHeader = TextFieldHeader;
|
|
142
|
-
exports.TextFieldIndicator = TextFieldIndicator;
|
|
143
125
|
exports.TextFieldInput = TextFieldInput;
|
|
144
|
-
exports.TextFieldLabel = TextFieldLabel;
|
|
145
|
-
exports.TextFieldMaxCharacterCount = TextFieldMaxCharacterCount;
|
|
146
126
|
exports.TextFieldPrefixIcon = TextFieldPrefixIcon;
|
|
147
127
|
exports.TextFieldPrefixText = TextFieldPrefixText;
|
|
148
128
|
exports.TextFieldRoot = TextFieldRoot;
|
|
@@ -1,23 +1,11 @@
|
|
|
1
1
|
import { PrimitiveProps } from '@seed-design/react-primitive';
|
|
2
2
|
import { TextField } from '@seed-design/react-text-field';
|
|
3
|
-
import {
|
|
3
|
+
import { TextInputVariantProps } from '@seed-design/css/recipes/text-input';
|
|
4
4
|
import { InternalIconProps } from '../private/Icon';
|
|
5
5
|
import type * as React from "react";
|
|
6
|
-
export interface TextFieldRootProps extends
|
|
6
|
+
export interface TextFieldRootProps extends TextInputVariantProps, TextField.RootProps {
|
|
7
7
|
}
|
|
8
8
|
export declare const TextFieldRoot: React.ForwardRefExoticComponent<TextFieldRootProps & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
-
export interface TextFieldHeaderProps extends PrimitiveProps, React.HTMLAttributes<HTMLDivElement> {
|
|
10
|
-
}
|
|
11
|
-
export declare const TextFieldHeader: React.ForwardRefExoticComponent<TextFieldHeaderProps & React.RefAttributes<HTMLDivElement>>;
|
|
12
|
-
export interface TextFieldLabelProps extends TextField.LabelProps {
|
|
13
|
-
}
|
|
14
|
-
export declare const TextFieldLabel: React.ForwardRefExoticComponent<TextFieldLabelProps & React.RefAttributes<HTMLLabelElement>>;
|
|
15
|
-
export interface TextFieldIndicatorProps extends PrimitiveProps, React.HTMLAttributes<HTMLSpanElement> {
|
|
16
|
-
}
|
|
17
|
-
export declare const TextFieldIndicator: React.ForwardRefExoticComponent<TextFieldIndicatorProps & React.RefAttributes<HTMLSpanElement>>;
|
|
18
|
-
export interface TextFieldFieldProps extends PrimitiveProps, React.HTMLAttributes<HTMLDivElement> {
|
|
19
|
-
}
|
|
20
|
-
export declare const TextFieldField: React.ForwardRefExoticComponent<TextFieldFieldProps & React.RefAttributes<HTMLDivElement>>;
|
|
21
9
|
export interface TextFieldPrefixIconProps extends InternalIconProps {
|
|
22
10
|
}
|
|
23
11
|
export declare const TextFieldPrefixIcon: React.ForwardRefExoticComponent<TextFieldPrefixIconProps & React.RefAttributes<SVGSVGElement>>;
|
|
@@ -41,25 +29,4 @@ export interface TextFieldTextareaProps extends TextField.TextareaProps {
|
|
|
41
29
|
autoresize?: boolean;
|
|
42
30
|
}
|
|
43
31
|
export declare const TextFieldTextarea: React.ForwardRefExoticComponent<TextFieldTextareaProps & React.RefAttributes<HTMLTextAreaElement>>;
|
|
44
|
-
export interface TextFieldFooterProps extends PrimitiveProps, React.HTMLAttributes<HTMLDivElement> {
|
|
45
|
-
}
|
|
46
|
-
export declare const TextFieldFooter: React.ForwardRefExoticComponent<TextFieldFooterProps & React.RefAttributes<HTMLDivElement>>;
|
|
47
|
-
export interface TextFieldDescriptionProps extends TextField.DescriptionProps {
|
|
48
|
-
}
|
|
49
|
-
export declare const TextFieldDescription: React.ForwardRefExoticComponent<TextFieldDescriptionProps & React.RefAttributes<HTMLSpanElement>>;
|
|
50
|
-
export interface TextFieldErrorMessageProps extends TextField.ErrorMessageProps {
|
|
51
|
-
}
|
|
52
|
-
export declare const TextFieldErrorMessage: React.ForwardRefExoticComponent<TextFieldErrorMessageProps & React.RefAttributes<HTMLSpanElement>>;
|
|
53
|
-
export interface TextFieldErrorIconProps extends InternalIconProps {
|
|
54
|
-
}
|
|
55
|
-
export declare const TextFieldErrorIcon: React.ForwardRefExoticComponent<TextFieldErrorIconProps & React.RefAttributes<SVGSVGElement>>;
|
|
56
|
-
export interface TextFieldCharacterCountAreaProps extends PrimitiveProps, React.HTMLAttributes<HTMLDivElement> {
|
|
57
|
-
}
|
|
58
|
-
export declare const TextFieldCharacterCountArea: React.ForwardRefExoticComponent<TextFieldCharacterCountAreaProps & React.RefAttributes<HTMLDivElement>>;
|
|
59
|
-
export interface TextFieldCharacterCountProps extends TextField.GraphemeCountProps {
|
|
60
|
-
}
|
|
61
|
-
export declare const TextFieldCharacterCount: React.ForwardRefExoticComponent<TextFieldCharacterCountProps & React.RefAttributes<HTMLDivElement>>;
|
|
62
|
-
export interface TextFieldMaxCharacterCountProps extends PrimitiveProps, React.HTMLAttributes<HTMLSpanElement> {
|
|
63
|
-
}
|
|
64
|
-
export declare const TextFieldMaxCharacterCount: React.ForwardRefExoticComponent<TextFieldMaxCharacterCountProps & React.RefAttributes<HTMLSpanElement>>;
|
|
65
32
|
//# sourceMappingURL=TextField.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/TextField.tsx"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAuB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/TextField.tsx"],"names":[],"mappings":"AACA,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAuB,MAAM,+BAA+B,CAAC;AAE/E,OAAO,EAAa,KAAK,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5F,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAIpC,OAAO,EAAgB,KAAK,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAcvE,MAAM,WAAW,kBAAmB,SAAQ,qBAAqB,EAAE,SAAS,CAAC,SAAS;CAAG;AAEzF,eAAO,MAAM,aAAa,2FAGzB,CAAC;AAIF,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;CAAG;AAEtE,eAAO,MAAM,mBAAmB,gGAG/B,CAAC;AAEF,MAAM,WAAW,wBACf,SAAQ,cAAc,EACpB,KAAK,CAAC,cAAc,CAAC,eAAe,CAAC;CAAG;AAE5C,eAAO,MAAM,mBAAmB,kGAG/B,CAAC;AAEF,MAAM,WAAW,wBAAyB,SAAQ,iBAAiB;CAAG;AAEtE,eAAO,MAAM,mBAAmB,gGAG/B,CAAC;AAEF,MAAM,WAAW,wBACf,SAAQ,cAAc,EACpB,KAAK,CAAC,cAAc,CAAC,eAAe,CAAC;CAAG;AAE5C,eAAO,MAAM,mBAAmB,kGAG/B,CAAC;AAIF,MAAM,WAAW,mBAAoB,SAAQ,SAAS,CAAC,UAAU;CAAG;AAEpE,eAAO,MAAM,cAAc,8FA6B1B,CAAC;AAGF,MAAM,WAAW,sBAAuB,SAAQ,SAAS,CAAC,aAAa;IACrE;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,iBAAiB,oGAuE7B,CAAC"}
|
|
@@ -1,51 +1,28 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
2
|
+
import { jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { useLayoutEffect } from '@radix-ui/react-use-layout-effect';
|
|
4
4
|
import { Primitive } from '@seed-design/react-primitive';
|
|
5
5
|
import { TextField, useTextFieldContext } from '@seed-design/react-text-field';
|
|
6
|
-
import {
|
|
6
|
+
import { useFieldContext } from '@seed-design/react-field';
|
|
7
|
+
import { textInput } from '@seed-design/css/recipes/text-input';
|
|
7
8
|
import clsx from 'clsx';
|
|
8
9
|
import { forwardRef, useRef, useCallback } from 'react';
|
|
9
10
|
import { createSlotRecipeContext } from '../../utils/createSlotRecipeContext.js';
|
|
10
11
|
import { createWithStateProps } from '../../utils/createWithStateProps.js';
|
|
11
12
|
import { InternalIcon } from '../private/Icon.js';
|
|
12
13
|
import { composeRefs } from '@radix-ui/react-compose-refs';
|
|
14
|
+
import { mergeProps } from '@seed-design/dom-utils';
|
|
13
15
|
|
|
14
|
-
const { withProvider, withContext, useClassNames } = createSlotRecipeContext(
|
|
15
|
-
const
|
|
16
|
+
const { withProvider, withContext, useClassNames } = createSlotRecipeContext(textInput);
|
|
17
|
+
const withFieldStateProps = createWithStateProps([{ useContext: useFieldContext, strict: false }]);
|
|
18
|
+
const withStateProps = createWithStateProps([
|
|
19
|
+
useTextFieldContext,
|
|
20
|
+
{ useContext: useFieldContext, strict: false }
|
|
21
|
+
]);
|
|
16
22
|
const TextFieldRoot = withProvider(
|
|
17
|
-
TextField.Root,
|
|
23
|
+
withFieldStateProps(TextField.Root),
|
|
18
24
|
"root"
|
|
19
25
|
);
|
|
20
|
-
const TextFieldHeader = withContext(
|
|
21
|
-
withStateProps(Primitive.div),
|
|
22
|
-
"header"
|
|
23
|
-
);
|
|
24
|
-
const TextFieldLabel = withContext(
|
|
25
|
-
TextField.Label,
|
|
26
|
-
"label"
|
|
27
|
-
);
|
|
28
|
-
const TextFieldIndicator = forwardRef(
|
|
29
|
-
(props, ref) => {
|
|
30
|
-
const { className, ...otherProps } = props;
|
|
31
|
-
const classNames = useClassNames();
|
|
32
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
33
|
-
/* @__PURE__ */ jsx(Primitive.span, { children: " " }),
|
|
34
|
-
/* @__PURE__ */ jsx(
|
|
35
|
-
Primitive.span,
|
|
36
|
-
{
|
|
37
|
-
ref,
|
|
38
|
-
className: clsx(classNames.indicator, className),
|
|
39
|
-
...otherProps
|
|
40
|
-
}
|
|
41
|
-
)
|
|
42
|
-
] });
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
const TextFieldField = withContext(
|
|
46
|
-
withStateProps(Primitive.div),
|
|
47
|
-
"field"
|
|
48
|
-
);
|
|
49
26
|
const TextFieldPrefixIcon = withContext(
|
|
50
27
|
withStateProps(InternalIcon),
|
|
51
28
|
"prefixIcon"
|
|
@@ -62,15 +39,50 @@ const TextFieldSuffixText = withContext(
|
|
|
62
39
|
withStateProps(Primitive.span),
|
|
63
40
|
"suffixText"
|
|
64
41
|
);
|
|
65
|
-
const TextFieldInput =
|
|
66
|
-
|
|
67
|
-
|
|
42
|
+
const TextFieldInput = forwardRef(
|
|
43
|
+
({ className, ...otherProps }, ref) => {
|
|
44
|
+
const classNames = useClassNames();
|
|
45
|
+
const textFieldContext = useTextFieldContext();
|
|
46
|
+
const fieldContext = useFieldContext({ strict: false });
|
|
47
|
+
const mergedProps = mergeProps(
|
|
48
|
+
fieldContext ? fieldContext.stateProps : {},
|
|
49
|
+
fieldContext ? fieldContext.inputAriaAttributes : {},
|
|
50
|
+
textFieldContext.inputProps,
|
|
51
|
+
fieldContext ? fieldContext.inputProps : {},
|
|
52
|
+
otherProps
|
|
53
|
+
);
|
|
54
|
+
if (
|
|
55
|
+
// if not in field, then must have aria-label or aria-labelledby
|
|
56
|
+
!fieldContext && !otherProps["aria-label"] && !otherProps["aria-labelledby"]
|
|
57
|
+
) {
|
|
58
|
+
console.warn(
|
|
59
|
+
"TextFieldInput: Please provide `aria-label` or `aria-labelledby` for accessibility, or put `TextFieldInput` inside a `Field` where a `FieldLabel` is provided."
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
return /* @__PURE__ */ jsx(TextField.Input, { ref, ...mergedProps, className: clsx(classNames.value, className) });
|
|
63
|
+
}
|
|
68
64
|
);
|
|
65
|
+
TextFieldInput.displayName = "TextFieldInput";
|
|
69
66
|
const TextFieldTextarea = forwardRef(
|
|
70
|
-
(
|
|
71
|
-
const { className, autoresize = true, ...otherProps } = props;
|
|
67
|
+
({ className, autoresize = true, ...otherProps }, ref) => {
|
|
72
68
|
const classNames = useClassNames();
|
|
73
|
-
const
|
|
69
|
+
const textFieldContext = useTextFieldContext();
|
|
70
|
+
const fieldContext = useFieldContext({ strict: false });
|
|
71
|
+
const mergedProps = mergeProps(
|
|
72
|
+
fieldContext ? fieldContext.stateProps : {},
|
|
73
|
+
fieldContext ? fieldContext.inputAriaAttributes : {},
|
|
74
|
+
textFieldContext.inputProps,
|
|
75
|
+
fieldContext ? fieldContext.inputProps : {},
|
|
76
|
+
otherProps
|
|
77
|
+
);
|
|
78
|
+
if (
|
|
79
|
+
// if not in field, then must have aria-label or aria-labelledby
|
|
80
|
+
!fieldContext && !otherProps["aria-label"] && !otherProps["aria-labelledby"]
|
|
81
|
+
) {
|
|
82
|
+
console.warn(
|
|
83
|
+
"TextFieldTextarea: Please provide `aria-label` or `aria-labelledby` for accessibility, or put `TextFieldTextarea` inside a `Field` where a `FieldLabel` is provided."
|
|
84
|
+
);
|
|
85
|
+
}
|
|
74
86
|
const inputRef = useRef(null);
|
|
75
87
|
const onHeightChange = useCallback(() => {
|
|
76
88
|
if (!inputRef.current) return;
|
|
@@ -93,38 +105,17 @@ const TextFieldTextarea = forwardRef(
|
|
|
93
105
|
if (inputRef.current) {
|
|
94
106
|
onHeightChange();
|
|
95
107
|
}
|
|
96
|
-
}, [onHeightChange, value, inputRef]);
|
|
108
|
+
}, [onHeightChange, textFieldContext.value, inputRef]);
|
|
97
109
|
return /* @__PURE__ */ jsx(
|
|
98
110
|
TextField.Textarea,
|
|
99
111
|
{
|
|
100
112
|
ref: composeRefs(inputRef, ref),
|
|
101
|
-
...
|
|
113
|
+
...mergedProps,
|
|
102
114
|
className: clsx(classNames.value, className)
|
|
103
115
|
}
|
|
104
116
|
);
|
|
105
117
|
}
|
|
106
118
|
);
|
|
107
|
-
|
|
108
|
-
withStateProps(Primitive.div),
|
|
109
|
-
"footer"
|
|
110
|
-
);
|
|
111
|
-
const TextFieldDescription = withContext(
|
|
112
|
-
TextField.Description,
|
|
113
|
-
"description"
|
|
114
|
-
);
|
|
115
|
-
const TextFieldErrorMessage = withContext(
|
|
116
|
-
TextField.ErrorMessage,
|
|
117
|
-
"errorMessage"
|
|
118
|
-
);
|
|
119
|
-
const TextFieldErrorIcon = withContext(
|
|
120
|
-
withStateProps(InternalIcon),
|
|
121
|
-
"errorIcon"
|
|
122
|
-
);
|
|
123
|
-
const TextFieldCharacterCountArea = withContext(withStateProps(Primitive.div), "characterCountArea");
|
|
124
|
-
const TextFieldCharacterCount = withContext(
|
|
125
|
-
TextField.GraphemeCount,
|
|
126
|
-
"characterCount"
|
|
127
|
-
);
|
|
128
|
-
const TextFieldMaxCharacterCount = withContext(withStateProps(Primitive.span), "maxCharacterCount");
|
|
119
|
+
TextFieldTextarea.displayName = "TextFieldTextarea";
|
|
129
120
|
|
|
130
|
-
export {
|
|
121
|
+
export { TextFieldInput, TextFieldPrefixIcon, TextFieldPrefixText, TextFieldRoot, TextFieldSuffixIcon, TextFieldSuffixText, TextFieldTextarea };
|
|
@@ -6,18 +6,7 @@ const TextField = require('./TextField.cjs');
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
exports.CharacterCount = TextField.TextFieldCharacterCount;
|
|
10
|
-
exports.CharacterCountArea = TextField.TextFieldCharacterCountArea;
|
|
11
|
-
exports.Description = TextField.TextFieldDescription;
|
|
12
|
-
exports.ErrorIcon = TextField.TextFieldErrorIcon;
|
|
13
|
-
exports.ErrorMessage = TextField.TextFieldErrorMessage;
|
|
14
|
-
exports.Field = TextField.TextFieldField;
|
|
15
|
-
exports.Footer = TextField.TextFieldFooter;
|
|
16
|
-
exports.Header = TextField.TextFieldHeader;
|
|
17
|
-
exports.Indicator = TextField.TextFieldIndicator;
|
|
18
9
|
exports.Input = TextField.TextFieldInput;
|
|
19
|
-
exports.Label = TextField.TextFieldLabel;
|
|
20
|
-
exports.MaxCharacterCount = TextField.TextFieldMaxCharacterCount;
|
|
21
10
|
exports.PrefixIcon = TextField.TextFieldPrefixIcon;
|
|
22
11
|
exports.PrefixText = TextField.TextFieldPrefixText;
|
|
23
12
|
exports.Root = TextField.TextFieldRoot;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { TextFieldRoot as Root, TextFieldInput as Input, TextFieldTextarea as Textarea, TextFieldPrefixIcon as PrefixIcon, TextFieldPrefixText as PrefixText, TextFieldSuffixIcon as SuffixIcon, TextFieldSuffixText as SuffixText, type TextFieldRootProps as RootProps, type TextFieldInputProps as InputProps, type TextFieldTextareaProps as TextareaProps, type TextFieldPrefixIconProps as PrefixIconProps, type TextFieldPrefixTextProps as PrefixTextProps, type TextFieldSuffixIconProps as SuffixIconProps, type TextFieldSuffixTextProps as SuffixTextProps, } from './TextField';
|
|
2
2
|
//# sourceMappingURL=TextField.namespace.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TextField.namespace.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/TextField.namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"TextField.namespace.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/TextField.namespace.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,IAAI,IAAI,EACrB,cAAc,IAAI,KAAK,EACvB,iBAAiB,IAAI,QAAQ,EAC7B,mBAAmB,IAAI,UAAU,EACjC,mBAAmB,IAAI,UAAU,EACjC,mBAAmB,IAAI,UAAU,EACjC,mBAAmB,IAAI,UAAU,EACjC,KAAK,kBAAkB,IAAI,SAAS,EACpC,KAAK,mBAAmB,IAAI,UAAU,EACtC,KAAK,sBAAsB,IAAI,aAAa,EAC5C,KAAK,wBAAwB,IAAI,eAAe,EAChD,KAAK,wBAAwB,IAAI,eAAe,EAChD,KAAK,wBAAwB,IAAI,eAAe,EAChD,KAAK,wBAAwB,IAAI,eAAe,GACjD,MAAM,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { TextFieldInput as Input, TextFieldPrefixIcon as PrefixIcon, TextFieldPrefixText as PrefixText, TextFieldRoot as Root, TextFieldSuffixIcon as SuffixIcon, TextFieldSuffixText as SuffixText, TextFieldTextarea as Textarea } from './TextField.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=TextField.test.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextField.test.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/TextField.test.tsx"],"names":[],"mappings":"AAAA,OAAO,kCAAkC,CAAC"}
|
|
@@ -3,26 +3,17 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
5
|
const TextField = require('./TextField.cjs');
|
|
6
|
+
const useTextFieldWithGraphemes = require('./useTextFieldWithGraphemes.cjs');
|
|
6
7
|
const TextField_namespace = require('./TextField.namespace.cjs');
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
|
|
10
|
-
exports.TextFieldCharacterCount = TextField.TextFieldCharacterCount;
|
|
11
|
-
exports.TextFieldCharacterCountArea = TextField.TextFieldCharacterCountArea;
|
|
12
|
-
exports.TextFieldDescription = TextField.TextFieldDescription;
|
|
13
|
-
exports.TextFieldErrorIcon = TextField.TextFieldErrorIcon;
|
|
14
|
-
exports.TextFieldErrorMessage = TextField.TextFieldErrorMessage;
|
|
15
|
-
exports.TextFieldField = TextField.TextFieldField;
|
|
16
|
-
exports.TextFieldFooter = TextField.TextFieldFooter;
|
|
17
|
-
exports.TextFieldHeader = TextField.TextFieldHeader;
|
|
18
|
-
exports.TextFieldIndicator = TextField.TextFieldIndicator;
|
|
19
11
|
exports.TextFieldInput = TextField.TextFieldInput;
|
|
20
|
-
exports.TextFieldLabel = TextField.TextFieldLabel;
|
|
21
|
-
exports.TextFieldMaxCharacterCount = TextField.TextFieldMaxCharacterCount;
|
|
22
12
|
exports.TextFieldPrefixIcon = TextField.TextFieldPrefixIcon;
|
|
23
13
|
exports.TextFieldPrefixText = TextField.TextFieldPrefixText;
|
|
24
14
|
exports.TextFieldRoot = TextField.TextFieldRoot;
|
|
25
15
|
exports.TextFieldSuffixIcon = TextField.TextFieldSuffixIcon;
|
|
26
16
|
exports.TextFieldSuffixText = TextField.TextFieldSuffixText;
|
|
27
17
|
exports.TextFieldTextarea = TextField.TextFieldTextarea;
|
|
18
|
+
exports.useTextFieldWithGraphemes = useTextFieldWithGraphemes.useTextFieldWithGraphemes;
|
|
28
19
|
exports.TextField = TextField_namespace;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { TextFieldRoot, TextFieldInput, TextFieldTextarea, TextFieldPrefixIcon, TextFieldPrefixText, TextFieldSuffixIcon, TextFieldSuffixText, type TextFieldRootProps, type TextFieldInputProps, type TextFieldTextareaProps, type TextFieldPrefixIconProps, type TextFieldPrefixTextProps, type TextFieldSuffixIconProps, type TextFieldSuffixTextProps, } from './TextField';
|
|
2
|
+
export { useTextFieldWithGraphemes, type UseTextFieldWithGraphemesParams, } from './useTextFieldWithGraphemes';
|
|
2
3
|
export * as TextField from './TextField.namespace';
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,GAC9B,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,yBAAyB,EACzB,KAAK,+BAA+B,GACrC,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,SAAS,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { TextFieldInput, TextFieldPrefixIcon, TextFieldPrefixText, TextFieldRoot, TextFieldSuffixIcon, TextFieldSuffixText, TextFieldTextarea } from './TextField.js';
|
|
2
|
+
export { useTextFieldWithGraphemes } from './useTextFieldWithGraphemes.js';
|
|
2
3
|
import * as TextField_namespace from './TextField.namespace.js';
|
|
3
4
|
export { TextField_namespace as TextField };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
function memoize(fn) {
|
|
7
|
+
const cache = /* @__PURE__ */ new Map();
|
|
8
|
+
return (arg) => {
|
|
9
|
+
if (cache.has(arg)) {
|
|
10
|
+
return cache.get(arg);
|
|
11
|
+
}
|
|
12
|
+
const result = fn(arg);
|
|
13
|
+
cache.set(arg, result);
|
|
14
|
+
return result;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.memoize = memoize;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memoize.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/memoize.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,MAAM,CAanF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
function memoize(fn) {
|
|
3
|
+
const cache = /* @__PURE__ */ new Map();
|
|
4
|
+
return (arg) => {
|
|
5
|
+
if (cache.has(arg)) {
|
|
6
|
+
return cache.get(arg);
|
|
7
|
+
}
|
|
8
|
+
const result = fn(arg);
|
|
9
|
+
cache.set(arg, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { memoize };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
5
|
+
|
|
6
|
+
const React = require('react');
|
|
7
|
+
const grapheme = require('../../node_modules/unicode-segmenter/grapheme.cjs');
|
|
8
|
+
const memoize = require('./memoize.cjs');
|
|
9
|
+
|
|
10
|
+
const getGraphemes = (string) => Array.from(grapheme.splitGraphemes(string));
|
|
11
|
+
const memoizedGetGraphemes = memoize.memoize(getGraphemes);
|
|
12
|
+
function useTextFieldWithGraphemes({
|
|
13
|
+
maxGraphemeCount,
|
|
14
|
+
value: controlledValue,
|
|
15
|
+
defaultValue = "",
|
|
16
|
+
onValueChange
|
|
17
|
+
}) {
|
|
18
|
+
const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue);
|
|
19
|
+
const isControlled = controlledValue !== void 0;
|
|
20
|
+
const value = isControlled ? controlledValue : uncontrolledValue;
|
|
21
|
+
const graphemes = React.useMemo(() => memoizedGetGraphemes(value), [value]);
|
|
22
|
+
const handleValueChange = React.useCallback(
|
|
23
|
+
(newValue) => {
|
|
24
|
+
const newGraphemes = memoizedGetGraphemes(newValue);
|
|
25
|
+
const newSlicedGraphemes = maxGraphemeCount === void 0 ? newGraphemes : newGraphemes.slice(0, maxGraphemeCount);
|
|
26
|
+
const newSlicedValue = newSlicedGraphemes.join("");
|
|
27
|
+
if (!isControlled) {
|
|
28
|
+
setUncontrolledValue(newValue);
|
|
29
|
+
}
|
|
30
|
+
onValueChange?.({
|
|
31
|
+
value: newValue,
|
|
32
|
+
graphemes: newGraphemes,
|
|
33
|
+
slicedValue: newSlicedValue,
|
|
34
|
+
slicedGraphemes: newSlicedGraphemes
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
[isControlled, maxGraphemeCount, onValueChange]
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
textFieldRootProps: {
|
|
41
|
+
value,
|
|
42
|
+
onValueChange: handleValueChange
|
|
43
|
+
},
|
|
44
|
+
counterProps: {
|
|
45
|
+
current: graphemes.length,
|
|
46
|
+
max: maxGraphemeCount ?? 0
|
|
47
|
+
},
|
|
48
|
+
graphemes
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
exports.useTextFieldWithGraphemes = useTextFieldWithGraphemes;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface UseTextFieldWithGraphemesParams {
|
|
2
|
+
maxGraphemeCount?: number;
|
|
3
|
+
value?: string;
|
|
4
|
+
defaultValue?: string;
|
|
5
|
+
onValueChange?: (values: {
|
|
6
|
+
value: string;
|
|
7
|
+
graphemes: string[];
|
|
8
|
+
slicedValue: string;
|
|
9
|
+
slicedGraphemes: string[];
|
|
10
|
+
}) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useTextFieldWithGraphemes({ maxGraphemeCount, value: controlledValue, defaultValue, onValueChange, }: UseTextFieldWithGraphemesParams): {
|
|
13
|
+
textFieldRootProps: {
|
|
14
|
+
value: string;
|
|
15
|
+
onValueChange: (newValue: string) => void;
|
|
16
|
+
};
|
|
17
|
+
counterProps: {
|
|
18
|
+
current: number;
|
|
19
|
+
max: number;
|
|
20
|
+
};
|
|
21
|
+
graphemes: string[];
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=useTextFieldWithGraphemes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTextFieldWithGraphemes.d.ts","sourceRoot":"","sources":["../../../src/components/TextField/useTextFieldWithGraphemes.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,+BAA+B;IAC9C,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE;QACvB,KAAK,EAAE,MAAM,CAAC;QACd,SAAS,EAAE,MAAM,EAAE,CAAC;QACpB,WAAW,EAAE,MAAM,CAAC;QACpB,eAAe,EAAE,MAAM,EAAE,CAAC;KAC3B,KAAK,IAAI,CAAC;CACZ;AAKD,wBAAgB,yBAAyB,CAAC,EACxC,gBAAgB,EAChB,KAAK,EAAE,eAAe,EACtB,YAAiB,EACjB,aAAa,GACd,EAAE,+BAA+B;;;kCAQnB,MAAM;;;;;;;EAgCpB"}
|