@snack-uikit/fields 0.9.1 → 0.10.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 +20 -0
- package/README.md +32 -32
- package/dist/components/FieldDate/FieldDate.d.ts +2 -8
- package/dist/components/FieldDate/FieldDate.js +11 -16
- package/dist/components/FieldDecorator/FieldDecorator.d.ts +0 -6
- package/dist/components/FieldDecorator/FieldDecorator.js +4 -6
- package/dist/components/FieldDecorator/Footer.d.ts +1 -1
- package/dist/components/FieldDecorator/Footer.js +6 -6
- package/dist/components/FieldDecorator/Header.d.ts +1 -1
- package/dist/components/FieldDecorator/Header.js +1 -1
- package/dist/components/FieldSecure/FieldSecure.d.ts +2 -8
- package/dist/components/FieldSecure/FieldSecure.js +5 -10
- package/dist/components/FieldSelect/FieldSelect.d.ts +5 -12
- package/dist/components/FieldSelect/FieldSelect.js +5 -13
- package/dist/components/FieldSelect/FieldSelectBase.d.ts +5 -4
- package/dist/components/FieldSelect/FieldSelectBase.js +6 -6
- package/dist/components/FieldSelect/FieldSelectMulti.d.ts +2 -2
- package/dist/components/FieldSelect/FieldSelectMulti.js +2 -3
- package/dist/components/FieldSelect/FieldSelectSingle.d.ts +2 -2
- package/dist/components/FieldSelect/FieldSelectSingle.js +2 -3
- package/dist/components/FieldSelect/constants.d.ts +4 -0
- package/dist/components/FieldSelect/constants.js +4 -0
- package/dist/components/FieldSelect/helpers/getArrowIcon.d.ts +2 -2
- package/dist/components/FieldSelect/helpers/getArrowIcon.js +5 -2
- package/dist/components/FieldSelect/helpers/getDisplayedValue.d.ts +4 -3
- package/dist/components/FieldSelect/helpers/getDisplayedValue.js +2 -2
- package/dist/components/FieldSelect/types.d.ts +0 -4
- package/dist/components/FieldSelect/types.js +1 -5
- package/dist/components/FieldText/FieldText.d.ts +2 -8
- package/dist/components/FieldText/FieldText.js +5 -10
- package/dist/components/FieldTextArea/FieldTextArea.d.ts +1 -8
- package/dist/components/FieldTextArea/FieldTextArea.js +5 -10
- package/dist/constants.d.ts +10 -10
- package/dist/constants.js +10 -12
- package/dist/helperComponents/ButtonCopyValue/helpers.js +3 -3
- package/dist/helperComponents/ButtonHideValue/ButtonHideValue.js +2 -2
- package/dist/helperComponents/FieldContainerPrivate/FieldContainerPrivate.d.ts +1 -1
- package/dist/helperComponents/FieldContainerPrivate/FieldContainerPrivate.js +2 -2
- package/dist/types.d.ts +4 -0
- package/dist/types.js +1 -0
- package/package.json +9 -9
- package/src/components/FieldDate/FieldDate.tsx +16 -26
- package/src/components/FieldDecorator/FieldDecorator.tsx +5 -8
- package/src/components/FieldDecorator/Footer.tsx +7 -6
- package/src/components/FieldDecorator/Header.tsx +2 -2
- package/src/components/FieldSecure/FieldSecure.tsx +7 -18
- package/src/components/FieldSelect/FieldSelect.tsx +8 -23
- package/src/components/FieldSelect/FieldSelectBase.tsx +14 -13
- package/src/components/FieldSelect/FieldSelectMulti.tsx +3 -3
- package/src/components/FieldSelect/FieldSelectSingle.tsx +3 -3
- package/src/components/FieldSelect/constants.ts +5 -0
- package/src/components/FieldSelect/helpers/getArrowIcon.ts +5 -2
- package/src/components/FieldSelect/helpers/getDisplayedValue.ts +5 -4
- package/src/components/FieldSelect/types.ts +0 -5
- package/src/components/FieldText/FieldText.tsx +7 -18
- package/src/components/FieldTextArea/FieldTextArea.tsx +9 -20
- package/src/constants.ts +10 -10
- package/src/helperComponents/ButtonCopyValue/helpers.tsx +3 -3
- package/src/helperComponents/ButtonHideValue/ButtonHideValue.tsx +5 -5
- package/src/helperComponents/FieldContainerPrivate/FieldContainerPrivate.tsx +3 -2
- package/src/types.ts +7 -0
|
@@ -18,7 +18,7 @@ export type HeaderProps = {
|
|
|
18
18
|
size?: Size;
|
|
19
19
|
/**
|
|
20
20
|
* Расположение подсказки лейбла
|
|
21
|
-
* @default
|
|
21
|
+
* @default top
|
|
22
22
|
*/
|
|
23
23
|
labelTooltipPlacement?: TooltipProps['placement'];
|
|
24
24
|
};
|
|
@@ -29,7 +29,7 @@ export function Header({
|
|
|
29
29
|
labelFor,
|
|
30
30
|
size,
|
|
31
31
|
required = false,
|
|
32
|
-
labelTooltipPlacement =
|
|
32
|
+
labelTooltipPlacement = 'top',
|
|
33
33
|
}: HeaderProps) {
|
|
34
34
|
return (
|
|
35
35
|
<span className={styles.header} data-size={size}>
|
|
@@ -7,13 +7,12 @@ import {
|
|
|
7
7
|
InputPrivateProps,
|
|
8
8
|
moveCursorToEnd,
|
|
9
9
|
runAfterRerender,
|
|
10
|
-
|
|
10
|
+
SIZE,
|
|
11
11
|
useButtonNavigation,
|
|
12
12
|
} from '@snack-uikit/input-private';
|
|
13
|
-
import { Tooltip } from '@snack-uikit/tooltip';
|
|
14
13
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
15
14
|
|
|
16
|
-
import {
|
|
15
|
+
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
17
16
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
18
17
|
import { useCopyButton, useHideButton } from '../../hooks';
|
|
19
18
|
import { FieldDecorator, FieldDecoratorProps } from '../FieldDecorator';
|
|
@@ -49,7 +48,7 @@ type FieldSecureOwnProps = {
|
|
|
49
48
|
|
|
50
49
|
export type FieldSecureProps = WithSupportProps<FieldSecureOwnProps & InputProps & WrapperProps>;
|
|
51
50
|
|
|
52
|
-
const
|
|
51
|
+
export const FieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(
|
|
53
52
|
(
|
|
54
53
|
{
|
|
55
54
|
id,
|
|
@@ -73,8 +72,8 @@ const ForwardedFieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(
|
|
|
73
72
|
labelTooltipPlacement,
|
|
74
73
|
required = false,
|
|
75
74
|
hint,
|
|
76
|
-
size =
|
|
77
|
-
validationState =
|
|
75
|
+
size = SIZE.S,
|
|
76
|
+
validationState = VALIDATION_STATE.Default,
|
|
78
77
|
prefixIcon,
|
|
79
78
|
...rest
|
|
80
79
|
},
|
|
@@ -130,7 +129,7 @@ const ForwardedFieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(
|
|
|
130
129
|
validationState={validationState}
|
|
131
130
|
disabled={disabled}
|
|
132
131
|
readonly={readonly}
|
|
133
|
-
variant={
|
|
132
|
+
variant={CONTAINER_VARIANT.SingleLine}
|
|
134
133
|
inputRef={localRef}
|
|
135
134
|
prefix={prefixIcon}
|
|
136
135
|
postfix={buttons}
|
|
@@ -147,7 +146,7 @@ const ForwardedFieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(
|
|
|
147
146
|
placeholder={placeholder}
|
|
148
147
|
disabled={disabled}
|
|
149
148
|
readonly={readonly}
|
|
150
|
-
type={hidden ?
|
|
149
|
+
type={hidden ? 'password' : 'text'}
|
|
151
150
|
maxLength={allowMoreThanMaxLength ? undefined : maxLength || undefined}
|
|
152
151
|
id={id}
|
|
153
152
|
name={name}
|
|
@@ -158,13 +157,3 @@ const ForwardedFieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(
|
|
|
158
157
|
);
|
|
159
158
|
},
|
|
160
159
|
);
|
|
161
|
-
|
|
162
|
-
export const FieldSecure = ForwardedFieldSecure as typeof ForwardedFieldSecure & {
|
|
163
|
-
sizes: typeof Size;
|
|
164
|
-
validationStates: typeof ValidationState;
|
|
165
|
-
labelTooltipPlacements: typeof Tooltip.placements;
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
FieldSecure.sizes = Size;
|
|
169
|
-
FieldSecure.validationStates = ValidationState;
|
|
170
|
-
FieldSecure.labelTooltipPlacements = Tooltip.placements;
|
|
@@ -1,41 +1,26 @@
|
|
|
1
1
|
import { forwardRef } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { Tooltip } from '@snack-uikit/tooltip';
|
|
5
|
-
|
|
6
|
-
import { ValidationState } from '../../constants';
|
|
3
|
+
import { SELECTION_MODE } from './constants';
|
|
7
4
|
import { FieldSelectMulti } from './FieldSelectMulti';
|
|
8
5
|
import { FieldSelectSingle } from './FieldSelectSingle';
|
|
9
|
-
import { FieldSelectMultiProps, FieldSelectSingleProps
|
|
6
|
+
import { FieldSelectMultiProps, FieldSelectSingleProps } from './types';
|
|
10
7
|
|
|
11
8
|
export type FieldSelectProps =
|
|
12
9
|
| ({
|
|
13
|
-
selectionMode?:
|
|
10
|
+
selectionMode?: typeof SELECTION_MODE.Single;
|
|
14
11
|
} & FieldSelectSingleProps)
|
|
15
12
|
| ({
|
|
16
|
-
selectionMode:
|
|
13
|
+
selectionMode: typeof SELECTION_MODE.Multi;
|
|
17
14
|
} & FieldSelectMultiProps);
|
|
18
15
|
|
|
19
|
-
const
|
|
20
|
-
({ selectionMode =
|
|
16
|
+
export const FieldSelect = forwardRef<HTMLInputElement, FieldSelectProps>(
|
|
17
|
+
({ selectionMode = SELECTION_MODE.Single, ...props }, ref) => {
|
|
21
18
|
switch (selectionMode) {
|
|
22
|
-
case
|
|
19
|
+
case SELECTION_MODE.Multi:
|
|
23
20
|
return <FieldSelectMulti {...(props as FieldSelectMultiProps)} ref={ref} />;
|
|
24
|
-
case
|
|
21
|
+
case SELECTION_MODE.Single:
|
|
25
22
|
default:
|
|
26
23
|
return <FieldSelectSingle {...(props as FieldSelectSingleProps)} ref={ref} />;
|
|
27
24
|
}
|
|
28
25
|
},
|
|
29
26
|
);
|
|
30
|
-
|
|
31
|
-
export const FieldSelect = ForwardedFieldSelect as typeof ForwardedFieldSelect & {
|
|
32
|
-
sizes: typeof Size;
|
|
33
|
-
validationStates: typeof ValidationState;
|
|
34
|
-
selectionModes: typeof SelectionMode;
|
|
35
|
-
labelTooltipPlacements: typeof Tooltip.placements;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
FieldSelect.sizes = Size;
|
|
39
|
-
FieldSelect.validationStates = ValidationState;
|
|
40
|
-
FieldSelect.selectionModes = SelectionMode;
|
|
41
|
-
FieldSelect.labelTooltipPlacements = Tooltip.placements;
|
|
@@ -10,17 +10,18 @@ import {
|
|
|
10
10
|
} from 'react';
|
|
11
11
|
|
|
12
12
|
import { Droplist } from '@snack-uikit/droplist';
|
|
13
|
-
import { InputPrivate,
|
|
13
|
+
import { InputPrivate, SIZE, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
14
14
|
import { extractSupportProps } from '@snack-uikit/utils';
|
|
15
15
|
|
|
16
|
-
import {
|
|
16
|
+
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
17
17
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
18
18
|
import { useCopyButton } from '../../hooks';
|
|
19
19
|
import { useHandlers } from '../FieldDate/hooks/useHandlers';
|
|
20
20
|
import { FieldDecorator } from '../FieldDecorator';
|
|
21
|
+
import { SELECTION_MODE } from './constants';
|
|
21
22
|
import { getArrowIcon } from './helpers';
|
|
22
23
|
import styles from './styles.module.scss';
|
|
23
|
-
import { ExtendedOption, FieldSelectBaseProps, Option
|
|
24
|
+
import { ExtendedOption, FieldSelectBaseProps, Option } from './types';
|
|
24
25
|
|
|
25
26
|
type BaseProps = Omit<FieldSelectBaseProps, 'open' | 'onOpenChange' | 'options'> &
|
|
26
27
|
Required<Pick<FieldSelectBaseProps, 'open' | 'onOpenChange'>> & {
|
|
@@ -39,17 +40,17 @@ type BaseProps = Omit<FieldSelectBaseProps, 'open' | 'onOpenChange' | 'options'>
|
|
|
39
40
|
copyButtonRef: RefObject<HTMLButtonElement>;
|
|
40
41
|
onClick?: MouseEventHandler<HTMLElement>;
|
|
41
42
|
onContainerPrivateMouseDown?: MouseEventHandler<HTMLElement>;
|
|
42
|
-
onDroplistFocusLeave
|
|
43
|
+
onDroplistFocusLeave(direction: string): void;
|
|
43
44
|
firstDroplistItemRefCallback: RefCallback<HTMLButtonElement>;
|
|
44
45
|
};
|
|
45
46
|
|
|
46
47
|
type Props =
|
|
47
48
|
| ({
|
|
48
|
-
selectionMode:
|
|
49
|
+
selectionMode: typeof SELECTION_MODE.Single;
|
|
49
50
|
selected: Option;
|
|
50
51
|
} & BaseProps)
|
|
51
52
|
| ({
|
|
52
|
-
selectionMode:
|
|
53
|
+
selectionMode: typeof SELECTION_MODE.Multi;
|
|
53
54
|
selected: Option[];
|
|
54
55
|
} & BaseProps);
|
|
55
56
|
|
|
@@ -89,8 +90,8 @@ export const FieldSelectBase = forwardRef<HTMLInputElement, Props>(
|
|
|
89
90
|
required = false,
|
|
90
91
|
hint,
|
|
91
92
|
showHintIcon,
|
|
92
|
-
size =
|
|
93
|
-
validationState =
|
|
93
|
+
size = SIZE.S,
|
|
94
|
+
validationState = VALIDATION_STATE.Default,
|
|
94
95
|
prefixIcon,
|
|
95
96
|
locale,
|
|
96
97
|
noDataText = locale?.language === 'ru' ? 'Нет данных' : 'No data',
|
|
@@ -101,7 +102,7 @@ export const FieldSelectBase = forwardRef<HTMLInputElement, Props>(
|
|
|
101
102
|
ref,
|
|
102
103
|
) => {
|
|
103
104
|
const { ArrowIcon, arrowIconSize } = getArrowIcon({ size, open });
|
|
104
|
-
const Item = selectionMode ===
|
|
105
|
+
const Item = selectionMode === SELECTION_MODE.Single ? Droplist.ItemSingle : Droplist.ItemMultiple;
|
|
105
106
|
|
|
106
107
|
const clearButtonSettings = useClearButton({ clearButtonRef, showClearButton, size, onClear });
|
|
107
108
|
const copyButtonSettings = useCopyButton({ copyButtonRef, showCopyButton, size, valueToCopy });
|
|
@@ -147,10 +148,10 @@ export const FieldSelectBase = forwardRef<HTMLInputElement, Props>(
|
|
|
147
148
|
{...extractSupportProps(rest)}
|
|
148
149
|
>
|
|
149
150
|
<Droplist
|
|
150
|
-
trigger=
|
|
151
|
+
trigger='click'
|
|
151
152
|
triggerClassName={styles.triggerClassName}
|
|
152
153
|
triggerClickByKeys={!searchable}
|
|
153
|
-
placement=
|
|
154
|
+
placement='bottom'
|
|
154
155
|
onFocusLeave={onFocusLeaveHandler}
|
|
155
156
|
firstElementRefCallback={firstDroplistItemRefCallback}
|
|
156
157
|
data-test-id='field-select__list'
|
|
@@ -162,7 +163,7 @@ export const FieldSelectBase = forwardRef<HTMLInputElement, Props>(
|
|
|
162
163
|
validationState={validationState}
|
|
163
164
|
disabled={disabled}
|
|
164
165
|
readonly={readonly}
|
|
165
|
-
variant={
|
|
166
|
+
variant={CONTAINER_VARIANT.SingleLine}
|
|
166
167
|
focused={open}
|
|
167
168
|
selectable={!searchable}
|
|
168
169
|
inputRef={localRef}
|
|
@@ -178,7 +179,7 @@ export const FieldSelectBase = forwardRef<HTMLInputElement, Props>(
|
|
|
178
179
|
<InputPrivate
|
|
179
180
|
id={id}
|
|
180
181
|
name={name}
|
|
181
|
-
type=
|
|
182
|
+
type='text'
|
|
182
183
|
placeholder={placeholder}
|
|
183
184
|
ref={mergeRefs(ref, localRef)}
|
|
184
185
|
onFocus={onFocus}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { FocusEventHandler, forwardRef, MouseEventHandler, useCallback, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
3
3
|
|
|
4
|
-
import { DEFAULT_LOCALE } from './constants';
|
|
4
|
+
import { DEFAULT_LOCALE, SELECTION_MODE } from './constants';
|
|
5
5
|
import { FieldSelectBase } from './FieldSelectBase';
|
|
6
6
|
import { getDisplayedValue } from './helpers';
|
|
7
7
|
import { useList } from './hooks';
|
|
8
|
-
import { FieldSelectMultiProps, Option
|
|
8
|
+
import { FieldSelectMultiProps, Option } from './types';
|
|
9
9
|
|
|
10
10
|
export const FieldSelectMulti = forwardRef<HTMLInputElement, FieldSelectMultiProps>(
|
|
11
11
|
(
|
|
@@ -28,7 +28,7 @@ export const FieldSelectMulti = forwardRef<HTMLInputElement, FieldSelectMultiPro
|
|
|
28
28
|
},
|
|
29
29
|
ref,
|
|
30
30
|
) => {
|
|
31
|
-
const selectionMode =
|
|
31
|
+
const selectionMode = SELECTION_MODE.Multi;
|
|
32
32
|
const [value, setValue] = useUncontrolledProp(valueProp, [], onChange);
|
|
33
33
|
const selected = useMemo(() => options.filter(option => value?.includes(option.value)), [options, value]);
|
|
34
34
|
const displayedValue = getDisplayedValue({ selectionMode, selected, getSelectedItemsText });
|
|
@@ -3,11 +3,11 @@ import { useUncontrolledProp } from 'uncontrollable';
|
|
|
3
3
|
|
|
4
4
|
import { selectAll } from '@snack-uikit/input-private';
|
|
5
5
|
|
|
6
|
-
import { DEFAULT_LOCALE, EMPTY_OPTION } from './constants';
|
|
6
|
+
import { DEFAULT_LOCALE, EMPTY_OPTION, SELECTION_MODE } from './constants';
|
|
7
7
|
import { FieldSelectBase } from './FieldSelectBase';
|
|
8
8
|
import { getDisplayedValue } from './helpers';
|
|
9
9
|
import { useList } from './hooks';
|
|
10
|
-
import { FieldSelectSingleProps, Option
|
|
10
|
+
import { FieldSelectSingleProps, Option } from './types';
|
|
11
11
|
|
|
12
12
|
export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleProps>(
|
|
13
13
|
(
|
|
@@ -27,7 +27,7 @@ export const FieldSelectSingle = forwardRef<HTMLInputElement, FieldSelectSingleP
|
|
|
27
27
|
},
|
|
28
28
|
ref,
|
|
29
29
|
) => {
|
|
30
|
-
const selectionMode =
|
|
30
|
+
const selectionMode = SELECTION_MODE.Single;
|
|
31
31
|
const [value, setValue] = useUncontrolledProp(valueProp, '', onChange);
|
|
32
32
|
const selected = useMemo(() => options.find(option => option.value === value) ?? EMPTY_OPTION, [options, value]);
|
|
33
33
|
const displayedValue = getDisplayedValue({ selectionMode, selected });
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
|
|
2
|
-
import {
|
|
2
|
+
import { ICON_SIZE, SIZE, Size } from '@snack-uikit/input-private';
|
|
3
3
|
|
|
4
4
|
export function getArrowIcon({ size, open }: { size: Size; open: boolean }) {
|
|
5
|
-
return {
|
|
5
|
+
return {
|
|
6
|
+
ArrowIcon: open ? ChevronUpSVG : ChevronDownSVG,
|
|
7
|
+
arrowIconSize: size === SIZE.S ? ICON_SIZE.Xs : ICON_SIZE.S,
|
|
8
|
+
};
|
|
6
9
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SELECTION_MODE } from '../constants';
|
|
2
|
+
import { Option } from '../types';
|
|
2
3
|
|
|
3
4
|
export const getDisplayedValue = (
|
|
4
5
|
props:
|
|
5
|
-
| { selectionMode:
|
|
6
|
-
| { selectionMode:
|
|
6
|
+
| { selectionMode: typeof SELECTION_MODE.Single; selected: Option }
|
|
7
|
+
| { selectionMode: typeof SELECTION_MODE.Multi; selected: Option[]; getSelectedItemsText(amount: number): string },
|
|
7
8
|
) => {
|
|
8
|
-
if (props.selectionMode ===
|
|
9
|
+
if (props.selectionMode === SELECTION_MODE.Single) {
|
|
9
10
|
return props.selected.label;
|
|
10
11
|
}
|
|
11
12
|
|
|
@@ -6,11 +6,6 @@ import { WithSupportProps } from '@snack-uikit/utils';
|
|
|
6
6
|
|
|
7
7
|
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
8
8
|
|
|
9
|
-
export enum SelectionMode {
|
|
10
|
-
Single = 'single',
|
|
11
|
-
Multi = 'multi',
|
|
12
|
-
}
|
|
13
|
-
|
|
14
9
|
export type Option = Pick<ItemSingleProps, 'caption' | 'description' | 'tagLabel' | 'icon' | 'avatar' | 'disabled'> & {
|
|
15
10
|
value: string;
|
|
16
11
|
label: string;
|
|
@@ -2,11 +2,10 @@ import mergeRefs from 'merge-refs';
|
|
|
2
2
|
import { forwardRef, ReactElement, useMemo, useRef } from 'react';
|
|
3
3
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
4
4
|
|
|
5
|
-
import { InputPrivate, InputPrivateProps,
|
|
6
|
-
import { Tooltip } from '@snack-uikit/tooltip';
|
|
5
|
+
import { InputPrivate, InputPrivateProps, SIZE, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
7
6
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
8
7
|
|
|
9
|
-
import {
|
|
8
|
+
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
10
9
|
import { FieldContainerPrivate } from '../../helperComponents';
|
|
11
10
|
import { useCopyButton } from '../../hooks';
|
|
12
11
|
import { FieldDecorator, FieldDecoratorProps } from '../FieldDecorator';
|
|
@@ -38,7 +37,7 @@ type FieldTextOwnProps = {
|
|
|
38
37
|
|
|
39
38
|
export type FieldTextProps = WithSupportProps<FieldTextOwnProps & InputProps & WrapperProps>;
|
|
40
39
|
|
|
41
|
-
const
|
|
40
|
+
export const FieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
42
41
|
(
|
|
43
42
|
{
|
|
44
43
|
id,
|
|
@@ -60,8 +59,8 @@ const ForwardedFieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
|
60
59
|
required = false,
|
|
61
60
|
hint,
|
|
62
61
|
showHintIcon,
|
|
63
|
-
size =
|
|
64
|
-
validationState =
|
|
62
|
+
size = SIZE.S,
|
|
63
|
+
validationState = VALIDATION_STATE.Default,
|
|
65
64
|
prefixIcon,
|
|
66
65
|
...rest
|
|
67
66
|
},
|
|
@@ -114,7 +113,7 @@ const ForwardedFieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
|
114
113
|
validationState={validationState}
|
|
115
114
|
disabled={disabled}
|
|
116
115
|
readonly={readonly}
|
|
117
|
-
variant={
|
|
116
|
+
variant={CONTAINER_VARIANT.SingleLine}
|
|
118
117
|
inputRef={localRef}
|
|
119
118
|
prefix={prefixIcon}
|
|
120
119
|
postfix={buttons}
|
|
@@ -131,7 +130,7 @@ const ForwardedFieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
|
131
130
|
placeholder={placeholder}
|
|
132
131
|
disabled={disabled}
|
|
133
132
|
readonly={readonly}
|
|
134
|
-
type=
|
|
133
|
+
type='text'
|
|
135
134
|
maxLength={allowMoreThanMaxLength ? undefined : maxLength || undefined}
|
|
136
135
|
id={id}
|
|
137
136
|
name={name}
|
|
@@ -142,13 +141,3 @@ const ForwardedFieldText = forwardRef<HTMLInputElement, FieldTextProps>(
|
|
|
142
141
|
);
|
|
143
142
|
},
|
|
144
143
|
);
|
|
145
|
-
|
|
146
|
-
export const FieldText = ForwardedFieldText as typeof ForwardedFieldText & {
|
|
147
|
-
sizes: typeof Size;
|
|
148
|
-
validationStates: typeof ValidationState;
|
|
149
|
-
labelTooltipPlacements: typeof Tooltip.placements;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
FieldText.sizes = Size;
|
|
153
|
-
FieldText.validationStates = ValidationState;
|
|
154
|
-
FieldText.labelTooltipPlacements = Tooltip.placements;
|
|
@@ -2,12 +2,11 @@ import mergeRefs from 'merge-refs';
|
|
|
2
2
|
import { ChangeEvent, forwardRef, useMemo, useRef } from 'react';
|
|
3
3
|
import { useUncontrolledProp } from 'uncontrollable';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { SIZE, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
6
6
|
import { Scroll } from '@snack-uikit/scroll';
|
|
7
|
-
import { Tooltip } from '@snack-uikit/tooltip';
|
|
8
7
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
11
10
|
import { FieldContainerPrivate, TextArea, TextAreaProps } from '../../helperComponents';
|
|
12
11
|
import { useCopyButton } from '../../hooks';
|
|
13
12
|
import { FieldDecorator, FieldDecoratorProps } from '../FieldDecorator';
|
|
@@ -44,7 +43,7 @@ type FieldTextAreaOwnProps = {
|
|
|
44
43
|
|
|
45
44
|
export type FieldTextAreaProps = WithSupportProps<FieldTextAreaOwnProps & InputProps & WrapperProps>;
|
|
46
45
|
|
|
47
|
-
const
|
|
46
|
+
export const FieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProps>(
|
|
48
47
|
(
|
|
49
48
|
{
|
|
50
49
|
id,
|
|
@@ -68,8 +67,8 @@ const ForwardedFieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProp
|
|
|
68
67
|
labelTooltipPlacement,
|
|
69
68
|
required = false,
|
|
70
69
|
hint,
|
|
71
|
-
size =
|
|
72
|
-
validationState =
|
|
70
|
+
size = SIZE.S,
|
|
71
|
+
validationState = VALIDATION_STATE.Default,
|
|
73
72
|
...rest
|
|
74
73
|
},
|
|
75
74
|
ref,
|
|
@@ -123,16 +122,16 @@ const ForwardedFieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProp
|
|
|
123
122
|
disabled={disabled}
|
|
124
123
|
readonly={readonly}
|
|
125
124
|
data-resizable={isResizable || undefined}
|
|
126
|
-
variant={
|
|
125
|
+
variant={CONTAINER_VARIANT.MultiLine}
|
|
127
126
|
style={{ '--max-rows': maxRows }}
|
|
128
127
|
inputRef={localRef}
|
|
129
128
|
postfix={<span className={styles.postfix}>{buttons}</span>}
|
|
130
129
|
>
|
|
131
130
|
<Scroll
|
|
132
131
|
className={styles.scrollContainer}
|
|
133
|
-
size=
|
|
134
|
-
barHideStrategy=
|
|
135
|
-
resize={isResizable ?
|
|
132
|
+
size='s'
|
|
133
|
+
barHideStrategy='never'
|
|
134
|
+
resize={isResizable ? 'vertical' : 'none'}
|
|
136
135
|
data-test-id='field-textarea__scroll-area'
|
|
137
136
|
>
|
|
138
137
|
<TextArea
|
|
@@ -159,13 +158,3 @@ const ForwardedFieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProp
|
|
|
159
158
|
);
|
|
160
159
|
},
|
|
161
160
|
);
|
|
162
|
-
|
|
163
|
-
export const FieldTextArea = ForwardedFieldTextArea as typeof ForwardedFieldTextArea & {
|
|
164
|
-
sizes: typeof Size;
|
|
165
|
-
validationStates: typeof ValidationState;
|
|
166
|
-
labelTooltipPlacements: typeof Tooltip.placements;
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
FieldTextArea.sizes = Size;
|
|
170
|
-
FieldTextArea.validationStates = ValidationState;
|
|
171
|
-
FieldTextArea.labelTooltipPlacements = Tooltip.placements;
|
package/src/constants.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
Default
|
|
3
|
-
Error
|
|
4
|
-
Warning
|
|
5
|
-
Success
|
|
6
|
-
}
|
|
1
|
+
export const VALIDATION_STATE = {
|
|
2
|
+
Default: 'default',
|
|
3
|
+
Error: 'error',
|
|
4
|
+
Warning: 'warning',
|
|
5
|
+
Success: 'success',
|
|
6
|
+
} as const;
|
|
7
7
|
|
|
8
|
-
export
|
|
9
|
-
SingleLine
|
|
10
|
-
MultiLine
|
|
11
|
-
}
|
|
8
|
+
export const CONTAINER_VARIANT = {
|
|
9
|
+
SingleLine: 'single-line-container',
|
|
10
|
+
MultiLine: 'multi-line-container',
|
|
11
|
+
} as const;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { CheckSVG, CopySVG } from '@snack-uikit/icons';
|
|
2
|
-
import { ButtonSize } from '@snack-uikit/input-private';
|
|
2
|
+
import { BUTTON_SIZE, ButtonSize } from '@snack-uikit/input-private';
|
|
3
3
|
|
|
4
4
|
type GetIconProps = {
|
|
5
5
|
size: ButtonSize;
|
|
@@ -8,10 +8,10 @@ type GetIconProps = {
|
|
|
8
8
|
|
|
9
9
|
export function getIcon({ size, isChecked }: GetIconProps) {
|
|
10
10
|
switch (size) {
|
|
11
|
-
case
|
|
11
|
+
case BUTTON_SIZE.S: {
|
|
12
12
|
return isChecked ? <CheckSVG size={16} /> : <CopySVG size={16} />;
|
|
13
13
|
}
|
|
14
|
-
case
|
|
14
|
+
case BUTTON_SIZE.M:
|
|
15
15
|
default: {
|
|
16
16
|
return isChecked ? <CheckSVG size={24} /> : <CopySVG size={24} />;
|
|
17
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { forwardRef, KeyboardEventHandler, MouseEventHandler } from 'react';
|
|
2
2
|
|
|
3
3
|
import { EyeClosedSVG, EyeSVG } from '@snack-uikit/icons';
|
|
4
|
-
import { ButtonSize } from '@snack-uikit/input-private';
|
|
4
|
+
import { BUTTON_SIZE, ButtonSize } from '@snack-uikit/input-private';
|
|
5
5
|
|
|
6
6
|
import styles from './styles.module.scss';
|
|
7
7
|
|
|
@@ -40,13 +40,13 @@ export const ButtonHideValue = forwardRef<HTMLButtonElement, ButtonHideValueProp
|
|
|
40
40
|
>
|
|
41
41
|
{hidden ? (
|
|
42
42
|
<>
|
|
43
|
-
{size ===
|
|
44
|
-
{size ===
|
|
43
|
+
{size === BUTTON_SIZE.S && <EyeClosedSVG size={16} />}
|
|
44
|
+
{size === BUTTON_SIZE.M && <EyeClosedSVG />}
|
|
45
45
|
</>
|
|
46
46
|
) : (
|
|
47
47
|
<>
|
|
48
|
-
{size ===
|
|
49
|
-
{size ===
|
|
48
|
+
{size === BUTTON_SIZE.S && <EyeSVG size={16} />}
|
|
49
|
+
{size === BUTTON_SIZE.M && <EyeSVG />}
|
|
50
50
|
</>
|
|
51
51
|
)}
|
|
52
52
|
</button>
|
|
@@ -4,7 +4,8 @@ import { CSSProperties, MouseEventHandler, ReactElement, ReactNode, RefObject }
|
|
|
4
4
|
import { Size } from '@snack-uikit/input-private';
|
|
5
5
|
import { extractSupportProps, WithSupportProps } from '@snack-uikit/utils';
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { VALIDATION_STATE } from '../../constants';
|
|
8
|
+
import { ContainerVariant, ValidationState } from '../../types';
|
|
8
9
|
import styles from './styles.module.scss';
|
|
9
10
|
|
|
10
11
|
export type FieldContainerPrivateProps = WithSupportProps<{
|
|
@@ -53,7 +54,7 @@ export function FieldContainerPrivate({
|
|
|
53
54
|
className={cn(className, styles.container)}
|
|
54
55
|
style={style}
|
|
55
56
|
data-size={size}
|
|
56
|
-
data-validation={disabled || readonly ?
|
|
57
|
+
data-validation={disabled || readonly ? VALIDATION_STATE.Default : validationState}
|
|
57
58
|
data-variant={variant}
|
|
58
59
|
data-disabled={disabled || undefined}
|
|
59
60
|
data-readonly={readonly || undefined}
|
package/src/types.ts
ADDED