@snack-uikit/fields 0.45.0 → 0.47.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/CHANGELOG.md +22 -0
- package/README.md +2 -0
- package/dist/cjs/components/FieldColor/FieldColor.d.ts +1 -1
- package/dist/cjs/components/FieldSecure/FieldSecure.d.ts +1 -1
- package/dist/cjs/components/FieldSelect/FieldSelectMultiple.d.ts +1 -1
- package/dist/cjs/components/FieldSelect/FieldSelectSingle.d.ts +1 -1
- package/dist/cjs/components/FieldSlider/FieldSlider.d.ts +1 -1
- package/dist/cjs/components/FieldText/FieldText.d.ts +2 -2
- package/dist/cjs/components/FieldText/FieldText.js +4 -2
- package/dist/cjs/components/FieldTextArea/FieldTextArea.d.ts +2 -2
- package/dist/cjs/components/FieldTextArea/FieldTextArea.js +4 -2
- package/dist/cjs/helperComponents/ButtonFieldList/ButtonFieldList.d.ts +1 -1
- package/dist/cjs/helperComponents/TextArea/TextArea.d.ts +2 -0
- package/dist/cjs/helperComponents/TextArea/TextArea.js +5 -3
- package/dist/cjs/hooks/addonButton/index.d.ts +2 -0
- package/dist/cjs/hooks/addonButton/index.js +26 -0
- package/dist/cjs/hooks/addonButton/useAddonButton.d.ts +14 -0
- package/dist/cjs/hooks/{usePostfixButton.js → addonButton/useAddonButton.js} +22 -16
- package/dist/cjs/hooks/addonButton/usePostfixButton.d.ts +6 -0
- package/dist/cjs/hooks/addonButton/usePostfixButton.js +26 -0
- package/dist/cjs/hooks/addonButton/usePrefixButton.d.ts +6 -0
- package/dist/cjs/hooks/addonButton/usePrefixButton.js +26 -0
- package/dist/cjs/hooks/index.d.ts +1 -2
- package/dist/cjs/hooks/index.js +1 -2
- package/dist/cjs/types/allFields.d.ts +9 -4
- package/dist/esm/components/FieldColor/FieldColor.d.ts +1 -1
- package/dist/esm/components/FieldSecure/FieldSecure.d.ts +1 -1
- package/dist/esm/components/FieldSelect/FieldSelectMultiple.d.ts +1 -1
- package/dist/esm/components/FieldSelect/FieldSelectSingle.d.ts +1 -1
- package/dist/esm/components/FieldSlider/FieldSlider.d.ts +1 -1
- package/dist/esm/components/FieldText/FieldText.d.ts +2 -2
- package/dist/esm/components/FieldText/FieldText.js +2 -2
- package/dist/esm/components/FieldTextArea/FieldTextArea.d.ts +2 -2
- package/dist/esm/components/FieldTextArea/FieldTextArea.js +2 -2
- package/dist/esm/helperComponents/ButtonFieldList/ButtonFieldList.d.ts +1 -1
- package/dist/esm/helperComponents/TextArea/TextArea.d.ts +2 -0
- package/dist/esm/helperComponents/TextArea/TextArea.js +2 -2
- package/dist/esm/hooks/addonButton/index.d.ts +2 -0
- package/dist/esm/hooks/addonButton/index.js +2 -0
- package/dist/esm/hooks/addonButton/useAddonButton.d.ts +14 -0
- package/dist/esm/hooks/addonButton/useAddonButton.js +30 -0
- package/dist/esm/hooks/addonButton/usePostfixButton.d.ts +6 -0
- package/dist/esm/hooks/addonButton/usePostfixButton.js +16 -0
- package/dist/esm/hooks/addonButton/usePrefixButton.d.ts +6 -0
- package/dist/esm/hooks/addonButton/usePrefixButton.js +16 -0
- package/dist/esm/hooks/index.d.ts +1 -2
- package/dist/esm/hooks/index.js +1 -2
- package/dist/esm/types/allFields.d.ts +9 -4
- package/package.json +6 -6
- package/src/components/FieldText/FieldText.tsx +3 -0
- package/src/components/FieldTextArea/FieldTextArea.tsx +12 -1
- package/src/helperComponents/TextArea/TextArea.tsx +4 -0
- package/src/hooks/addonButton/index.ts +2 -0
- package/src/hooks/{usePostfixButton.tsx → addonButton/useAddonButton.tsx} +30 -23
- package/src/hooks/addonButton/usePostfixButton.tsx +12 -0
- package/src/hooks/addonButton/usePrefixButton.tsx +12 -0
- package/src/hooks/index.ts +1 -2
- package/src/types/allFields.ts +15 -5
- package/dist/cjs/hooks/usePostfixButton.d.ts +0 -11
- package/dist/cjs/hooks/usePrefixButton.d.ts +0 -11
- package/dist/cjs/hooks/usePrefixButton.js +0 -63
- package/dist/esm/hooks/usePostfixButton.d.ts +0 -11
- package/dist/esm/hooks/usePostfixButton.js +0 -28
- package/dist/esm/hooks/usePrefixButton.d.ts +0 -11
- package/dist/esm/hooks/usePrefixButton.js +0 -28
- package/src/hooks/usePrefixButton.tsx +0 -76
|
@@ -16,12 +16,12 @@ import TextareaAutosize from 'react-textarea-autosize';
|
|
|
16
16
|
import { extractSupportProps, useLayoutEffect } from '@snack-uikit/utils';
|
|
17
17
|
import styles from './styles.module.css';
|
|
18
18
|
export const TextArea = forwardRef((_a, ref) => {
|
|
19
|
-
var { name, value = '', onChange, placeholder, id, className, disabled = false, readonly = false, autoComplete = false, maxLength, onFocus, onBlur, onKeyDown, tabIndex, minRows = 3 } = _a, rest = __rest(_a, ["name", "value", "onChange", "placeholder", "id", "className", "disabled", "readonly", "autoComplete", "maxLength", "onFocus", "onBlur", "onKeyDown", "tabIndex", "minRows"]);
|
|
19
|
+
var { name, value = '', onChange, placeholder, id, className, disabled = false, readonly = false, autoComplete = false, maxLength, onFocus, onBlur, onKeyDown, tabIndex, minRows = 3, spellCheck } = _a, rest = __rest(_a, ["name", "value", "onChange", "placeholder", "id", "className", "disabled", "readonly", "autoComplete", "maxLength", "onFocus", "onBlur", "onKeyDown", "tabIndex", "minRows", "spellCheck"]);
|
|
20
20
|
// fix of height on the initial render
|
|
21
21
|
// see https://github.com/Andarist/react-textarea-autosize/issues/337#issuecomment-1024980737
|
|
22
22
|
const [, setIsRerendered] = useState(false);
|
|
23
23
|
useLayoutEffect(() => setIsRerendered(true), []);
|
|
24
24
|
const onChangeHandler = e => onChange === null || onChange === void 0 ? void 0 : onChange(e.target.value, e);
|
|
25
25
|
const stopPropagation = e => e.stopPropagation();
|
|
26
|
-
return (_jsx(TextareaAutosize, Object.assign({ id: id, name: name, value: value, ref: ref, className: cn(className, styles.textarea), autoComplete: autoComplete ? 'on' : 'off', placeholder: placeholder, disabled: disabled, readOnly: readonly, maxLength: maxLength, onChange: onChangeHandler, onClick: stopPropagation, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, tabIndex: tabIndex, minRows: minRows }, extractSupportProps(rest))));
|
|
26
|
+
return (_jsx(TextareaAutosize, Object.assign({ id: id, name: name, value: value, ref: ref, className: cn(className, styles.textarea), autoComplete: autoComplete ? 'on' : 'off', placeholder: placeholder, disabled: disabled, readOnly: readonly, maxLength: maxLength, onChange: onChangeHandler, onClick: stopPropagation, onFocus: onFocus, onBlur: onBlur, onKeyDown: onKeyDown, tabIndex: tabIndex, minRows: minRows, spellCheck: spellCheck }, extractSupportProps(rest))));
|
|
27
27
|
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { ButtonProps, Size } from '@snack-uikit/input-private';
|
|
3
|
+
import { ButtonFieldProps } from '../../helperComponents';
|
|
4
|
+
import { Button, ButtonVariant } from '../../types';
|
|
5
|
+
export type UseAddonProps = {
|
|
6
|
+
button?: Button;
|
|
7
|
+
size: Size;
|
|
8
|
+
icon?: ReactElement;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
readonly?: boolean;
|
|
11
|
+
variant: ButtonVariant;
|
|
12
|
+
type: 'prefix' | 'postfix';
|
|
13
|
+
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>;
|
|
14
|
+
export declare function useAddonButton({ variant, button, icon, size, disabled, readonly, type, onFocus, onBlur, }: UseAddonProps): ButtonProps;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useMemo, useRef } from 'react';
|
|
3
|
+
import { ButtonField, ButtonFieldList } from '../../helperComponents';
|
|
4
|
+
export function useAddonButton({ variant, button, icon, size, disabled, readonly, type, onFocus, onBlur, }) {
|
|
5
|
+
const buttonListRef = useRef(null);
|
|
6
|
+
const addonIconProps = useMemo(() => ({
|
|
7
|
+
id: `${type}Icon`,
|
|
8
|
+
active: false,
|
|
9
|
+
show: Boolean(icon && !button),
|
|
10
|
+
render: () => _jsx(_Fragment, { children: icon }),
|
|
11
|
+
}), [button, icon, type]);
|
|
12
|
+
const addonButtonProps = useMemo(() => ({
|
|
13
|
+
id: `${type}Button`,
|
|
14
|
+
active: false,
|
|
15
|
+
show: Boolean(button && button.variant === variant),
|
|
16
|
+
render: renderProps => {
|
|
17
|
+
const buttonProps = Object.assign(Object.assign({}, renderProps), { variant,
|
|
18
|
+
size, content: button === null || button === void 0 ? void 0 : button.content, disabled: disabled || readonly, onFocus,
|
|
19
|
+
onBlur });
|
|
20
|
+
if (button === null || button === void 0 ? void 0 : button.items) {
|
|
21
|
+
return (_jsx(ButtonFieldList, Object.assign({}, buttonProps, { ref: buttonListRef, onClick: () => {
|
|
22
|
+
setTimeout(() => { var _a; return (_a = buttonListRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 0);
|
|
23
|
+
}, search: button.search, items: button.items, selection: button.selection, open: button.open, scroll: button.scroll, onOpenChange: button.onOpenChange })));
|
|
24
|
+
}
|
|
25
|
+
const buttonField = _jsx(ButtonField, Object.assign({}, buttonProps, { hasArrow: button === null || button === void 0 ? void 0 : button.hasArrow, arrowOpen: button === null || button === void 0 ? void 0 : button.arrowOpen }));
|
|
26
|
+
return (button === null || button === void 0 ? void 0 : button.wrapper) ? button.wrapper(buttonField) : buttonField;
|
|
27
|
+
},
|
|
28
|
+
}), [type, button, variant, size, disabled, readonly, onFocus, onBlur]);
|
|
29
|
+
return button ? addonButtonProps : addonIconProps;
|
|
30
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { ButtonProps } from '@snack-uikit/input-private';
|
|
3
|
+
import { UseAddonProps } from './useAddonButton';
|
|
4
|
+
export declare function usePostfixButton({ postfixIcon, ...props }: Omit<UseAddonProps, 'type' | 'variant'> & {
|
|
5
|
+
postfixIcon?: ReactElement;
|
|
6
|
+
}): ButtonProps;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { useAddonButton } from './useAddonButton';
|
|
13
|
+
export function usePostfixButton(_a) {
|
|
14
|
+
var { postfixIcon } = _a, props = __rest(_a, ["postfixIcon"]);
|
|
15
|
+
return useAddonButton(Object.assign(Object.assign({}, props), { icon: postfixIcon, type: 'postfix', variant: 'after' }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { ButtonProps } from '@snack-uikit/input-private';
|
|
3
|
+
import { UseAddonProps } from './useAddonButton';
|
|
4
|
+
export declare function usePrefixButton({ prefixIcon, ...props }: Omit<UseAddonProps, 'type' | 'variant'> & {
|
|
5
|
+
prefixIcon?: ReactElement;
|
|
6
|
+
}): ButtonProps;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { useAddonButton } from './useAddonButton';
|
|
13
|
+
export function usePrefixButton(_a) {
|
|
14
|
+
var { prefixIcon } = _a, props = __rest(_a, ["prefixIcon"]);
|
|
15
|
+
return useAddonButton(Object.assign(Object.assign({}, props), { icon: prefixIcon, type: 'prefix', variant: 'before' }));
|
|
16
|
+
}
|
|
@@ -2,7 +2,6 @@ export * from './dateHandlers';
|
|
|
2
2
|
export * from './useCopyButton';
|
|
3
3
|
export * from './useHideButton';
|
|
4
4
|
export * from './usePostfix';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './addonButton';
|
|
6
6
|
export * from './usePrefix';
|
|
7
|
-
export * from './usePrefixButton';
|
|
8
7
|
export * from './useValueControl';
|
package/dist/esm/hooks/index.js
CHANGED
|
@@ -2,7 +2,6 @@ export * from './dateHandlers';
|
|
|
2
2
|
export * from './useCopyButton';
|
|
3
3
|
export * from './useHideButton';
|
|
4
4
|
export * from './usePostfix';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './addonButton';
|
|
6
6
|
export * from './usePrefix';
|
|
7
|
-
export * from './usePrefixButton';
|
|
8
7
|
export * from './useValueControl';
|
|
@@ -2,6 +2,7 @@ import { ReactNode } from 'react';
|
|
|
2
2
|
import { DroplistProps, SelectionSingleState } from '@snack-uikit/list';
|
|
3
3
|
import { ValueOf } from '@snack-uikit/utils';
|
|
4
4
|
import { BUTTON_VARIANT, CONTAINER_VARIANT, VALIDATION_STATE } from '../constants';
|
|
5
|
+
import { ButtonFieldProps } from '../helperComponents';
|
|
5
6
|
export type ValidationState = ValueOf<typeof VALIDATION_STATE>;
|
|
6
7
|
export type ContainerVariant = ValueOf<typeof CONTAINER_VARIANT>;
|
|
7
8
|
export type ButtonVariant = ValueOf<typeof BUTTON_VARIANT>;
|
|
@@ -12,8 +13,12 @@ export type AsyncValueRequest = Promise<{
|
|
|
12
13
|
export type NativeDroplistProps = Pick<DroplistProps, 'items' | 'open' | 'onOpenChange' | 'search' | 'scroll'> & {
|
|
13
14
|
selection?: Omit<SelectionSingleState, 'mode'>;
|
|
14
15
|
};
|
|
15
|
-
export type Button = Omit<NativeDroplistProps, 'items'> & {
|
|
16
|
-
variant: ButtonVariant;
|
|
17
|
-
content?: ReactNode;
|
|
16
|
+
export type Button = Omit<NativeDroplistProps, 'items'> & Pick<ButtonFieldProps, 'variant' | 'content'> & ({
|
|
18
17
|
items?: DroplistProps['items'];
|
|
19
|
-
|
|
18
|
+
hasArrow?: never;
|
|
19
|
+
arrowOpen?: never;
|
|
20
|
+
wrapper?: never;
|
|
21
|
+
} | (Pick<ButtonFieldProps, 'hasArrow' | 'arrowOpen'> & {
|
|
22
|
+
items?: never;
|
|
23
|
+
wrapper?: (button: ReactNode) => JSX.Element;
|
|
24
|
+
}));
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.47.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"scripts": {},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@snack-uikit/button": "0.19.11",
|
|
40
|
-
"@snack-uikit/calendar": "0.12.
|
|
41
|
-
"@snack-uikit/color-picker": "0.3.
|
|
40
|
+
"@snack-uikit/calendar": "0.12.5",
|
|
41
|
+
"@snack-uikit/color-picker": "0.3.29",
|
|
42
42
|
"@snack-uikit/divider": "3.2.6",
|
|
43
43
|
"@snack-uikit/dropdown": "0.4.8",
|
|
44
44
|
"@snack-uikit/icons": "0.26.3",
|
|
45
|
-
"@snack-uikit/input-private": "4.
|
|
46
|
-
"@snack-uikit/list": "0.29.
|
|
45
|
+
"@snack-uikit/input-private": "4.6.0",
|
|
46
|
+
"@snack-uikit/list": "0.29.3",
|
|
47
47
|
"@snack-uikit/scroll": "0.10.1",
|
|
48
48
|
"@snack-uikit/skeleton": "0.6.5",
|
|
49
49
|
"@snack-uikit/slider": "0.3.18",
|
|
@@ -65,5 +65,5 @@
|
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@snack-uikit/locale": "*"
|
|
67
67
|
},
|
|
68
|
-
"gitHead": "
|
|
68
|
+
"gitHead": "ccea2a8bfe66ef6b5e55747de61d55fe7a2368f7"
|
|
69
69
|
}
|
|
@@ -35,6 +35,7 @@ type InputProps = Pick<Partial<InputPrivateProps>, 'value' | 'onChange'> &
|
|
|
35
35
|
| 'autoComplete'
|
|
36
36
|
| 'onPaste'
|
|
37
37
|
| 'onKeyDown'
|
|
38
|
+
| 'spellCheck'
|
|
38
39
|
>;
|
|
39
40
|
|
|
40
41
|
type WrapperProps = Pick<
|
|
@@ -115,6 +116,7 @@ export const FieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
|
115
116
|
onPaste,
|
|
116
117
|
onKeyDown,
|
|
117
118
|
type = 'text',
|
|
119
|
+
spellCheck,
|
|
118
120
|
...rest
|
|
119
121
|
},
|
|
120
122
|
ref,
|
|
@@ -259,6 +261,7 @@ export const FieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
|
259
261
|
id={id}
|
|
260
262
|
name={name}
|
|
261
263
|
autoComplete={autoComplete}
|
|
264
|
+
spellCheck={spellCheck}
|
|
262
265
|
data-test-id='field-text__input'
|
|
263
266
|
/>
|
|
264
267
|
</FieldContainerPrivate>
|
|
@@ -15,7 +15,16 @@ import styles from './styles.module.scss';
|
|
|
15
15
|
type InputProps = Pick<Partial<TextAreaProps>, 'value'> &
|
|
16
16
|
Pick<
|
|
17
17
|
TextAreaProps,
|
|
18
|
-
|
|
18
|
+
| 'id'
|
|
19
|
+
| 'name'
|
|
20
|
+
| 'placeholder'
|
|
21
|
+
| 'maxLength'
|
|
22
|
+
| 'disabled'
|
|
23
|
+
| 'readonly'
|
|
24
|
+
| 'onFocus'
|
|
25
|
+
| 'onBlur'
|
|
26
|
+
| 'onKeyDown'
|
|
27
|
+
| 'spellCheck'
|
|
19
28
|
>;
|
|
20
29
|
|
|
21
30
|
type WrapperProps = Pick<
|
|
@@ -92,6 +101,7 @@ export const FieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProps>
|
|
|
92
101
|
validationState = VALIDATION_STATE.Default,
|
|
93
102
|
onCopyButtonClick,
|
|
94
103
|
footer,
|
|
104
|
+
spellCheck,
|
|
95
105
|
...rest
|
|
96
106
|
},
|
|
97
107
|
ref,
|
|
@@ -197,6 +207,7 @@ export const FieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProps>
|
|
|
197
207
|
onBlur={onBlur}
|
|
198
208
|
onKeyDown={handleKeyDown}
|
|
199
209
|
tabIndex={inputTabIndex}
|
|
210
|
+
spellCheck={spellCheck}
|
|
200
211
|
maxLength={allowMoreThanMaxLength ? undefined : maxLength || undefined}
|
|
201
212
|
data-test-id='field-textarea__input'
|
|
202
213
|
/>
|
|
@@ -46,6 +46,8 @@ export type TextAreaProps = RefAttributes<HTMLTextAreaElement> &
|
|
|
46
46
|
tabIndex?: number;
|
|
47
47
|
/** Минимальное кол-во строк, до которого размер поля может быть увеличен @default 3*/
|
|
48
48
|
minRows?: number;
|
|
49
|
+
/** Включение проверки орфографии @default true*/
|
|
50
|
+
spellCheck?: boolean;
|
|
49
51
|
}>;
|
|
50
52
|
|
|
51
53
|
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
|
|
@@ -66,6 +68,7 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
|
|
|
66
68
|
onKeyDown,
|
|
67
69
|
tabIndex,
|
|
68
70
|
minRows = 3,
|
|
71
|
+
spellCheck,
|
|
69
72
|
...rest
|
|
70
73
|
},
|
|
71
74
|
ref,
|
|
@@ -97,6 +100,7 @@ export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
|
|
|
97
100
|
onKeyDown={onKeyDown}
|
|
98
101
|
tabIndex={tabIndex}
|
|
99
102
|
minRows={minRows}
|
|
103
|
+
spellCheck={spellCheck}
|
|
100
104
|
{...extractSupportProps(rest)}
|
|
101
105
|
/>
|
|
102
106
|
);
|
|
@@ -2,45 +2,51 @@ import { ReactElement, useMemo, useRef } from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { ButtonProps, InactiveItem, Size } from '@snack-uikit/input-private';
|
|
4
4
|
|
|
5
|
-
import { ButtonField, ButtonFieldList, ButtonFieldProps } from '
|
|
6
|
-
import { Button } from '
|
|
5
|
+
import { ButtonField, ButtonFieldList, ButtonFieldProps } from '../../helperComponents';
|
|
6
|
+
import { Button, ButtonVariant } from '../../types';
|
|
7
7
|
|
|
8
|
-
export
|
|
8
|
+
export type UseAddonProps = {
|
|
9
|
+
button?: Button;
|
|
10
|
+
size: Size;
|
|
11
|
+
icon?: ReactElement;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
readonly?: boolean;
|
|
14
|
+
variant: ButtonVariant;
|
|
15
|
+
type: 'prefix' | 'postfix';
|
|
16
|
+
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>;
|
|
17
|
+
|
|
18
|
+
export function useAddonButton({
|
|
19
|
+
variant,
|
|
9
20
|
button,
|
|
21
|
+
icon,
|
|
10
22
|
size,
|
|
11
|
-
postfixIcon,
|
|
12
23
|
disabled,
|
|
13
24
|
readonly,
|
|
25
|
+
type,
|
|
14
26
|
onFocus,
|
|
15
27
|
onBlur,
|
|
16
|
-
}: {
|
|
17
|
-
button?: Button;
|
|
18
|
-
size: Size;
|
|
19
|
-
postfixIcon?: ReactElement;
|
|
20
|
-
disabled?: boolean;
|
|
21
|
-
readonly?: boolean;
|
|
22
|
-
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>): ButtonProps {
|
|
28
|
+
}: UseAddonProps): ButtonProps {
|
|
23
29
|
const buttonListRef = useRef<HTMLButtonElement>(null);
|
|
24
30
|
|
|
25
|
-
const
|
|
31
|
+
const addonIconProps: InactiveItem = useMemo(
|
|
26
32
|
() => ({
|
|
27
|
-
id:
|
|
33
|
+
id: `${type}Icon`,
|
|
28
34
|
active: false,
|
|
29
|
-
show: Boolean(
|
|
30
|
-
render: () => <>{
|
|
35
|
+
show: Boolean(icon && !button),
|
|
36
|
+
render: () => <>{icon}</>,
|
|
31
37
|
}),
|
|
32
|
-
[button,
|
|
38
|
+
[button, icon, type],
|
|
33
39
|
);
|
|
34
40
|
|
|
35
|
-
const
|
|
41
|
+
const addonButtonProps: InactiveItem = useMemo(
|
|
36
42
|
() => ({
|
|
37
|
-
id:
|
|
43
|
+
id: `${type}Button`,
|
|
38
44
|
active: false,
|
|
39
|
-
show: Boolean(button && button.variant ===
|
|
45
|
+
show: Boolean(button && button.variant === variant),
|
|
40
46
|
render: renderProps => {
|
|
41
47
|
const buttonProps: ButtonFieldProps = {
|
|
42
48
|
...renderProps,
|
|
43
|
-
variant
|
|
49
|
+
variant,
|
|
44
50
|
size,
|
|
45
51
|
content: button?.content,
|
|
46
52
|
disabled: disabled || readonly,
|
|
@@ -66,11 +72,12 @@ export function usePostfixButton({
|
|
|
66
72
|
);
|
|
67
73
|
}
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
const buttonField = <ButtonField {...buttonProps} hasArrow={button?.hasArrow} arrowOpen={button?.arrowOpen} />;
|
|
76
|
+
return button?.wrapper ? button.wrapper(buttonField) : buttonField;
|
|
70
77
|
},
|
|
71
78
|
}),
|
|
72
|
-
[button, size, disabled, readonly, onFocus, onBlur],
|
|
79
|
+
[type, button, variant, size, disabled, readonly, onFocus, onBlur],
|
|
73
80
|
);
|
|
74
81
|
|
|
75
|
-
return button ?
|
|
82
|
+
return button ? addonButtonProps : addonIconProps;
|
|
76
83
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ButtonProps } from '@snack-uikit/input-private';
|
|
4
|
+
|
|
5
|
+
import { useAddonButton, UseAddonProps } from './useAddonButton';
|
|
6
|
+
|
|
7
|
+
export function usePostfixButton({
|
|
8
|
+
postfixIcon,
|
|
9
|
+
...props
|
|
10
|
+
}: Omit<UseAddonProps, 'type' | 'variant'> & { postfixIcon?: ReactElement }): ButtonProps {
|
|
11
|
+
return useAddonButton({ ...props, icon: postfixIcon, type: 'postfix', variant: 'after' });
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { ButtonProps } from '@snack-uikit/input-private';
|
|
4
|
+
|
|
5
|
+
import { useAddonButton, UseAddonProps } from './useAddonButton';
|
|
6
|
+
|
|
7
|
+
export function usePrefixButton({
|
|
8
|
+
prefixIcon,
|
|
9
|
+
...props
|
|
10
|
+
}: Omit<UseAddonProps, 'type' | 'variant'> & { prefixIcon?: ReactElement }): ButtonProps {
|
|
11
|
+
return useAddonButton({ ...props, icon: prefixIcon, type: 'prefix', variant: 'before' });
|
|
12
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,7 +2,6 @@ export * from './dateHandlers';
|
|
|
2
2
|
export * from './useCopyButton';
|
|
3
3
|
export * from './useHideButton';
|
|
4
4
|
export * from './usePostfix';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './addonButton';
|
|
6
6
|
export * from './usePrefix';
|
|
7
|
-
export * from './usePrefixButton';
|
|
8
7
|
export * from './useValueControl';
|
package/src/types/allFields.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { DroplistProps, SelectionSingleState } from '@snack-uikit/list';
|
|
|
4
4
|
import { ValueOf } from '@snack-uikit/utils';
|
|
5
5
|
|
|
6
6
|
import { BUTTON_VARIANT, CONTAINER_VARIANT, VALIDATION_STATE } from '../constants';
|
|
7
|
+
import { ButtonFieldProps } from '../helperComponents';
|
|
7
8
|
|
|
8
9
|
export type ValidationState = ValueOf<typeof VALIDATION_STATE>;
|
|
9
10
|
|
|
@@ -17,8 +18,17 @@ export type NativeDroplistProps = Pick<DroplistProps, 'items' | 'open' | 'onOpen
|
|
|
17
18
|
selection?: Omit<SelectionSingleState, 'mode'>;
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
export type Button = Omit<NativeDroplistProps, 'items'> &
|
|
21
|
-
variant
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
export type Button = Omit<NativeDroplistProps, 'items'> &
|
|
22
|
+
Pick<ButtonFieldProps, 'variant' | 'content'> &
|
|
23
|
+
(
|
|
24
|
+
| {
|
|
25
|
+
items?: DroplistProps['items'];
|
|
26
|
+
hasArrow?: never;
|
|
27
|
+
arrowOpen?: never;
|
|
28
|
+
wrapper?: never;
|
|
29
|
+
}
|
|
30
|
+
| (Pick<ButtonFieldProps, 'hasArrow' | 'arrowOpen'> & {
|
|
31
|
+
items?: never;
|
|
32
|
+
wrapper?: (button: ReactNode) => JSX.Element;
|
|
33
|
+
})
|
|
34
|
+
);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
|
-
import { ButtonProps, Size } from '@snack-uikit/input-private';
|
|
3
|
-
import { ButtonFieldProps } from '../helperComponents';
|
|
4
|
-
import { Button } from '../types';
|
|
5
|
-
export declare function usePostfixButton({ button, size, postfixIcon, disabled, readonly, onFocus, onBlur, }: {
|
|
6
|
-
button?: Button;
|
|
7
|
-
size: Size;
|
|
8
|
-
postfixIcon?: ReactElement;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
readonly?: boolean;
|
|
11
|
-
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>): ButtonProps;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
|
-
import { ButtonProps, Size } from '@snack-uikit/input-private';
|
|
3
|
-
import { ButtonFieldProps } from '../helperComponents';
|
|
4
|
-
import { Button } from '../types';
|
|
5
|
-
export declare function usePrefixButton({ button, prefixIcon, size, disabled, readonly, onFocus, onBlur, }: {
|
|
6
|
-
button?: Button;
|
|
7
|
-
prefixIcon?: ReactElement;
|
|
8
|
-
size: Size;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
readonly?: boolean;
|
|
11
|
-
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>): ButtonProps;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.usePrefixButton = usePrefixButton;
|
|
7
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
const helperComponents_1 = require("../helperComponents");
|
|
10
|
-
function usePrefixButton(_ref) {
|
|
11
|
-
let {
|
|
12
|
-
button,
|
|
13
|
-
prefixIcon,
|
|
14
|
-
size,
|
|
15
|
-
disabled,
|
|
16
|
-
readonly,
|
|
17
|
-
onFocus,
|
|
18
|
-
onBlur
|
|
19
|
-
} = _ref;
|
|
20
|
-
const buttonListRef = (0, react_1.useRef)(null);
|
|
21
|
-
const prefixIconProps = (0, react_1.useMemo)(() => ({
|
|
22
|
-
id: 'prefixIcon',
|
|
23
|
-
active: false,
|
|
24
|
-
show: Boolean(prefixIcon && !button),
|
|
25
|
-
render: () => (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {
|
|
26
|
-
children: prefixIcon
|
|
27
|
-
})
|
|
28
|
-
}), [button, prefixIcon]);
|
|
29
|
-
const prefixButtonProps = (0, react_1.useMemo)(() => ({
|
|
30
|
-
id: 'prefixButton',
|
|
31
|
-
active: false,
|
|
32
|
-
show: Boolean(button && button.variant === 'before'),
|
|
33
|
-
render: renderProps => {
|
|
34
|
-
const buttonProps = Object.assign(Object.assign({}, renderProps), {
|
|
35
|
-
variant: 'before',
|
|
36
|
-
size,
|
|
37
|
-
content: button === null || button === void 0 ? void 0 : button.content,
|
|
38
|
-
disabled: disabled || readonly,
|
|
39
|
-
onFocus,
|
|
40
|
-
onBlur
|
|
41
|
-
});
|
|
42
|
-
if (button === null || button === void 0 ? void 0 : button.items) {
|
|
43
|
-
return (0, jsx_runtime_1.jsx)(helperComponents_1.ButtonFieldList, Object.assign({}, buttonProps, {
|
|
44
|
-
ref: buttonListRef,
|
|
45
|
-
onClick: () => {
|
|
46
|
-
setTimeout(() => {
|
|
47
|
-
var _a;
|
|
48
|
-
return (_a = buttonListRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
49
|
-
}, 0);
|
|
50
|
-
},
|
|
51
|
-
search: button.search,
|
|
52
|
-
items: button.items,
|
|
53
|
-
selection: button.selection,
|
|
54
|
-
open: button.open,
|
|
55
|
-
scroll: button.scroll,
|
|
56
|
-
onOpenChange: button.onOpenChange
|
|
57
|
-
}));
|
|
58
|
-
}
|
|
59
|
-
return (0, jsx_runtime_1.jsx)(helperComponents_1.ButtonField, Object.assign({}, buttonProps));
|
|
60
|
-
}
|
|
61
|
-
}), [button, size, disabled, readonly, onFocus, onBlur]);
|
|
62
|
-
return button ? prefixButtonProps : prefixIconProps;
|
|
63
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
|
-
import { ButtonProps, Size } from '@snack-uikit/input-private';
|
|
3
|
-
import { ButtonFieldProps } from '../helperComponents';
|
|
4
|
-
import { Button } from '../types';
|
|
5
|
-
export declare function usePostfixButton({ button, size, postfixIcon, disabled, readonly, onFocus, onBlur, }: {
|
|
6
|
-
button?: Button;
|
|
7
|
-
size: Size;
|
|
8
|
-
postfixIcon?: ReactElement;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
readonly?: boolean;
|
|
11
|
-
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>): ButtonProps;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo, useRef } from 'react';
|
|
3
|
-
import { ButtonField, ButtonFieldList } from '../helperComponents';
|
|
4
|
-
export function usePostfixButton({ button, size, postfixIcon, disabled, readonly, onFocus, onBlur, }) {
|
|
5
|
-
const buttonListRef = useRef(null);
|
|
6
|
-
const postfixIconProps = useMemo(() => ({
|
|
7
|
-
id: 'postfixIcon',
|
|
8
|
-
active: false,
|
|
9
|
-
show: Boolean(postfixIcon && !button),
|
|
10
|
-
render: () => _jsx(_Fragment, { children: postfixIcon }),
|
|
11
|
-
}), [button, postfixIcon]);
|
|
12
|
-
const postfixButtonProps = useMemo(() => ({
|
|
13
|
-
id: 'postfixButton',
|
|
14
|
-
active: false,
|
|
15
|
-
show: Boolean(button && button.variant === 'after'),
|
|
16
|
-
render: renderProps => {
|
|
17
|
-
const buttonProps = Object.assign(Object.assign({}, renderProps), { variant: 'after', size, content: button === null || button === void 0 ? void 0 : button.content, disabled: disabled || readonly, onFocus,
|
|
18
|
-
onBlur });
|
|
19
|
-
if (button === null || button === void 0 ? void 0 : button.items) {
|
|
20
|
-
return (_jsx(ButtonFieldList, Object.assign({}, buttonProps, { ref: buttonListRef, onClick: () => {
|
|
21
|
-
setTimeout(() => { var _a; return (_a = buttonListRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 0);
|
|
22
|
-
}, search: button.search, items: button.items, selection: button.selection, open: button.open, scroll: button.scroll, onOpenChange: button.onOpenChange })));
|
|
23
|
-
}
|
|
24
|
-
return _jsx(ButtonField, Object.assign({}, buttonProps));
|
|
25
|
-
},
|
|
26
|
-
}), [button, size, disabled, readonly, onFocus, onBlur]);
|
|
27
|
-
return button ? postfixButtonProps : postfixIconProps;
|
|
28
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { ReactElement } from 'react';
|
|
2
|
-
import { ButtonProps, Size } from '@snack-uikit/input-private';
|
|
3
|
-
import { ButtonFieldProps } from '../helperComponents';
|
|
4
|
-
import { Button } from '../types';
|
|
5
|
-
export declare function usePrefixButton({ button, prefixIcon, size, disabled, readonly, onFocus, onBlur, }: {
|
|
6
|
-
button?: Button;
|
|
7
|
-
prefixIcon?: ReactElement;
|
|
8
|
-
size: Size;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
readonly?: boolean;
|
|
11
|
-
} & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>): ButtonProps;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { useMemo, useRef } from 'react';
|
|
3
|
-
import { ButtonField, ButtonFieldList } from '../helperComponents';
|
|
4
|
-
export function usePrefixButton({ button, prefixIcon, size, disabled, readonly, onFocus, onBlur, }) {
|
|
5
|
-
const buttonListRef = useRef(null);
|
|
6
|
-
const prefixIconProps = useMemo(() => ({
|
|
7
|
-
id: 'prefixIcon',
|
|
8
|
-
active: false,
|
|
9
|
-
show: Boolean(prefixIcon && !button),
|
|
10
|
-
render: () => _jsx(_Fragment, { children: prefixIcon }),
|
|
11
|
-
}), [button, prefixIcon]);
|
|
12
|
-
const prefixButtonProps = useMemo(() => ({
|
|
13
|
-
id: 'prefixButton',
|
|
14
|
-
active: false,
|
|
15
|
-
show: Boolean(button && button.variant === 'before'),
|
|
16
|
-
render: renderProps => {
|
|
17
|
-
const buttonProps = Object.assign(Object.assign({}, renderProps), { variant: 'before', size, content: button === null || button === void 0 ? void 0 : button.content, disabled: disabled || readonly, onFocus,
|
|
18
|
-
onBlur });
|
|
19
|
-
if (button === null || button === void 0 ? void 0 : button.items) {
|
|
20
|
-
return (_jsx(ButtonFieldList, Object.assign({}, buttonProps, { ref: buttonListRef, onClick: () => {
|
|
21
|
-
setTimeout(() => { var _a; return (_a = buttonListRef.current) === null || _a === void 0 ? void 0 : _a.focus(); }, 0);
|
|
22
|
-
}, search: button.search, items: button.items, selection: button.selection, open: button.open, scroll: button.scroll, onOpenChange: button.onOpenChange })));
|
|
23
|
-
}
|
|
24
|
-
return _jsx(ButtonField, Object.assign({}, buttonProps));
|
|
25
|
-
},
|
|
26
|
-
}), [button, size, disabled, readonly, onFocus, onBlur]);
|
|
27
|
-
return button ? prefixButtonProps : prefixIconProps;
|
|
28
|
-
}
|