@scaleflex/ui-tw 0.0.82 → 0.0.85

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.
@@ -0,0 +1,12 @@
1
+ import { FormSizeType } from '@scaleflex/ui-tw/types/form-size';
2
+ import React from 'react';
3
+ type CommandSkeletonProps = {
4
+ count?: number;
5
+ size?: FormSizeType;
6
+ isGroup?: boolean;
7
+ withIcons?: boolean;
8
+ withCheckbox?: boolean;
9
+ className?: string;
10
+ };
11
+ declare function CommandSkeleton({ count, size, isGroup, withIcons, withCheckbox, className, }: CommandSkeletonProps): React.JSX.Element;
12
+ export { CommandSkeleton };
@@ -0,0 +1,47 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { selectItemVariants } from '@scaleflex/ui-tw/select/select.component';
3
+ import { getOptionInGroupPaddingLeft } from '@scaleflex/ui-tw/select/select.utils';
4
+ import { FormSize } from '@scaleflex/ui-tw/types/form-size';
5
+ import { cn } from '@scaleflex/ui-tw/utils/cn';
6
+ import React from 'react';
7
+ var iconSizeByFormSize = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'size-4'), FormSize.Md, 'size-4'), FormSize.Lg, 'size-5');
8
+ var rowSizes = ['w-3/4', 'w-2/3', 'w-5/6', 'w-1/2', 'w-11/12', 'w-4/5', 'w-1/3', 'w-1/4'];
9
+ function CommandSkeleton(_ref) {
10
+ var _ref$count = _ref.count,
11
+ count = _ref$count === void 0 ? 5 : _ref$count,
12
+ _ref$size = _ref.size,
13
+ size = _ref$size === void 0 ? FormSize.Md : _ref$size,
14
+ _ref$isGroup = _ref.isGroup,
15
+ isGroup = _ref$isGroup === void 0 ? false : _ref$isGroup,
16
+ _ref$withIcons = _ref.withIcons,
17
+ withIcons = _ref$withIcons === void 0 ? false : _ref$withIcons,
18
+ _ref$withCheckbox = _ref.withCheckbox,
19
+ withCheckbox = _ref$withCheckbox === void 0 ? false : _ref$withCheckbox,
20
+ className = _ref.className;
21
+ return /*#__PURE__*/React.createElement("div", {
22
+ "data-slot": "command-skeleton",
23
+ role: "status",
24
+ "aria-live": "polite",
25
+ className: cn('flex flex-col gap-1 px-2', className)
26
+ }, Array.from({
27
+ length: count > 8 ? 5 : count
28
+ }).map(function (_, i) {
29
+ return /*#__PURE__*/React.createElement("div", {
30
+ key: i,
31
+ className: cn('flex w-full animate-pulse items-center gap-3 rounded', selectItemVariants({
32
+ size: size
33
+ }), isGroup && getOptionInGroupPaddingLeft(size))
34
+ }, withCheckbox && /*#__PURE__*/React.createElement("div", {
35
+ "aria-hidden": "true",
36
+ className: cn('bg-muted shrink-0 rounded-[4px]', size === FormSize.Lg ? 'h-5 w-5' : 'h-4 w-4')
37
+ }), withIcons && /*#__PURE__*/React.createElement("div", {
38
+ "aria-hidden": "true",
39
+ className: cn('bg-muted shrink-0 rounded', iconSizeByFormSize[size])
40
+ }), /*#__PURE__*/React.createElement("div", {
41
+ className: "flex-1 space-y-2 overflow-hidden"
42
+ }, /*#__PURE__*/React.createElement("div", {
43
+ className: cn('bg-muted/70 h-3 rounded', rowSizes[i])
44
+ })));
45
+ }));
46
+ }
47
+ export { CommandSkeleton };
@@ -1 +1,2 @@
1
1
  export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator, } from './command.component';
2
+ export { CommandSkeleton } from './command.skeleton';
package/command/index.js CHANGED
@@ -1 +1,2 @@
1
- export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator } from './command.component';
1
+ export { Command, CommandDialog, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, CommandShortcut, CommandSeparator } from './command.component';
2
+ export { CommandSkeleton } from './command.skeleton';
@@ -14,9 +14,9 @@ import { FormSize } from '@scaleflex/ui-tw/types/form-size';
14
14
  import { cn } from '@scaleflex/ui-tw/utils/cn';
15
15
  import { format, isValid, parse } from 'date-fns';
16
16
  import { enGB } from 'date-fns/locale';
17
- import { CalendarIcon } from 'lucide-react';
17
+ import { CalendarIcon, X as XIcon } from 'lucide-react';
18
18
  import React, { useRef, useState } from 'react';
19
- import { buttonSizeInTriggerOptions, iconSizeInTriggerOptions } from './date-picker.constants';
19
+ import { buttonSizeInTriggerOptions, iconSizeInTriggerOptions, inputRightPaddingBySize } from './date-picker.constants';
20
20
  function DatePicker(_ref) {
21
21
  var minDate = _ref.minDate,
22
22
  maxDate = _ref.maxDate,
@@ -34,7 +34,8 @@ function DatePicker(_ref) {
34
34
  popoverContentProps = _ref.popoverContentProps,
35
35
  onKeyDown = _ref.onKeyDown,
36
36
  onBlur = _ref.onBlur,
37
- placeholder = _ref.placeholder,
37
+ _ref$placeholder = _ref.placeholder,
38
+ placeholder = _ref$placeholder === void 0 ? 'DD/MM/YYYY' : _ref$placeholder,
38
39
  _ref$format = _ref.format,
39
40
  dateFormat = _ref$format === void 0 ? 'dd/MM/yyyy' : _ref$format,
40
41
  _ref$locale = _ref.locale,
@@ -73,7 +74,6 @@ function DatePicker(_ref) {
73
74
  locale: locale
74
75
  });
75
76
  if (isValid(parsed)) {
76
- setSelectedDate(parsed);
77
77
  setCalendarMonth(parsed);
78
78
  }
79
79
  };
@@ -90,27 +90,63 @@ function DatePicker(_ref) {
90
90
  (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
91
91
  }
92
92
  };
93
+ var handleClear = function handleClear() {
94
+ setInputValue('');
95
+ setSelectedDate(undefined);
96
+ onChange === null || onChange === void 0 || onChange(undefined);
97
+ requestAnimationFrame(function () {
98
+ var _inputRef$current2;
99
+ return (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus();
100
+ });
101
+ };
102
+ var commitTypedDate = function commitTypedDate() {
103
+ var raw = inputValue.trim();
104
+ if (!raw) {
105
+ if (selectedDate) {
106
+ setSelectedDate(undefined);
107
+ onChange === null || onChange === void 0 || onChange(undefined);
108
+ }
109
+ return;
110
+ }
111
+ var parsed = parse(raw, dateFormat, new Date(), {
112
+ locale: locale
113
+ });
114
+ if (!isValid(parsed)) return;
115
+ if (minDate && parsed < minDate) return;
116
+ if (maxDate && parsed > maxDate) return;
117
+ setSelectedDate(parsed);
118
+ setCalendarMonth(parsed);
119
+ setInputValue(format(parsed, dateFormat, {
120
+ locale: locale
121
+ }));
122
+ onChange === null || onChange === void 0 || onChange(parsed);
123
+ };
93
124
  var handleKeyDown = function handleKeyDown(event) {
94
125
  var allowed = '0123456789/';
95
126
  if (event.key.length === 1 && !allowed.includes(event.key)) {
96
127
  event.preventDefault();
97
128
  }
129
+ if (event.key === 'Enter') {
130
+ event.preventDefault();
131
+ commitTypedDate();
132
+ }
98
133
  if (event.key === 'Escape') {
99
- var _inputRef$current2;
134
+ var _inputRef$current3;
100
135
  event.preventDefault();
101
136
  isEscapeBlur.current = true;
102
- (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 || _inputRef$current2.blur();
137
+ (_inputRef$current3 = inputRef.current) === null || _inputRef$current3 === void 0 || _inputRef$current3.blur();
103
138
  }
104
139
  onKeyDown === null || onKeyDown === void 0 || onKeyDown(event);
105
140
  };
106
141
  var handleBlur = function handleBlur(event) {
107
- if (event.relatedTarget instanceof HTMLButtonElement && event.relatedTarget.id === 'date-picker') {
142
+ if (event.relatedTarget instanceof HTMLButtonElement && ['date-picker', 'clear-date'].includes(event.relatedTarget.id)) {
108
143
  return;
109
144
  }
110
145
  if (isEscapeBlur.current) {
111
146
  isEscapeBlur.current = false;
112
147
  return;
113
148
  }
149
+ commitTypedDate();
114
150
  onBlur === null || onBlur === void 0 || onBlur(event);
115
151
  };
116
152
  return /*#__PURE__*/React.createElement("div", {
@@ -129,11 +165,26 @@ function DatePicker(_ref) {
129
165
  disabled: disabled,
130
166
  className: cn.apply(void 0, _toConsumableArray(getBaseSelectClassNames()).concat(_toConsumableArray(getBaseInputClasses()), ['hover:border-secondary-foreground/50', selectTriggerVariants({
131
167
  size: size
132
- }), readOnly && selectReadOnlyClassNames, !isInputValid && 'border-destructive', className])),
168
+ }), inputRightPaddingBySize[size], readOnly && selectReadOnlyClassNames, !isInputValid && 'border-destructive', className])),
133
169
  onChange: handleInputChange,
134
170
  onKeyDown: handleKeyDown,
135
171
  onBlur: handleBlur
136
- }, rest)), /*#__PURE__*/React.createElement(Popover, {
172
+ }, rest)), /*#__PURE__*/React.createElement("div", {
173
+ className: "pointer-events-none absolute top-1/2 right-2 flex -translate-y-1/2 items-center gap-1"
174
+ }, inputValue && !readOnly && !disabled && /*#__PURE__*/React.createElement(Button, {
175
+ id: "clear-date",
176
+ type: "button",
177
+ size: buttonSizeInTriggerOptions[size],
178
+ variant: "ghost-secondary",
179
+ className: "pointer-events-auto",
180
+ onMouseDown: function onMouseDown(e) {
181
+ return e.preventDefault();
182
+ },
183
+ onClick: handleClear,
184
+ "aria-label": "Clear date"
185
+ }, /*#__PURE__*/React.createElement(XIcon, {
186
+ className: iconSizeInTriggerOptions[size]
187
+ })), /*#__PURE__*/React.createElement(Popover, {
137
188
  open: open,
138
189
  defaultOpen: defaultOpen,
139
190
  onOpenChange: setOpen
@@ -143,7 +194,7 @@ function DatePicker(_ref) {
143
194
  id: "date-picker",
144
195
  size: buttonSizeInTriggerOptions[size],
145
196
  variant: "ghost-secondary",
146
- className: "absolute top-1/2 right-2 -translate-y-1/2",
197
+ className: "pointer-events-auto",
147
198
  onClick: function onClick() {
148
199
  return setOpen(function (prev) {
149
200
  return !prev;
@@ -172,7 +223,7 @@ function DatePicker(_ref) {
172
223
  after: maxDate
173
224
  }].filter(Boolean),
174
225
  locale: locale
175
- }, calendarProps))))), !isInputValid && /*#__PURE__*/React.createElement("span", {
226
+ }, calendarProps)))))), !isInputValid && /*#__PURE__*/React.createElement("span", {
176
227
  className: "px-1 text-xs text-red-500"
177
228
  }, invalidDateText !== null && invalidDateText !== void 0 ? invalidDateText : "Invalid date. Use ".concat(placeholder || dateFormat)));
178
229
  }
@@ -9,6 +9,11 @@ export declare const buttonSizeInTriggerOptions: {
9
9
  md: string;
10
10
  lg: string;
11
11
  };
12
+ export declare const inputRightPaddingBySize: {
13
+ sm: string;
14
+ md: string;
15
+ lg: string;
16
+ };
12
17
  export declare const SUPPORTED_DATE_LOCALES: Record<string, {
13
18
  label: string;
14
19
  locale: Locale;
@@ -3,6 +3,7 @@ import { FormSize } from '@scaleflex/ui-tw/types/form-size';
3
3
  import { de, enGB, enUS, es, fr, id, it, ja, nl, pl, pt, ro, zhCN } from 'date-fns/locale';
4
4
  export var iconSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'size-3'), FormSize.Md, 'size-4'), FormSize.Lg, 'size-5');
5
5
  export var buttonSizeInTriggerOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'icon-xs'), FormSize.Md, 'icon-sm'), FormSize.Lg, 'icon-md');
6
+ export var inputRightPaddingBySize = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, 'pr-16'), FormSize.Md, 'pr-16'), FormSize.Lg, 'pr-20');
6
7
  export var SUPPORTED_DATE_LOCALES = {
7
8
  en: {
8
9
  label: 'English (US)',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleflex/ui-tw",
3
- "version": "0.0.82",
3
+ "version": "0.0.85",
4
4
  "author": "scaleflex",
5
5
  "repository": "github:scaleflex/ui",
6
6
  "homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
@@ -23,7 +23,7 @@
23
23
  "@radix-ui/react-slot": "^1.1.2",
24
24
  "@radix-ui/react-switch": "^1.0.1",
25
25
  "@radix-ui/react-tooltip": "^1.2.6",
26
- "@scaleflex/icons-tw": "^0.0.82",
26
+ "@scaleflex/icons-tw": "^0.0.85",
27
27
  "@tanstack/react-table": "^8.21.3",
28
28
  "@types/lodash.merge": "^4.6.9",
29
29
  "class-variance-authority": "^0.7.1",