@timeax/form-palette 0.0.26 → 0.0.27

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.
package/dist/index.d.mts CHANGED
@@ -3014,7 +3014,7 @@ type NormalizedSelectItem = {
3014
3014
  /**
3015
3015
  * Shadcn-based Select variant.
3016
3016
  */
3017
- interface ShadcnSelectVariantProps extends Pick<VariantBaseProps<SelectPrimitive | undefined>, "value" | "onValue" | "error" | "disabled" | "readOnly" | "size" | "density"> {
3017
+ interface SelectBaseProps extends Pick<VariantBaseProps<SelectPrimitive | undefined>, "value" | "onValue" | "error" | "disabled" | "readOnly" | "size" | "density"> {
3018
3018
  /**
3019
3019
  * Options for the select.
3020
3020
  *
@@ -3119,13 +3119,6 @@ interface ShadcnSelectVariantProps extends Pick<VariantBaseProps<SelectPrimitive
3119
3119
  selectedItem: NormalizedSelectItem | null;
3120
3120
  placeholder?: React.ReactNode;
3121
3121
  }) => React.ReactNode;
3122
- /**
3123
- * One or more icons displayed inside the trigger, on the left.
3124
- *
3125
- * If not provided and `icon` is set, that single icon
3126
- * is treated as `leadingIcons[0]`.
3127
- */
3128
- leadingIcons?: React.ReactNode[];
3129
3122
  /**
3130
3123
  * Icons displayed on the right side of the trigger,
3131
3124
  * near the clear button / chevron area.
@@ -3192,6 +3185,51 @@ interface ShadcnSelectVariantProps extends Pick<VariantBaseProps<SelectPrimitive
3192
3185
  */
3193
3186
  virtualScrollThreshold?: number;
3194
3187
  }
3188
+ type SelectDefaultModeProps = {
3189
+ mode?: "default";
3190
+ leadingIcons?: React.ReactNode[];
3191
+ trailingIcons?: React.ReactNode[];
3192
+ icon?: React.ReactNode;
3193
+ iconGap?: number;
3194
+ leadingIconSpacing?: number;
3195
+ trailingIconSpacing?: number;
3196
+ leadingControl?: React.ReactNode;
3197
+ trailingControl?: React.ReactNode;
3198
+ leadingControlClassName?: string;
3199
+ trailingControlClassName?: string;
3200
+ joinControls?: boolean;
3201
+ extendBoxToControls?: boolean;
3202
+ button?: never;
3203
+ children?: never;
3204
+ };
3205
+ type SelectButtonModeButton = React.ReactNode | ((ctx: {
3206
+ open: boolean;
3207
+ selectedItem: NormalizedSelectItem | null;
3208
+ selectedValue: SelectPrimitive | undefined;
3209
+ placeholder?: React.ReactNode;
3210
+ }) => React.ReactNode);
3211
+ type SelectButtonModeProps = {
3212
+ mode: "button";
3213
+ /**
3214
+ * Used when mode="button". If provided, this is the trigger.
3215
+ * If not provided, `children` is used.
3216
+ */
3217
+ button?: SelectButtonModeButton;
3218
+ children?: SelectButtonModeButton;
3219
+ leadingIcons?: never;
3220
+ trailingIcons?: never;
3221
+ icon?: never;
3222
+ iconGap?: never;
3223
+ leadingIconSpacing?: never;
3224
+ trailingIconSpacing?: never;
3225
+ leadingControl?: never;
3226
+ trailingControl?: never;
3227
+ leadingControlClassName?: never;
3228
+ trailingControlClassName?: never;
3229
+ joinControls?: never;
3230
+ extendBoxToControls?: never;
3231
+ };
3232
+ type ShadcnSelectVariantProps = SelectBaseProps & (SelectDefaultModeProps | SelectButtonModeProps);
3195
3233
 
3196
3234
  type SelectVariantProps = ShadcnSelectVariantProps;
3197
3235
 
package/dist/index.d.ts CHANGED
@@ -3014,7 +3014,7 @@ type NormalizedSelectItem = {
3014
3014
  /**
3015
3015
  * Shadcn-based Select variant.
3016
3016
  */
3017
- interface ShadcnSelectVariantProps extends Pick<VariantBaseProps<SelectPrimitive | undefined>, "value" | "onValue" | "error" | "disabled" | "readOnly" | "size" | "density"> {
3017
+ interface SelectBaseProps extends Pick<VariantBaseProps<SelectPrimitive | undefined>, "value" | "onValue" | "error" | "disabled" | "readOnly" | "size" | "density"> {
3018
3018
  /**
3019
3019
  * Options for the select.
3020
3020
  *
@@ -3119,13 +3119,6 @@ interface ShadcnSelectVariantProps extends Pick<VariantBaseProps<SelectPrimitive
3119
3119
  selectedItem: NormalizedSelectItem | null;
3120
3120
  placeholder?: React.ReactNode;
3121
3121
  }) => React.ReactNode;
3122
- /**
3123
- * One or more icons displayed inside the trigger, on the left.
3124
- *
3125
- * If not provided and `icon` is set, that single icon
3126
- * is treated as `leadingIcons[0]`.
3127
- */
3128
- leadingIcons?: React.ReactNode[];
3129
3122
  /**
3130
3123
  * Icons displayed on the right side of the trigger,
3131
3124
  * near the clear button / chevron area.
@@ -3192,6 +3185,51 @@ interface ShadcnSelectVariantProps extends Pick<VariantBaseProps<SelectPrimitive
3192
3185
  */
3193
3186
  virtualScrollThreshold?: number;
3194
3187
  }
3188
+ type SelectDefaultModeProps = {
3189
+ mode?: "default";
3190
+ leadingIcons?: React.ReactNode[];
3191
+ trailingIcons?: React.ReactNode[];
3192
+ icon?: React.ReactNode;
3193
+ iconGap?: number;
3194
+ leadingIconSpacing?: number;
3195
+ trailingIconSpacing?: number;
3196
+ leadingControl?: React.ReactNode;
3197
+ trailingControl?: React.ReactNode;
3198
+ leadingControlClassName?: string;
3199
+ trailingControlClassName?: string;
3200
+ joinControls?: boolean;
3201
+ extendBoxToControls?: boolean;
3202
+ button?: never;
3203
+ children?: never;
3204
+ };
3205
+ type SelectButtonModeButton = React.ReactNode | ((ctx: {
3206
+ open: boolean;
3207
+ selectedItem: NormalizedSelectItem | null;
3208
+ selectedValue: SelectPrimitive | undefined;
3209
+ placeholder?: React.ReactNode;
3210
+ }) => React.ReactNode);
3211
+ type SelectButtonModeProps = {
3212
+ mode: "button";
3213
+ /**
3214
+ * Used when mode="button". If provided, this is the trigger.
3215
+ * If not provided, `children` is used.
3216
+ */
3217
+ button?: SelectButtonModeButton;
3218
+ children?: SelectButtonModeButton;
3219
+ leadingIcons?: never;
3220
+ trailingIcons?: never;
3221
+ icon?: never;
3222
+ iconGap?: never;
3223
+ leadingIconSpacing?: never;
3224
+ trailingIconSpacing?: never;
3225
+ leadingControl?: never;
3226
+ trailingControl?: never;
3227
+ leadingControlClassName?: never;
3228
+ trailingControlClassName?: never;
3229
+ joinControls?: never;
3230
+ extendBoxToControls?: never;
3231
+ };
3232
+ type ShadcnSelectVariantProps = SelectBaseProps & (SelectDefaultModeProps | SelectButtonModeProps);
3195
3233
 
3196
3234
  type SelectVariantProps = ShadcnSelectVariantProps;
3197
3235
 
package/dist/index.js CHANGED
@@ -16337,6 +16337,8 @@ var ShadcnSelectVariant = React10__namespace.forwardRef(function ShadcnSelectVar
16337
16337
  contentClassName,
16338
16338
  renderOption,
16339
16339
  renderValue,
16340
+ // Mode
16341
+ mode = "default",
16340
16342
  // Icons & controls
16341
16343
  leadingIcons,
16342
16344
  trailingIcons,
@@ -16350,11 +16352,15 @@ var ShadcnSelectVariant = React10__namespace.forwardRef(function ShadcnSelectVar
16350
16352
  trailingControlClassName,
16351
16353
  joinControls = true,
16352
16354
  extendBoxToControls = true,
16355
+ // Button mode only
16356
+ button,
16357
+ children,
16353
16358
  // Virtual scroll / incremental render
16354
16359
  virtualScroll = false,
16355
16360
  virtualScrollPageSize = 50,
16356
16361
  virtualScrollThreshold = 48
16357
16362
  } = props;
16363
+ const isButtonMode = mode === "button";
16358
16364
  const [open, setOpen] = React10__namespace.useState(false);
16359
16365
  const [query, setQuery] = React10__namespace.useState("");
16360
16366
  const items = React10__namespace.useMemo(
@@ -16447,18 +16453,19 @@ var ShadcnSelectVariant = React10__namespace.forwardRef(function ShadcnSelectVar
16447
16453
  const padCls = triggerPadding(density);
16448
16454
  const showClear = clearable && value != null;
16449
16455
  const resolvedLeadingIcons = (() => {
16456
+ if (isButtonMode) return [];
16450
16457
  if (leadingIcons && leadingIcons.length) return leadingIcons;
16451
16458
  if (icon) return [icon];
16452
16459
  return [];
16453
16460
  })();
16454
- const resolvedTrailingIcons = trailingIcons != null ? trailingIcons : [];
16461
+ const resolvedTrailingIcons = isButtonMode ? [] : trailingIcons != null ? trailingIcons : [];
16455
16462
  const baseIconGap = iconGap != null ? iconGap : 4;
16456
16463
  const leadingGap = leadingIconSpacing != null ? leadingIconSpacing : baseIconGap;
16457
16464
  const trailingGap = trailingIconSpacing != null ? trailingIconSpacing : baseIconGap;
16458
16465
  const hasLeadingIcons = resolvedLeadingIcons.length > 0;
16459
16466
  const hasTrailingIcons = resolvedTrailingIcons.length > 0;
16460
- const hasLeadingControl = !!leadingControl;
16461
- const hasTrailingControl = !!trailingControl;
16467
+ const hasLeadingControl = !isButtonMode && !!leadingControl;
16468
+ const hasTrailingControl = !isButtonMode && !!trailingControl;
16462
16469
  const hasControls = hasLeadingControl || hasTrailingControl;
16463
16470
  const triggerInner = renderValue ? renderValue({
16464
16471
  selectedItem,
@@ -16473,7 +16480,57 @@ var ShadcnSelectVariant = React10__namespace.forwardRef(function ShadcnSelectVar
16473
16480
  "focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]",
16474
16481
  "aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive"
16475
16482
  );
16476
- const TriggerBody = /* @__PURE__ */ jsxRuntime.jsx(
16483
+ const ButtonModeTrigger = React10__namespace.useMemo(() => {
16484
+ if (!isButtonMode) return null;
16485
+ const selectedValue = value;
16486
+ const renderable = button != null ? button : children;
16487
+ const content = (() => {
16488
+ var _a2, _b2, _c, _d;
16489
+ if (typeof renderable === "function") {
16490
+ return renderable({
16491
+ open,
16492
+ selectedItem,
16493
+ selectedValue,
16494
+ placeholder
16495
+ });
16496
+ }
16497
+ if (renderable != null) return renderable;
16498
+ const iconNode = (_c = (_b2 = selectedItem == null ? void 0 : selectedItem.icon) != null ? _b2 : (_a2 = items.find((it) => it.icon)) == null ? void 0 : _a2.icon) != null ? _c : null;
16499
+ if (iconNode) {
16500
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "inline-flex items-center justify-center", children: iconNode });
16501
+ }
16502
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: (_d = selectedItem == null ? void 0 : selectedItem.labelNode) != null ? _d : placeholder != null ? placeholder : "Select..." });
16503
+ })();
16504
+ return /* @__PURE__ */ jsxRuntime.jsx(
16505
+ "button",
16506
+ {
16507
+ ref: _ref,
16508
+ type: "button",
16509
+ disabled: disabled || readOnly,
16510
+ className: cn(
16511
+ "inline-flex items-center justify-center",
16512
+ "focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50",
16513
+ triggerClassName
16514
+ ),
16515
+ "aria-label": (selectedItem == null ? void 0 : selectedItem.labelText) ? `Selected: ${selectedItem.labelText}` : "Select",
16516
+ children: content
16517
+ }
16518
+ );
16519
+ }, [
16520
+ isButtonMode,
16521
+ button,
16522
+ children,
16523
+ open,
16524
+ selectedItem,
16525
+ value,
16526
+ placeholder,
16527
+ items,
16528
+ disabled,
16529
+ readOnly,
16530
+ triggerClassName,
16531
+ _ref
16532
+ ]);
16533
+ const TriggerBody = isButtonMode ? /* @__PURE__ */ jsxRuntime.jsx(SelectTrigger, { asChild: true, children: ButtonModeTrigger }) : /* @__PURE__ */ jsxRuntime.jsx(
16477
16534
  SelectTrigger,
16478
16535
  {
16479
16536
  onPointerDown: (e) => {
@@ -16566,7 +16623,7 @@ var ShadcnSelectVariant = React10__namespace.forwardRef(function ShadcnSelectVar
16566
16623
  /* @__PURE__ */ jsxRuntime.jsxs(
16567
16624
  SelectContent,
16568
16625
  {
16569
- className: cn("min-w-[8rem]", contentClassName),
16626
+ className: cn("min-w-32", contentClassName),
16570
16627
  children: [
16571
16628
  searchable && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "p-1", children: /* @__PURE__ */ jsxRuntime.jsx(
16572
16629
  Input,
@@ -16635,7 +16692,7 @@ var ShadcnSelectVariant = React10__namespace.forwardRef(function ShadcnSelectVar
16635
16692
  ]
16636
16693
  }
16637
16694
  );
16638
- if (!hasControls) {
16695
+ if (isButtonMode || !hasControls) {
16639
16696
  return /* @__PURE__ */ jsxRuntime.jsx(
16640
16697
  "div",
16641
16698
  {