@godxjp/ui 16.0.0 → 16.1.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.
@@ -242,8 +242,8 @@ function Cascader({
242
242
  className: cn(
243
243
  "w-full justify-start font-normal",
244
244
  controlOpenRingClass,
245
- // Reserve trailing room for the clear + chevron overlay rendered below.
246
- showClear ? "pe-14" : "pe-9",
245
+ // Reserve trailing room for the single clear-or-chevron overlay rendered below.
246
+ "pe-9",
247
247
  !displayLabel && "text-muted-foreground"
248
248
  ),
249
249
  children: /* @__PURE__ */ jsx("span", { className: "truncate", children: displayLabel ?? resolvedPlaceholder })
@@ -307,19 +307,16 @@ function Cascader({
307
307
  }
308
308
  )
309
309
  ] }),
310
- /* @__PURE__ */ jsxs("div", { className: "pointer-events-none absolute inset-y-0 end-3 flex items-center gap-1", children: [
311
- showClear && /* @__PURE__ */ jsx(
312
- "button",
313
- {
314
- type: "button",
315
- "aria-label": t("dataEntry.cascader.clear"),
316
- className: "pointer-events-auto flex size-4 items-center justify-center rounded-sm opacity-50 hover:opacity-100 focus-visible:opacity-100",
317
- onClick: clearValue,
318
- children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
319
- }
320
- ),
321
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-4 shrink-0 opacity-50", "aria-hidden": "true" })
322
- ] })
310
+ /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-y-0 end-3 flex items-center", children: showClear ? /* @__PURE__ */ jsx(
311
+ "button",
312
+ {
313
+ type: "button",
314
+ "aria-label": t("dataEntry.cascader.clear"),
315
+ className: "pointer-events-auto flex size-4 items-center justify-center rounded-sm opacity-50 hover:opacity-100 focus-visible:opacity-100",
316
+ onClick: clearValue,
317
+ children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
318
+ }
319
+ ) : /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-4 shrink-0 opacity-50", "aria-hidden": "true" }) })
323
320
  ] });
324
321
  }
325
322
  export {
@@ -1,11 +1,10 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { CalendarIcon, X } from "lucide-react";
3
+ import { CalendarIcon } from "lucide-react";
4
4
  import { usePickerLocales, useTranslation } from "../../i18n/use-translation";
5
5
  import { parseDateInput, toIsoDate } from "../../lib/datetime/parse";
6
6
  import { useControlledLatch } from "../../lib/hooks";
7
7
  import { cn } from "../../lib/utils";
8
- import { Button } from "../general/button";
9
8
  import { Input } from "./input";
10
9
  import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../data-display/popover";
11
10
  import { Calendar } from "./calendar";
@@ -39,7 +38,6 @@ function DatePicker({
39
38
  setText(toIsoDate(value));
40
39
  }, [value]);
41
40
  const resolvedPlaceholder = placeholder ?? t("dataEntry.datePicker.placeholder") ?? ISO_HINT;
42
- const showClear = allowClear && Boolean(value) && !disabled;
43
41
  const clear = () => {
44
42
  emit(void 0);
45
43
  setText("");
@@ -70,7 +68,19 @@ function DatePicker({
70
68
  role: "combobox",
71
69
  "aria-expanded": open,
72
70
  "aria-haspopup": "dialog",
73
- className: cn("pe-10", showClear && "pe-16"),
71
+ allowClear,
72
+ onClear: clear,
73
+ trailingIcon: /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
74
+ "button",
75
+ {
76
+ type: "button",
77
+ disabled,
78
+ tabIndex: -1,
79
+ "aria-label": t("dataEntry.datePicker.openCalendar") ?? "Open calendar",
80
+ className: "text-muted-foreground hover:text-foreground inline-flex size-5 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100",
81
+ children: /* @__PURE__ */ jsx(CalendarIcon, { className: "size-4", "aria-hidden": "true" })
82
+ }
83
+ ) }),
74
84
  onClick: () => {
75
85
  if (!disabled) setOpen(true);
76
86
  },
@@ -92,33 +102,6 @@ function DatePicker({
92
102
  }
93
103
  }
94
104
  ),
95
- showClear ? /* @__PURE__ */ jsx(
96
- Button,
97
- {
98
- type: "button",
99
- variant: "ghost",
100
- size: "icon",
101
- disabled,
102
- tabIndex: -1,
103
- "aria-label": t("common.clear") ?? "Clear",
104
- className: "text-muted-foreground absolute inset-y-0 end-8 h-full px-2 hover:bg-transparent",
105
- onClick: clear,
106
- children: /* @__PURE__ */ jsx(X, { className: "size-4 shrink-0", "aria-hidden": "true" })
107
- }
108
- ) : null,
109
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
110
- Button,
111
- {
112
- type: "button",
113
- variant: "ghost",
114
- size: "icon",
115
- disabled,
116
- tabIndex: -1,
117
- "aria-label": t("dataEntry.datePicker.openCalendar") ?? "Open calendar",
118
- className: "text-muted-foreground absolute inset-y-0 end-0 h-full px-2 hover:bg-transparent",
119
- children: /* @__PURE__ */ jsx(CalendarIcon, { className: "size-4 shrink-0", "aria-hidden": "true" })
120
- }
121
- ) }),
122
105
  /* @__PURE__ */ jsx(
123
106
  PopoverContent,
124
107
  {
@@ -142,8 +142,7 @@ function DateRangePicker({
142
142
  },
143
143
  children: /* @__PURE__ */ jsx(X, { className: "size-4 shrink-0", "aria-hidden": "true" })
144
144
  }
145
- ) : null,
146
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
145
+ ) : /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
147
146
  "button",
148
147
  {
149
148
  type: "button",
@@ -4,10 +4,22 @@ export type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
4
4
  allowClear?: boolean;
5
5
  /** Called after the field is cleared via the inline ✕. */
6
6
  onClear?: () => void;
7
+ /**
8
+ * A trailing affordance pinned inside the field — e.g. a calendar / clock popover
9
+ * trigger button. ONE trailing icon shows at a time: when `allowClear` and the field
10
+ * holds a value the clear ✕ REPLACES this icon; otherwise this icon shows. Never both.
11
+ */
12
+ trailingIcon?: React.ReactNode;
7
13
  };
8
14
  export declare const Input: React.ForwardRefExoticComponent<React.InputHTMLAttributes<HTMLInputElement> & {
9
15
  /** Show an inline ✕ that clears the field while it holds text (default false). */
10
16
  allowClear?: boolean;
11
17
  /** Called after the field is cleared via the inline ✕. */
12
18
  onClear?: () => void;
19
+ /**
20
+ * A trailing affordance pinned inside the field — e.g. a calendar / clock popover
21
+ * trigger button. ONE trailing icon shows at a time: when `allowClear` and the field
22
+ * holds a value the clear ✕ REPLACES this icon; otherwise this icon shows. Never both.
23
+ */
24
+ trailingIcon?: React.ReactNode;
13
25
  } & React.RefAttributes<HTMLInputElement>>;
@@ -13,7 +13,17 @@ const inputBaseClass = [
13
13
  "aria-invalid:border-destructive aria-invalid:ring-destructive/20"
14
14
  ];
15
15
  const Input = React.forwardRef(
16
- ({ className, type, allowClear = false, onClear, value, defaultValue, onChange, ...props }, ref) => {
16
+ ({
17
+ className,
18
+ type,
19
+ allowClear = false,
20
+ onClear,
21
+ trailingIcon,
22
+ value,
23
+ defaultValue,
24
+ onChange,
25
+ ...props
26
+ }, ref) => {
17
27
  const { t } = useTranslation();
18
28
  const innerRef = React.useRef(null);
19
29
  const setRefs = React.useCallback(
@@ -48,7 +58,7 @@ const Input = React.forwardRef(
48
58
  setHasText(false);
49
59
  onClear?.();
50
60
  };
51
- if (!allowClear) {
61
+ if (!allowClear && trailingIcon == null) {
52
62
  return /* @__PURE__ */ jsx(
53
63
  "input",
54
64
  {
@@ -63,7 +73,18 @@ const Input = React.forwardRef(
63
73
  }
64
74
  );
65
75
  }
66
- const showClear = hasText && !props.disabled && !props.readOnly;
76
+ const showClear = allowClear && hasText && !props.disabled && !props.readOnly;
77
+ const trailing = showClear ? /* @__PURE__ */ jsx(
78
+ "button",
79
+ {
80
+ type: "button",
81
+ tabIndex: -1,
82
+ "aria-label": t("common.clear") ?? "Clear",
83
+ onClick: clear,
84
+ className: "text-muted-foreground hover:text-foreground inline-flex size-5 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:opacity-100",
85
+ children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
86
+ }
87
+ ) : trailingIcon;
67
88
  return /* @__PURE__ */ jsxs("span", { "data-slot": "input-affix-wrapper", className: "relative inline-flex w-full items-center", children: [
68
89
  /* @__PURE__ */ jsx(
69
90
  "input",
@@ -74,21 +95,11 @@ const Input = React.forwardRef(
74
95
  value,
75
96
  defaultValue,
76
97
  onChange: handleChange,
77
- className: cn(inputBaseClass, showClear && "pe-9", className),
98
+ className: cn(inputBaseClass, (showClear || trailingIcon != null) && "pe-9", className),
78
99
  ...props
79
100
  }
80
101
  ),
81
- showClear ? /* @__PURE__ */ jsx(
82
- "button",
83
- {
84
- type: "button",
85
- tabIndex: -1,
86
- "aria-label": t("common.clear") ?? "Clear",
87
- onClick: clear,
88
- className: "text-muted-foreground hover:text-foreground absolute end-2 inline-flex size-5 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:opacity-100",
89
- children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
90
- }
91
- ) : null
102
+ trailing != null ? /* @__PURE__ */ jsx("span", { className: "absolute inset-y-0 end-2 inline-flex items-center", children: trailing }) : null
92
103
  ] });
93
104
  }
94
105
  );
@@ -109,8 +109,7 @@ function MonthPicker({
109
109
  },
110
110
  children: /* @__PURE__ */ jsx(X, { className: "size-4 shrink-0", "aria-hidden": "true" })
111
111
  }
112
- ) : null,
113
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
112
+ ) : /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
114
113
  "button",
115
114
  {
116
115
  type: "button",
@@ -164,8 +164,7 @@ function MonthRangePicker({
164
164
  },
165
165
  children: /* @__PURE__ */ jsx(X, { className: "size-4 shrink-0", "aria-hidden": "true" })
166
166
  }
167
- ) : null,
168
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
167
+ ) : /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
169
168
  "button",
170
169
  {
171
170
  type: "button",
@@ -172,8 +172,8 @@ function SearchSelect({
172
172
  className: cn(
173
173
  "w-full justify-start font-normal",
174
174
  controlOpenRingClass,
175
- // Reserve trailing room for the clear + chevron overlay rendered below.
176
- showClear ? "pe-14" : "pe-9"
175
+ // Reserve trailing room for the single clear-or-chevron overlay rendered below.
176
+ "pe-9"
177
177
  ),
178
178
  children: /* @__PURE__ */ jsx(
179
179
  "span",
@@ -265,20 +265,17 @@ function SearchSelect({
265
265
  ]
266
266
  }
267
267
  ),
268
- /* @__PURE__ */ jsxs("div", { className: "pointer-events-none absolute inset-y-0 end-3 flex items-center gap-1", children: [
269
- showClear ? /* @__PURE__ */ jsx(
270
- "button",
271
- {
272
- type: "button",
273
- "aria-label": clearLabel ?? t("dataEntry.searchSelect.clear"),
274
- "data-testid": optionTestId("clear"),
275
- className: "pointer-events-auto flex size-4 items-center justify-center rounded-sm opacity-50 hover:opacity-100 focus-visible:opacity-100",
276
- onClick: clear,
277
- children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
278
- }
279
- ) : null,
280
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-4 shrink-0 opacity-50", "aria-hidden": "true" })
281
- ] })
268
+ /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-y-0 end-3 flex items-center", children: showClear ? /* @__PURE__ */ jsx(
269
+ "button",
270
+ {
271
+ type: "button",
272
+ "aria-label": clearLabel ?? t("dataEntry.searchSelect.clear"),
273
+ "data-testid": optionTestId("clear"),
274
+ className: "pointer-events-auto flex size-4 items-center justify-center rounded-sm opacity-50 hover:opacity-100 focus-visible:opacity-100",
275
+ onClick: clear,
276
+ children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
277
+ }
278
+ ) : /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-4 shrink-0 opacity-50", "aria-hidden": "true" }) })
282
279
  ] });
283
280
  }
284
281
  export {
@@ -1,10 +1,9 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
- import { Clock, X } from "lucide-react";
3
+ import { Clock } from "lucide-react";
4
4
  import { usePickerLocales, useTranslation } from "../../i18n/use-translation";
5
5
  import { isValidHhmm, normalizeHhmm } from "../../lib/datetime";
6
6
  import { cn } from "../../lib/utils";
7
- import { Button } from "../general/button";
8
7
  import { Popover, PopoverAnchor, PopoverContent, PopoverTrigger } from "../data-display/popover";
9
8
  import { Input } from "./input";
10
9
  function pad2(n) {
@@ -228,76 +227,60 @@ function TimePicker({
228
227
  if (!isControlled) setInternal(next);
229
228
  onValueChange?.(next);
230
229
  };
231
- const showClear = allowClear && Boolean(value) && !disabled;
232
230
  const clear = () => {
233
231
  setValue("");
234
232
  setText("");
235
233
  };
236
234
  return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: setOpen, children: [
237
- /* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsxs("div", { className: cn("relative", className), children: [
238
- /* @__PURE__ */ jsx(
239
- Input,
240
- {
241
- id,
242
- name,
243
- value: text,
244
- disabled,
245
- placeholder: resolvedPlaceholder,
246
- inputMode: "numeric",
247
- autoComplete: "off",
248
- role: "combobox",
249
- "aria-expanded": open,
250
- "aria-haspopup": "dialog",
251
- className: cn("tabular-nums", "pe-10"),
252
- onClick: () => {
253
- if (!disabled) setOpen(true);
254
- },
255
- onKeyDown: (event) => {
256
- if (event.key === "ArrowDown") {
257
- event.preventDefault();
258
- setOpen(true);
259
- } else if (event.key === "Escape" && open) {
260
- setOpen(false);
261
- }
262
- },
263
- onChange: (event) => {
264
- setText(event.target.value);
265
- const normalized = normalizeHhmm(event.target.value);
266
- if (normalized) setValue(normalized);
267
- },
268
- onBlur: (event) => {
269
- const normalized = normalizeHhmm(event.target.value);
270
- setText(normalized ?? (isValidHhmm(value) ? value : ""));
235
+ /* @__PURE__ */ jsx(PopoverAnchor, { asChild: true, children: /* @__PURE__ */ jsx("div", { className: cn("relative", className), children: /* @__PURE__ */ jsx(
236
+ Input,
237
+ {
238
+ id,
239
+ name,
240
+ value: text,
241
+ disabled,
242
+ placeholder: resolvedPlaceholder,
243
+ inputMode: "numeric",
244
+ autoComplete: "off",
245
+ role: "combobox",
246
+ "aria-expanded": open,
247
+ "aria-haspopup": "dialog",
248
+ className: "tabular-nums",
249
+ allowClear,
250
+ onClear: clear,
251
+ trailingIcon: /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
252
+ "button",
253
+ {
254
+ type: "button",
255
+ disabled,
256
+ tabIndex: -1,
257
+ "aria-label": t("dataEntry.timePicker.openPicker") ?? "Open time picker",
258
+ className: "text-muted-foreground hover:text-foreground inline-flex size-5 items-center justify-center rounded-sm opacity-70 transition-opacity hover:opacity-100",
259
+ children: /* @__PURE__ */ jsx(Clock, { className: "size-4", "aria-hidden": "true" })
271
260
  }
261
+ ) }),
262
+ onClick: () => {
263
+ if (!disabled) setOpen(true);
264
+ },
265
+ onKeyDown: (event) => {
266
+ if (event.key === "ArrowDown") {
267
+ event.preventDefault();
268
+ setOpen(true);
269
+ } else if (event.key === "Escape" && open) {
270
+ setOpen(false);
271
+ }
272
+ },
273
+ onChange: (event) => {
274
+ setText(event.target.value);
275
+ const normalized = normalizeHhmm(event.target.value);
276
+ if (normalized) setValue(normalized);
277
+ },
278
+ onBlur: (event) => {
279
+ const normalized = normalizeHhmm(event.target.value);
280
+ setText(normalized ?? (isValidHhmm(value) ? value : ""));
272
281
  }
273
- ),
274
- showClear ? /* @__PURE__ */ jsx(
275
- Button,
276
- {
277
- type: "button",
278
- variant: "ghost",
279
- size: "icon",
280
- disabled,
281
- tabIndex: -1,
282
- "aria-label": t("common.clear") ?? "Clear",
283
- className: "text-muted-foreground absolute inset-y-0 end-0 h-full px-2 hover:bg-transparent",
284
- onClick: clear,
285
- children: /* @__PURE__ */ jsx(X, { className: "size-4 shrink-0", "aria-hidden": "true" })
286
- }
287
- ) : /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
288
- Button,
289
- {
290
- type: "button",
291
- variant: "ghost",
292
- size: "icon",
293
- disabled,
294
- tabIndex: -1,
295
- "aria-label": t("dataEntry.timePicker.openPicker") ?? "Open time picker",
296
- className: "text-muted-foreground absolute inset-y-0 end-0 h-full px-2 hover:bg-transparent",
297
- children: /* @__PURE__ */ jsx(Clock, { className: "size-4 shrink-0", "aria-hidden": "true" })
298
- }
299
- ) })
300
- ] }) }),
282
+ }
283
+ ) }) }),
301
284
  /* @__PURE__ */ jsx(
302
285
  PopoverContent,
303
286
  {
@@ -185,19 +185,16 @@ function TreeSelectRoot({
185
185
  ),
186
186
  children: [
187
187
  /* @__PURE__ */ jsx("span", { className: "truncate", children: displayKeys.length ? displayLabel : resolvedPlaceholder }),
188
- /* @__PURE__ */ jsxs("span", { className: "ms-2 flex shrink-0 items-center gap-1", children: [
189
- allowClear && displayKeys.length > 0 && !disabled && /* @__PURE__ */ jsx(
190
- "button",
191
- {
192
- type: "button",
193
- "aria-label": t("dataEntry.treeSelect.clear"),
194
- className: "flex size-4 items-center justify-center rounded-sm opacity-50 hover:opacity-100 focus-visible:opacity-100",
195
- onClick: clearValue,
196
- children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
197
- }
198
- ),
199
- /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-4 opacity-50", "aria-hidden": "true" })
200
- ] })
188
+ /* @__PURE__ */ jsx("span", { className: "ms-2 flex shrink-0 items-center", children: allowClear && displayKeys.length > 0 && !disabled ? /* @__PURE__ */ jsx(
189
+ "button",
190
+ {
191
+ type: "button",
192
+ "aria-label": t("dataEntry.treeSelect.clear"),
193
+ className: "flex size-4 items-center justify-center rounded-sm opacity-50 hover:opacity-100 focus-visible:opacity-100",
194
+ onClick: clearValue,
195
+ children: /* @__PURE__ */ jsx(X, { className: "size-4", "aria-hidden": "true" })
196
+ }
197
+ ) : /* @__PURE__ */ jsx(ChevronsUpDown, { className: "size-4 opacity-50", "aria-hidden": "true" }) })
201
198
  ]
202
199
  }
203
200
  ) }),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godxjp/ui",
3
- "version": "16.0.0",
3
+ "version": "16.1.0",
4
4
  "type": "module",
5
5
  "packageManager": "pnpm@10.29.1",
6
6
  "sideEffects": false,