anvilui 0.2.0 → 0.3.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.
Files changed (45) hide show
  1. package/AGENTS.md +29 -29
  2. package/README.md +42 -89
  3. package/dist/components/Combobox/Combobox.d.ts +8 -2
  4. package/dist/components/DateInput/DateInput.d.ts +5 -3
  5. package/dist/components/IconButton/IconButton.d.ts +5 -3
  6. package/dist/components/Input/Input.d.ts +5 -3
  7. package/dist/components/PinInput/PinInput.d.ts +5 -3
  8. package/dist/components/Progress/Progress.d.ts +4 -1
  9. package/dist/components/RadioGroup/RadioGroup.d.ts +2 -2
  10. package/dist/components/Search/Search.d.ts +22 -6
  11. package/dist/components/Select/Select.d.ts +6 -2
  12. package/dist/components/Slider/Slider.d.ts +2 -1
  13. package/dist/components/SquigglyWave/SquigglyWave.d.ts +26 -4
  14. package/dist/components/Textarea/Textarea.d.ts +6 -3
  15. package/dist/components/TimePicker/TimePicker.d.ts +7 -5
  16. package/dist/components/Toggle/Toggle.d.ts +2 -1
  17. package/dist/components/ToggleGroup/ToggleGroup.d.ts +2 -2
  18. package/dist/index.cjs +302 -62
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.css +48 -25
  21. package/dist/index.css.map +1 -1
  22. package/dist/index.js +336 -88
  23. package/dist/index.js.map +1 -1
  24. package/dist/themes/types.d.ts +0 -4
  25. package/dist/utils.d.ts +4 -0
  26. package/docs/badge.md +41 -41
  27. package/docs/combobox.md +2 -1
  28. package/docs/composition.md +1 -1
  29. package/docs/date-input.md +4 -3
  30. package/docs/forms.md +1 -1
  31. package/docs/icon-button.md +3 -2
  32. package/docs/input.md +1 -0
  33. package/docs/morph.md +4 -1
  34. package/docs/pin-input.md +1 -1
  35. package/docs/progress.md +37 -37
  36. package/docs/radio-group.md +17 -0
  37. package/docs/search.md +7 -7
  38. package/docs/select.md +3 -2
  39. package/docs/slider.md +49 -49
  40. package/docs/textarea.md +1 -1
  41. package/docs/theming.md +2 -1
  42. package/docs/time-picker.md +3 -2
  43. package/docs/toggle-group.md +1 -1
  44. package/docs/toggle.md +2 -2
  45. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -12,6 +12,16 @@ function cx(...parts) {
12
12
  function withClass(base, className) {
13
13
  return (state) => cx(base, typeof className === "function" ? className(state) : className);
14
14
  }
15
+ function splitControlProps(props) {
16
+ const control = {};
17
+ const rest = {};
18
+ for (const [key, value] of Object.entries(props)) {
19
+ if (key.startsWith("aria-") || key.startsWith("data-"))
20
+ control[key] = value;
21
+ else rest[key] = value;
22
+ }
23
+ return { control, rest };
24
+ }
15
25
  function mergeRefs(...refs) {
16
26
  return (value) => {
17
27
  for (const ref of refs) {
@@ -845,6 +855,7 @@ function IconButton({
845
855
  icon,
846
856
  color,
847
857
  fillType,
858
+ size = "normal",
848
859
  className,
849
860
  ...props
850
861
  }) {
@@ -877,7 +888,7 @@ function IconButton({
877
888
  {
878
889
  ...props,
879
890
  className: withClass(
880
- `avl-icon-button ${colorClass(color, fillType)}`,
891
+ `avl-icon-button ${colorClass(color, fillType)} avl-icon-button-size-${size}`,
881
892
  className
882
893
  ),
883
894
  children: /* @__PURE__ */ jsx13(Icon, { name: icon })
@@ -1789,51 +1800,150 @@ import { useId } from "react";
1789
1800
  import { Separator } from "@base-ui/react/separator";
1790
1801
 
1791
1802
  // src/components/SquigglyWave/SquigglyWave.tsx
1792
- import { useEffect as useEffect4, useRef as useRef8 } from "react";
1803
+ import { useEffect as useEffect4, useRef as useRef8, useState as useState6 } from "react";
1793
1804
  import { jsx as jsx19, jsxs as jsxs11 } from "react/jsx-runtime";
1794
1805
  var WAVE_LENGTH = 40;
1795
1806
  var WAVE_AMPLITUDE = 3;
1796
- var WAVE_MIDDLE = 6;
1797
- var STROKE_CAP = 2;
1807
+ var WAVE_STROKE = 4;
1798
1808
  var WAVE_PERIOD = 1500;
1799
- function wavePath(from, to, phase) {
1800
- const start = from + STROKE_CAP;
1801
- const end = to - STROKE_CAP;
1809
+ var K = 2 * Math.PI / WAVE_LENGTH;
1810
+ var waveY = (x, phase, shape) => (
1811
+ // + phase: the ripple travels from the leading end back to the start
1812
+ shape.middle + shape.amplitude * Math.sin(K * x + phase)
1813
+ );
1814
+ var waveSlope = (x, phase, shape) => shape.amplitude * K * Math.cos(K * x + phase);
1815
+ function wavePath(from, to, phase, shape) {
1816
+ const start = from + shape.cap;
1817
+ const end = to - shape.cap;
1802
1818
  if (end < start) return "";
1803
- const y = (x) => WAVE_MIDDLE + // + phase: the ripple travels from the leading end back to the start
1804
- WAVE_AMPLITUDE * Math.sin(2 * Math.PI * x / WAVE_LENGTH + phase);
1819
+ const y = (x) => waveY(x, phase, shape);
1805
1820
  let d = `M${start} ${y(start)}`;
1806
1821
  for (let x = start + 2; x < end; x += 2) d += `L${x} ${y(x)}`;
1807
1822
  return d + `L${end} ${y(end)}`;
1808
1823
  }
1809
- function linePath(from, to) {
1810
- const start = from + STROKE_CAP;
1811
- const end = to - STROKE_CAP;
1812
- return end < start ? "" : `M${start} ${WAVE_MIDDLE}L${end} ${WAVE_MIDDLE}`;
1824
+ function linePath(from, to, shape) {
1825
+ const start = from + shape.cap;
1826
+ const end = to - shape.cap;
1827
+ return end < start ? "" : `M${start} ${shape.middle}L${end} ${shape.middle}`;
1828
+ }
1829
+ function smoothEasing(style) {
1830
+ const match = style.getPropertyValue("--avl-ease-smooth").match(/cubic-bezier\(([^)]+)\)/);
1831
+ const parts = match?.[1].split(",").map(Number);
1832
+ const [x1, y1, x2, y2] = parts?.length === 4 && parts.every((n) => !Number.isNaN(n)) ? parts : [0.2, 0, 0, 1];
1833
+ const bezier = (a, b, t) => 3 * a * t * (1 - t) ** 2 + 3 * b * t ** 2 * (1 - t) + t ** 3;
1834
+ return (x) => {
1835
+ if (x <= 0 || x >= 1) return x;
1836
+ let lo = 0;
1837
+ let hi = 1;
1838
+ for (let i = 0; i < 20; i++) {
1839
+ const mid = (lo + hi) / 2;
1840
+ if (bezier(x1, x2, mid) < x) lo = mid;
1841
+ else hi = mid;
1842
+ }
1843
+ return bezier(y1, y2, (lo + hi) / 2);
1844
+ };
1845
+ }
1846
+ function cssNumber(style, name, fallback) {
1847
+ const raw = style.getPropertyValue(name).trim();
1848
+ const n = parseFloat(raw);
1849
+ if (Number.isNaN(n)) return fallback;
1850
+ return raw.endsWith("ms") ? n : raw.endsWith("s") ? n * 1e3 : n;
1851
+ }
1852
+ function cssLength(el, name, fallback) {
1853
+ const host = el.parentElement;
1854
+ if (!host || !getComputedStyle(el).getPropertyValue(name).trim())
1855
+ return fallback;
1856
+ const probe = document.createElement("div");
1857
+ probe.style.cssText = `position:absolute;visibility:hidden;width:var(${name})`;
1858
+ host.append(probe);
1859
+ const px = probe.getBoundingClientRect().width;
1860
+ probe.remove();
1861
+ return px;
1862
+ }
1863
+ function capPath(x, y, slope, dir, half, length, radius) {
1864
+ const norm = Math.hypot(1, slope);
1865
+ const tx = dir / norm;
1866
+ const ty = dir * slope / norm;
1867
+ const p = (u, v) => `${x + u * tx - v * ty} ${y + u * ty + v * tx}`;
1868
+ const r = Math.max(0, Math.min(radius, length, half));
1869
+ return `M${p(-0.5, -half)}L${p(length - r, -half)}A${r} ${r} 0 0 1 ${p(length, r - half)}L${p(length, half - r)}A${r} ${r} 0 0 1 ${p(length - r, half)}L${p(-0.5, half)}Z`;
1870
+ }
1871
+ function useWaveMorph(squiggly) {
1872
+ const [previous, setPrevious] = useState6(squiggly);
1873
+ const [leaving, setLeaving] = useState6(false);
1874
+ const [changed, setChanged] = useState6(false);
1875
+ if (squiggly !== previous) {
1876
+ setPrevious(squiggly);
1877
+ setLeaving(!squiggly);
1878
+ setChanged(true);
1879
+ }
1880
+ return {
1881
+ show: squiggly || leaving,
1882
+ wave: {
1883
+ flat: !squiggly,
1884
+ startFlat: changed,
1885
+ onFlat: () => setLeaving(false)
1886
+ }
1887
+ };
1813
1888
  }
1814
1889
  function SquigglyWave(props) {
1815
1890
  const svgRef = useRef8(null);
1816
1891
  const waveRef = useRef8(null);
1817
1892
  const restRef = useRef8(null);
1818
- const dotRef = useRef8(null);
1893
+ const waveCapsRef = useRef8(null);
1894
+ const restCapsRef = useRef8(null);
1819
1895
  const span = useRef8(props.span);
1820
1896
  span.current = props.span;
1897
+ const flat = useRef8(props.flat ?? false);
1898
+ flat.current = props.flat ?? false;
1899
+ const onFlat = useRef8(props.onFlat);
1900
+ onFlat.current = props.onFlat;
1901
+ const startFlat = useRef8(props.startFlat ?? false);
1821
1902
  const still = props.still ?? false;
1822
1903
  const vertical = props.vertical ?? false;
1823
1904
  useEffect4(() => {
1824
1905
  const svg = svgRef.current;
1825
1906
  const wave = waveRef.current;
1826
1907
  const rest = restRef.current;
1827
- const dot = dotRef.current;
1828
- if (!svg || !wave || !rest || !dot) return;
1908
+ const waveCaps = waveCapsRef.current;
1909
+ const restCaps = restCapsRef.current;
1910
+ if (!svg || !wave || !rest || !waveCaps || !restCaps) return;
1829
1911
  const reduced = still || matchMedia("(prefers-reduced-motion: reduce)").matches;
1830
- const gap = parseFloat(
1831
- getComputedStyle(svg).getPropertyValue("--avl-wave-gap")
1832
- ) || 0;
1912
+ const style = getComputedStyle(svg);
1913
+ const gap = cssLength(svg, "--avl-wave-gap", 0);
1914
+ const flatStroke = cssLength(svg, "--avl-wave-flat-stroke", WAVE_STROKE);
1915
+ const flatRadius = cssLength(svg, "--avl-wave-flat-radius", -1);
1916
+ const flatRestRadius = cssLength(svg, "--avl-wave-flat-rest-radius", -1);
1917
+ const shapedCaps = flatRadius >= 0 || flatRestRadius >= 0;
1918
+ const linecap = shapedCaps ? "butt" : "";
1919
+ wave.style.strokeLinecap = linecap;
1920
+ rest.style.strokeLinecap = linecap;
1921
+ const duration = cssNumber(style, "--avl-ease-length-slow", 300);
1922
+ const ease = smoothEasing(style);
1833
1923
  let current = null;
1834
1924
  let frame = 0;
1925
+ let flatness = startFlat.current ? 1 : 0;
1926
+ let notified = false;
1927
+ let last = null;
1835
1928
  const draw = (now) => {
1929
+ const target = flat.current ? 1 : 0;
1930
+ const step = reduced || last === null || duration <= 0 ? 1 : (now - last) / duration;
1931
+ if (last === null && !reduced) {
1932
+ last = now;
1933
+ } else {
1934
+ last = now;
1935
+ flatness = target > flatness ? Math.min(target, flatness + step) : Math.max(target, flatness - step);
1936
+ }
1937
+ if (flatness < 1) notified = false;
1938
+ const eased = target === 1 ? ease(flatness) : 1 - ease(1 - flatness);
1939
+ const stroke = WAVE_STROKE + (flatStroke - WAVE_STROKE) * eased;
1940
+ svg.style.setProperty("--avl-wave-stroke", `${stroke}px`);
1836
1941
  const width = vertical ? svg.clientHeight : svg.clientWidth;
1942
+ const shape = {
1943
+ middle: (vertical ? svg.clientWidth : svg.clientHeight) / 2,
1944
+ amplitude: WAVE_AMPLITUDE * (1 - eased),
1945
+ cap: stroke / 2
1946
+ };
1837
1947
  const next = span.current(width, gap, svg, now);
1838
1948
  if (!current || next.snap || reduced) {
1839
1949
  current = { from: next.from, to: next.to };
@@ -1842,17 +1952,61 @@ function SquigglyWave(props) {
1842
1952
  current.to += (next.to - current.to) * 0.15;
1843
1953
  }
1844
1954
  const phase = reduced ? 0 : now / WAVE_PERIOD * 2 * Math.PI;
1845
- wave.setAttribute("d", wavePath(current.from, current.to, phase));
1955
+ wave.setAttribute(
1956
+ "d",
1957
+ wavePath(current.from, current.to, phase, shape)
1958
+ );
1846
1959
  rest.setAttribute(
1847
1960
  "d",
1848
1961
  (next.rest ?? []).map(
1849
- ([a, b]) => next.restWave ? wavePath(a, b, phase) : linePath(a, b)
1962
+ ([a, b]) => next.restWave ? wavePath(a, b, phase, shape) : linePath(a, b, shape)
1850
1963
  ).join("")
1851
1964
  );
1852
- dot.setAttribute(
1853
- "d",
1854
- next.dot ? linePath(width - 2 * STROKE_CAP, width) : ""
1855
- );
1965
+ if (shapedCaps) {
1966
+ const half = stroke / 2;
1967
+ const caps = (a, b, wavy, insideRadius) => {
1968
+ if (b - a <= 0) return "";
1969
+ const length = Math.min(half, (b - a) / 2);
1970
+ const radius = (inside) => inside && insideRadius >= 0 ? half + (insideRadius - half) * eased : half;
1971
+ const at = (x) => wavy ? [
1972
+ waveY(x, phase, shape),
1973
+ waveSlope(x, phase, shape)
1974
+ ] : [shape.middle, 0];
1975
+ const [y0, s0] = at(a + length);
1976
+ const [y1, s1] = at(b - length);
1977
+ return capPath(
1978
+ a + length,
1979
+ y0,
1980
+ s0,
1981
+ -1,
1982
+ half,
1983
+ length,
1984
+ radius(a > 0.5)
1985
+ ) + capPath(
1986
+ b - length,
1987
+ y1,
1988
+ s1,
1989
+ 1,
1990
+ half,
1991
+ length,
1992
+ radius(b < width - 0.5)
1993
+ );
1994
+ };
1995
+ waveCaps.setAttribute(
1996
+ "d",
1997
+ caps(current.from, current.to, true, flatRadius)
1998
+ );
1999
+ restCaps.setAttribute(
2000
+ "d",
2001
+ (next.rest ?? []).map(
2002
+ ([a, b]) => caps(a, b, next.restWave ?? false, flatRestRadius)
2003
+ ).join("")
2004
+ );
2005
+ }
2006
+ if (flatness === 1 && target === 1 && !notified) {
2007
+ notified = true;
2008
+ onFlat.current?.();
2009
+ }
1856
2010
  if (!still) frame = requestAnimationFrame(draw);
1857
2011
  };
1858
2012
  if (still) {
@@ -1865,8 +2019,15 @@ function SquigglyWave(props) {
1865
2019
  }, [still, vertical]);
1866
2020
  return /* @__PURE__ */ jsx19("svg", { ref: svgRef, className: "avl-squiggly-wave", "aria-hidden": true, children: /* @__PURE__ */ jsxs11("g", { transform: vertical ? "matrix(0 1 1 0 0 0)" : void 0, children: [
1867
2021
  /* @__PURE__ */ jsx19("path", { ref: restRef, className: "avl-squiggly-wave-rest" }),
2022
+ /* @__PURE__ */ jsx19(
2023
+ "path",
2024
+ {
2025
+ ref: restCapsRef,
2026
+ className: "avl-squiggly-wave-cap avl-squiggly-wave-rest"
2027
+ }
2028
+ ),
1868
2029
  /* @__PURE__ */ jsx19("path", { ref: waveRef }),
1869
- /* @__PURE__ */ jsx19("path", { ref: dotRef })
2030
+ /* @__PURE__ */ jsx19("path", { ref: waveCapsRef, className: "avl-squiggly-wave-cap" })
1870
2031
  ] }) });
1871
2032
  }
1872
2033
 
@@ -2025,7 +2186,7 @@ function FAB({
2025
2186
  }
2026
2187
 
2027
2188
  // src/components/FABMenu/FABMenu.tsx
2028
- import { createContext as createContext4, useContext as useContext10, useRef as useRef10, useState as useState6 } from "react";
2189
+ import { createContext as createContext4, useContext as useContext10, useRef as useRef10, useState as useState7 } from "react";
2029
2190
  import { Menu as BaseMenu } from "@base-ui/react/menu";
2030
2191
  import { jsx as jsx22, jsxs as jsxs14 } from "react/jsx-runtime";
2031
2192
  var FABMenuColorContext = createContext4("primary");
@@ -2046,7 +2207,7 @@ function FABMenu({
2046
2207
  if (process.env.NODE_ENV !== "production") {
2047
2208
  checkRoot(avl !== null, "FABMenu");
2048
2209
  }
2049
- const [localOpen, setLocalOpen] = useState6(props.defaultOpen ?? false);
2210
+ const [localOpen, setLocalOpen] = useState7(props.defaultOpen ?? false);
2050
2211
  const open = props.open ?? localOpen;
2051
2212
  const trigger = useRef10(null);
2052
2213
  useMagnet(trigger, sticky && !open && !props.disabled);
@@ -2159,6 +2320,7 @@ function Input({
2159
2320
  label,
2160
2321
  size = "normal",
2161
2322
  className,
2323
+ style,
2162
2324
  placeholder,
2163
2325
  ...props
2164
2326
  }) {
@@ -2169,6 +2331,7 @@ function Input({
2169
2331
  return /* @__PURE__ */ jsxs15(
2170
2332
  "label",
2171
2333
  {
2334
+ style,
2172
2335
  className: cx(
2173
2336
  "avl-input",
2174
2337
  `avl-input-size-${size}`,
@@ -2192,7 +2355,7 @@ function Input({
2192
2355
  }
2193
2356
 
2194
2357
  // src/components/Kbd/Kbd.tsx
2195
- import { useEffect as useEffect6, useState as useState7 } from "react";
2358
+ import { useEffect as useEffect6, useState as useState8 } from "react";
2196
2359
  import { jsx as jsx25 } from "react/jsx-runtime";
2197
2360
  function Kbd({
2198
2361
  listen = true,
@@ -2246,7 +2409,7 @@ function keyFromText(children) {
2246
2409
  return aliases[text] ?? (text || null);
2247
2410
  }
2248
2411
  function useKeyHeld(key) {
2249
- const [held, setHeld] = useState7(false);
2412
+ const [held, setHeld] = useState8(false);
2250
2413
  useEffect6(() => {
2251
2414
  if (!key) return;
2252
2415
  const target = key.toLowerCase();
@@ -2729,6 +2892,8 @@ function Progress({
2729
2892
  );
2730
2893
  }
2731
2894
  const { value, min = 0, max = 100 } = props;
2895
+ const wavy = squiggly && type === "linear";
2896
+ const morph2 = useWaveMorph(wavy);
2732
2897
  const fraction = value == null ? 0 : Math.min(1, Math.max(0, (value - min) / (max - min)));
2733
2898
  const pct = fraction * 100;
2734
2899
  const ring = type === "inline" ? INLINE_RING : RING;
@@ -2743,7 +2908,9 @@ function Progress({
2743
2908
  `avl-progress-${type}`,
2744
2909
  // Inline is a smaller ring, so it shares the circular styles
2745
2910
  type === "inline" && "avl-progress-circular",
2746
- squiggly && type === "linear" && "avl-progress-squiggly"
2911
+ wavy && "avl-progress-squiggly",
2912
+ // Also while flattening into the plain bar
2913
+ morph2.show && "avl-progress-wave"
2747
2914
  ),
2748
2915
  className
2749
2916
  ),
@@ -2754,9 +2921,10 @@ function Progress({
2754
2921
  children: [
2755
2922
  label != null && /* @__PURE__ */ jsx33(BaseProgress.Label, { className: "avl-progress-label", children: label }),
2756
2923
  type === "linear" ? /* @__PURE__ */ jsxs19(BaseProgress.Track, { className: "avl-progress-track", children: [
2757
- squiggly ? /* @__PURE__ */ jsx33(
2924
+ morph2.show ? /* @__PURE__ */ jsx33(
2758
2925
  SquigglyWave,
2759
2926
  {
2927
+ ...morph2.wave,
2760
2928
  span: (width, gap, _svg, now) => value == null ? loadingSpan(width, gap, now) : (
2761
2929
  // Fill up to the value; .avl-progress-rest
2762
2930
  // draws the track one gap after it
@@ -3012,9 +3180,12 @@ function Select({
3012
3180
  placeholder,
3013
3181
  size = "normal",
3014
3182
  className,
3183
+ style,
3184
+ ref,
3015
3185
  children,
3016
- ...props
3186
+ ...allProps
3017
3187
  }) {
3188
+ const { control, rest: props } = splitControlProps(allProps);
3018
3189
  const avl = useContext16(AnvilContext);
3019
3190
  if (process.env.NODE_ENV !== "production") {
3020
3191
  checkRoot(avl !== null, "Select");
@@ -3023,6 +3194,7 @@ function Select({
3023
3194
  /* @__PURE__ */ jsxs21(
3024
3195
  "div",
3025
3196
  {
3197
+ style,
3026
3198
  className: cx(
3027
3199
  "avl-input",
3028
3200
  "avl-select",
@@ -3031,16 +3203,24 @@ function Select({
3031
3203
  className
3032
3204
  ),
3033
3205
  children: [
3034
- /* @__PURE__ */ jsxs21(BaseSelect.Trigger, { className: "avl-input-field avl-select-trigger", children: [
3035
- /* @__PURE__ */ jsx36(
3036
- BaseSelect.Value,
3037
- {
3038
- className: "avl-select-value",
3039
- placeholder
3040
- }
3041
- ),
3042
- /* @__PURE__ */ jsx36(BaseSelect.Icon, { className: "avl-select-icon", children: /* @__PURE__ */ jsx36(Icon, { name: "arrow_drop_down" }) })
3043
- ] }),
3206
+ /* @__PURE__ */ jsxs21(
3207
+ BaseSelect.Trigger,
3208
+ {
3209
+ ...control,
3210
+ ref,
3211
+ className: "avl-input-field avl-select-trigger",
3212
+ children: [
3213
+ /* @__PURE__ */ jsx36(
3214
+ BaseSelect.Value,
3215
+ {
3216
+ className: "avl-select-value",
3217
+ placeholder
3218
+ }
3219
+ ),
3220
+ /* @__PURE__ */ jsx36(BaseSelect.Icon, { className: "avl-select-icon", children: /* @__PURE__ */ jsx36(Icon, { name: "arrow_drop_down" }) })
3221
+ ]
3222
+ }
3223
+ ),
3044
3224
  label != null && /* @__PURE__ */ jsx36(BaseSelect.Label, { className: "avl-input-label", children: label }),
3045
3225
  /* @__PURE__ */ jsx36("fieldset", { "aria-hidden": true, className: "avl-input-outline", children: /* @__PURE__ */ jsx36("legend", { children: label != null && size === "normal" && /* @__PURE__ */ jsx36("span", { children: label }) }) })
3046
3226
  ]
@@ -3072,7 +3252,7 @@ function SelectItem({ className, children, ...props }) {
3072
3252
  }
3073
3253
 
3074
3254
  // src/components/TimePicker/TimePicker.tsx
3075
- import { useId as useId2, useRef as useRef12, useState as useState8 } from "react";
3255
+ import { useId as useId2, useRef as useRef12, useState as useState9 } from "react";
3076
3256
  import { Fragment as Fragment4, jsx as jsx37, jsxs as jsxs22 } from "react/jsx-runtime";
3077
3257
  var pad2 = (n) => String(n).padStart(2, "0");
3078
3258
  function localeHourCycle() {
@@ -3097,16 +3277,19 @@ function TimePicker({
3097
3277
  defaultOpen,
3098
3278
  onOpenChange,
3099
3279
  className,
3100
- ...props
3280
+ ref,
3281
+ id,
3282
+ ...allProps
3101
3283
  }) {
3102
- const [internal, setInternal] = useState8(defaultValue);
3284
+ const { control, rest: props } = splitControlProps(allProps);
3285
+ const [internal, setInternal] = useState9(defaultValue);
3103
3286
  const value = valueProp !== void 0 ? valueProp : internal;
3104
3287
  const time = parseTime(value);
3105
3288
  const cycle = hourCycle ?? localeHourCycle();
3106
3289
  const labelId = useId2();
3107
3290
  const valueId = useId2();
3108
3291
  const setTime = (t) => {
3109
- const next = `${pad2(t.h)}:${pad2(t.m)}`;
3292
+ const next = t && `${pad2(t.h)}:${pad2(t.m)}`;
3110
3293
  setInternal(next);
3111
3294
  onValueChange?.(next);
3112
3295
  };
@@ -3138,6 +3321,9 @@ function TimePicker({
3138
3321
  /* @__PURE__ */ jsxs22(
3139
3322
  PopoverTrigger,
3140
3323
  {
3324
+ ...control,
3325
+ ref,
3326
+ id,
3141
3327
  disabled,
3142
3328
  className: "avl-input-field avl-select-trigger",
3143
3329
  "data-placeholder": time ? void 0 : "",
@@ -3160,7 +3346,8 @@ function TimePicker({
3160
3346
  type,
3161
3347
  time,
3162
3348
  cycle,
3163
- onChange: setTime
3349
+ onChange: setTime,
3350
+ onClear: () => setTime(null)
3164
3351
  }
3165
3352
  ) })
3166
3353
  ]
@@ -3168,8 +3355,8 @@ function TimePicker({
3168
3355
  );
3169
3356
  }
3170
3357
  function TimePanel(props) {
3171
- const { type, time, cycle, onChange } = props;
3172
- const [mode, setMode] = useState8("hour");
3358
+ const { type, time, cycle, onChange, onClear } = props;
3359
+ const [mode, setMode] = useState9("hour");
3173
3360
  const pm = time ? time.h >= 12 : false;
3174
3361
  const hourText = time ? pad2(displayHour(time.h, cycle)) : "--";
3175
3362
  const minuteText = time ? pad2(time.m) : "--";
@@ -3257,12 +3444,20 @@ function TimePanel(props) {
3257
3444
  onChange,
3258
3445
  onHourDone: () => setMode("minute")
3259
3446
  }
3260
- )
3447
+ ),
3448
+ time && /* @__PURE__ */ jsx37("div", { className: "avl-time-picker-actions", children: /* @__PURE__ */ jsx37(
3449
+ PopoverClose,
3450
+ {
3451
+ render: /* @__PURE__ */ jsx37(Button, { fillType: "text", size: "small" }),
3452
+ onClick: onClear,
3453
+ children: "Clear"
3454
+ }
3455
+ ) })
3261
3456
  ] });
3262
3457
  }
3263
3458
  function SpinInput(props) {
3264
3459
  const { label, value, min, max, onChange } = props;
3265
- const [draft, setDraft] = useState8(null);
3460
+ const [draft, setDraft] = useState9(null);
3266
3461
  const range = max - min + 1;
3267
3462
  return /* @__PURE__ */ jsx37(
3268
3463
  "input",
@@ -3311,7 +3506,7 @@ function Dial(props) {
3311
3506
  const h = time?.h ?? 0;
3312
3507
  const m = time?.m ?? 0;
3313
3508
  const isHour = mode === "hour";
3314
- const [dragging, setDragging] = useState8(false);
3509
+ const [dragging, setDragging] = useState9(false);
3315
3510
  const labels = Array.from(
3316
3511
  { length: 12 },
3317
3512
  (_, i) => !isHour ? [{ value: i * 5, text: pad2(i * 5), inner: false }] : cycle === 12 ? [{ value: i, text: String(i || 12), inner: false }] : [
@@ -3470,7 +3665,12 @@ function Dial(props) {
3470
3665
  }
3471
3666
 
3472
3667
  // src/components/DateInput/DateInput.tsx
3473
- import { useId as useId3, useRef as useRef13, useState as useState9 } from "react";
3668
+ import {
3669
+ useEffect as useEffect7,
3670
+ useId as useId3,
3671
+ useRef as useRef13,
3672
+ useState as useState10
3673
+ } from "react";
3474
3674
  import { Input as BaseInput2 } from "@base-ui/react/input";
3475
3675
  import { jsx as jsx38, jsxs as jsxs23 } from "react/jsx-runtime";
3476
3676
  var numericFormat = () => new Intl.DateTimeFormat(void 0, {
@@ -3488,17 +3688,33 @@ function DateInput({
3488
3688
  id,
3489
3689
  onBlur,
3490
3690
  className,
3691
+ style,
3692
+ ref,
3491
3693
  ...props
3492
3694
  }) {
3493
- const [internal, setInternal] = useState9(defaultValue);
3695
+ const [internal, setInternal] = useState10(defaultValue);
3494
3696
  const value = valueProp !== void 0 ? valueProp : internal;
3495
3697
  const date = fromIso(value);
3496
- const [draft, setDraft] = useState9(null);
3497
- const [open, setOpen] = useState9(false);
3698
+ const [draft, setDraft] = useState10(null);
3699
+ const [open, setOpen] = useState10(false);
3498
3700
  const fieldRef = useRef13(null);
3499
3701
  const popupRef = useRef13(null);
3500
3702
  const generatedId = useId3();
3501
3703
  const inputId = id ?? generatedId;
3704
+ const inputRef = useRef13(null);
3705
+ const iso = useRef13("");
3706
+ iso.current = date ? toIso(date) : "";
3707
+ useEffect7(() => {
3708
+ const form = inputRef.current?.form;
3709
+ if (!form) return;
3710
+ const onFormData = (event) => {
3711
+ const input = inputRef.current;
3712
+ if (input?.name && !input.disabled)
3713
+ event.formData.set(input.name, iso.current);
3714
+ };
3715
+ form.addEventListener("formdata", onFormData);
3716
+ return () => form.removeEventListener("formdata", onFormData);
3717
+ }, []);
3502
3718
  const fmt = numericFormat();
3503
3719
  const order = fieldOrder(fmt);
3504
3720
  const invalid = draft != null && draft.trim() !== "" && !parseTyped(draft, order);
@@ -3512,6 +3728,7 @@ function DateInput({
3512
3728
  "div",
3513
3729
  {
3514
3730
  ref: fieldRef,
3731
+ style,
3515
3732
  className: cx(
3516
3733
  "avl-input",
3517
3734
  "avl-date-input",
@@ -3524,6 +3741,7 @@ function DateInput({
3524
3741
  BaseInput2,
3525
3742
  {
3526
3743
  ...props,
3744
+ ref: mergeRefs(inputRef, ref),
3527
3745
  id: inputId,
3528
3746
  disabled,
3529
3747
  className: "avl-input-field",
@@ -3581,8 +3799,8 @@ function DateInput({
3581
3799
  Calendar,
3582
3800
  {
3583
3801
  value: date && toIso(date),
3584
- onValueChange: (iso) => {
3585
- commit(fromIso(iso));
3802
+ onValueChange: (iso2) => {
3803
+ commit(fromIso(iso2));
3586
3804
  setDraft(null);
3587
3805
  setOpen(false);
3588
3806
  }
@@ -3594,7 +3812,10 @@ function DateInput({
3594
3812
  }
3595
3813
 
3596
3814
  // src/components/Combobox/Combobox.tsx
3597
- import { useContext as useContext17, useId as useId4 } from "react";
3815
+ import {
3816
+ useContext as useContext17,
3817
+ useId as useId4
3818
+ } from "react";
3598
3819
  import { Combobox as BaseCombobox } from "@base-ui/react/combobox";
3599
3820
  import { jsx as jsx39, jsxs as jsxs24 } from "react/jsx-runtime";
3600
3821
  function Combobox({
@@ -3604,8 +3825,12 @@ function Combobox({
3604
3825
  empty,
3605
3826
  size = "normal",
3606
3827
  className,
3607
- ...props
3828
+ style,
3829
+ ref,
3830
+ id,
3831
+ ...allProps
3608
3832
  }) {
3833
+ const { control, rest: props } = splitControlProps(allProps);
3609
3834
  const avl = useContext17(AnvilContext);
3610
3835
  if (process.env.NODE_ENV !== "production") {
3611
3836
  checkRoot(avl !== null, "Combobox");
@@ -3616,12 +3841,14 @@ function Combobox({
3616
3841
  "combobox.md"
3617
3842
  );
3618
3843
  }
3619
- const inputId = useId4();
3844
+ const generatedId = useId4();
3845
+ const inputId = id ?? generatedId;
3620
3846
  const labelId = useId4();
3621
3847
  return /* @__PURE__ */ jsxs24(BaseCombobox.Root, { ...props, children: [
3622
3848
  /* @__PURE__ */ jsxs24(
3623
3849
  BaseCombobox.InputGroup,
3624
3850
  {
3851
+ style,
3625
3852
  className: cx(
3626
3853
  "avl-input",
3627
3854
  "avl-combobox",
@@ -3633,6 +3860,8 @@ function Combobox({
3633
3860
  /* @__PURE__ */ jsx39(
3634
3861
  BaseCombobox.Input,
3635
3862
  {
3863
+ ...control,
3864
+ ref,
3636
3865
  id: inputId,
3637
3866
  className: "avl-input-field",
3638
3867
  placeholder: placeholder ?? " "
@@ -3702,6 +3931,7 @@ function PinInput({
3702
3931
  size = "normal",
3703
3932
  slotLabel = defaultSlotLabel,
3704
3933
  className,
3934
+ style,
3705
3935
  id,
3706
3936
  length,
3707
3937
  ...props
@@ -3712,6 +3942,7 @@ function PinInput({
3712
3942
  return /* @__PURE__ */ jsxs25(
3713
3943
  "div",
3714
3944
  {
3945
+ style,
3715
3946
  className: cx(
3716
3947
  "avl-pin-input",
3717
3948
  `avl-pin-input-size-${size}`,
@@ -3784,7 +4015,7 @@ function Toggle2({
3784
4015
  ...props,
3785
4016
  className: (state) => cx(
3786
4017
  "avl-toggle",
3787
- icon ? "avl-icon-button" : `avl-button avl-button-size-${size}`,
4018
+ icon ? `avl-icon-button avl-icon-button-size-${size}` : `avl-button avl-button-size-${size}`,
3788
4019
  state.pressed ? colorClass(color, "filled") : colorClass("container", fillType),
3789
4020
  typeof className === "function" ? className(state) : className
3790
4021
  ),
@@ -3806,11 +4037,17 @@ function Search({
3806
4037
  placeholder,
3807
4038
  "aria-label": ariaLabel,
3808
4039
  empty,
4040
+ color = "surface",
3809
4041
  clearLabel = "Clear",
3810
4042
  className,
3811
- ...props
4043
+ style,
4044
+ ref,
4045
+ id,
4046
+ ...allProps
3812
4047
  }) {
4048
+ const { control, rest: props } = splitControlProps(allProps);
3813
4049
  const avl = useContext18(AnvilContext);
4050
+ const suggests = children !== void 0;
3814
4051
  if (process.env.NODE_ENV !== "production") {
3815
4052
  checkRoot(avl !== null, "Search");
3816
4053
  checkName(
@@ -3819,23 +4056,37 @@ function Search({
3819
4056
  '<Search aria-label="Search mail" items={items}>{(item) => ...}</Search>',
3820
4057
  "search.md"
3821
4058
  );
3822
- if (typeof children !== "function")
4059
+ if (children !== void 0 && typeof children !== "function")
3823
4060
  devError(
3824
4061
  "<Search> children must be a function that renders one suggestion, plus an `items` array to filter.",
3825
4062
  '<Search aria-label="Search" items={items}>\n {(item: string) => <SearchItem key={item} value={item}>{item}</SearchItem>}\n</Search>',
3826
4063
  "search.md"
3827
4064
  );
4065
+ if (children === void 0 && props.items?.length)
4066
+ devError(
4067
+ "<Search> has `items` but no children, so the suggestions never show.",
4068
+ '<Search aria-label="Search" items={items}>\n {(item: string) => <SearchItem key={item} value={item}>{item}</SearchItem>}\n</Search>',
4069
+ "search.md"
4070
+ );
3828
4071
  }
3829
- return /* @__PURE__ */ jsxs27(BaseAutocomplete.Root, { ...props, children: [
4072
+ return /* @__PURE__ */ jsxs27(BaseAutocomplete.Root, { ...props, ...!suggests && { open: false }, children: [
3830
4073
  /* @__PURE__ */ jsxs27(
3831
4074
  BaseAutocomplete.InputGroup,
3832
4075
  {
3833
- className: cx("avl-search", className),
4076
+ style,
4077
+ className: cx(
4078
+ "avl-search",
4079
+ colorClass(color, "filled"),
4080
+ className
4081
+ ),
3834
4082
  children: [
3835
4083
  /* @__PURE__ */ jsx42(Icon, { name: "search" }),
3836
4084
  /* @__PURE__ */ jsx42(
3837
4085
  BaseAutocomplete.Input,
3838
4086
  {
4087
+ ...control,
4088
+ ref,
4089
+ id,
3839
4090
  className: "avl-search-input",
3840
4091
  placeholder,
3841
4092
  "aria-label": ariaLabel
@@ -3849,7 +4100,7 @@ function Search({
3849
4100
  {
3850
4101
  icon: "close",
3851
4102
  fillType: "text",
3852
- color: "container",
4103
+ color,
3853
4104
  "aria-label": clearLabel
3854
4105
  }
3855
4106
  )
@@ -3858,7 +4109,7 @@ function Search({
3858
4109
  ]
3859
4110
  }
3860
4111
  ),
3861
- /* @__PURE__ */ jsx42(BaseAutocomplete.Portal, { container: avl?.rootRef, children: /* @__PURE__ */ jsx42(
4112
+ suggests && /* @__PURE__ */ jsx42(BaseAutocomplete.Portal, { container: avl?.rootRef, children: /* @__PURE__ */ jsx42(
3862
4113
  BaseAutocomplete.Positioner,
3863
4114
  {
3864
4115
  className: "avl-menu-positioner",
@@ -3935,6 +4186,7 @@ function Slider({
3935
4186
  const initial = props.value ?? props.defaultValue;
3936
4187
  const thumbCount = Array.isArray(initial) ? initial.length : 1;
3937
4188
  const wavy = squiggly && props.orientation !== "vertical";
4189
+ const morph2 = useWaveMorph(wavy);
3938
4190
  return /* @__PURE__ */ jsxs28(
3939
4191
  BaseSlider.Root,
3940
4192
  {
@@ -3950,7 +4202,7 @@ function Slider({
3950
4202
  children: [
3951
4203
  label != null && /* @__PURE__ */ jsx44(BaseSlider.Label, { className: "avl-slider-label", children: label }),
3952
4204
  /* @__PURE__ */ jsx44(BaseSlider.Control, { className: "avl-slider-control", children: /* @__PURE__ */ jsxs28(BaseSlider.Track, { className: "avl-slider-track", children: [
3953
- wavy ? /* @__PURE__ */ jsx44(SquigglyWave, { span: handleSpan }) : (
4205
+ morph2.show ? /* @__PURE__ */ jsx44(SquigglyWave, { span: handleSpan, ...morph2.wave }) : (
3954
4206
  // Clips the track pieces to the rounded track, without
3955
4207
  // also clipping the handles, which are taller
3956
4208
  /* @__PURE__ */ jsxs28("div", { className: "avl-slider-rail", children: [
@@ -4000,13 +4252,12 @@ function handleSpan(width, gap, svg) {
4000
4252
  [0, first - gap],
4001
4253
  [last + gap, width]
4002
4254
  ] : [[last + gap, width]],
4003
- dot: last + gap < width - gap,
4004
4255
  snap: true
4005
4256
  };
4006
4257
  }
4007
4258
 
4008
4259
  // src/components/Snackbar/Snackbar.tsx
4009
- import { useContext as useContext19, useEffect as useEffect7, useRef as useRef14, useState as useState10 } from "react";
4260
+ import { useContext as useContext19, useEffect as useEffect8, useRef as useRef14, useState as useState11 } from "react";
4010
4261
  import { Toast } from "@base-ui/react/toast";
4011
4262
  import { jsx as jsx45, jsxs as jsxs29 } from "react/jsx-runtime";
4012
4263
  function useSnackbar() {
@@ -4034,16 +4285,16 @@ function useSnackbar() {
4034
4285
  function SnackbarViewport() {
4035
4286
  const { toasts } = Toast.useToastManager();
4036
4287
  const viewportRef = useRef14(null);
4037
- const [expanded, setExpanded] = useState10(false);
4038
- const [hovered, setHovered] = useState10(false);
4288
+ const [expanded, setExpanded] = useState11(false);
4289
+ const [hovered, setHovered] = useState11(false);
4039
4290
  const visibleCount = toasts.filter(
4040
4291
  (toast) => toast.transitionStatus !== "ending"
4041
4292
  ).length;
4042
4293
  const collapsed = visibleCount > 1 && !expanded && !hovered;
4043
- useEffect7(() => {
4294
+ useEffect8(() => {
4044
4295
  if (visibleCount <= 1) setExpanded(false);
4045
4296
  }, [visibleCount]);
4046
- useEffect7(() => {
4297
+ useEffect8(() => {
4047
4298
  if (!expanded) return;
4048
4299
  const viewport = viewportRef.current;
4049
4300
  const close = (event) => {
@@ -4249,12 +4500,14 @@ function Textarea({
4249
4500
  label,
4250
4501
  size = "normal",
4251
4502
  className,
4503
+ style,
4252
4504
  placeholder,
4253
4505
  ...props
4254
4506
  }) {
4255
4507
  return /* @__PURE__ */ jsxs32(
4256
4508
  "label",
4257
4509
  {
4510
+ style,
4258
4511
  className: cx(
4259
4512
  "avl-input",
4260
4513
  "avl-textarea",
@@ -4443,7 +4696,7 @@ function NavigationBarItem({
4443
4696
  import {
4444
4697
  createContext as createContext7,
4445
4698
  useContext as useContext21,
4446
- useState as useState11
4699
+ useState as useState12
4447
4700
  } from "react";
4448
4701
  import { useRender as useRender3 } from "@base-ui/react/use-render";
4449
4702
  import { mergeProps as mergeProps3 } from "@base-ui/react/merge-props";
@@ -4456,7 +4709,7 @@ function NavigationRail({
4456
4709
  className,
4457
4710
  ...props
4458
4711
  }) {
4459
- const [internal, setInternal] = useState11(defaultExpanded);
4712
+ const [internal, setInternal] = useState12(defaultExpanded);
4460
4713
  const expanded = expandedProp ?? internal;
4461
4714
  const setExpanded = (next) => {
4462
4715
  setInternal(next);
@@ -4993,11 +5246,11 @@ var monochromeDarkTheme = {
4993
5246
 
4994
5247
  // src/components/AnvilRoot/AnvilRoot.tsx
4995
5248
  import {
4996
- useEffect as useEffect8,
5249
+ useEffect as useEffect9,
4997
5250
  useId as useId6,
4998
5251
  useLayoutEffect as useLayoutEffect4,
4999
5252
  useRef as useRef15,
5000
- useState as useState12,
5253
+ useState as useState13,
5001
5254
  useSyncExternalStore
5002
5255
  } from "react";
5003
5256
  import { Toast as Toast2 } from "@base-ui/react/toast";
@@ -5006,24 +5259,19 @@ import { Tooltip as Tooltip2 } from "@base-ui/react/tooltip";
5006
5259
  // src/themes/toCssVariables.ts
5007
5260
  function themeToCssVariables(theme) {
5008
5261
  const cssVars = {};
5009
- const { surfaceVariant, onSurfaceVariant, ...rest } = theme;
5010
5262
  const filled = {
5011
5263
  inverseSurface: theme.onBackground,
5012
5264
  inverseOnSurface: theme.background,
5013
5265
  inversePrimary: `color-mix(in srgb, ${theme.primary} 55%, ${theme.background})`,
5014
5266
  shadow: "rgb(0 0 0 / 0.3)",
5015
5267
  scrim: "rgb(0 0 0 / 0.4)",
5016
- ...rest,
5017
- surface: rest.surface ?? surfaceVariant,
5018
- onSurface: rest.onSurface ?? onSurfaceVariant
5268
+ ...theme
5019
5269
  };
5020
5270
  for (const [key, value] of Object.entries(filled)) {
5021
5271
  if (value === void 0) continue;
5022
5272
  const kebabKey = key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
5023
5273
  cssVars[`--avl-color-${kebabKey}`] = value;
5024
5274
  }
5025
- cssVars["--avl-color-surface-variant"] = "var(--avl-color-surface)";
5026
- cssVars["--avl-color-on-surface-variant"] = "var(--avl-color-on-surface)";
5027
5275
  return cssVars;
5028
5276
  }
5029
5277
 
@@ -5067,7 +5315,7 @@ function subscribeToOs(onChange) {
5067
5315
  var getOsMode = () => matchMedia(darkQuery).matches ? "dark" : "light";
5068
5316
  var declarations = (vars) => Object.entries(vars).map(([name, value]) => `${name}:${value};`).join("");
5069
5317
  function AnvilRoot(props) {
5070
- const [internalSetting, setInternalSetting] = useState12(
5318
+ const [internalSetting, setInternalSetting] = useState13(
5071
5319
  props.defaultColorMode ?? "system"
5072
5320
  );
5073
5321
  const setting = props.colorMode ?? internalSetting;
@@ -5103,7 +5351,7 @@ function AnvilRoot(props) {
5103
5351
  const lightTheme = props.lightTheme || baseLightTheme;
5104
5352
  const darkTheme = props.darkTheme || baseDarkTheme;
5105
5353
  const rootRef = useRef15(null);
5106
- useEffect8(() => {
5354
+ useEffect9(() => {
5107
5355
  if (process.env.NODE_ENV === "production") return;
5108
5356
  const timer = setTimeout(() => {
5109
5357
  const root2 = rootRef.current;