@scaleflex/ui-tw 0.0.135 → 0.0.136

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.
@@ -3,5 +3,5 @@ import type { InputProps } from './input.types';
3
3
  declare const inputVariants: (props?: ({
4
4
  size?: "sm" | "md" | "lg" | null | undefined;
5
5
  } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
6
- declare function Input({ className, type, size, disabled, readOnly, icon: Icon, suffix, ...props }: InputProps): React.JSX.Element;
6
+ declare function Input({ className, type, size, disabled, readOnly, icon: Icon, suffix, clearable, onClear, value, ...props }: InputProps): React.JSX.Element;
7
7
  export { Input, inputVariants };
@@ -1,13 +1,16 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["className", "type", "size", "disabled", "readOnly", "icon", "suffix"];
4
+ var _excluded = ["className", "type", "size", "disabled", "readOnly", "icon", "suffix", "clearable", "onClear", "value"];
5
+ import { buttonVariants } from '@scaleflex/ui-tw/button';
6
+ import { ButtonVariant } from '@scaleflex/ui-tw/button/button.constants';
5
7
  import { getBaseInputClasses, readOnlyClassNames, selectionHighlightClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
6
8
  import { FormSize } from '@scaleflex/ui-tw/types/form-size';
7
9
  import { cn } from '@scaleflex/ui-tw/utils/cn';
8
10
  import { cva } from 'class-variance-authority';
11
+ import { XIcon } from 'lucide-react';
9
12
  import React from 'react';
10
- import { InputType, inputIconSizeOptions, inputSizeOptions, inputSuffixSizeOptions, inputWithIconSizeOptions } from './input.constants';
13
+ import { InputType, inputClearButtonSizeOptions, inputClearablePaddingOptions, inputIconSizeOptions, inputSizeOptions, inputSuffixSizeOptions, inputWithIconSizeOptions } from './input.constants';
11
14
  var inputVariants = cva('', {
12
15
  variants: {
13
16
  size: inputSizeOptions
@@ -52,19 +55,25 @@ function Input(_ref) {
52
55
  readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
53
56
  Icon = _ref.icon,
54
57
  suffix = _ref.suffix,
58
+ _ref$clearable = _ref.clearable,
59
+ clearable = _ref$clearable === void 0 ? false : _ref$clearable,
60
+ onClear = _ref.onClear,
61
+ value = _ref.value,
55
62
  props = _objectWithoutProperties(_ref, _excluded);
56
- var hasAddon = Icon || suffix;
63
+ var showClearButton = clearable && value && !readOnly && !disabled;
64
+ var hasAddon = Icon || suffix || clearable;
57
65
  var inputElement = /*#__PURE__*/React.createElement("input", _extends({
58
66
  type: type,
59
67
  "data-slot": "input",
60
68
  disabled: disabled,
61
69
  readOnly: readOnly,
70
+ value: value,
62
71
  className: cn.apply(void 0, ['flex w-full min-w-0'].concat(_toConsumableArray(getBaseInputClasses()), [readOnlyClassNames, selectionHighlightClassNames, inputVariants({
63
72
  size: size,
64
73
  className: hasAddon ? undefined : className
65
- }), hasAddon && inputWithIconVariants({
74
+ }), (Icon || suffix) && !clearable && inputWithIconVariants({
66
75
  size: size
67
- })]))
76
+ }), clearable && inputClearablePaddingOptions[size]]))
68
77
  }, props));
69
78
  if (!hasAddon) {
70
79
  return inputElement;
@@ -75,10 +84,23 @@ function Input(_ref) {
75
84
  className: cn(inputIconSizeVariants({
76
85
  size: size
77
86
  }), 'text-muted-foreground absolute top-1/2 -translate-y-1/2 transform', disabled && 'opacity-50')
78
- }), suffix && /*#__PURE__*/React.createElement("span", {
87
+ }), suffix && !showClearButton && /*#__PURE__*/React.createElement("span", {
79
88
  className: cn(inputSuffixSizeVariants({
80
89
  size: size
81
90
  }), 'text-muted-foreground absolute top-1/2 -translate-y-1/2 transform', disabled && 'opacity-50')
82
- }, suffix));
91
+ }, suffix), showClearButton && /*#__PURE__*/React.createElement("button", {
92
+ type: "button",
93
+ tabIndex: 0,
94
+ onClick: onClear,
95
+ "data-clear-icon": "true",
96
+ "aria-label": "Clear",
97
+ className: cn(buttonVariants({
98
+ size: inputClearButtonSizeOptions[size],
99
+ variant: ButtonVariant.GhostSecondary
100
+ }), 'absolute top-1/2 right-2 -translate-y-1/2')
101
+ }, /*#__PURE__*/React.createElement(XIcon, {
102
+ "data-clear-icon": true,
103
+ className: "text-muted-foreground/70 hover:text-muted-foreground shrink-0"
104
+ })));
83
105
  }
84
106
  export { Input, inputVariants };
@@ -3,6 +3,11 @@ export declare const inputSizeOptions: {
3
3
  readonly md: "py-3 px-4 h-10 text-base ";
4
4
  readonly lg: "py-3 px-4 h-12 text-lg ";
5
5
  };
6
+ export declare const inputClearButtonSizeOptions: {
7
+ readonly sm: "icon-xs";
8
+ readonly md: "icon-sm";
9
+ readonly lg: "icon-md";
10
+ };
6
11
  export declare const inputItemSizeOptions: {
7
12
  readonly sm: "py-2 px-3 min-h-8 text-sm";
8
13
  readonly md: "py-2 px-4 min-h-10 text-base ";
@@ -28,3 +33,8 @@ export declare const inputWithIconSizeOptions: {
28
33
  md: string;
29
34
  lg: string;
30
35
  };
36
+ export declare const inputClearablePaddingOptions: {
37
+ sm: string;
38
+ md: string;
39
+ lg: string;
40
+ };
@@ -1,6 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { ButtonSize } from '@scaleflex/ui-tw/button';
2
3
  import { FormSize } from '@scaleflex/ui-tw/types/form-size';
3
4
  export var inputSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'py-2 px-3 h-8 text-sm'), FormSize.Md, 'py-3 px-4 h-10 text-base '), FormSize.Lg, 'py-3 px-4 h-12 text-lg ');
5
+ export var inputClearButtonSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, ButtonSize.IconXs), FormSize.Md, ButtonSize.IconSm), FormSize.Lg, ButtonSize.IconMd);
4
6
  export var inputItemSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'py-2 px-3 min-h-8 text-sm'), FormSize.Md, 'py-2 px-4 min-h-10 text-base '), FormSize.Lg, 'py-2.5 px-4 min-h-12 text-lg ');
5
7
  export var InputType = {
6
8
  Text: 'text',
@@ -9,4 +11,5 @@ export var InputType = {
9
11
  };
10
12
  export var inputIconSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'right-2 size-3'), FormSize.Md, 'right-3 size-4'), FormSize.Lg, 'right-4 size-5');
11
13
  export var inputSuffixSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'right-2 text-xs'), FormSize.Md, 'right-3 text-sm'), FormSize.Lg, 'right-4 text-base');
12
- export var inputWithIconSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'pr-6'), FormSize.Md, 'pr-8'), FormSize.Lg, 'pr-10');
14
+ export var inputWithIconSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'pr-6'), FormSize.Md, 'pr-8'), FormSize.Lg, 'pr-10');
15
+ export var inputClearablePaddingOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'pr-9'), FormSize.Md, 'pr-11'), FormSize.Lg, 'pr-12');
@@ -6,4 +6,6 @@ export interface InputProps extends Omit<ComponentProps<'input'>, 'size'> {
6
6
  'aria-invalid'?: boolean;
7
7
  icon?: LucideIcon;
8
8
  suffix?: string;
9
+ clearable?: boolean;
10
+ onClear?: () => void;
9
11
  }
@@ -34,7 +34,7 @@ function Label(_ref) {
34
34
  className: className
35
35
  }))
36
36
  }, props), noTruncate ? children : /*#__PURE__*/React.createElement("span", {
37
- className: cn('truncate')
37
+ className: cn('min-w-0 flex-1 truncate')
38
38
  }, children), (icon || tooltip || disabledTooltip) && /*#__PURE__*/React.createElement(LabelIcon, {
39
39
  size: size,
40
40
  icon: icon,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleflex/ui-tw",
3
- "version": "0.0.135",
3
+ "version": "0.0.136",
4
4
  "author": "scaleflex",
5
5
  "repository": "github:scaleflex/ui",
6
6
  "homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
@@ -29,7 +29,7 @@
29
29
  "@radix-ui/react-switch": "^1.0.1",
30
30
  "@radix-ui/react-tabs": "^1.1.13",
31
31
  "@radix-ui/react-tooltip": "^1.2.6",
32
- "@scaleflex/icons-tw": "^0.0.135",
32
+ "@scaleflex/icons-tw": "^0.0.136",
33
33
  "@tanstack/react-table": "^8.21.3",
34
34
  "@types/lodash.merge": "^4.6.9",
35
35
  "class-variance-authority": "^0.7.1",
@@ -3,5 +3,5 @@ import type { TextareaProps } from './textarea.types';
3
3
  declare const textareaVariants: (props?: ({
4
4
  size?: "sm" | "md" | "lg" | null | undefined;
5
5
  } & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
6
- declare function Textarea({ className, size, disabled, readOnly, ...props }: TextareaProps): React.JSX.Element;
6
+ declare function Textarea({ className, size, disabled, readOnly, clearable, onClear, value, ...props }: TextareaProps): React.JSX.Element;
7
7
  export { Textarea, textareaVariants };
@@ -1,12 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
- var _excluded = ["className", "size", "disabled", "readOnly"];
3
+ var _excluded = ["className", "size", "disabled", "readOnly", "clearable", "onClear", "value"];
4
+ import { buttonVariants } from '@scaleflex/ui-tw/button';
5
+ import { ButtonVariant } from '@scaleflex/ui-tw/button/button.constants';
4
6
  import { focusRingClassNames, getBaseInputClasses, readOnlyClassNames, selectionHighlightClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
5
7
  import { FormSize } from '@scaleflex/ui-tw/types/form-size';
6
8
  import { cn } from '@scaleflex/ui-tw/utils/cn';
7
9
  import { cva } from 'class-variance-authority';
10
+ import { XIcon } from 'lucide-react';
8
11
  import React from 'react';
9
- import { textareaSizeOptions } from './textarea.constants';
12
+ import { textareaClearButtonSizeOptions, textareaClearablePaddingOptions, textareaSizeOptions } from './textarea.constants';
10
13
  var textareaVariants = cva('', {
11
14
  variants: {
12
15
  size: textareaSizeOptions
@@ -23,14 +26,39 @@ function Textarea(_ref) {
23
26
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
24
27
  _ref$readOnly = _ref.readOnly,
25
28
  readOnly = _ref$readOnly === void 0 ? false : _ref$readOnly,
29
+ _ref$clearable = _ref.clearable,
30
+ clearable = _ref$clearable === void 0 ? false : _ref$clearable,
31
+ onClear = _ref.onClear,
32
+ value = _ref.value,
26
33
  props = _objectWithoutProperties(_ref, _excluded);
27
- return /*#__PURE__*/React.createElement("textarea", _extends({
34
+ var showClearButton = clearable && value && !readOnly && !disabled;
35
+ var textareaElement = /*#__PURE__*/React.createElement("textarea", _extends({
28
36
  "data-slot": "textarea",
29
37
  disabled: disabled,
30
38
  readOnly: readOnly,
39
+ value: value,
31
40
  className: cn('flex field-sizing-content w-full resize-y', getBaseInputClasses(), readOnlyClassNames, selectionHighlightClassNames, focusRingClassNames, textareaVariants({
32
41
  size: size
33
- }), className)
42
+ }), clearable && textareaClearablePaddingOptions[size], clearable ? undefined : className)
34
43
  }, props));
44
+ if (!clearable) {
45
+ return textareaElement;
46
+ }
47
+ return /*#__PURE__*/React.createElement("div", {
48
+ className: cn('relative', className)
49
+ }, textareaElement, showClearButton && /*#__PURE__*/React.createElement("button", {
50
+ type: "button",
51
+ tabIndex: 0,
52
+ onClick: onClear,
53
+ "data-clear-icon": "true",
54
+ "aria-label": "Clear",
55
+ className: cn(buttonVariants({
56
+ size: textareaClearButtonSizeOptions[size],
57
+ variant: ButtonVariant.GhostSecondary
58
+ }), 'absolute top-2 right-2')
59
+ }, /*#__PURE__*/React.createElement(XIcon, {
60
+ "data-clear-icon": true,
61
+ className: "text-muted-foreground/70 hover:text-muted-foreground shrink-0"
62
+ })));
35
63
  }
36
64
  export { Textarea, textareaVariants };
@@ -3,6 +3,16 @@ export declare const textareaSizeOptions: {
3
3
  readonly md: "py-3 px-4 text-base min-h-16 max-h-48";
4
4
  readonly lg: "py-3 px-4 text-lg min-h-20 max-h-60";
5
5
  };
6
+ export declare const textareaClearButtonSizeOptions: {
7
+ readonly sm: "icon-xs";
8
+ readonly md: "icon-sm";
9
+ readonly lg: "icon-md";
10
+ };
11
+ export declare const textareaClearablePaddingOptions: {
12
+ readonly sm: "pr-9";
13
+ readonly md: "pr-11";
14
+ readonly lg: "pr-12";
15
+ };
6
16
  export declare const textareaWithActionsSizeOptions: {
7
17
  readonly sm: "pb-10 scroll-pb-10";
8
18
  readonly md: "pb-12 scroll-pb-12";
@@ -1,5 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { ButtonSize } from '@scaleflex/ui-tw/button';
2
3
  import { FormSize } from '@scaleflex/ui-tw/types/form-size';
3
4
  export var textareaSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'py-2 px-3 text-sm min-h-14 max-h-44'), FormSize.Md, 'py-3 px-4 text-base min-h-16 max-h-48'), FormSize.Lg, 'py-3 px-4 text-lg min-h-20 max-h-60');
5
+ export var textareaClearButtonSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, ButtonSize.IconXs), FormSize.Md, ButtonSize.IconSm), FormSize.Lg, ButtonSize.IconMd);
6
+ export var textareaClearablePaddingOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'pr-9'), FormSize.Md, 'pr-11'), FormSize.Lg, 'pr-12');
4
7
  export var textareaWithActionsSizeOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'pb-10 scroll-pb-10'), FormSize.Md, 'pb-12 scroll-pb-12'), FormSize.Lg, 'pb-14 scroll-pb-14');
5
8
  export var textareaBottomActionAreaPadding = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'h-8'), FormSize.Md, 'h-10'), FormSize.Lg, 'h-12');
@@ -3,6 +3,8 @@ import type { ComponentProps, ReactElement } from 'react';
3
3
  export interface TextareaProps extends Omit<ComponentProps<'textarea'>, 'size'> {
4
4
  size?: FormSizeType;
5
5
  'aria-invalid'?: boolean;
6
+ clearable?: boolean;
7
+ onClear?: () => void;
6
8
  }
7
9
  export interface TextareaWithActionsProps extends TextareaProps {
8
10
  leftToolbar?: ReactElement;