@vitavision/ui 0.14.2 → 0.14.3

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.ts CHANGED
@@ -600,7 +600,7 @@ export declare function ProgressBar({ fraction, label, "aria-label": ariaLabel,
600
600
  * pick them up; give it `aria-describedby` yourself. State is exposed as `data-invalid` and
601
601
  * `data-required`.
602
602
  */
603
- export declare function Field({ label, description, error, required, annotation, as, className, children }: {
603
+ export declare function Field({ label, description, error, required, annotation, as, layout, className, children }: {
604
604
  /** The field's name, shown above the control. */
605
605
  label: string;
606
606
  /** What the value means or does. Always visible, and read with the control. */
@@ -616,6 +616,14 @@ export declare function Field({ label, description, error, required, annotation,
616
616
  * `role="group"` named by `label`, for a set of radios or a segmented control.
617
617
  */
618
618
  as?: "label" | "group";
619
+ /**
620
+ * `top` (the default) puts the label above the control. `side` is the property-sheet row:
621
+ * the label in a fixed column on the left (one line, truncated, the full text in its
622
+ * `title`), the control on the right, the annotation after the label. The column's width
623
+ * is the CSS variable `--field-label-w` (default `8.5rem`), so a parent can set it once
624
+ * for every row. The description and the error line up under the control.
625
+ */
626
+ layout?: "top" | "side";
619
627
  /** Merged with the field's own classes through `cn`. */
620
628
  className?: string | undefined;
621
629
  /** The control. */
@@ -691,6 +699,83 @@ type HighlightedTextProps = Omit<ComponentProps<"span">, "children"> & {
691
699
  */
692
700
  export declare function HighlightedText({ text, spans, labels, className, ...rest }: HighlightedTextProps): import("react").JSX.Element;
693
701
  //#endregion
702
+ //#region src/components/ui/IconButton.d.ts
703
+ /**
704
+ * An icon-only button. `label` is its accessible name *and* its tooltip, so it is required;
705
+ * `shortcut` adds a key cap to the tooltip and `aria-keyshortcuts`. `pressed` makes it a
706
+ * toggle (`aria-pressed`, `data-state="on"` / `"off"`).
707
+ *
708
+ * Needs a `TooltipProvider` above it. Takes every `<button>` prop, `ref` included. A
709
+ * disabled button shows no tooltip (browsers send it no pointer events), so say why in the
710
+ * surrounding UI when the reason is not obvious.
711
+ */
712
+ export declare function IconButton({ label, icon, hint, shortcut, pressed, variant, size, type, className, ...rest }: Omit<ComponentProps<"button">, "children" | "title" | "aria-label" | "aria-pressed"> & {
713
+ /** The accessible name, also the tooltip's text. */
714
+ label: string;
715
+ /** The icon, decorative (`aria-hidden`). Sized to 16 px. */
716
+ icon: ReactNode;
717
+ /** A second tooltip line after the label, e.g. why it is the way it is. */
718
+ hint?: ReactNode;
719
+ /** The key that does the same, shown in the tooltip. Display only: binding it is yours. */
720
+ shortcut?: string | undefined;
721
+ /** A toggle's state; omit for a plain action. */
722
+ pressed?: boolean | undefined;
723
+ /** Same variants as `Button`. Defaults to `ghost`, the toolbar look. */
724
+ variant?: ButtonVariant | undefined;
725
+ /** Defaults to the density in force — `md` comfortable, `sm` compact. */
726
+ size?: ButtonSize | undefined;
727
+ }): import("react").JSX.Element;
728
+ /** One item of an `IconToggleGroup`. */
729
+ interface IconToggleItem {
730
+ /** Its identity, reported through `onValueChange`. */
731
+ value: string;
732
+ /** The accessible name and tooltip text. */
733
+ label: string;
734
+ /** The icon, decorative. */
735
+ icon: ReactNode;
736
+ /** A key that does the same, shown in the tooltip. */
737
+ shortcut?: string | undefined;
738
+ /** Blocks this item only. */
739
+ disabled?: boolean | undefined;
740
+ }
741
+ type GroupCommon = {
742
+ /** The items, in order. */
743
+ items: readonly IconToggleItem[];
744
+ /** Names the group. */
745
+ "aria-label": string;
746
+ /** Defaults to the density in force. */
747
+ size?: ButtonSize | undefined;
748
+ /** Blocks every item. */
749
+ disabled?: boolean | undefined;
750
+ /** Merged onto the group with `cn`. */
751
+ className?: string | undefined;
752
+ };
753
+ /** Props of `IconToggleGroup`: one selected value, or any number. */
754
+ type IconToggleGroupProps = GroupCommon & ({
755
+ /** One item at a time. Selecting the selected one keeps it (`""` means none). */
756
+ type?: "single" | undefined;
757
+ value?: string | undefined;
758
+ defaultValue?: string | undefined;
759
+ onValueChange?: ((value: string) => void) | undefined;
760
+ } | {
761
+ /** Any subset. */
762
+ type: "multiple";
763
+ value?: readonly string[] | undefined;
764
+ defaultValue?: readonly string[] | undefined;
765
+ onValueChange?: ((value: string[]) => void) | undefined;
766
+ });
767
+ /**
768
+ * A strip of icon toggles — a tool picker, a view-mode switch, text-style toggles — each
769
+ * named by its tooltip. `type="single"` (the default) keeps exactly the chosen item
770
+ * pressed; `type="multiple"` lets each toggle on its own. Controlled with `value` or
771
+ * uncontrolled with `defaultValue`.
772
+ *
773
+ * Each item is a button with `aria-pressed` inside a `role="group"`. One item is a tab stop
774
+ * (the pressed one, else the first); Arrow keys, Home and End move focus along the strip.
775
+ * Needs a `TooltipProvider` above it.
776
+ */
777
+ export declare function IconToggleGroup(props: IconToggleGroupProps): import("react").JSX.Element;
778
+ //#endregion
694
779
  //#region src/components/ui/Input.d.ts
695
780
  /**
696
781
  * The shared look of a text-like control — border, palette, placeholder, hover, disabled and
@@ -1751,5 +1836,5 @@ export declare function Tabs<Id extends string>({ items, active, onSelect, label
1751
1836
  className?: string | undefined;
1752
1837
  }): import("react").JSX.Element;
1753
1838
  //#endregion
1754
- export type { BackLink, BreakdownProps, BreakdownSegment, BreakdownTextOptions, BreakdownTone, ButtonSize, ButtonVariant, CalloutTone, Column, DeltaCellProps, DeltaStrength, Density, DropdownMenuProps, HighlightKind, HighlightRule, HighlightSpan, HighlightedTextProps, ListboxOption, ListboxOptionState, ListboxProps, MeasureTone, MenuCheckboxItemProps, MenuItemProps, NumberInputProps, PopoverProps, PoseInputProps, PoseValue, ProgressProps, Quaternion, ReadoutItem, RotationView, SelectOption, Shortcut, ShortcutGroup, ShortcutListProps, SortDirection, TabItem, TableSort, TableWindowing, TextareaProps, ThemeChoice, ToastOptions, ToastRecord, ToastStore, ToastTone, ToasterProps, Tone, Vec3, VectorInputProps };
1839
+ export type { BackLink, BreakdownProps, BreakdownSegment, BreakdownTextOptions, BreakdownTone, ButtonSize, ButtonVariant, CalloutTone, Column, DeltaCellProps, DeltaStrength, Density, DropdownMenuProps, HighlightKind, HighlightRule, HighlightSpan, HighlightedTextProps, IconToggleGroupProps, IconToggleItem, ListboxOption, ListboxOptionState, ListboxProps, MeasureTone, MenuCheckboxItemProps, MenuItemProps, NumberInputProps, PopoverProps, PoseInputProps, PoseValue, ProgressProps, Quaternion, ReadoutItem, RotationView, SelectOption, Shortcut, ShortcutGroup, ShortcutListProps, SortDirection, TabItem, TableSort, TableWindowing, TextareaProps, ThemeChoice, ToastOptions, ToastRecord, ToastStore, ToastTone, ToasterProps, Tone, Vec3, VectorInputProps };
1755
1840
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -952,6 +952,10 @@ function ProgressBar({ fraction, label, "aria-label": ariaLabel, className }) {
952
952
  }
953
953
  //#endregion
954
954
  //#region src/components/ui/Field.tsx
955
+ /** The `side` row: a label column and the control, centred on one line. */
956
+ const SIDE_ROW = "grid min-w-0 grid-cols-[var(--field-label-w,8.5rem)_minmax(0,1fr)] items-center gap-x-3";
957
+ /** Lines the description and the error up under the control of a `side` row. */
958
+ const SIDE_UNDER = "ml-[calc(var(--field-label-w,8.5rem)+0.75rem)]";
955
959
  const FieldContext = createContext({
956
960
  describedBy: void 0,
957
961
  invalid: false
@@ -980,7 +984,7 @@ function useFieldDescription(own) {
980
984
  * pick them up; give it `aria-describedby` yourself. State is exposed as `data-invalid` and
981
985
  * `data-required`.
982
986
  */
983
- function Field({ label, description, error, required = false, annotation, as = "label", className, children }) {
987
+ function Field({ label, description, error, required = false, annotation, as = "label", layout = "top", className, children }) {
984
988
  const descriptionId = useId();
985
989
  const errorId = useId();
986
990
  const density = useDensity();
@@ -995,15 +999,30 @@ function Field({ label, description, error, required = false, annotation, as = "
995
999
  hasError
996
1000
  ]);
997
1001
  const gap = byDensity(density, "gap-1.5", "gap-1");
998
- const labelled = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
1002
+ const side = layout === "side";
1003
+ const labelText = /* @__PURE__ */ jsxs(Fragment$1, { children: [label, required && /* @__PURE__ */ jsx("span", {
1004
+ className: "ml-0.5 text-defect",
1005
+ title: "Required",
1006
+ children: "*"
1007
+ })] });
1008
+ const labelled = side ? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
1009
+ className: "flex min-w-0 items-center gap-1.5",
1010
+ children: [/* @__PURE__ */ jsx("span", {
1011
+ className: cn("min-w-0 truncate font-medium text-fg", byDensity(density, "text-xs", "text-[11px]")),
1012
+ title: label,
1013
+ children: labelText
1014
+ }), annotation && /* @__PURE__ */ jsx("span", {
1015
+ className: "shrink-0 font-mono text-[11px] text-fg-subtle",
1016
+ children: annotation
1017
+ })]
1018
+ }), /* @__PURE__ */ jsx(FieldContext, {
1019
+ value: control,
1020
+ children
1021
+ })] }) : /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("span", {
999
1022
  className: "flex items-baseline gap-2",
1000
- children: [/* @__PURE__ */ jsxs("span", {
1023
+ children: [/* @__PURE__ */ jsx("span", {
1001
1024
  className: cn("font-medium text-fg", byDensity(density, "text-xs", "text-[11px]")),
1002
- children: [label, required && /* @__PURE__ */ jsx("span", {
1003
- className: "ml-0.5 text-defect",
1004
- title: "Required",
1005
- children: "*"
1006
- })]
1025
+ children: labelText
1007
1026
  }), annotation && /* @__PURE__ */ jsx("span", {
1008
1027
  className: "ml-auto font-mono text-[11px] text-fg-subtle",
1009
1028
  children: annotation
@@ -1012,8 +1031,11 @@ function Field({ label, description, error, required = false, annotation, as = "
1012
1031
  value: control,
1013
1032
  children
1014
1033
  })] });
1034
+ const rowClasses = side ? SIDE_ROW : cn("flex min-w-0 flex-col", gap);
1035
+ const under = side ? SIDE_UNDER : void 0;
1015
1036
  return /* @__PURE__ */ jsxs("div", {
1016
- className: cn("flex min-w-0 flex-col", gap, className),
1037
+ className: cn("flex min-w-0 flex-col", side ? "gap-0.5" : gap, className),
1038
+ "data-layout": side ? "side" : void 0,
1017
1039
  "data-invalid": hasError ? "" : void 0,
1018
1040
  "data-required": required ? "" : void 0,
1019
1041
  ...as === "group" ? {
@@ -1023,18 +1045,21 @@ function Field({ label, description, error, required = false, annotation, as = "
1023
1045
  } : {},
1024
1046
  children: [
1025
1047
  as === "label" ? /* @__PURE__ */ jsx("label", {
1026
- className: cn("flex min-w-0 flex-col", gap),
1048
+ className: rowClasses,
1049
+ children: labelled
1050
+ }) : side ? /* @__PURE__ */ jsx("div", {
1051
+ className: rowClasses,
1027
1052
  children: labelled
1028
1053
  }) : labelled,
1029
1054
  description && /* @__PURE__ */ jsx("span", {
1030
1055
  id: descriptionId,
1031
- className: "text-xs leading-snug text-fg-muted",
1056
+ className: cn("text-xs leading-snug text-fg-muted", under),
1032
1057
  children: description
1033
1058
  }),
1034
1059
  hasError && /* @__PURE__ */ jsx("span", {
1035
1060
  id: errorId,
1036
1061
  role: "alert",
1037
- className: "text-xs leading-snug text-defect",
1062
+ className: cn("text-xs leading-snug text-defect", under),
1038
1063
  children: error
1039
1064
  })
1040
1065
  ]
@@ -1166,6 +1191,141 @@ function HighlightedText({ text, spans = [], labels, className, ...rest }) {
1166
1191
  });
1167
1192
  }
1168
1193
  //#endregion
1194
+ //#region src/components/ui/IconButton.tsx
1195
+ /** The square box of each size: `sm` 28 px, `md` 32 px — the heights of `Button`. */
1196
+ const BOX_CLASSES = {
1197
+ sm: "size-7 p-0 [&>svg]:size-4",
1198
+ md: "size-8 p-0 [&>svg]:size-4"
1199
+ };
1200
+ /** What the tooltip shows: the label, an optional hint line, an optional key cap. */
1201
+ function TipContent({ label, hint, shortcut }) {
1202
+ return /* @__PURE__ */ jsxs("span", {
1203
+ className: "flex items-center gap-2",
1204
+ children: [/* @__PURE__ */ jsxs("span", { children: [/* @__PURE__ */ jsx("span", {
1205
+ className: "font-medium",
1206
+ children: label
1207
+ }), hint !== void 0 && /* @__PURE__ */ jsx("span", {
1208
+ className: "block text-fg-muted",
1209
+ children: hint
1210
+ })] }), shortcut && /* @__PURE__ */ jsx(Kbd, { children: shortcut })]
1211
+ });
1212
+ }
1213
+ /**
1214
+ * An icon-only button. `label` is its accessible name *and* its tooltip, so it is required;
1215
+ * `shortcut` adds a key cap to the tooltip and `aria-keyshortcuts`. `pressed` makes it a
1216
+ * toggle (`aria-pressed`, `data-state="on"` / `"off"`).
1217
+ *
1218
+ * Needs a `TooltipProvider` above it. Takes every `<button>` prop, `ref` included. A
1219
+ * disabled button shows no tooltip (browsers send it no pointer events), so say why in the
1220
+ * surrounding UI when the reason is not obvious.
1221
+ */
1222
+ function IconButton({ label, icon, hint, shortcut, pressed, variant = "ghost", size, type = "button", className, ...rest }) {
1223
+ const density = useDensity();
1224
+ const resolved = size ?? byDensity(density, "md", "sm");
1225
+ return /* @__PURE__ */ jsx(Tooltip, {
1226
+ content: /* @__PURE__ */ jsx(TipContent, {
1227
+ label,
1228
+ hint,
1229
+ shortcut
1230
+ }),
1231
+ children: /* @__PURE__ */ jsx("button", {
1232
+ ...rest,
1233
+ type,
1234
+ "aria-label": label,
1235
+ "aria-keyshortcuts": shortcut,
1236
+ "aria-pressed": pressed,
1237
+ "data-variant": variant,
1238
+ "data-state": pressed === void 0 ? void 0 : pressed ? "on" : "off",
1239
+ className: buttonClasses({
1240
+ variant,
1241
+ size: resolved,
1242
+ className: cn(BOX_CLASSES[resolved], pressed && variant === "ghost" && "bg-signal/15 text-signal hover:bg-signal/20 hover:text-signal", className)
1243
+ }),
1244
+ children: /* @__PURE__ */ jsx("span", {
1245
+ "aria-hidden": true,
1246
+ className: "contents",
1247
+ children: icon
1248
+ })
1249
+ })
1250
+ });
1251
+ }
1252
+ /**
1253
+ * A strip of icon toggles — a tool picker, a view-mode switch, text-style toggles — each
1254
+ * named by its tooltip. `type="single"` (the default) keeps exactly the chosen item
1255
+ * pressed; `type="multiple"` lets each toggle on its own. Controlled with `value` or
1256
+ * uncontrolled with `defaultValue`.
1257
+ *
1258
+ * Each item is a button with `aria-pressed` inside a `role="group"`. One item is a tab stop
1259
+ * (the pressed one, else the first); Arrow keys, Home and End move focus along the strip.
1260
+ * Needs a `TooltipProvider` above it.
1261
+ */
1262
+ function IconToggleGroup(props) {
1263
+ const { items, size, disabled = false, className, "aria-label": ariaLabel } = props;
1264
+ const multiple = props.type === "multiple";
1265
+ const density = useDensity();
1266
+ const resolved = size ?? byDensity(density, "md", "sm");
1267
+ const [internal, setInternal] = useControllable(props.value, props.defaultValue);
1268
+ const selected = toArray(internal);
1269
+ const stripRef = useRef(null);
1270
+ const toggle = (value) => {
1271
+ if (props.type === "multiple") {
1272
+ const next = selected.includes(value) ? selected.filter((v) => v !== value) : [...selected, value];
1273
+ setInternal(next);
1274
+ props.onValueChange?.(next);
1275
+ } else {
1276
+ if (selected.includes(value)) return;
1277
+ setInternal(value);
1278
+ props.onValueChange?.(value);
1279
+ }
1280
+ };
1281
+ const enabled = items.filter((item) => !item.disabled && !disabled);
1282
+ const stop = enabled.find((item) => selected.includes(item.value)) ?? enabled[0];
1283
+ const onKeyDown = (event) => {
1284
+ if (![
1285
+ "ArrowRight",
1286
+ "ArrowDown",
1287
+ "ArrowLeft",
1288
+ "ArrowUp",
1289
+ "Home",
1290
+ "End"
1291
+ ].includes(event.key)) return;
1292
+ const buttons = Array.from(stripRef.current?.querySelectorAll("button:not(:disabled)") ?? []);
1293
+ const at = buttons.indexOf(document.activeElement);
1294
+ if (at < 0 || buttons.length === 0) return;
1295
+ event.preventDefault();
1296
+ buttons[event.key === "Home" ? 0 : event.key === "End" ? buttons.length - 1 : (at + (event.key === "ArrowRight" || event.key === "ArrowDown" ? 1 : -1) + buttons.length) % buttons.length]?.focus();
1297
+ };
1298
+ return /* @__PURE__ */ jsx("div", {
1299
+ ref: stripRef,
1300
+ role: "group",
1301
+ "aria-label": ariaLabel,
1302
+ "data-type": multiple ? "multiple" : "single",
1303
+ "data-disabled": disabled ? "" : void 0,
1304
+ onKeyDown,
1305
+ className: cn("inline-flex shrink-0 items-center gap-0.5 rounded-control border border-line-strong bg-raised p-0.5", className),
1306
+ children: items.map((item) => /* @__PURE__ */ jsx(IconButton, {
1307
+ label: item.label,
1308
+ icon: item.icon,
1309
+ shortcut: item.shortcut,
1310
+ size: resolved,
1311
+ pressed: selected.includes(item.value),
1312
+ disabled: disabled || item.disabled,
1313
+ tabIndex: stop?.value === item.value ? 0 : -1,
1314
+ onClick: () => toggle(item.value),
1315
+ className: cn("rounded-[0.3rem]", selected.includes(item.value) && "bg-surface text-signal shadow-sm")
1316
+ }, item.value))
1317
+ });
1318
+ }
1319
+ function toArray(value) {
1320
+ if (value === void 0 || value === "") return [];
1321
+ return typeof value === "string" ? [value] : value;
1322
+ }
1323
+ /** Minimal controlled/uncontrolled state: `value` wins when given. */
1324
+ function useControllable(value, defaultValue) {
1325
+ const [state, setState] = useState(defaultValue);
1326
+ return [value !== void 0 ? value : state, setState];
1327
+ }
1328
+ //#endregion
1169
1329
  //#region src/components/ui/numberText.ts
1170
1330
  /**
1171
1331
  * A number at a fixed number of decimals, without a negative zero (`-0.000` reads as a sign
@@ -3022,6 +3182,6 @@ function Tabs({ items, active, onSelect, label, idPrefix, className }) {
3022
3182
  });
3023
3183
  }
3024
3184
  //#endregion
3025
- export { Badge, Breakdown, Button, ButtonLink, Callout, Checkbox, ConfirmDialog, CountRun, DEFAULT_THEME_STORAGE_KEY, DeltaCell, DensityProvider, Dialog, DialogClose, Disclosure, DropdownMenu, Empty, ErrorBox, Field, HighlightedText, InfoHint, Input, Kbd, Listbox, MenuCheckboxItem, MenuItem, MenuLabel, MenuSeparator, NumberInput, PageHeader, Panel, Popover, PopoverClose, PoseInput, Progress, ProgressBar, ReadoutStrip, Section, SegmentedControl, Select, ShortcutList, Skeleton, SkeletonRows, Slider, StatusDot, Switch, Table, Tabs, Textarea, ThemeToggle, Toaster, ToggleChip, Tooltip, TooltipProvider, VectorInput, breakdownText, buttonClasses, byDensity, cn, controlClasses, createToastStore, defaultToastStore, deltaStrength, findSpans, focusRing, focusRingInset, formatNumber, initTheme, inputClasses, parseNumber, progressText, readThemeChoice, resolveTheme, setThemeChoice, sortRows, toast, toneColor, useControlHeight, useDensity };
3185
+ export { Badge, Breakdown, Button, ButtonLink, Callout, Checkbox, ConfirmDialog, CountRun, DEFAULT_THEME_STORAGE_KEY, DeltaCell, DensityProvider, Dialog, DialogClose, Disclosure, DropdownMenu, Empty, ErrorBox, Field, HighlightedText, IconButton, IconToggleGroup, InfoHint, Input, Kbd, Listbox, MenuCheckboxItem, MenuItem, MenuLabel, MenuSeparator, NumberInput, PageHeader, Panel, Popover, PopoverClose, PoseInput, Progress, ProgressBar, ReadoutStrip, Section, SegmentedControl, Select, ShortcutList, Skeleton, SkeletonRows, Slider, StatusDot, Switch, Table, Tabs, Textarea, ThemeToggle, Toaster, ToggleChip, Tooltip, TooltipProvider, VectorInput, breakdownText, buttonClasses, byDensity, cn, controlClasses, createToastStore, defaultToastStore, deltaStrength, findSpans, focusRing, focusRingInset, formatNumber, initTheme, inputClasses, parseNumber, progressText, readThemeChoice, resolveTheme, setThemeChoice, sortRows, toast, toneColor, useControlHeight, useDensity };
3026
3186
 
3027
3187
  //# sourceMappingURL=index.js.map