@snack-uikit/fields 0.9.2 → 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.
Files changed (61) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +32 -32
  3. package/dist/components/FieldDate/FieldDate.d.ts +2 -8
  4. package/dist/components/FieldDate/FieldDate.js +11 -16
  5. package/dist/components/FieldDecorator/FieldDecorator.d.ts +0 -6
  6. package/dist/components/FieldDecorator/FieldDecorator.js +4 -6
  7. package/dist/components/FieldDecorator/Footer.d.ts +1 -1
  8. package/dist/components/FieldDecorator/Footer.js +6 -6
  9. package/dist/components/FieldDecorator/Header.d.ts +1 -1
  10. package/dist/components/FieldDecorator/Header.js +1 -1
  11. package/dist/components/FieldSecure/FieldSecure.d.ts +2 -8
  12. package/dist/components/FieldSecure/FieldSecure.js +5 -10
  13. package/dist/components/FieldSelect/FieldSelect.d.ts +5 -12
  14. package/dist/components/FieldSelect/FieldSelect.js +5 -13
  15. package/dist/components/FieldSelect/FieldSelectBase.d.ts +5 -4
  16. package/dist/components/FieldSelect/FieldSelectBase.js +6 -6
  17. package/dist/components/FieldSelect/FieldSelectMulti.d.ts +2 -2
  18. package/dist/components/FieldSelect/FieldSelectMulti.js +2 -3
  19. package/dist/components/FieldSelect/FieldSelectSingle.d.ts +2 -2
  20. package/dist/components/FieldSelect/FieldSelectSingle.js +2 -3
  21. package/dist/components/FieldSelect/constants.d.ts +4 -0
  22. package/dist/components/FieldSelect/constants.js +4 -0
  23. package/dist/components/FieldSelect/helpers/getArrowIcon.d.ts +2 -2
  24. package/dist/components/FieldSelect/helpers/getArrowIcon.js +5 -2
  25. package/dist/components/FieldSelect/helpers/getDisplayedValue.d.ts +4 -3
  26. package/dist/components/FieldSelect/helpers/getDisplayedValue.js +2 -2
  27. package/dist/components/FieldSelect/types.d.ts +0 -4
  28. package/dist/components/FieldSelect/types.js +1 -5
  29. package/dist/components/FieldText/FieldText.d.ts +2 -8
  30. package/dist/components/FieldText/FieldText.js +5 -10
  31. package/dist/components/FieldTextArea/FieldTextArea.d.ts +1 -8
  32. package/dist/components/FieldTextArea/FieldTextArea.js +5 -10
  33. package/dist/constants.d.ts +10 -10
  34. package/dist/constants.js +10 -12
  35. package/dist/helperComponents/ButtonCopyValue/helpers.js +3 -3
  36. package/dist/helperComponents/ButtonHideValue/ButtonHideValue.js +2 -2
  37. package/dist/helperComponents/FieldContainerPrivate/FieldContainerPrivate.d.ts +1 -1
  38. package/dist/helperComponents/FieldContainerPrivate/FieldContainerPrivate.js +2 -2
  39. package/dist/types.d.ts +4 -0
  40. package/dist/types.js +1 -0
  41. package/package.json +9 -9
  42. package/src/components/FieldDate/FieldDate.tsx +16 -26
  43. package/src/components/FieldDecorator/FieldDecorator.tsx +5 -8
  44. package/src/components/FieldDecorator/Footer.tsx +7 -6
  45. package/src/components/FieldDecorator/Header.tsx +2 -2
  46. package/src/components/FieldSecure/FieldSecure.tsx +7 -18
  47. package/src/components/FieldSelect/FieldSelect.tsx +8 -23
  48. package/src/components/FieldSelect/FieldSelectBase.tsx +14 -13
  49. package/src/components/FieldSelect/FieldSelectMulti.tsx +3 -3
  50. package/src/components/FieldSelect/FieldSelectSingle.tsx +3 -3
  51. package/src/components/FieldSelect/constants.ts +5 -0
  52. package/src/components/FieldSelect/helpers/getArrowIcon.ts +5 -2
  53. package/src/components/FieldSelect/helpers/getDisplayedValue.ts +5 -4
  54. package/src/components/FieldSelect/types.ts +0 -5
  55. package/src/components/FieldText/FieldText.tsx +7 -18
  56. package/src/components/FieldTextArea/FieldTextArea.tsx +9 -20
  57. package/src/constants.ts +10 -10
  58. package/src/helperComponents/ButtonCopyValue/helpers.tsx +3 -3
  59. package/src/helperComponents/ButtonHideValue/ButtonHideValue.tsx +5 -5
  60. package/src/helperComponents/FieldContainerPrivate/FieldContainerPrivate.tsx +3 -2
  61. package/src/types.ts +7 -0
@@ -18,7 +18,7 @@ export type HeaderProps = {
18
18
  size?: Size;
19
19
  /**
20
20
  * Расположение подсказки лейбла
21
- * @default Tooltip.placements.Top
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 = Tooltip.placements.Top,
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
- Size,
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 { ContainerVariant, ValidationState } from '../../constants';
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 ForwardedFieldSecure = forwardRef<HTMLInputElement, FieldSecureProps>(
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 = Size.S,
77
- validationState = ValidationState.Default,
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={ContainerVariant.SingleLine}
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 ? InputPrivate.types.Password : InputPrivate.types.Text}
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 { Size } from '@snack-uikit/input-private';
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, SelectionMode } from './types';
6
+ import { FieldSelectMultiProps, FieldSelectSingleProps } from './types';
10
7
 
11
8
  export type FieldSelectProps =
12
9
  | ({
13
- selectionMode?: SelectionMode.Single;
10
+ selectionMode?: typeof SELECTION_MODE.Single;
14
11
  } & FieldSelectSingleProps)
15
12
  | ({
16
- selectionMode: SelectionMode.Multi;
13
+ selectionMode: typeof SELECTION_MODE.Multi;
17
14
  } & FieldSelectMultiProps);
18
15
 
19
- const ForwardedFieldSelect = forwardRef<HTMLInputElement, FieldSelectProps>(
20
- ({ selectionMode = SelectionMode.Single, ...props }, ref) => {
16
+ export const FieldSelect = forwardRef<HTMLInputElement, FieldSelectProps>(
17
+ ({ selectionMode = SELECTION_MODE.Single, ...props }, ref) => {
21
18
  switch (selectionMode) {
22
- case SelectionMode.Multi:
19
+ case SELECTION_MODE.Multi:
23
20
  return <FieldSelectMulti {...(props as FieldSelectMultiProps)} ref={ref} />;
24
- case SelectionMode.Single:
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, Size, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
13
+ import { InputPrivate, SIZE, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
14
14
  import { extractSupportProps } from '@snack-uikit/utils';
15
15
 
16
- import { ContainerVariant, ValidationState } from '../../constants';
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, SelectionMode } from './types';
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: (direction: string) => void;
43
+ onDroplistFocusLeave(direction: string): void;
43
44
  firstDroplistItemRefCallback: RefCallback<HTMLButtonElement>;
44
45
  };
45
46
 
46
47
  type Props =
47
48
  | ({
48
- selectionMode: SelectionMode.Single;
49
+ selectionMode: typeof SELECTION_MODE.Single;
49
50
  selected: Option;
50
51
  } & BaseProps)
51
52
  | ({
52
- selectionMode: SelectionMode.Multi;
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 = Size.S,
93
- validationState = ValidationState.Default,
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 === SelectionMode.Single ? Droplist.ItemSingle : Droplist.ItemMultiple;
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={Droplist.triggers.Click}
151
+ trigger='click'
151
152
  triggerClassName={styles.triggerClassName}
152
153
  triggerClickByKeys={!searchable}
153
- placement={Droplist.placements.Bottom}
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={ContainerVariant.SingleLine}
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={InputPrivate.types.Text}
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, SelectionMode } from './types';
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 = SelectionMode.Multi;
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, SelectionMode } from './types';
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 = SelectionMode.Single;
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 });
@@ -2,3 +2,8 @@ import { Option } from './types';
2
2
 
3
3
  export const EMPTY_OPTION: Option = { value: '', label: '' };
4
4
  export const DEFAULT_LOCALE = new Intl.Locale('ru-RU');
5
+
6
+ export const SELECTION_MODE = {
7
+ Single: 'single',
8
+ Multi: 'multi',
9
+ } as const;
@@ -1,6 +1,9 @@
1
1
  import { ChevronDownSVG, ChevronUpSVG } from '@snack-uikit/icons';
2
- import { IconSize, Size } from '@snack-uikit/input-private';
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 { ArrowIcon: open ? ChevronUpSVG : ChevronDownSVG, arrowIconSize: size === Size.S ? IconSize.Xs : IconSize.S };
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 { Option, SelectionMode } from '../types';
1
+ import { SELECTION_MODE } from '../constants';
2
+ import { Option } from '../types';
2
3
 
3
4
  export const getDisplayedValue = (
4
5
  props:
5
- | { selectionMode: SelectionMode.Single; selected: Option }
6
- | { selectionMode: SelectionMode.Multi; selected: Option[]; getSelectedItemsText(amount: number): string },
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 === SelectionMode.Single) {
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, Size, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
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 { ContainerVariant, ValidationState } from '../../constants';
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 ForwardedFieldText = forwardRef<HTMLInputElement, FieldTextProps>(
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 = Size.S,
64
- validationState = ValidationState.Default,
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={ContainerVariant.SingleLine}
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={InputPrivate.types.Text}
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 { Size, useButtonNavigation, useClearButton } from '@snack-uikit/input-private';
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 { ContainerVariant, ValidationState } from '../../constants';
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 ForwardedFieldTextArea = forwardRef<HTMLTextAreaElement, FieldTextAreaProps>(
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 = Size.S,
72
- validationState = ValidationState.Default,
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={ContainerVariant.MultiLine}
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={Scroll.sizes.S}
134
- barHideStrategy={Scroll.barHideStrategies.Never}
135
- resize={isResizable ? Scroll.resizes.Vertical : Scroll.resizes.None}
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 enum ValidationState {
2
- Default = 'default',
3
- Error = 'error',
4
- Warning = 'warning',
5
- Success = '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 enum ContainerVariant {
9
- SingleLine = 'single-line-container',
10
- MultiLine = 'multi-line-container',
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 ButtonSize.S: {
11
+ case BUTTON_SIZE.S: {
12
12
  return isChecked ? <CheckSVG size={16} /> : <CopySVG size={16} />;
13
13
  }
14
- case ButtonSize.M:
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 === ButtonSize.S && <EyeClosedSVG size={16} />}
44
- {size === ButtonSize.M && <EyeClosedSVG />}
43
+ {size === BUTTON_SIZE.S && <EyeClosedSVG size={16} />}
44
+ {size === BUTTON_SIZE.M && <EyeClosedSVG />}
45
45
  </>
46
46
  ) : (
47
47
  <>
48
- {size === ButtonSize.S && <EyeSVG size={16} />}
49
- {size === ButtonSize.M && <EyeSVG />}
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 { ContainerVariant, ValidationState } from '../../constants';
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 ? ValidationState.Default : validationState}
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
@@ -0,0 +1,7 @@
1
+ import { ValueOf } from '@snack-uikit/utils';
2
+
3
+ import { CONTAINER_VARIANT, VALIDATION_STATE } from './constants';
4
+
5
+ export type ValidationState = ValueOf<typeof VALIDATION_STATE>;
6
+
7
+ export type ContainerVariant = ValueOf<typeof CONTAINER_VARIANT>;