anvilui 0.3.0 → 0.4.1

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.cjs CHANGED
@@ -161,7 +161,10 @@ function cx(...parts) {
161
161
  return parts.filter(Boolean).join(" ");
162
162
  }
163
163
  function withClass(base, className) {
164
- return (state) => cx(base, typeof className === "function" ? className(state) : className);
164
+ return (state) => cx(
165
+ typeof base === "function" ? base(state) : base,
166
+ typeof className === "function" ? className(state) : className
167
+ );
165
168
  }
166
169
  function splitControlProps(props) {
167
170
  const control = {};
@@ -325,13 +328,15 @@ import 'anvilui/styles.css'
325
328
  "setup.md"
326
329
  );
327
330
  }
328
- function checkName(props, component, example, doc) {
331
+ var NO_TEXT = "It shows no text, so screen readers need an `aria-label`.";
332
+ var UNNAMED_GROUP = "Screen readers announce the group without saying what it's for: give it an `aria-label`.";
333
+ var UNNAMED_NAV = 'Screen readers list it as just "navigation": give it an `aria-label` to tell it apart from other navigation.';
334
+ function inNamedFieldset(el) {
335
+ return !!el?.closest("fieldset")?.querySelector(":scope > legend");
336
+ }
337
+ function checkName(props, component, example, doc, reason = NO_TEXT) {
329
338
  if (props["aria-label"] || props["aria-labelledby"]) return;
330
- devError(
331
- `<${component}> has no accessible name. It shows no text, so screen readers need an \`aria-label\`.`,
332
- example,
333
- doc
334
- );
339
+ devError(`<${component}> has no accessible name. ${reason}`, example, doc);
335
340
  }
336
341
 
337
342
  // src/components/Typography/Typography.tsx
@@ -467,12 +472,13 @@ function Avatar({
467
472
  const groupSize = (0, import_react5.useContext)(AvatarGroupContext);
468
473
  const size = sizeProp ?? groupSize ?? "normal";
469
474
  const letters = name ? initials(name) : "";
475
+ const named = !!(name || props["aria-label"] || props["aria-labelledby"]);
470
476
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
471
477
  import_avatar.Avatar.Root,
472
478
  {
473
- role: name ? "img" : void 0,
479
+ role: named ? "img" : void 0,
474
480
  "aria-label": name,
475
- "aria-hidden": name ? void 0 : true,
481
+ "aria-hidden": named ? void 0 : true,
476
482
  ...props,
477
483
  className: withClass(
478
484
  cx(
@@ -516,6 +522,15 @@ function AvatarGroup({
516
522
  children,
517
523
  ...props
518
524
  }) {
525
+ if (process.env.NODE_ENV !== "production") {
526
+ checkName(
527
+ props,
528
+ "AvatarGroup",
529
+ '<AvatarGroup aria-label="Project members">...</AvatarGroup>',
530
+ "avatar-group.md",
531
+ UNNAMED_GROUP
532
+ );
533
+ }
519
534
  const avatars = import_react6.Children.toArray(children);
520
535
  const overflow = max !== void 0 && avatars.length > max;
521
536
  const shown = overflow ? avatars.slice(0, Math.max(0, max - 1)) : avatars;
@@ -826,10 +841,9 @@ function HoldButton({
826
841
  "aria-description": "Press and hold to confirm",
827
842
  "data-hold": state === "idle" ? void 0 : state,
828
843
  "data-nudge": nudges % 2 === 0 ? "even" : "odd",
829
- className: (buttonState) => cx(
830
- "avl-hold-button",
831
- nudges > 0 && "avl-hold-button-nudged",
832
- typeof className === "function" ? className(buttonState) : className
844
+ className: withClass(
845
+ cx("avl-hold-button", nudges > 0 && "avl-hold-button-nudged"),
846
+ className
833
847
  ),
834
848
  style: (buttonState) => ({
835
849
  "--avl-hold-duration": `${holdDuration}ms`,
@@ -1094,6 +1108,12 @@ function Calendar({
1094
1108
  const now = /* @__PURE__ */ new Date();
1095
1109
  return selected ?? new Date(now.getFullYear(), now.getMonth(), now.getDate());
1096
1110
  });
1111
+ const selectedIso = selected && toIso(selected);
1112
+ const [shownSelection, setShownSelection] = (0, import_react12.useState)(selectedIso);
1113
+ if (selectedIso !== shownSelection) {
1114
+ setShownSelection(selectedIso);
1115
+ if (selected) setFocused(selected);
1116
+ }
1097
1117
  const [weekStart] = (0, import_react12.useState)(localeWeekStart);
1098
1118
  const dayRef = (0, import_react12.useRef)(null);
1099
1119
  const moveFocus = (0, import_react12.useRef)(false);
@@ -1126,7 +1146,6 @@ function Calendar({
1126
1146
  onValueChange?.(iso);
1127
1147
  };
1128
1148
  const today = toIso(/* @__PURE__ */ new Date());
1129
- const selectedIso = selected && toIso(selected);
1130
1149
  const focusedIso = toIso(focused);
1131
1150
  const offset = (new Date(year, month, 1).getDay() - weekStart + 7) % 7;
1132
1151
  const daysInMonth = new Date(year, month + 1, 0).getDate();
@@ -2333,6 +2352,7 @@ function FABMenu({
2333
2352
  align = "end",
2334
2353
  sticky = true,
2335
2354
  className,
2355
+ ref,
2336
2356
  children,
2337
2357
  ...props
2338
2358
  }) {
@@ -2356,10 +2376,10 @@ function FABMenu({
2356
2376
  /* @__PURE__ */ (0, import_jsx_runtime22.jsxs)(
2357
2377
  import_menu.Menu.Trigger,
2358
2378
  {
2359
- ref: trigger,
2379
+ ref: mergeRefs(trigger, ref),
2360
2380
  "aria-label": ariaLabel,
2361
2381
  className: cx(
2362
- "avl-fab avl-fab-size-normal avl-fab-menu-trigger",
2382
+ "avl-fab avl-fab-size-normal avl-fab-menu avl-fab-menu-trigger",
2363
2383
  colorClass(color, fillType),
2364
2384
  className
2365
2385
  ),
@@ -2681,7 +2701,10 @@ function MenuSubmenuTrigger({
2681
2701
  import_menu2.Menu.SubmenuTrigger,
2682
2702
  {
2683
2703
  ...props,
2684
- className: withClass("avl-menu-item", className),
2704
+ className: withClass(
2705
+ "avl-menu-item avl-menu-submenu-trigger",
2706
+ className
2707
+ ),
2685
2708
  children: [
2686
2709
  startIcon && /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Icon, { name: startIcon }),
2687
2710
  /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: "avl-menu-item-label", children }),
@@ -2992,7 +3015,7 @@ function PreviewCardPopup({
2992
3015
  {
2993
3016
  ...props,
2994
3017
  className: withClass(
2995
- "avl-menu-popup avl-popover-popup",
3018
+ "avl-menu-popup avl-popover-popup avl-preview-card-popup",
2996
3019
  className
2997
3020
  )
2998
3021
  }
@@ -3143,6 +3166,17 @@ function ToggleGroup({
3143
3166
  }) {
3144
3167
  const groupRef = (0, import_react28.useRef)(null);
3145
3168
  const indicatorRef = (0, import_react28.useRef)(null);
3169
+ (0, import_react28.useEffect)(() => {
3170
+ if (process.env.NODE_ENV === "production") return;
3171
+ if (inNamedFieldset(groupRef.current)) return;
3172
+ checkName(
3173
+ props,
3174
+ "ToggleGroup",
3175
+ '<ToggleGroup aria-label="View" defaultValue="list">...</ToggleGroup>',
3176
+ "toggle-group.md",
3177
+ UNNAMED_GROUP
3178
+ );
3179
+ }, []);
3146
3180
  (0, import_react28.useLayoutEffect)(() => {
3147
3181
  const group = groupRef.current;
3148
3182
  const indicator = indicatorRef.current;
@@ -3190,7 +3224,7 @@ function ToggleGroup({
3190
3224
  {
3191
3225
  ...props,
3192
3226
  multiple: true,
3193
- ref,
3227
+ ref: mergeRefs(groupRef, ref),
3194
3228
  className: classes,
3195
3229
  children
3196
3230
  }
@@ -3270,15 +3304,30 @@ function ToggleGroupItem({
3270
3304
  // src/components/RadioGroup/RadioGroup.tsx
3271
3305
  var import_radio2 = require("@base-ui/react/radio");
3272
3306
  var import_radio_group2 = require("@base-ui/react/radio-group");
3307
+ var import_react29 = require("react");
3273
3308
  var import_jsx_runtime35 = require("react/jsx-runtime");
3274
3309
  function RadioGroup({
3275
3310
  className,
3311
+ ref,
3276
3312
  ...props
3277
3313
  }) {
3314
+ const local = (0, import_react29.useRef)(null);
3315
+ (0, import_react29.useEffect)(() => {
3316
+ if (process.env.NODE_ENV === "production") return;
3317
+ if (inNamedFieldset(local.current)) return;
3318
+ checkName(
3319
+ props,
3320
+ "RadioGroup",
3321
+ '<RadioGroup aria-label="Plan" defaultValue="free">...</RadioGroup>\n// or inside <fieldset><legend>Plan</legend>...</fieldset>',
3322
+ "radio-group.md",
3323
+ UNNAMED_GROUP
3324
+ );
3325
+ }, []);
3278
3326
  return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
3279
3327
  import_radio_group2.RadioGroup,
3280
3328
  {
3281
3329
  ...props,
3330
+ ref: mergeRefs(local, ref),
3282
3331
  className: withClass("avl-radio-group", className)
3283
3332
  }
3284
3333
  );
@@ -3305,7 +3354,7 @@ function Radio({ className, ...props }) {
3305
3354
  }
3306
3355
 
3307
3356
  // src/components/Select/Select.tsx
3308
- var import_react29 = require("react");
3357
+ var import_react30 = require("react");
3309
3358
  var import_select = require("@base-ui/react/select");
3310
3359
  var import_jsx_runtime36 = require("react/jsx-runtime");
3311
3360
  function Select({
@@ -3319,7 +3368,7 @@ function Select({
3319
3368
  ...allProps
3320
3369
  }) {
3321
3370
  const { control, rest: props } = splitControlProps(allProps);
3322
- const avl = (0, import_react29.useContext)(AnvilContext);
3371
+ const avl = (0, import_react30.useContext)(AnvilContext);
3323
3372
  if (process.env.NODE_ENV !== "production") {
3324
3373
  checkRoot(avl !== null, "Select");
3325
3374
  }
@@ -3385,7 +3434,7 @@ function SelectItem({ className, children, ...props }) {
3385
3434
  }
3386
3435
 
3387
3436
  // src/components/TimePicker/TimePicker.tsx
3388
- var import_react30 = require("react");
3437
+ var import_react31 = require("react");
3389
3438
  var import_jsx_runtime37 = require("react/jsx-runtime");
3390
3439
  var pad2 = (n) => String(n).padStart(2, "0");
3391
3440
  function localeHourCycle() {
@@ -3415,12 +3464,22 @@ function TimePicker({
3415
3464
  ...allProps
3416
3465
  }) {
3417
3466
  const { control, rest: props } = splitControlProps(allProps);
3418
- const [internal, setInternal] = (0, import_react30.useState)(defaultValue);
3467
+ const [internal, setInternal] = (0, import_react31.useState)(defaultValue);
3419
3468
  const value = valueProp !== void 0 ? valueProp : internal;
3420
3469
  const time = parseTime(value);
3421
3470
  const cycle = hourCycle ?? localeHourCycle();
3422
- const labelId = (0, import_react30.useId)();
3423
- const valueId = (0, import_react30.useId)();
3471
+ const labelId = (0, import_react31.useId)();
3472
+ const valueId = (0, import_react31.useId)();
3473
+ const trigger = (0, import_react31.useRef)(null);
3474
+ (0, import_react31.useEffect)(() => {
3475
+ if (process.env.NODE_ENV === "production") return;
3476
+ if (trigger.current?.closest(".avl-field"))
3477
+ devError(
3478
+ "<TimePicker> is inside a <Field>, but it doesn't take the Field's `name`, `disabled` or validation.",
3479
+ '<TimePicker label="Alarm" name="alarm" disabled={locked} /> // outside any Field',
3480
+ "time-picker.md"
3481
+ );
3482
+ }, []);
3424
3483
  const setTime = (t) => {
3425
3484
  const next = t && `${pad2(t.h)}:${pad2(t.m)}`;
3426
3485
  setInternal(next);
@@ -3455,7 +3514,7 @@ function TimePicker({
3455
3514
  PopoverTrigger,
3456
3515
  {
3457
3516
  ...control,
3458
- ref,
3517
+ ref: mergeRefs(trigger, ref),
3459
3518
  id,
3460
3519
  disabled,
3461
3520
  className: "avl-input-field avl-select-trigger",
@@ -3489,7 +3548,7 @@ function TimePicker({
3489
3548
  }
3490
3549
  function TimePanel(props) {
3491
3550
  const { type, time, cycle, onChange, onClear } = props;
3492
- const [mode, setMode] = (0, import_react30.useState)("hour");
3551
+ const [mode, setMode] = (0, import_react31.useState)("hour");
3493
3552
  const pm = time ? time.h >= 12 : false;
3494
3553
  const hourText = time ? pad2(displayHour(time.h, cycle)) : "--";
3495
3554
  const minuteText = time ? pad2(time.m) : "--";
@@ -3590,7 +3649,7 @@ function TimePanel(props) {
3590
3649
  }
3591
3650
  function SpinInput(props) {
3592
3651
  const { label, value, min, max, onChange } = props;
3593
- const [draft, setDraft] = (0, import_react30.useState)(null);
3652
+ const [draft, setDraft] = (0, import_react31.useState)(null);
3594
3653
  const range = max - min + 1;
3595
3654
  return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(
3596
3655
  "input",
@@ -3639,7 +3698,7 @@ function Dial(props) {
3639
3698
  const h = time?.h ?? 0;
3640
3699
  const m = time?.m ?? 0;
3641
3700
  const isHour = mode === "hour";
3642
- const [dragging, setDragging] = (0, import_react30.useState)(false);
3701
+ const [dragging, setDragging] = (0, import_react31.useState)(false);
3643
3702
  const labels = Array.from(
3644
3703
  { length: 12 },
3645
3704
  (_, i) => !isHour ? [{ value: i * 5, text: pad2(i * 5), inner: false }] : cycle === 12 ? [{ value: i, text: String(i || 12), inner: false }] : [
@@ -3649,7 +3708,7 @@ function Dial(props) {
3649
3708
  ).flat();
3650
3709
  const radius = isHour && cycle === 24 && h >= 12 ? INNER : OUTER;
3651
3710
  const target = isHour ? h % 12 * 30 : m * 6;
3652
- const angleRef = (0, import_react30.useRef)(null);
3711
+ const angleRef = (0, import_react31.useRef)(null);
3653
3712
  const prev = angleRef.current;
3654
3713
  const angle = prev == null ? target : prev + ((target - prev) % 360 + 540) % 360 - 180;
3655
3714
  angleRef.current = angle;
@@ -3798,7 +3857,7 @@ function Dial(props) {
3798
3857
  }
3799
3858
 
3800
3859
  // src/components/DateInput/DateInput.tsx
3801
- var import_react31 = require("react");
3860
+ var import_react32 = require("react");
3802
3861
  var import_input5 = require("@base-ui/react/input");
3803
3862
  var import_jsx_runtime38 = require("react/jsx-runtime");
3804
3863
  var numericFormat = () => new Intl.DateTimeFormat(void 0, {
@@ -3814,25 +3873,26 @@ function DateInput({
3814
3873
  size = "normal",
3815
3874
  disabled,
3816
3875
  id,
3876
+ onChange,
3817
3877
  onBlur,
3818
3878
  className,
3819
3879
  style,
3820
3880
  ref,
3821
3881
  ...props
3822
3882
  }) {
3823
- const [internal, setInternal] = (0, import_react31.useState)(defaultValue);
3883
+ const [internal, setInternal] = (0, import_react32.useState)(defaultValue);
3824
3884
  const value = valueProp !== void 0 ? valueProp : internal;
3825
3885
  const date = fromIso(value);
3826
- const [draft, setDraft] = (0, import_react31.useState)(null);
3827
- const [open, setOpen] = (0, import_react31.useState)(false);
3828
- const fieldRef = (0, import_react31.useRef)(null);
3829
- const popupRef = (0, import_react31.useRef)(null);
3830
- const generatedId = (0, import_react31.useId)();
3886
+ const [draft, setDraft] = (0, import_react32.useState)(null);
3887
+ const [open, setOpen] = (0, import_react32.useState)(false);
3888
+ const fieldRef = (0, import_react32.useRef)(null);
3889
+ const popupRef = (0, import_react32.useRef)(null);
3890
+ const generatedId = (0, import_react32.useId)();
3831
3891
  const inputId = id ?? generatedId;
3832
- const inputRef = (0, import_react31.useRef)(null);
3833
- const iso = (0, import_react31.useRef)("");
3892
+ const inputRef = (0, import_react32.useRef)(null);
3893
+ const iso = (0, import_react32.useRef)("");
3834
3894
  iso.current = date ? toIso(date) : "";
3835
- (0, import_react31.useEffect)(() => {
3895
+ (0, import_react32.useEffect)(() => {
3836
3896
  const form = inputRef.current?.form;
3837
3897
  if (!form) return;
3838
3898
  const onFormData = (event) => {
@@ -3886,6 +3946,7 @@ function DateInput({
3886
3946
  const typed = parseTyped(text, order);
3887
3947
  if (typed) commit(typed);
3888
3948
  }
3949
+ onChange?.(e);
3889
3950
  },
3890
3951
  onBlur: (e) => {
3891
3952
  if (!invalid) setDraft(null);
@@ -3940,7 +4001,7 @@ function DateInput({
3940
4001
  }
3941
4002
 
3942
4003
  // src/components/Combobox/Combobox.tsx
3943
- var import_react32 = require("react");
4004
+ var import_react33 = require("react");
3944
4005
  var import_combobox = require("@base-ui/react/combobox");
3945
4006
  var import_jsx_runtime39 = require("react/jsx-runtime");
3946
4007
  function Combobox({
@@ -3956,7 +4017,7 @@ function Combobox({
3956
4017
  ...allProps
3957
4018
  }) {
3958
4019
  const { control, rest: props } = splitControlProps(allProps);
3959
- const avl = (0, import_react32.useContext)(AnvilContext);
4020
+ const avl = (0, import_react33.useContext)(AnvilContext);
3960
4021
  if (process.env.NODE_ENV !== "production") {
3961
4022
  checkRoot(avl !== null, "Combobox");
3962
4023
  if (typeof children !== "function")
@@ -3966,9 +4027,9 @@ function Combobox({
3966
4027
  "combobox.md"
3967
4028
  );
3968
4029
  }
3969
- const generatedId = (0, import_react32.useId)();
4030
+ const generatedId = (0, import_react33.useId)();
3970
4031
  const inputId = id ?? generatedId;
3971
- const labelId = (0, import_react32.useId)();
4032
+ const labelId = (0, import_react33.useId)();
3972
4033
  return /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(import_combobox.Combobox.Root, { ...props, children: [
3973
4034
  /* @__PURE__ */ (0, import_jsx_runtime39.jsxs)(
3974
4035
  import_combobox.Combobox.InputGroup,
@@ -4035,7 +4096,10 @@ function ComboboxItem({
4035
4096
  import_combobox.Combobox.Item,
4036
4097
  {
4037
4098
  ...props,
4038
- className: withClass("avl-menu-item avl-select-item", className),
4099
+ className: withClass(
4100
+ "avl-menu-item avl-select-item avl-combobox-item",
4101
+ className
4102
+ ),
4039
4103
  children: [
4040
4104
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)("span", { className: "avl-menu-item-label", children }),
4041
4105
  /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(import_combobox.Combobox.ItemIndicator, { className: "avl-select-item-indicator", children: /* @__PURE__ */ (0, import_jsx_runtime39.jsx)(Icon, { name: "check" }) })
@@ -4045,7 +4109,7 @@ function ComboboxItem({
4045
4109
  }
4046
4110
 
4047
4111
  // src/components/PinInput/PinInput.tsx
4048
- var import_react33 = require("react");
4112
+ var import_react34 = require("react");
4049
4113
  var import_otp_field = require("@base-ui/react/otp-field");
4050
4114
  var import_jsx_runtime40 = require("react/jsx-runtime");
4051
4115
  var defaultSlotLabel = (index, length) => `Character ${index + 1} of ${length}`;
@@ -4061,7 +4125,7 @@ function PinInput({
4061
4125
  length,
4062
4126
  ...props
4063
4127
  }) {
4064
- const generatedId = (0, import_react33.useId)();
4128
+ const generatedId = (0, import_react34.useId)();
4065
4129
  const inputId = id ?? generatedId;
4066
4130
  const labelId = `${inputId}-label`;
4067
4131
  return /* @__PURE__ */ (0, import_jsx_runtime40.jsxs)(
@@ -4138,11 +4202,13 @@ function Toggle2({
4138
4202
  import_toggle3.Toggle,
4139
4203
  {
4140
4204
  ...props,
4141
- className: (state) => cx(
4142
- "avl-toggle",
4143
- icon ? `avl-icon-button avl-icon-button-size-${size}` : `avl-button avl-button-size-${size}`,
4144
- state.pressed ? colorClass(color, "filled") : colorClass("container", fillType),
4145
- typeof className === "function" ? className(state) : className
4205
+ className: withClass(
4206
+ (state) => cx(
4207
+ "avl-toggle",
4208
+ icon ? `avl-icon-button avl-icon-button-size-${size}` : `avl-button avl-button-size-${size}`,
4209
+ state.pressed ? colorClass(color, "filled") : colorClass("container", fillType)
4210
+ ),
4211
+ className
4146
4212
  ),
4147
4213
  children: icon ? /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Icon, { name: icon }) : /* @__PURE__ */ (0, import_jsx_runtime41.jsxs)(import_jsx_runtime41.Fragment, { children: [
4148
4214
  startIcon && /* @__PURE__ */ (0, import_jsx_runtime41.jsx)(Icon, { name: startIcon }),
@@ -4154,7 +4220,7 @@ function Toggle2({
4154
4220
  }
4155
4221
 
4156
4222
  // src/components/Search/Search.tsx
4157
- var import_react34 = require("react");
4223
+ var import_react35 = require("react");
4158
4224
  var import_autocomplete = require("@base-ui/react/autocomplete");
4159
4225
  var import_jsx_runtime42 = require("react/jsx-runtime");
4160
4226
  function Search({
@@ -4171,7 +4237,7 @@ function Search({
4171
4237
  ...allProps
4172
4238
  }) {
4173
4239
  const { control, rest: props } = splitControlProps(allProps);
4174
- const avl = (0, import_react34.useContext)(AnvilContext);
4240
+ const avl = (0, import_react35.useContext)(AnvilContext);
4175
4241
  const suggests = children !== void 0;
4176
4242
  if (process.env.NODE_ENV !== "production") {
4177
4243
  checkRoot(avl !== null, "Search");
@@ -4257,7 +4323,7 @@ function SearchItem({
4257
4323
  import_autocomplete.Autocomplete.Item,
4258
4324
  {
4259
4325
  ...props,
4260
- className: withClass("avl-menu-item", className),
4326
+ className: withClass("avl-menu-item avl-search-item", className),
4261
4327
  children: [
4262
4328
  startIcon && /* @__PURE__ */ (0, import_jsx_runtime42.jsx)(Icon, { name: startIcon }),
4263
4329
  /* @__PURE__ */ (0, import_jsx_runtime42.jsx)("span", { className: "avl-menu-item-label", children })
@@ -4269,11 +4335,21 @@ function SearchItem({
4269
4335
  // src/components/Skeleton/Skeleton.tsx
4270
4336
  var import_jsx_runtime43 = require("react/jsx-runtime");
4271
4337
  function Skeleton({
4272
- variant = "text",
4338
+ type = "text",
4273
4339
  animation = "pulse",
4274
4340
  className,
4275
4341
  ...props
4276
4342
  }) {
4343
+ if (process.env.NODE_ENV !== "production") {
4344
+ checkProp(
4345
+ props,
4346
+ "variant",
4347
+ "Skeleton",
4348
+ "The shape is `type`, as on Progress and Typography.",
4349
+ '<Skeleton type="circular" style={{ width: 40, height: 40 }} />\n// type: text | circular | rectangular',
4350
+ "skeleton.md"
4351
+ );
4352
+ }
4277
4353
  return /* @__PURE__ */ (0, import_jsx_runtime43.jsx)(
4278
4354
  "span",
4279
4355
  {
@@ -4281,7 +4357,7 @@ function Skeleton({
4281
4357
  ...props,
4282
4358
  className: cx(
4283
4359
  "avl-skeleton",
4284
- `avl-skeleton-${variant}`,
4360
+ `avl-skeleton-${type}`,
4285
4361
  animation === "pulse" && "avl-skeleton-pulse",
4286
4362
  className
4287
4363
  )
@@ -4297,19 +4373,31 @@ function Slider({
4297
4373
  "aria-label": ariaLabel,
4298
4374
  showValue = true,
4299
4375
  squiggly = false,
4376
+ getAriaLabel,
4300
4377
  className,
4301
4378
  ...props
4302
4379
  }) {
4303
- if (process.env.NODE_ENV !== "production" && label == null) {
4304
- checkName(
4305
- { "aria-label": ariaLabel, ...props },
4306
- "Slider",
4307
- '<Slider label="Volume" /> // or <Slider aria-label="Volume" />',
4308
- "slider.md"
4309
- );
4310
- }
4311
4380
  const initial = props.value ?? props.defaultValue;
4312
4381
  const thumbCount = Array.isArray(initial) ? initial.length : 1;
4382
+ if (process.env.NODE_ENV !== "production") {
4383
+ if (label == null)
4384
+ checkName(
4385
+ { "aria-label": ariaLabel, ...props },
4386
+ "Slider",
4387
+ '<Slider label="Volume" /> // or <Slider aria-label="Volume" />',
4388
+ "slider.md"
4389
+ );
4390
+ if (thumbCount > 1 && !getAriaLabel)
4391
+ devError(
4392
+ "<Slider> has several handles but no `getAriaLabel`, so screen readers give every handle the same name.",
4393
+ `<Slider
4394
+ label="Price"
4395
+ defaultValue={[20, 80]}
4396
+ getAriaLabel={(i) => (i === 0 ? 'Minimum price' : 'Maximum price')}
4397
+ />`,
4398
+ "slider.md"
4399
+ );
4400
+ }
4313
4401
  const wavy = squiggly && props.orientation !== "vertical";
4314
4402
  const morph2 = useWaveMorph(wavy);
4315
4403
  return /* @__PURE__ */ (0, import_jsx_runtime44.jsxs)(
@@ -4340,6 +4428,7 @@ function Slider({
4340
4428
  {
4341
4429
  index: i,
4342
4430
  "aria-label": ariaLabel,
4431
+ getAriaLabel,
4343
4432
  className: "avl-slider-thumb",
4344
4433
  render: (thumbProps, state) => /* @__PURE__ */ (0, import_jsx_runtime44.jsx)(
4345
4434
  "div",
@@ -4382,11 +4471,11 @@ function handleSpan(width, gap, svg) {
4382
4471
  }
4383
4472
 
4384
4473
  // src/components/Snackbar/Snackbar.tsx
4385
- var import_react35 = require("react");
4474
+ var import_react36 = require("react");
4386
4475
  var import_toast = require("@base-ui/react/toast");
4387
4476
  var import_jsx_runtime45 = require("react/jsx-runtime");
4388
4477
  function useSnackbar() {
4389
- const avl = (0, import_react35.useContext)(AnvilContext);
4478
+ const avl = (0, import_react36.useContext)(AnvilContext);
4390
4479
  if (process.env.NODE_ENV !== "production" && !avl)
4391
4480
  throw new Error(
4392
4481
  "[anvilui] useSnackbar() was called outside <AnvilRoot>.\n\nFix: call it from a component rendered inside <AnvilRoot>, not in the component that renders AnvilRoot:\n<AnvilRoot><App /></AnvilRoot> // useSnackbar() inside App works\n\nDocs: node_modules/anvilui/docs/snackbar.md"
@@ -4409,17 +4498,17 @@ function useSnackbar() {
4409
4498
  }
4410
4499
  function SnackbarViewport() {
4411
4500
  const { toasts } = import_toast.Toast.useToastManager();
4412
- const viewportRef = (0, import_react35.useRef)(null);
4413
- const [expanded, setExpanded] = (0, import_react35.useState)(false);
4414
- const [hovered, setHovered] = (0, import_react35.useState)(false);
4501
+ const viewportRef = (0, import_react36.useRef)(null);
4502
+ const [expanded, setExpanded] = (0, import_react36.useState)(false);
4503
+ const [hovered, setHovered] = (0, import_react36.useState)(false);
4415
4504
  const visibleCount = toasts.filter(
4416
4505
  (toast) => toast.transitionStatus !== "ending"
4417
4506
  ).length;
4418
4507
  const collapsed = visibleCount > 1 && !expanded && !hovered;
4419
- (0, import_react35.useEffect)(() => {
4508
+ (0, import_react36.useEffect)(() => {
4420
4509
  if (visibleCount <= 1) setExpanded(false);
4421
4510
  }, [visibleCount]);
4422
- (0, import_react35.useEffect)(() => {
4511
+ (0, import_react36.useEffect)(() => {
4423
4512
  if (!expanded) return;
4424
4513
  const viewport = viewportRef.current;
4425
4514
  const close = (event) => {
@@ -4665,6 +4754,15 @@ function FloatingToolbar({
4665
4754
  className,
4666
4755
  ...props
4667
4756
  }) {
4757
+ if (process.env.NODE_ENV !== "production") {
4758
+ checkName(
4759
+ props,
4760
+ "FloatingToolbar",
4761
+ '<FloatingToolbar aria-label="Formatting">...</FloatingToolbar>',
4762
+ "floating-toolbar.md",
4763
+ UNNAMED_GROUP
4764
+ );
4765
+ }
4668
4766
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
4669
4767
  import_toolbar.Toolbar.Root,
4670
4768
  {
@@ -4684,13 +4782,25 @@ function FloatingToolbarButton({
4684
4782
  // Filled means highlighted: primary stands out on the toolbar's surface
4685
4783
  color = fillType === "filled" ? "primary" : "container",
4686
4784
  disabled,
4785
+ className,
4687
4786
  ...props
4688
4787
  }) {
4689
4788
  return /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
4690
4789
  import_toolbar.Toolbar.Button,
4691
4790
  {
4692
4791
  disabled,
4693
- render: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(IconButton, { ...props, color, fillType })
4792
+ render: /* @__PURE__ */ (0, import_jsx_runtime51.jsx)(
4793
+ IconButton,
4794
+ {
4795
+ ...props,
4796
+ color,
4797
+ fillType,
4798
+ className: withClass(
4799
+ "avl-floating-toolbar-button",
4800
+ className
4801
+ )
4802
+ }
4803
+ )
4694
4804
  }
4695
4805
  );
4696
4806
  }
@@ -4711,7 +4821,7 @@ function FloatingToolbarSeparator({
4711
4821
  }
4712
4822
 
4713
4823
  // src/components/Tooltip/Tooltip.tsx
4714
- var import_react36 = require("react");
4824
+ var import_react37 = require("react");
4715
4825
  var import_tooltip2 = require("@base-ui/react/tooltip");
4716
4826
  var import_jsx_runtime52 = require("react/jsx-runtime");
4717
4827
  function Tooltip({
@@ -4726,7 +4836,7 @@ function Tooltip({
4726
4836
  className,
4727
4837
  ...props
4728
4838
  }) {
4729
- const avl = (0, import_react36.useContext)(AnvilContext);
4839
+ const avl = (0, import_react37.useContext)(AnvilContext);
4730
4840
  if (process.env.NODE_ENV !== "production") {
4731
4841
  checkRoot(avl !== null, "Tooltip");
4732
4842
  checkProp(
@@ -4745,7 +4855,7 @@ function Tooltip({
4745
4855
  '<Tooltip label="Delete">\n <IconButton icon="delete" aria-label="Delete" />\n</Tooltip>',
4746
4856
  "tooltip.md"
4747
4857
  );
4748
- if (!(0, import_react36.isValidElement)(children))
4858
+ if (!(0, import_react37.isValidElement)(children))
4749
4859
  devError(
4750
4860
  "<Tooltip> needs exactly one element child (the trigger), not text or several elements.",
4751
4861
  '<Tooltip label="Delete">\n <IconButton icon="delete" aria-label="Delete" />\n</Tooltip>\n// for plain text: <Tooltip label="..."><span tabIndex={0}>text</span></Tooltip>',
@@ -4786,6 +4896,15 @@ var import_use_render2 = require("@base-ui/react/use-render");
4786
4896
  var import_merge_props2 = require("@base-ui/react/merge-props");
4787
4897
  var import_jsx_runtime53 = require("react/jsx-runtime");
4788
4898
  function NavigationBar({ className, ...props }) {
4899
+ if (process.env.NODE_ENV !== "production") {
4900
+ checkName(
4901
+ props,
4902
+ "NavigationBar",
4903
+ '<NavigationBar aria-label="Main">...</NavigationBar>',
4904
+ "navigation-bar.md",
4905
+ UNNAMED_NAV
4906
+ );
4907
+ }
4789
4908
  return /* @__PURE__ */ (0, import_jsx_runtime53.jsx)("nav", { ...props, className: cx("avl-navigation-bar", className) });
4790
4909
  }
4791
4910
  function NavigationBarItem({
@@ -4815,11 +4934,11 @@ function NavigationBarItem({
4815
4934
  }
4816
4935
 
4817
4936
  // src/components/NavigationRail/NavigationRail.tsx
4818
- var import_react37 = require("react");
4937
+ var import_react38 = require("react");
4819
4938
  var import_use_render3 = require("@base-ui/react/use-render");
4820
4939
  var import_merge_props3 = require("@base-ui/react/merge-props");
4821
4940
  var import_jsx_runtime54 = require("react/jsx-runtime");
4822
- var RailContext = (0, import_react37.createContext)(null);
4941
+ var RailContext = (0, import_react38.createContext)(null);
4823
4942
  function NavigationRail({
4824
4943
  expanded: expandedProp,
4825
4944
  defaultExpanded = false,
@@ -4827,7 +4946,16 @@ function NavigationRail({
4827
4946
  className,
4828
4947
  ...props
4829
4948
  }) {
4830
- const [internal, setInternal] = (0, import_react37.useState)(defaultExpanded);
4949
+ if (process.env.NODE_ENV !== "production") {
4950
+ checkName(
4951
+ props,
4952
+ "NavigationRail",
4953
+ '<NavigationRail aria-label="Main">...</NavigationRail>',
4954
+ "navigation-rail.md",
4955
+ UNNAMED_NAV
4956
+ );
4957
+ }
4958
+ const [internal, setInternal] = (0, import_react38.useState)(defaultExpanded);
4831
4959
  const expanded = expandedProp ?? internal;
4832
4960
  const setExpanded = (next) => {
4833
4961
  setInternal(next);
@@ -4847,7 +4975,7 @@ function NavigationRailToggle({
4847
4975
  onClick,
4848
4976
  ...props
4849
4977
  }) {
4850
- const rail = (0, import_react37.useContext)(RailContext);
4978
+ const rail = (0, import_react38.useContext)(RailContext);
4851
4979
  if (process.env.NODE_ENV !== "production" && !rail) {
4852
4980
  devError(
4853
4981
  "<NavigationRailToggle> is rendered outside a <NavigationRail>, so it has nothing to expand.",
@@ -4906,6 +5034,15 @@ var import_use_render4 = require("@base-ui/react/use-render");
4906
5034
  var import_merge_props4 = require("@base-ui/react/merge-props");
4907
5035
  var import_jsx_runtime55 = require("react/jsx-runtime");
4908
5036
  function NavigationList({ className, ...props }) {
5037
+ if (process.env.NODE_ENV !== "production") {
5038
+ checkName(
5039
+ props,
5040
+ "NavigationList",
5041
+ '<NavigationList aria-label="Settings">...</NavigationList>',
5042
+ "navigation-list.md",
5043
+ UNNAMED_NAV
5044
+ );
5045
+ }
4909
5046
  return /* @__PURE__ */ (0, import_jsx_runtime55.jsx)("nav", { ...props, className: cx("avl-navigation-list", className) });
4910
5047
  }
4911
5048
  function NavigationListItem({
@@ -4931,7 +5068,7 @@ function NavigationListItem({
4931
5068
  }
4932
5069
 
4933
5070
  // src/components/NavigationDrawer/NavigationDrawer.tsx
4934
- var import_react38 = require("react");
5071
+ var import_react39 = require("react");
4935
5072
  var import_drawer2 = require("@base-ui/react/drawer");
4936
5073
  var import_jsx_runtime56 = require("react/jsx-runtime");
4937
5074
  function NavigationDrawer(props) {
@@ -4961,7 +5098,7 @@ function NavigationDrawerPopup({
4961
5098
  className,
4962
5099
  ...props
4963
5100
  }) {
4964
- const avl = (0, import_react38.useContext)(AnvilContext);
5101
+ const avl = (0, import_react39.useContext)(AnvilContext);
4965
5102
  if (process.env.NODE_ENV !== "production") {
4966
5103
  checkRoot(avl !== null, "NavigationDrawerPopup");
4967
5104
  }
@@ -5194,23 +5331,72 @@ var neutralRoles = [
5194
5331
  "inverseSurface",
5195
5332
  "inverseOnSurface"
5196
5333
  ];
5334
+ var statusSwaps = [
5335
+ {
5336
+ roles: [
5337
+ "success",
5338
+ "onSuccess",
5339
+ "successContainer",
5340
+ "onSuccessContainer"
5341
+ ],
5342
+ from: 105,
5343
+ to: 190,
5344
+ hue: 255
5345
+ },
5346
+ {
5347
+ roles: ["error", "onError", "errorContainer", "onErrorContainer"],
5348
+ from: 10,
5349
+ to: 60,
5350
+ hue: 350
5351
+ },
5352
+ // Only yellow/gold: past orange there's no hue left that still reads as
5353
+ // a warning without looking like the error color
5354
+ {
5355
+ roles: [
5356
+ "warning",
5357
+ "onWarning",
5358
+ "warningContainer",
5359
+ "onWarningContainer"
5360
+ ],
5361
+ from: 75,
5362
+ to: 105,
5363
+ hue: 55
5364
+ }
5365
+ ];
5197
5366
  var reference = toOklch(parseHex(baseLightTheme.primary));
5198
5367
  function generate(base, primary, secondary) {
5199
5368
  const theme = { ...base };
5369
+ const roleOf = (key) => toOklch(parseHex(base[key]));
5370
+ const write = (key, l, c, h) => {
5371
+ ;
5372
+ theme[key] = toHex(l, c, h);
5373
+ };
5200
5374
  const set = (keys, seed, neutral) => {
5201
5375
  const scale = seed.c / reference.c;
5202
5376
  for (const key of keys) {
5203
- const role = toOklch(parseHex(base[key]));
5377
+ const role = roleOf(key);
5204
5378
  const c = role.c * (neutral ? Math.min(scale, 1) : scale);
5205
- const h = seed.h + role.h - reference.h;
5206
- theme[key] = toHex(role.l, c, h);
5379
+ write(key, role.l, c, seed.h + role.h - reference.h);
5207
5380
  }
5208
5381
  };
5209
5382
  set(primaryRoles, primary, false);
5210
5383
  set(tonalRoles, secondary, false);
5211
5384
  set(neutralRoles, primary, true);
5385
+ if (primary.c >= 0.04) {
5386
+ for (const swap of statusSwaps) {
5387
+ if (!hueInRange(primary.h, swap.from, swap.to)) continue;
5388
+ const shift = swap.hue - roleOf(swap.roles[0]).h;
5389
+ for (const key of swap.roles) {
5390
+ const role = roleOf(key);
5391
+ write(key, role.l, role.c, role.h + shift);
5392
+ }
5393
+ }
5394
+ }
5212
5395
  return theme;
5213
5396
  }
5397
+ function hueInRange(h, from, to) {
5398
+ return from <= to ? h >= from && h <= to : h >= from || h <= to;
5399
+ }
5214
5400
  function mainColors(pixels) {
5215
5401
  const bins = Array.from({ length: 36 }, () => ({ w: 0, l: 0, a: 0, b: 0 }));
5216
5402
  const grey = { w: 0, l: 0, a: 0, b: 0 };
@@ -5363,7 +5549,7 @@ var monochromeDarkTheme = {
5363
5549
  };
5364
5550
 
5365
5551
  // src/components/AnvilRoot/AnvilRoot.tsx
5366
- var import_react39 = require("react");
5552
+ var import_react40 = require("react");
5367
5553
  var import_toast2 = require("@base-ui/react/toast");
5368
5554
  var import_tooltip4 = require("@base-ui/react/tooltip");
5369
5555
 
@@ -5426,43 +5612,56 @@ function subscribeToOs(onChange) {
5426
5612
  var getOsMode = () => matchMedia(darkQuery).matches ? "dark" : "light";
5427
5613
  var declarations = (vars) => Object.entries(vars).map(([name, value]) => `${name}:${value};`).join("");
5428
5614
  function AnvilRoot(props) {
5429
- const [internalSetting, setInternalSetting] = (0, import_react39.useState)(
5430
- props.defaultColorMode ?? "system"
5615
+ const {
5616
+ children,
5617
+ className,
5618
+ colorMode: colorModeProp,
5619
+ defaultColorMode,
5620
+ onColorModeChange,
5621
+ storageKey,
5622
+ lightTheme: lightThemeProp,
5623
+ darkTheme: darkThemeProp,
5624
+ tokens: tokensProp,
5625
+ ref,
5626
+ ...divProps
5627
+ } = props;
5628
+ const [internalSetting, setInternalSetting] = (0, import_react40.useState)(
5629
+ defaultColorMode ?? "system"
5431
5630
  );
5432
- const setting = props.colorMode ?? internalSetting;
5433
- const osMode = (0, import_react39.useSyncExternalStore)(
5631
+ const setting = colorModeProp ?? internalSetting;
5632
+ const osMode = (0, import_react40.useSyncExternalStore)(
5434
5633
  subscribeToOs,
5435
5634
  getOsMode,
5436
5635
  () => "light"
5437
5636
  );
5438
5637
  const colorMode = setting === "system" ? osMode : setting;
5439
- const latestSetting = (0, import_react39.useRef)(setting);
5638
+ const latestSetting = (0, import_react40.useRef)(setting);
5440
5639
  latestSetting.current = setting;
5441
- (0, import_react39.useLayoutEffect)(() => {
5442
- if (!props.storageKey) return;
5443
- const stored = readStored(props.storageKey);
5640
+ (0, import_react40.useLayoutEffect)(() => {
5641
+ if (!storageKey) return;
5642
+ const stored = readStored(storageKey);
5444
5643
  if (stored) {
5445
5644
  latestSetting.current = stored;
5446
5645
  setInternalSetting(stored);
5447
5646
  }
5448
- }, [props.storageKey]);
5647
+ }, [storageKey]);
5449
5648
  const setColorMode = (next) => {
5450
5649
  const value = typeof next === "function" ? next(latestSetting.current) : next;
5451
5650
  latestSetting.current = value;
5452
5651
  setInternalSetting(value);
5453
- props.onColorModeChange?.(value);
5454
- if (props.storageKey) {
5652
+ onColorModeChange?.(value);
5653
+ if (storageKey) {
5455
5654
  try {
5456
- localStorage.setItem(props.storageKey, value);
5655
+ localStorage.setItem(storageKey, value);
5457
5656
  } catch {
5458
5657
  }
5459
5658
  }
5460
5659
  };
5461
- const tokens = { ...baseDesignTokens, ...props.tokens };
5462
- const lightTheme = props.lightTheme || baseLightTheme;
5463
- const darkTheme = props.darkTheme || baseDarkTheme;
5464
- const rootRef = (0, import_react39.useRef)(null);
5465
- (0, import_react39.useEffect)(() => {
5660
+ const tokens = { ...baseDesignTokens, ...tokensProp };
5661
+ const lightTheme = lightThemeProp || baseLightTheme;
5662
+ const darkTheme = darkThemeProp || baseDarkTheme;
5663
+ const rootRef = (0, import_react40.useRef)(null);
5664
+ (0, import_react40.useEffect)(() => {
5466
5665
  if (process.env.NODE_ENV === "production") return;
5467
5666
  const timer = setTimeout(() => {
5468
5667
  const root2 = rootRef.current;
@@ -5477,12 +5676,12 @@ function AnvilRoot(props) {
5477
5676
  }, 1e3);
5478
5677
  return () => clearTimeout(timer);
5479
5678
  }, []);
5480
- const id = (0, import_react39.useId)();
5679
+ const id = (0, import_react40.useId)();
5481
5680
  const root = `[data-avl-root="${id}"]`;
5482
5681
  const light = `color-scheme:light;${declarations(themeToCssVariables(lightTheme))}`;
5483
5682
  const dark = `color-scheme:dark;${declarations(themeToCssVariables(darkTheme))}`;
5484
5683
  const css = `${root}{${declarations(tokensToCssVariables(tokens))}${light}}${root}[data-color-mode="dark"]{${dark}}@media ${darkQuery}{${root}[data-color-mode="system"]{${dark}}}`;
5485
- const restoreScript = props.storageKey && props.colorMode === void 0 ? `try{var m=localStorage.getItem(${JSON.stringify(props.storageKey)});if(m==='light'||m==='dark'||m==='system')document.currentScript.parentElement.dataset.colorMode=m}catch(e){}` : void 0;
5684
+ const restoreScript = storageKey && colorModeProp === void 0 ? `try{var m=localStorage.getItem(${JSON.stringify(storageKey)});if(m==='light'||m==='dark'||m==='system')document.currentScript.parentElement.dataset.colorMode=m}catch(e){}` : void 0;
5486
5685
  return /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(
5487
5686
  AnvilContext,
5488
5687
  {
@@ -5498,8 +5697,9 @@ function AnvilRoot(props) {
5498
5697
  children: /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)(
5499
5698
  "div",
5500
5699
  {
5501
- ref: rootRef,
5502
- className: cx("avl-root", props.className),
5700
+ ...divProps,
5701
+ ref: mergeRefs(rootRef, ref),
5702
+ className: cx("avl-root", className),
5503
5703
  "data-avl-root": id,
5504
5704
  "data-color-mode": setting,
5505
5705
  suppressHydrationWarning: true,
@@ -5514,7 +5714,7 @@ function AnvilRoot(props) {
5514
5714
  ),
5515
5715
  /* @__PURE__ */ (0, import_jsx_runtime57.jsx)("style", { children: css }),
5516
5716
  /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(import_tooltip4.Tooltip.Provider, { children: /* @__PURE__ */ (0, import_jsx_runtime57.jsxs)(import_toast2.Toast.Provider, { limit: 3, children: [
5517
- props.children,
5717
+ children,
5518
5718
  /* @__PURE__ */ (0, import_jsx_runtime57.jsx)(SnackbarViewport, {})
5519
5719
  ] }) })
5520
5720
  ]