@snack-uikit/fields 0.27.1 → 0.28.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 +11 -0
- package/README.md +33 -0
- package/dist/components/FieldColor/FieldColor.d.ts +40 -0
- package/dist/components/FieldColor/FieldColor.js +71 -0
- package/dist/components/FieldColor/index.d.ts +1 -0
- package/dist/components/FieldColor/index.js +1 -0
- package/dist/components/FieldColor/styles.module.css +23 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/package.json +8 -7
- package/src/components/FieldColor/FieldColor.tsx +210 -0
- package/src/components/FieldColor/index.ts +1 -0
- package/src/components/FieldColor/styles.module.scss +41 -0
- package/src/components/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 0.28.0 (2024-09-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* **PDS-691:** add FieldColor ([abba77c](https://github.com/cloud-ru-tech/snack-uikit/commit/abba77c02e2ee3181505dead81833a1adc37bc8e))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## 0.27.1 (2024-09-24)
|
|
7
18
|
|
|
8
19
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -456,6 +456,39 @@ FieldStepper в основном предназначен для работы с
|
|
|
456
456
|
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
457
457
|
| ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
|
|
458
458
|
| key | `Key` | - | |
|
|
459
|
+
## FieldColor
|
|
460
|
+
### Props
|
|
461
|
+
| name | type | default value | description |
|
|
462
|
+
|------|------|---------------|-------------|
|
|
463
|
+
| open | `boolean` | - | Открыт color-picker |
|
|
464
|
+
| onOpenChange | `(value: boolean) => void` | - | Колбек открытия пикера |
|
|
465
|
+
| showCopyButton | `boolean` | - | Отображение кнопки копирования |
|
|
466
|
+
| showClearButton | `boolean` | true | Отображение кнопки Очистки поля |
|
|
467
|
+
| value | `string` | - | Значение input |
|
|
468
|
+
| onChange | `(value: string) => void` | - | |
|
|
469
|
+
| className | `string` | - | Класснейм |
|
|
470
|
+
| withAlpha | `boolean` | - | Значение с альфаканалом |
|
|
471
|
+
| autoApply | `boolean` | - | Применять изменения автоматически, если значение false - то изменения происходят по кнопке |
|
|
472
|
+
| colorMode | `{ hex?: boolean; rgb?: boolean; hsv?: boolean; }` | - | |
|
|
473
|
+
| disabled | `boolean` | - | Является ли поле деактивированным |
|
|
474
|
+
| readonly | `boolean` | - | Является ли поле доступным только для чтения |
|
|
475
|
+
| id | `string` | - | Значение html-атрибута id |
|
|
476
|
+
| name | `string` | - | Значение html-атрибута name |
|
|
477
|
+
| placeholder | `string` | - | Значение плейсхолдера |
|
|
478
|
+
| onFocus | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки получения фокуса |
|
|
479
|
+
| onBlur | `FocusEventHandler<HTMLInputElement>` | - | Колбек обработки потери фокуса |
|
|
480
|
+
| error | `string` | - | |
|
|
481
|
+
| label | `string` | - | Лейбл |
|
|
482
|
+
| caption | `string` | - | Подпись справа от лейбла |
|
|
483
|
+
| labelTooltip | `ReactNode` | - | Всплывающая подсказка лейбла |
|
|
484
|
+
| required | `boolean` | - | Является ли поле обязательным |
|
|
485
|
+
| size | enum Size: `"s"`, `"m"`, `"l"` | SIZE.S | Размер |
|
|
486
|
+
| labelTooltipPlacement | enum Placement: `"left"`, `"left-start"`, `"left-end"`, `"right"`, `"right-start"`, `"right-end"`, `"top"`, `"top-start"`, `"top-end"`, `"bottom"`, `"bottom-start"`, `"bottom-end"` | top | Расположение подсказки лейбла |
|
|
487
|
+
| hint | `string` | - | Подсказка внизу |
|
|
488
|
+
| validationState | enum ValidationState: `"default"`, `"error"`, `"warning"`, `"success"` | default | Состояние валидации |
|
|
489
|
+
| showHintIcon | `boolean` | - | Отображать иконку подсказки |
|
|
490
|
+
| ref | `Ref<HTMLInputElement>` | - | Allows getting a ref to the component instance. Once the component unmounts, React will set `ref.current` to `null` (or call the ref with `null` if you passed a callback ref). @see https://react.dev/learn/referencing-values-with-refs#refs-and-the-dom |
|
|
491
|
+
| key | `Key` | - | |
|
|
459
492
|
|
|
460
493
|
|
|
461
494
|
[//]: DOCUMENTATION_SECTION_END
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ColorPickerProps } from '@snack-uikit/color-picker';
|
|
2
|
+
import { InputPrivateProps } from '@snack-uikit/input-private';
|
|
3
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
4
|
+
import { FieldDecoratorProps } from '../FieldDecorator';
|
|
5
|
+
type InputProps = Pick<InputPrivateProps, 'id' | 'name' | 'value' | 'disabled' | 'readonly' | 'onFocus' | 'onBlur' | 'placeholder'>;
|
|
6
|
+
type WrapperProps = Pick<FieldDecoratorProps, 'className' | 'label' | 'labelTooltip' | 'required' | 'caption' | 'hint' | 'showHintIcon' | 'size' | 'validationState' | 'labelTooltipPlacement' | 'error'>;
|
|
7
|
+
type FieldDateOwnProps = {
|
|
8
|
+
/** Открыт color-picker */
|
|
9
|
+
open?: boolean;
|
|
10
|
+
/** Колбек открытия пикера */
|
|
11
|
+
onOpenChange?(value: boolean): void;
|
|
12
|
+
/** Отображение кнопки копирования */
|
|
13
|
+
showCopyButton?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Отображение кнопки Очистки поля
|
|
16
|
+
* @default true
|
|
17
|
+
*/
|
|
18
|
+
showClearButton?: boolean;
|
|
19
|
+
value?: string;
|
|
20
|
+
onChange?(value: string): void;
|
|
21
|
+
} & Omit<ColorPickerProps, 'onChange' | 'value'>;
|
|
22
|
+
export type FieldColorProps = WithSupportProps<FieldDateOwnProps & InputProps & WrapperProps>;
|
|
23
|
+
export declare const FieldColor: import("react").ForwardRefExoticComponent<{
|
|
24
|
+
'data-test-id'?: string;
|
|
25
|
+
} & import("react").AriaAttributes & {
|
|
26
|
+
/** Открыт color-picker */
|
|
27
|
+
open?: boolean;
|
|
28
|
+
/** Колбек открытия пикера */
|
|
29
|
+
onOpenChange?(value: boolean): void;
|
|
30
|
+
/** Отображение кнопки копирования */
|
|
31
|
+
showCopyButton?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Отображение кнопки Очистки поля
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
showClearButton?: boolean;
|
|
37
|
+
value?: string;
|
|
38
|
+
onChange?(value: string): void;
|
|
39
|
+
} & Omit<ColorPickerProps, "onChange" | "value"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import mergeRefs from 'merge-refs';
|
|
14
|
+
import { forwardRef, useEffect, useMemo, useRef } from 'react';
|
|
15
|
+
import { useUncontrolledProp } from 'uncontrollable';
|
|
16
|
+
import { ColorPicker } from '@snack-uikit/color-picker';
|
|
17
|
+
import { Dropdown } from '@snack-uikit/dropdown';
|
|
18
|
+
import { InputPrivate, SIZE, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
19
|
+
import { extractSupportProps, useValueControl } from '@snack-uikit/utils';
|
|
20
|
+
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
21
|
+
import { FieldContainerPrivate } from '../../helperComponents';
|
|
22
|
+
import { useCopyButton } from '../../hooks';
|
|
23
|
+
import { getValidationState } from '../../utils/getValidationState';
|
|
24
|
+
import { FieldDecorator } from '../FieldDecorator';
|
|
25
|
+
import styles from './styles.module.css';
|
|
26
|
+
export const FieldColor = forwardRef((_a, ref) => {
|
|
27
|
+
var { id, name, value: valueProp, disabled = false, readonly = false, showCopyButton: showCopyButtonProp = true, showClearButton: showClearButtonProp = true, open, onChange, onOpenChange, className, label, labelTooltip, labelTooltipPlacement, required = false, caption, hint, showHintIcon, size = SIZE.S, validationState = VALIDATION_STATE.Default, error, withAlpha, autoApply, placeholder, onFocus, onBlur } = _a, rest = __rest(_a, ["id", "name", "value", "disabled", "readonly", "showCopyButton", "showClearButton", "open", "onChange", "onOpenChange", "className", "label", "labelTooltip", "labelTooltipPlacement", "required", "caption", "hint", "showHintIcon", "size", "validationState", "error", "withAlpha", "autoApply", "placeholder", "onFocus", "onBlur"]);
|
|
28
|
+
const [isOpen, setIsOpen] = useUncontrolledProp(open, false, onOpenChange);
|
|
29
|
+
const localRef = useRef(null);
|
|
30
|
+
const showDropList = isOpen && !readonly && !disabled;
|
|
31
|
+
const fieldValidationState = getValidationState({ validationState, error });
|
|
32
|
+
const [value = '', setValue] = useValueControl({ value: valueProp || '', onChange: onChange });
|
|
33
|
+
const clearButtonRef = useRef(null);
|
|
34
|
+
const copyButtonRef = useRef(null);
|
|
35
|
+
const showAdditionalButton = Boolean(value && !disabled);
|
|
36
|
+
const showClearButton = showClearButtonProp && showAdditionalButton && !readonly;
|
|
37
|
+
const showCopyButton = showCopyButtonProp && showAdditionalButton && readonly;
|
|
38
|
+
const onClear = () => {
|
|
39
|
+
var _a;
|
|
40
|
+
setValue === null || setValue === void 0 ? void 0 : setValue('');
|
|
41
|
+
if (required) {
|
|
42
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const clearButtonSettings = useClearButton({ clearButtonRef, showClearButton, size, onClear });
|
|
46
|
+
const copyButtonSettings = useCopyButton({ copyButtonRef, showCopyButton, size, valueToCopy: value });
|
|
47
|
+
const { buttons, inputTabIndex, onInputKeyDown } = useButtonNavigation({
|
|
48
|
+
inputRef: localRef,
|
|
49
|
+
buttons: useMemo(() => [clearButtonSettings, copyButtonSettings], [clearButtonSettings, copyButtonSettings]),
|
|
50
|
+
readonly,
|
|
51
|
+
submitKeys: ['Enter', 'Space', 'Tab'],
|
|
52
|
+
});
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
var _a;
|
|
55
|
+
if (open) {
|
|
56
|
+
(_a = localRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
57
|
+
}
|
|
58
|
+
}, [open]);
|
|
59
|
+
return (_jsx(FieldDecorator, Object.assign({ className: className, label: label, labelTooltip: labelTooltip, labelTooltipPlacement: labelTooltipPlacement, labelFor: id, required: required, caption: caption, hint: hint, disabled: disabled, readonly: readonly, showHintIcon: showHintIcon, size: size, error: error, validationState: fieldValidationState }, extractSupportProps(rest), { children: _jsx(Dropdown, Object.assign({ trigger: 'click', triggerClassName: styles.triggerClassName, widthStrategy: 'auto' }, (readonly || disabled
|
|
60
|
+
? { open: false }
|
|
61
|
+
: {
|
|
62
|
+
open: showDropList,
|
|
63
|
+
onOpenChange: setIsOpen,
|
|
64
|
+
}), { content: _jsx(ColorPicker, { withAlpha: withAlpha, autoApply: autoApply, value: value, onChange: ({ hex }) => {
|
|
65
|
+
setValue === null || setValue === void 0 ? void 0 : setValue(hex || '');
|
|
66
|
+
}, colorMode: {
|
|
67
|
+
hex: false,
|
|
68
|
+
} }), children: _jsx(FieldContainerPrivate, { className: styles.container, size: size, validationState: fieldValidationState, disabled: disabled, readonly: readonly, variant: CONTAINER_VARIANT.SingleLine, focused: showDropList, inputRef: localRef, postfix: buttons, prefix: _jsx("div", { className: styles.colorPreview, style: {
|
|
69
|
+
'--color': value,
|
|
70
|
+
} }), children: _jsx(InputPrivate, { ref: mergeRefs(ref, localRef), "data-size": size, value: value, onChange: onChange, onFocus: onFocus, onBlur: onBlur, tabIndex: inputTabIndex, onKeyDown: onInputKeyDown, disabled: disabled, readonly: readonly, placeholder: placeholder, type: 'text', id: id, name: name, "data-test-id": 'field-color__input' }) }) })) })));
|
|
71
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FieldColor';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FieldColor';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
.triggerClassName{
|
|
2
|
+
--offset:var(--space-drop-list-drop-offset, 4px);
|
|
3
|
+
display:block;
|
|
4
|
+
width:100%;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.colorPreview{
|
|
8
|
+
position:relative;
|
|
9
|
+
width:var(--dimension-2m, 16px);
|
|
10
|
+
height:var(--dimension-2m, 16px);
|
|
11
|
+
background-color:#fff;
|
|
12
|
+
border-radius:var(--dimension-050m, 4px);
|
|
13
|
+
}
|
|
14
|
+
.colorPreview::after{
|
|
15
|
+
content:"";
|
|
16
|
+
position:absolute;
|
|
17
|
+
top:0;
|
|
18
|
+
left:0;
|
|
19
|
+
width:100%;
|
|
20
|
+
height:100%;
|
|
21
|
+
background-color:var(--color);
|
|
22
|
+
border-radius:var(--dimension-050m, 4px);
|
|
23
|
+
}
|
package/dist/components/index.js
CHANGED
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
6
|
"title": "Fields",
|
|
7
|
-
"version": "0.
|
|
7
|
+
"version": "0.28.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -33,17 +33,18 @@
|
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/button": "0.17.5",
|
|
36
|
-
"@snack-uikit/calendar": "0.7.
|
|
36
|
+
"@snack-uikit/calendar": "0.7.12",
|
|
37
|
+
"@snack-uikit/color-picker": "0.1.0",
|
|
37
38
|
"@snack-uikit/dropdown": "0.2.7",
|
|
38
39
|
"@snack-uikit/icons": "0.22.1",
|
|
39
40
|
"@snack-uikit/input-private": "3.2.1",
|
|
40
|
-
"@snack-uikit/list": "0.16.
|
|
41
|
-
"@snack-uikit/scroll": "0.6.
|
|
41
|
+
"@snack-uikit/list": "0.16.4",
|
|
42
|
+
"@snack-uikit/scroll": "0.6.2",
|
|
42
43
|
"@snack-uikit/skeleton": "0.3.5",
|
|
43
44
|
"@snack-uikit/slider": "0.1.18",
|
|
44
|
-
"@snack-uikit/tag": "0.9.
|
|
45
|
+
"@snack-uikit/tag": "0.9.11",
|
|
45
46
|
"@snack-uikit/tooltip": "0.13.10",
|
|
46
|
-
"@snack-uikit/truncate-string": "0.4.
|
|
47
|
+
"@snack-uikit/truncate-string": "0.4.24",
|
|
47
48
|
"@snack-uikit/utils": "3.4.0",
|
|
48
49
|
"classnames": "2.3.2",
|
|
49
50
|
"copy-to-clipboard": "3.3.3",
|
|
@@ -59,5 +60,5 @@
|
|
|
59
60
|
"peerDependencies": {
|
|
60
61
|
"@snack-uikit/locale": "*"
|
|
61
62
|
},
|
|
62
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "6f68e2729e48e5b34674af649dc9dfb3bda3951f"
|
|
63
64
|
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import mergeRefs from 'merge-refs';
|
|
2
|
+
import { forwardRef, useEffect, useMemo, useRef } from 'react';
|
|
3
|
+
import { useUncontrolledProp } from 'uncontrollable';
|
|
4
|
+
|
|
5
|
+
import { ColorPicker, ColorPickerProps } from '@snack-uikit/color-picker';
|
|
6
|
+
import { Dropdown } from '@snack-uikit/dropdown';
|
|
7
|
+
import { InputPrivate, InputPrivateProps, SIZE, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
|
|
8
|
+
import { extractSupportProps, useValueControl, WithSupportProps } from '@snack-uikit/utils';
|
|
9
|
+
|
|
10
|
+
import { CONTAINER_VARIANT, VALIDATION_STATE } from '../../constants';
|
|
11
|
+
import { FieldContainerPrivate } from '../../helperComponents';
|
|
12
|
+
import { useCopyButton } from '../../hooks';
|
|
13
|
+
import { getValidationState } from '../../utils/getValidationState';
|
|
14
|
+
import { FieldDecorator, FieldDecoratorProps } from '../FieldDecorator';
|
|
15
|
+
import styles from './styles.module.scss';
|
|
16
|
+
|
|
17
|
+
type InputProps = Pick<
|
|
18
|
+
InputPrivateProps,
|
|
19
|
+
'id' | 'name' | 'value' | 'disabled' | 'readonly' | 'onFocus' | 'onBlur' | 'placeholder'
|
|
20
|
+
>;
|
|
21
|
+
|
|
22
|
+
type WrapperProps = Pick<
|
|
23
|
+
FieldDecoratorProps,
|
|
24
|
+
| 'className'
|
|
25
|
+
| 'label'
|
|
26
|
+
| 'labelTooltip'
|
|
27
|
+
| 'required'
|
|
28
|
+
| 'caption'
|
|
29
|
+
| 'hint'
|
|
30
|
+
| 'showHintIcon'
|
|
31
|
+
| 'size'
|
|
32
|
+
| 'validationState'
|
|
33
|
+
| 'labelTooltipPlacement'
|
|
34
|
+
| 'error'
|
|
35
|
+
>;
|
|
36
|
+
|
|
37
|
+
type FieldDateOwnProps = {
|
|
38
|
+
/** Открыт color-picker */
|
|
39
|
+
open?: boolean;
|
|
40
|
+
/** Колбек открытия пикера */
|
|
41
|
+
onOpenChange?(value: boolean): void;
|
|
42
|
+
/** Отображение кнопки копирования */
|
|
43
|
+
showCopyButton?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Отображение кнопки Очистки поля
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
showClearButton?: boolean;
|
|
49
|
+
|
|
50
|
+
value?: string;
|
|
51
|
+
onChange?(value: string): void;
|
|
52
|
+
} & Omit<ColorPickerProps, 'onChange' | 'value'>;
|
|
53
|
+
|
|
54
|
+
export type FieldColorProps = WithSupportProps<FieldDateOwnProps & InputProps & WrapperProps>;
|
|
55
|
+
|
|
56
|
+
export const FieldColor = forwardRef<HTMLInputElement, FieldColorProps>(
|
|
57
|
+
(
|
|
58
|
+
{
|
|
59
|
+
id,
|
|
60
|
+
name,
|
|
61
|
+
value: valueProp,
|
|
62
|
+
disabled = false,
|
|
63
|
+
readonly = false,
|
|
64
|
+
showCopyButton: showCopyButtonProp = true,
|
|
65
|
+
showClearButton: showClearButtonProp = true,
|
|
66
|
+
open,
|
|
67
|
+
onChange,
|
|
68
|
+
onOpenChange,
|
|
69
|
+
className,
|
|
70
|
+
label,
|
|
71
|
+
labelTooltip,
|
|
72
|
+
labelTooltipPlacement,
|
|
73
|
+
required = false,
|
|
74
|
+
caption,
|
|
75
|
+
hint,
|
|
76
|
+
showHintIcon,
|
|
77
|
+
size = SIZE.S,
|
|
78
|
+
validationState = VALIDATION_STATE.Default,
|
|
79
|
+
error,
|
|
80
|
+
withAlpha,
|
|
81
|
+
autoApply,
|
|
82
|
+
placeholder,
|
|
83
|
+
onFocus,
|
|
84
|
+
onBlur,
|
|
85
|
+
...rest
|
|
86
|
+
},
|
|
87
|
+
ref,
|
|
88
|
+
) => {
|
|
89
|
+
const [isOpen, setIsOpen] = useUncontrolledProp(open, false, onOpenChange);
|
|
90
|
+
|
|
91
|
+
const localRef = useRef<HTMLInputElement>(null);
|
|
92
|
+
|
|
93
|
+
const showDropList = isOpen && !readonly && !disabled;
|
|
94
|
+
const fieldValidationState = getValidationState({ validationState, error });
|
|
95
|
+
|
|
96
|
+
const [value = '', setValue] = useValueControl<string>({ value: valueProp || '', onChange: onChange });
|
|
97
|
+
|
|
98
|
+
const clearButtonRef = useRef<HTMLButtonElement>(null);
|
|
99
|
+
const copyButtonRef = useRef<HTMLButtonElement>(null);
|
|
100
|
+
const showAdditionalButton = Boolean(value && !disabled);
|
|
101
|
+
const showClearButton = showClearButtonProp && showAdditionalButton && !readonly;
|
|
102
|
+
const showCopyButton = showCopyButtonProp && showAdditionalButton && readonly;
|
|
103
|
+
|
|
104
|
+
const onClear = () => {
|
|
105
|
+
setValue?.('');
|
|
106
|
+
|
|
107
|
+
if (required) {
|
|
108
|
+
localRef.current?.focus();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
const clearButtonSettings = useClearButton({ clearButtonRef, showClearButton, size, onClear });
|
|
113
|
+
const copyButtonSettings = useCopyButton({ copyButtonRef, showCopyButton, size, valueToCopy: value });
|
|
114
|
+
const { buttons, inputTabIndex, onInputKeyDown } = useButtonNavigation({
|
|
115
|
+
inputRef: localRef,
|
|
116
|
+
buttons: useMemo(() => [clearButtonSettings, copyButtonSettings], [clearButtonSettings, copyButtonSettings]),
|
|
117
|
+
readonly,
|
|
118
|
+
submitKeys: ['Enter', 'Space', 'Tab'],
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
if (open) {
|
|
123
|
+
localRef.current?.focus();
|
|
124
|
+
}
|
|
125
|
+
}, [open]);
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<FieldDecorator
|
|
129
|
+
className={className}
|
|
130
|
+
label={label}
|
|
131
|
+
labelTooltip={labelTooltip}
|
|
132
|
+
labelTooltipPlacement={labelTooltipPlacement}
|
|
133
|
+
labelFor={id}
|
|
134
|
+
required={required}
|
|
135
|
+
caption={caption}
|
|
136
|
+
hint={hint}
|
|
137
|
+
disabled={disabled}
|
|
138
|
+
readonly={readonly}
|
|
139
|
+
showHintIcon={showHintIcon}
|
|
140
|
+
size={size}
|
|
141
|
+
error={error}
|
|
142
|
+
validationState={fieldValidationState}
|
|
143
|
+
{...extractSupportProps(rest)}
|
|
144
|
+
>
|
|
145
|
+
<Dropdown
|
|
146
|
+
trigger='click'
|
|
147
|
+
triggerClassName={styles.triggerClassName}
|
|
148
|
+
widthStrategy='auto'
|
|
149
|
+
{...(readonly || disabled
|
|
150
|
+
? { open: false }
|
|
151
|
+
: {
|
|
152
|
+
open: showDropList,
|
|
153
|
+
onOpenChange: setIsOpen,
|
|
154
|
+
})}
|
|
155
|
+
content={
|
|
156
|
+
<ColorPicker
|
|
157
|
+
withAlpha={withAlpha}
|
|
158
|
+
autoApply={autoApply}
|
|
159
|
+
value={value}
|
|
160
|
+
onChange={({ hex }) => {
|
|
161
|
+
setValue?.(hex || '');
|
|
162
|
+
}}
|
|
163
|
+
colorMode={{
|
|
164
|
+
hex: false,
|
|
165
|
+
}}
|
|
166
|
+
/>
|
|
167
|
+
}
|
|
168
|
+
>
|
|
169
|
+
<FieldContainerPrivate
|
|
170
|
+
className={styles.container}
|
|
171
|
+
size={size}
|
|
172
|
+
validationState={fieldValidationState}
|
|
173
|
+
disabled={disabled}
|
|
174
|
+
readonly={readonly}
|
|
175
|
+
variant={CONTAINER_VARIANT.SingleLine}
|
|
176
|
+
focused={showDropList}
|
|
177
|
+
inputRef={localRef}
|
|
178
|
+
postfix={buttons}
|
|
179
|
+
prefix={
|
|
180
|
+
<div
|
|
181
|
+
className={styles.colorPreview}
|
|
182
|
+
style={{
|
|
183
|
+
'--color': value,
|
|
184
|
+
}}
|
|
185
|
+
/>
|
|
186
|
+
}
|
|
187
|
+
>
|
|
188
|
+
<InputPrivate
|
|
189
|
+
ref={mergeRefs(ref, localRef)}
|
|
190
|
+
data-size={size}
|
|
191
|
+
value={value}
|
|
192
|
+
onChange={onChange}
|
|
193
|
+
onFocus={onFocus}
|
|
194
|
+
onBlur={onBlur}
|
|
195
|
+
tabIndex={inputTabIndex}
|
|
196
|
+
onKeyDown={onInputKeyDown}
|
|
197
|
+
disabled={disabled}
|
|
198
|
+
readonly={readonly}
|
|
199
|
+
placeholder={placeholder}
|
|
200
|
+
type='text'
|
|
201
|
+
id={id}
|
|
202
|
+
name={name}
|
|
203
|
+
data-test-id='field-color__input'
|
|
204
|
+
/>
|
|
205
|
+
</FieldContainerPrivate>
|
|
206
|
+
</Dropdown>
|
|
207
|
+
</FieldDecorator>
|
|
208
|
+
);
|
|
209
|
+
},
|
|
210
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './FieldColor';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-element';
|
|
2
|
+
@import '@snack-uikit/figma-tokens/build/scss/components/styles-tokens-fields';
|
|
3
|
+
|
|
4
|
+
$sizes: 's', 'm', 'l';
|
|
5
|
+
$icons-sizes: (
|
|
6
|
+
's': $icon-xs,
|
|
7
|
+
'm': $icon-s,
|
|
8
|
+
'l': $icon-s,
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
.triggerClassName {
|
|
12
|
+
--offset: #{$space-drop-list-drop-offset};
|
|
13
|
+
|
|
14
|
+
display: block;
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.colorPreview {
|
|
19
|
+
position: relative;
|
|
20
|
+
|
|
21
|
+
width: $dimension-2m;
|
|
22
|
+
height: $dimension-2m;
|
|
23
|
+
|
|
24
|
+
/* stylelint-disable-next-line color-no-hex */
|
|
25
|
+
background-color: #fff;
|
|
26
|
+
border-radius: $dimension-050m;
|
|
27
|
+
|
|
28
|
+
&::after {
|
|
29
|
+
content: '';
|
|
30
|
+
|
|
31
|
+
position: absolute;
|
|
32
|
+
top: 0;
|
|
33
|
+
left: 0;
|
|
34
|
+
|
|
35
|
+
width: 100%;
|
|
36
|
+
height: 100%;
|
|
37
|
+
|
|
38
|
+
background-color: var(--color);
|
|
39
|
+
border-radius: $dimension-050m;
|
|
40
|
+
}
|
|
41
|
+
}
|
package/src/components/index.ts
CHANGED