@snack-uikit/fields 0.46.0 → 0.47.1

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 (54) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/components/FieldColor/FieldColor.d.ts +1 -1
  3. package/dist/cjs/components/FieldSecure/FieldSecure.d.ts +1 -1
  4. package/dist/cjs/components/FieldSelect/FieldSelectMultiple.d.ts +1 -1
  5. package/dist/cjs/components/FieldSelect/FieldSelectSingle.d.ts +1 -1
  6. package/dist/cjs/components/FieldSlider/FieldSlider.d.ts +1 -1
  7. package/dist/cjs/components/FieldText/FieldText.d.ts +1 -1
  8. package/dist/cjs/components/FieldTextArea/FieldTextArea.d.ts +1 -1
  9. package/dist/cjs/helperComponents/ButtonFieldList/ButtonFieldList.d.ts +1 -1
  10. package/dist/cjs/hooks/addonButton/index.d.ts +2 -0
  11. package/dist/cjs/hooks/addonButton/index.js +26 -0
  12. package/dist/cjs/hooks/addonButton/useAddonButton.d.ts +14 -0
  13. package/dist/cjs/hooks/{usePostfixButton.js → addonButton/useAddonButton.js} +22 -16
  14. package/dist/cjs/hooks/addonButton/usePostfixButton.d.ts +6 -0
  15. package/dist/cjs/hooks/addonButton/usePostfixButton.js +26 -0
  16. package/dist/cjs/hooks/addonButton/usePrefixButton.d.ts +6 -0
  17. package/dist/cjs/hooks/addonButton/usePrefixButton.js +26 -0
  18. package/dist/cjs/hooks/index.d.ts +1 -2
  19. package/dist/cjs/hooks/index.js +1 -2
  20. package/dist/cjs/types/allFields.d.ts +9 -4
  21. package/dist/esm/components/FieldColor/FieldColor.d.ts +1 -1
  22. package/dist/esm/components/FieldSecure/FieldSecure.d.ts +1 -1
  23. package/dist/esm/components/FieldSelect/FieldSelectMultiple.d.ts +1 -1
  24. package/dist/esm/components/FieldSelect/FieldSelectSingle.d.ts +1 -1
  25. package/dist/esm/components/FieldSlider/FieldSlider.d.ts +1 -1
  26. package/dist/esm/components/FieldText/FieldText.d.ts +1 -1
  27. package/dist/esm/components/FieldTextArea/FieldTextArea.d.ts +1 -1
  28. package/dist/esm/helperComponents/ButtonFieldList/ButtonFieldList.d.ts +1 -1
  29. package/dist/esm/hooks/addonButton/index.d.ts +2 -0
  30. package/dist/esm/hooks/addonButton/index.js +2 -0
  31. package/dist/esm/hooks/addonButton/useAddonButton.d.ts +14 -0
  32. package/dist/esm/hooks/addonButton/useAddonButton.js +30 -0
  33. package/dist/esm/hooks/addonButton/usePostfixButton.d.ts +6 -0
  34. package/dist/esm/hooks/addonButton/usePostfixButton.js +16 -0
  35. package/dist/esm/hooks/addonButton/usePrefixButton.d.ts +6 -0
  36. package/dist/esm/hooks/addonButton/usePrefixButton.js +16 -0
  37. package/dist/esm/hooks/index.d.ts +1 -2
  38. package/dist/esm/hooks/index.js +1 -2
  39. package/dist/esm/types/allFields.d.ts +9 -4
  40. package/package.json +3 -3
  41. package/src/hooks/addonButton/index.ts +2 -0
  42. package/src/hooks/{usePostfixButton.tsx → addonButton/useAddonButton.tsx} +30 -23
  43. package/src/hooks/addonButton/usePostfixButton.tsx +12 -0
  44. package/src/hooks/addonButton/usePrefixButton.tsx +12 -0
  45. package/src/hooks/index.ts +1 -2
  46. package/src/types/allFields.ts +15 -5
  47. package/dist/cjs/hooks/usePostfixButton.d.ts +0 -11
  48. package/dist/cjs/hooks/usePrefixButton.d.ts +0 -11
  49. package/dist/cjs/hooks/usePrefixButton.js +0 -63
  50. package/dist/esm/hooks/usePostfixButton.d.ts +0 -11
  51. package/dist/esm/hooks/usePostfixButton.js +0 -28
  52. package/dist/esm/hooks/usePrefixButton.d.ts +0 -11
  53. package/dist/esm/hooks/usePrefixButton.js +0 -28
  54. package/src/hooks/usePrefixButton.tsx +0 -76
package/CHANGELOG.md CHANGED
@@ -3,6 +3,26 @@
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.47.1 (2025-05-28)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/color-picker@0.3.30](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/color-picker/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
15
+ # 0.47.0 (2025-05-27)
16
+
17
+
18
+ ### Features
19
+
20
+ * **PDS-2255:** extend button prefix props ([ee14165](https://github.com/cloud-ru-tech/snack-uikit/commit/ee14165a43d23faf09106434072df85faeaae3c1))
21
+
22
+
23
+
24
+
25
+
6
26
  # 0.46.0 (2025-05-26)
7
27
 
8
28
 
@@ -40,5 +40,5 @@ export declare const FieldColor: import("react").ForwardRefExoticComponent<{
40
40
  showClearButton?: boolean;
41
41
  value?: string;
42
42
  onChange?(value: string): void;
43
- } & Omit<ColorPickerProps, "value" | "onChange"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
43
+ } & Omit<ColorPickerProps, "onChange" | "value"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
44
44
  export {};
@@ -23,5 +23,5 @@ type FieldSecureOwnProps = {
23
23
  export type FieldSecureProps = WithSupportProps<FieldSecureOwnProps & InputProps & WrapperProps>;
24
24
  export declare const FieldSecure: import("react").ForwardRefExoticComponent<{
25
25
  'data-test-id'?: string;
26
- } & import("react").AriaAttributes & FieldSecureOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "autoComplete" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
26
+ } & import("react").AriaAttributes & FieldSecureOwnProps & Pick<Partial<InputPrivateProps>, "onChange" | "value"> & Pick<InputPrivateProps, "id" | "name" | "onFocus" | "onBlur" | "disabled" | "readonly" | "placeholder" | "autoComplete" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
27
27
  export {};
@@ -28,4 +28,4 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
28
28
  resetSearchOnOptionSelection?: boolean;
29
29
  onOpenChange?(open: boolean): void;
30
30
  selectedOptionFormatter?: SelectedOptionFormatter;
31
- } & Pick<import("@snack-uikit/list").DroplistProps, "scrollToSelectedItem" | "virtualized" | "untouchableScrollbars" | "dataFiltered" | "dataError" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton" | "onCopyButtonClick"> & import("react").RefAttributes<HTMLInputElement>>;
31
+ } & Pick<import("@snack-uikit/list").DroplistProps, "untouchableScrollbars" | "dataError" | "dataFiltered" | "scrollToSelectedItem" | "virtualized" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton" | "onCopyButtonClick"> & import("react").RefAttributes<HTMLInputElement>>;
@@ -26,4 +26,4 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
26
26
  resetSearchOnOptionSelection?: boolean;
27
27
  onOpenChange?(open: boolean): void;
28
28
  selectedOptionFormatter?: SelectedOptionFormatter;
29
- } & Pick<import("@snack-uikit/list").DroplistProps, "scrollToSelectedItem" | "virtualized" | "untouchableScrollbars" | "dataFiltered" | "dataError" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
29
+ } & Pick<import("@snack-uikit/list").DroplistProps, "untouchableScrollbars" | "dataError" | "dataFiltered" | "scrollToSelectedItem" | "virtualized" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
@@ -23,5 +23,5 @@ type FieldSliderOwnProps = {
23
23
  export type FieldSliderProps = WithSupportProps<FieldSliderOwnProps & SliderProps & WrapperProps>;
24
24
  export declare const FieldSlider: import("react").ForwardRefExoticComponent<{
25
25
  'data-test-id'?: string;
26
- } & import("react").AriaAttributes & FieldSliderOwnProps & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly"> & Pick<SliderComponentProps, "value" | "onChange" | "range" | "tipFormatter"> & Required<Pick<SliderComponentProps, "max" | "min" | "step" | "marks">> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
26
+ } & import("react").AriaAttributes & FieldSliderOwnProps & Pick<InputPrivateProps, "id" | "name" | "onFocus" | "onBlur" | "disabled" | "readonly"> & Pick<SliderComponentProps, "onChange" | "value" | "range" | "tipFormatter"> & Required<Pick<SliderComponentProps, "max" | "min" | "step" | "marks">> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
27
27
  export {};
@@ -30,5 +30,5 @@ type FieldTextOwnProps = {
30
30
  export type FieldTextProps = WithSupportProps<FieldTextOwnProps & InputProps & WrapperProps>;
31
31
  export declare const FieldText: import("react").ForwardRefExoticComponent<{
32
32
  'data-test-id'?: string;
33
- } & import("react").AriaAttributes & FieldTextOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onKeyDown" | "onFocus" | "onBlur" | "id" | "disabled" | "name" | "onPaste" | "readonly" | "placeholder" | "autoComplete" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
33
+ } & import("react").AriaAttributes & FieldTextOwnProps & Pick<Partial<InputPrivateProps>, "onChange" | "value"> & Pick<InputPrivateProps, "id" | "name" | "onPaste" | "onFocus" | "onBlur" | "onKeyDown" | "disabled" | "readonly" | "placeholder" | "autoComplete" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
34
34
  export {};
@@ -30,5 +30,5 @@ type FieldTextAreaOwnProps = {
30
30
  export type FieldTextAreaProps = WithSupportProps<FieldTextAreaOwnProps & InputProps & WrapperProps>;
31
31
  export declare const FieldTextArea: import("react").ForwardRefExoticComponent<{
32
32
  'data-test-id'?: string;
33
- } & import("react").AriaAttributes & FieldTextAreaOwnProps & Pick<Partial<TextAreaProps>, "value"> & Pick<TextAreaProps, "onKeyDown" | "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLTextAreaElement>>;
33
+ } & import("react").AriaAttributes & FieldTextAreaOwnProps & Pick<Partial<TextAreaProps>, "value"> & Pick<TextAreaProps, "id" | "name" | "onFocus" | "onBlur" | "onKeyDown" | "disabled" | "readonly" | "placeholder" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLTextAreaElement>>;
34
34
  export {};
@@ -1,4 +1,4 @@
1
1
  import { ButtonFieldProps } from '../ButtonField';
2
- export declare const ButtonFieldList: import("react").ForwardRefExoticComponent<Omit<ButtonFieldProps, "hasArrow" | "arrowOpen"> & Pick<import("@snack-uikit/list").DroplistProps, "open" | "onOpenChange" | "items" | "search" | "scroll"> & {
2
+ export declare const ButtonFieldList: import("react").ForwardRefExoticComponent<Omit<ButtonFieldProps, "hasArrow" | "arrowOpen"> & Pick<import("@snack-uikit/list").DroplistProps, "search" | "open" | "onOpenChange" | "items" | "scroll"> & {
3
3
  selection?: Omit<import("@snack-uikit/list").SelectionSingleState, "mode">;
4
4
  } & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,2 @@
1
+ export * from './usePostfixButton';
2
+ export * from './usePrefixButton';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = {
8
+ enumerable: true,
9
+ get: function () {
10
+ return m[k];
11
+ }
12
+ };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ } : function (o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ });
19
+ var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", {
23
+ value: true
24
+ });
25
+ __exportStar(require("./usePostfixButton"), exports);
26
+ __exportStar(require("./usePrefixButton"), exports);
@@ -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;
@@ -3,36 +3,38 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.usePostfixButton = usePostfixButton;
6
+ exports.useAddonButton = useAddonButton;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
8
  const react_1 = require("react");
9
- const helperComponents_1 = require("../helperComponents");
10
- function usePostfixButton(_ref) {
9
+ const helperComponents_1 = require("../../helperComponents");
10
+ function useAddonButton(_ref) {
11
11
  let {
12
+ variant,
12
13
  button,
14
+ icon,
13
15
  size,
14
- postfixIcon,
15
16
  disabled,
16
17
  readonly,
18
+ type,
17
19
  onFocus,
18
20
  onBlur
19
21
  } = _ref;
20
22
  const buttonListRef = (0, react_1.useRef)(null);
21
- const postfixIconProps = (0, react_1.useMemo)(() => ({
22
- id: 'postfixIcon',
23
+ const addonIconProps = (0, react_1.useMemo)(() => ({
24
+ id: `${type}Icon`,
23
25
  active: false,
24
- show: Boolean(postfixIcon && !button),
26
+ show: Boolean(icon && !button),
25
27
  render: () => (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {
26
- children: postfixIcon
28
+ children: icon
27
29
  })
28
- }), [button, postfixIcon]);
29
- const postfixButtonProps = (0, react_1.useMemo)(() => ({
30
- id: 'postfixButton',
30
+ }), [button, icon, type]);
31
+ const addonButtonProps = (0, react_1.useMemo)(() => ({
32
+ id: `${type}Button`,
31
33
  active: false,
32
- show: Boolean(button && button.variant === 'after'),
34
+ show: Boolean(button && button.variant === variant),
33
35
  render: renderProps => {
34
36
  const buttonProps = Object.assign(Object.assign({}, renderProps), {
35
- variant: 'after',
37
+ variant,
36
38
  size,
37
39
  content: button === null || button === void 0 ? void 0 : button.content,
38
40
  disabled: disabled || readonly,
@@ -56,8 +58,12 @@ function usePostfixButton(_ref) {
56
58
  onOpenChange: button.onOpenChange
57
59
  }));
58
60
  }
59
- return (0, jsx_runtime_1.jsx)(helperComponents_1.ButtonField, Object.assign({}, buttonProps));
61
+ const buttonField = (0, jsx_runtime_1.jsx)(helperComponents_1.ButtonField, Object.assign({}, buttonProps, {
62
+ hasArrow: button === null || button === void 0 ? void 0 : button.hasArrow,
63
+ arrowOpen: button === null || button === void 0 ? void 0 : button.arrowOpen
64
+ }));
65
+ return (button === null || button === void 0 ? void 0 : button.wrapper) ? button.wrapper(buttonField) : buttonField;
60
66
  }
61
- }), [button, size, disabled, readonly, onFocus, onBlur]);
62
- return button ? postfixButtonProps : postfixIconProps;
67
+ }), [type, button, variant, size, disabled, readonly, onFocus, onBlur]);
68
+ return button ? addonButtonProps : addonIconProps;
63
69
  }
@@ -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,26 @@
1
+ "use strict";
2
+
3
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") 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])) t[p[i]] = s[p[i]];
8
+ }
9
+ return t;
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.usePostfixButton = usePostfixButton;
15
+ const useAddonButton_1 = require("./useAddonButton");
16
+ function usePostfixButton(_a) {
17
+ var {
18
+ postfixIcon
19
+ } = _a,
20
+ props = __rest(_a, ["postfixIcon"]);
21
+ return (0, useAddonButton_1.useAddonButton)(Object.assign(Object.assign({}, props), {
22
+ icon: postfixIcon,
23
+ type: 'postfix',
24
+ variant: 'after'
25
+ }));
26
+ }
@@ -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,26 @@
1
+ "use strict";
2
+
3
+ var __rest = void 0 && (void 0).__rest || function (s, e) {
4
+ var t = {};
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") 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])) t[p[i]] = s[p[i]];
8
+ }
9
+ return t;
10
+ };
11
+ Object.defineProperty(exports, "__esModule", {
12
+ value: true
13
+ });
14
+ exports.usePrefixButton = usePrefixButton;
15
+ const useAddonButton_1 = require("./useAddonButton");
16
+ function usePrefixButton(_a) {
17
+ var {
18
+ prefixIcon
19
+ } = _a,
20
+ props = __rest(_a, ["prefixIcon"]);
21
+ return (0, useAddonButton_1.useAddonButton)(Object.assign(Object.assign({}, props), {
22
+ icon: prefixIcon,
23
+ type: 'prefix',
24
+ variant: 'before'
25
+ }));
26
+ }
@@ -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 './usePostfixButton';
5
+ export * from './addonButton';
6
6
  export * from './usePrefix';
7
- export * from './usePrefixButton';
8
7
  export * from './useValueControl';
@@ -26,7 +26,6 @@ __exportStar(require("./dateHandlers"), exports);
26
26
  __exportStar(require("./useCopyButton"), exports);
27
27
  __exportStar(require("./useHideButton"), exports);
28
28
  __exportStar(require("./usePostfix"), exports);
29
- __exportStar(require("./usePostfixButton"), exports);
29
+ __exportStar(require("./addonButton"), exports);
30
30
  __exportStar(require("./usePrefix"), exports);
31
- __exportStar(require("./usePrefixButton"), exports);
32
31
  __exportStar(require("./useValueControl"), exports);
@@ -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
+ }));
@@ -40,5 +40,5 @@ export declare const FieldColor: import("react").ForwardRefExoticComponent<{
40
40
  showClearButton?: boolean;
41
41
  value?: string;
42
42
  onChange?(value: string): void;
43
- } & Omit<ColorPickerProps, "value" | "onChange"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
43
+ } & Omit<ColorPickerProps, "onChange" | "value"> & InputProps & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
44
44
  export {};
@@ -23,5 +23,5 @@ type FieldSecureOwnProps = {
23
23
  export type FieldSecureProps = WithSupportProps<FieldSecureOwnProps & InputProps & WrapperProps>;
24
24
  export declare const FieldSecure: import("react").ForwardRefExoticComponent<{
25
25
  'data-test-id'?: string;
26
- } & import("react").AriaAttributes & FieldSecureOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "autoComplete" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
26
+ } & import("react").AriaAttributes & FieldSecureOwnProps & Pick<Partial<InputPrivateProps>, "onChange" | "value"> & Pick<InputPrivateProps, "id" | "name" | "onFocus" | "onBlur" | "disabled" | "readonly" | "placeholder" | "autoComplete" | "maxLength"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
27
27
  export {};
@@ -28,4 +28,4 @@ export declare const FieldSelectMultiple: import("react").ForwardRefExoticCompon
28
28
  resetSearchOnOptionSelection?: boolean;
29
29
  onOpenChange?(open: boolean): void;
30
30
  selectedOptionFormatter?: SelectedOptionFormatter;
31
- } & Pick<import("@snack-uikit/list").DroplistProps, "scrollToSelectedItem" | "virtualized" | "untouchableScrollbars" | "dataFiltered" | "dataError" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton" | "onCopyButtonClick"> & import("react").RefAttributes<HTMLInputElement>>;
31
+ } & Pick<import("@snack-uikit/list").DroplistProps, "untouchableScrollbars" | "dataError" | "dataFiltered" | "scrollToSelectedItem" | "virtualized" | "noDataState" | "noResultsState" | "errorDataState">, "showCopyButton" | "onCopyButtonClick"> & import("react").RefAttributes<HTMLInputElement>>;
@@ -26,4 +26,4 @@ export declare const FieldSelectSingle: import("react").ForwardRefExoticComponen
26
26
  resetSearchOnOptionSelection?: boolean;
27
27
  onOpenChange?(open: boolean): void;
28
28
  selectedOptionFormatter?: SelectedOptionFormatter;
29
- } & Pick<import("@snack-uikit/list").DroplistProps, "scrollToSelectedItem" | "virtualized" | "untouchableScrollbars" | "dataFiltered" | "dataError" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
29
+ } & Pick<import("@snack-uikit/list").DroplistProps, "untouchableScrollbars" | "dataError" | "dataFiltered" | "scrollToSelectedItem" | "virtualized" | "noDataState" | "noResultsState" | "errorDataState"> & import("react").RefAttributes<HTMLInputElement>>;
@@ -23,5 +23,5 @@ type FieldSliderOwnProps = {
23
23
  export type FieldSliderProps = WithSupportProps<FieldSliderOwnProps & SliderProps & WrapperProps>;
24
24
  export declare const FieldSlider: import("react").ForwardRefExoticComponent<{
25
25
  'data-test-id'?: string;
26
- } & import("react").AriaAttributes & FieldSliderOwnProps & Pick<InputPrivateProps, "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly"> & Pick<SliderComponentProps, "value" | "onChange" | "range" | "tipFormatter"> & Required<Pick<SliderComponentProps, "max" | "min" | "step" | "marks">> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
26
+ } & import("react").AriaAttributes & FieldSliderOwnProps & Pick<InputPrivateProps, "id" | "name" | "onFocus" | "onBlur" | "disabled" | "readonly"> & Pick<SliderComponentProps, "onChange" | "value" | "range" | "tipFormatter"> & Required<Pick<SliderComponentProps, "max" | "min" | "step" | "marks">> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
27
27
  export {};
@@ -30,5 +30,5 @@ type FieldTextOwnProps = {
30
30
  export type FieldTextProps = WithSupportProps<FieldTextOwnProps & InputProps & WrapperProps>;
31
31
  export declare const FieldText: import("react").ForwardRefExoticComponent<{
32
32
  'data-test-id'?: string;
33
- } & import("react").AriaAttributes & FieldTextOwnProps & Pick<Partial<InputPrivateProps>, "value" | "onChange"> & Pick<InputPrivateProps, "onKeyDown" | "onFocus" | "onBlur" | "id" | "disabled" | "name" | "onPaste" | "readonly" | "placeholder" | "autoComplete" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
33
+ } & import("react").AriaAttributes & FieldTextOwnProps & Pick<Partial<InputPrivateProps>, "onChange" | "value"> & Pick<InputPrivateProps, "id" | "name" | "onPaste" | "onFocus" | "onBlur" | "onKeyDown" | "disabled" | "readonly" | "placeholder" | "autoComplete" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLInputElement>>;
34
34
  export {};
@@ -30,5 +30,5 @@ type FieldTextAreaOwnProps = {
30
30
  export type FieldTextAreaProps = WithSupportProps<FieldTextAreaOwnProps & InputProps & WrapperProps>;
31
31
  export declare const FieldTextArea: import("react").ForwardRefExoticComponent<{
32
32
  'data-test-id'?: string;
33
- } & import("react").AriaAttributes & FieldTextAreaOwnProps & Pick<Partial<TextAreaProps>, "value"> & Pick<TextAreaProps, "onKeyDown" | "onFocus" | "onBlur" | "id" | "disabled" | "name" | "readonly" | "placeholder" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLTextAreaElement>>;
33
+ } & import("react").AriaAttributes & FieldTextAreaOwnProps & Pick<Partial<TextAreaProps>, "value"> & Pick<TextAreaProps, "id" | "name" | "onFocus" | "onBlur" | "onKeyDown" | "disabled" | "readonly" | "placeholder" | "maxLength" | "spellCheck"> & WrapperProps & import("react").RefAttributes<HTMLTextAreaElement>>;
34
34
  export {};
@@ -1,4 +1,4 @@
1
1
  import { ButtonFieldProps } from '../ButtonField';
2
- export declare const ButtonFieldList: import("react").ForwardRefExoticComponent<Omit<ButtonFieldProps, "hasArrow" | "arrowOpen"> & Pick<import("@snack-uikit/list").DroplistProps, "open" | "onOpenChange" | "items" | "search" | "scroll"> & {
2
+ export declare const ButtonFieldList: import("react").ForwardRefExoticComponent<Omit<ButtonFieldProps, "hasArrow" | "arrowOpen"> & Pick<import("@snack-uikit/list").DroplistProps, "search" | "open" | "onOpenChange" | "items" | "scroll"> & {
3
3
  selection?: Omit<import("@snack-uikit/list").SelectionSingleState, "mode">;
4
4
  } & import("react").RefAttributes<HTMLButtonElement>>;
@@ -0,0 +1,2 @@
1
+ export * from './usePostfixButton';
2
+ export * from './usePrefixButton';
@@ -0,0 +1,2 @@
1
+ export * from './usePostfixButton';
2
+ export * from './usePrefixButton';
@@ -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 './usePostfixButton';
5
+ export * from './addonButton';
6
6
  export * from './usePrefix';
7
- export * from './usePrefixButton';
8
7
  export * from './useValueControl';
@@ -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 './usePostfixButton';
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.46.0",
7
+ "version": "0.47.1",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -38,7 +38,7 @@
38
38
  "dependencies": {
39
39
  "@snack-uikit/button": "0.19.11",
40
40
  "@snack-uikit/calendar": "0.12.5",
41
- "@snack-uikit/color-picker": "0.3.29",
41
+ "@snack-uikit/color-picker": "0.3.30",
42
42
  "@snack-uikit/divider": "3.2.6",
43
43
  "@snack-uikit/dropdown": "0.4.8",
44
44
  "@snack-uikit/icons": "0.26.3",
@@ -65,5 +65,5 @@
65
65
  "peerDependencies": {
66
66
  "@snack-uikit/locale": "*"
67
67
  },
68
- "gitHead": "26339d9278602025de86964e817a842e97e69d94"
68
+ "gitHead": "c7d15bfb4027c8177ba19f9b55be31d6f7cfcdbb"
69
69
  }
@@ -0,0 +1,2 @@
1
+ export * from './usePostfixButton';
2
+ export * from './usePrefixButton';
@@ -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 '../helperComponents';
6
- import { Button } from '../types';
5
+ import { ButtonField, ButtonFieldList, ButtonFieldProps } from '../../helperComponents';
6
+ import { Button, ButtonVariant } from '../../types';
7
7
 
8
- export function usePostfixButton({
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 postfixIconProps: InactiveItem = useMemo(
31
+ const addonIconProps: InactiveItem = useMemo(
26
32
  () => ({
27
- id: 'postfixIcon',
33
+ id: `${type}Icon`,
28
34
  active: false,
29
- show: Boolean(postfixIcon && !button),
30
- render: () => <>{postfixIcon}</>,
35
+ show: Boolean(icon && !button),
36
+ render: () => <>{icon}</>,
31
37
  }),
32
- [button, postfixIcon],
38
+ [button, icon, type],
33
39
  );
34
40
 
35
- const postfixButtonProps: InactiveItem = useMemo(
41
+ const addonButtonProps: InactiveItem = useMemo(
36
42
  () => ({
37
- id: 'postfixButton',
43
+ id: `${type}Button`,
38
44
  active: false,
39
- show: Boolean(button && button.variant === 'after'),
45
+ show: Boolean(button && button.variant === variant),
40
46
  render: renderProps => {
41
47
  const buttonProps: ButtonFieldProps = {
42
48
  ...renderProps,
43
- variant: 'after',
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
- return <ButtonField {...buttonProps} />;
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 ? postfixButtonProps : postfixIconProps;
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
+ }
@@ -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 './usePostfixButton';
5
+ export * from './addonButton';
6
6
  export * from './usePrefix';
7
- export * from './usePrefixButton';
8
7
  export * from './useValueControl';
@@ -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: ButtonVariant;
22
- content?: ReactNode;
23
- items?: DroplistProps['items'];
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
- }
@@ -1,76 +0,0 @@
1
- import { ReactElement, useMemo, useRef } from 'react';
2
-
3
- import { ButtonProps, InactiveItem, Size } from '@snack-uikit/input-private';
4
-
5
- import { ButtonField, ButtonFieldList, ButtonFieldProps } from '../helperComponents';
6
- import { Button } from '../types';
7
-
8
- export function usePrefixButton({
9
- button,
10
- prefixIcon,
11
- size,
12
- disabled,
13
- readonly,
14
- onFocus,
15
- onBlur,
16
- }: {
17
- button?: Button;
18
- prefixIcon?: ReactElement;
19
- size: Size;
20
- disabled?: boolean;
21
- readonly?: boolean;
22
- } & Pick<ButtonFieldProps, 'onFocus' | 'onBlur'>): ButtonProps {
23
- const buttonListRef = useRef<HTMLButtonElement>(null);
24
-
25
- const prefixIconProps: InactiveItem = useMemo(
26
- () => ({
27
- id: 'prefixIcon',
28
- active: false,
29
- show: Boolean(prefixIcon && !button),
30
- render: () => <>{prefixIcon}</>,
31
- }),
32
- [button, prefixIcon],
33
- );
34
-
35
- const prefixButtonProps: InactiveItem = useMemo(
36
- () => ({
37
- id: 'prefixButton',
38
- active: false,
39
- show: Boolean(button && button.variant === 'before'),
40
- render: renderProps => {
41
- const buttonProps: ButtonFieldProps = {
42
- ...renderProps,
43
- variant: 'before',
44
- size,
45
- content: button?.content,
46
- disabled: disabled || readonly,
47
- onFocus,
48
- onBlur,
49
- };
50
-
51
- if (button?.items) {
52
- return (
53
- <ButtonFieldList
54
- {...buttonProps}
55
- ref={buttonListRef}
56
- onClick={() => {
57
- setTimeout(() => buttonListRef.current?.focus(), 0);
58
- }}
59
- search={button.search}
60
- items={button.items}
61
- selection={button.selection}
62
- open={button.open}
63
- scroll={button.scroll}
64
- onOpenChange={button.onOpenChange}
65
- />
66
- );
67
- }
68
-
69
- return <ButtonField {...buttonProps} />;
70
- },
71
- }),
72
- [button, size, disabled, readonly, onFocus, onBlur],
73
- );
74
-
75
- return button ? prefixButtonProps : prefixIconProps;
76
- }