@umami/react-zen 0.181.0 → 0.183.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.
package/dist/index.mjs CHANGED
@@ -35,12 +35,12 @@ var require_use_sync_external_store_shim_production = __commonJS({
35
35
  }
36
36
  var objectIs = "function" === typeof Object.is ? Object.is : is2;
37
37
  var useState19 = React5.useState;
38
- var useEffect13 = React5.useEffect;
39
- var useLayoutEffect2 = React5.useLayoutEffect;
38
+ var useEffect12 = React5.useEffect;
39
+ var useLayoutEffect3 = React5.useLayoutEffect;
40
40
  var useDebugValue = React5.useDebugValue;
41
41
  function useSyncExternalStore$2(subscribe, getSnapshot) {
42
42
  var value = getSnapshot(), _useState = useState19({ inst: { value, getSnapshot } }), inst = _useState[0].inst, forceUpdate = _useState[1];
43
- useLayoutEffect2(
43
+ useLayoutEffect3(
44
44
  function() {
45
45
  inst.value = value;
46
46
  inst.getSnapshot = getSnapshot;
@@ -48,7 +48,7 @@ var require_use_sync_external_store_shim_production = __commonJS({
48
48
  },
49
49
  [subscribe, value, getSnapshot]
50
50
  );
51
- useEffect13(
51
+ useEffect12(
52
52
  function() {
53
53
  checkIfSnapshotChanged(inst) && forceUpdate({ inst });
54
54
  return subscribe(function() {
@@ -101,7 +101,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
101
101
  inst: { value, getSnapshot }
102
102
  });
103
103
  var inst = cachedValue[0].inst, forceUpdate = cachedValue[1];
104
- useLayoutEffect2(
104
+ useLayoutEffect3(
105
105
  function() {
106
106
  inst.value = value;
107
107
  inst.getSnapshot = getSnapshot;
@@ -109,7 +109,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
109
109
  },
110
110
  [subscribe, value, getSnapshot]
111
111
  );
112
- useEffect13(
112
+ useEffect12(
113
113
  function() {
114
114
  checkIfSnapshotChanged(inst) && forceUpdate({ inst });
115
115
  return subscribe(function() {
@@ -135,7 +135,7 @@ var require_use_sync_external_store_shim_development = __commonJS({
135
135
  return getSnapshot();
136
136
  }
137
137
  "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
138
- var React5 = __import_react2, objectIs = "function" === typeof Object.is ? Object.is : is2, useState19 = React5.useState, useEffect13 = React5.useEffect, useLayoutEffect2 = React5.useLayoutEffect, useDebugValue = React5.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
138
+ var React5 = __import_react2, objectIs = "function" === typeof Object.is ? Object.is : is2, useState19 = React5.useState, useEffect12 = React5.useEffect, useLayoutEffect3 = React5.useLayoutEffect, useDebugValue = React5.useDebugValue, didWarnOld18Alpha = false, didWarnUncachedGetSnapshot = false, shim = "undefined" === typeof window || "undefined" === typeof window.document || "undefined" === typeof window.document.createElement ? useSyncExternalStore$1 : useSyncExternalStore$2;
139
139
  exports.useSyncExternalStore = void 0 !== React5.useSyncExternalStore ? React5.useSyncExternalStore : shim;
140
140
  "undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
141
141
  })();
@@ -1814,8 +1814,8 @@ function $64fa3d84918910a7$export$29f1550f4b0d4415(props, ref, context) {
1814
1814
  mergedRef
1815
1815
  ];
1816
1816
  }
1817
- function $64fa3d84918910a7$export$9d4c57ee4c6ffdd8(initialState3 = true) {
1818
- let [hasSlot, setHasSlot] = (0, $iETbY$useState)(initialState3);
1817
+ function $64fa3d84918910a7$export$9d4c57ee4c6ffdd8(initialState2 = true) {
1818
+ let [hasSlot, setHasSlot] = (0, $iETbY$useState)(initialState2);
1819
1819
  let hasRun = (0, $iETbY$useRef)(false);
1820
1820
  let ref = (0, $iETbY$useCallback)((el) => {
1821
1821
  hasRun.current = true;
@@ -28407,9 +28407,16 @@ function FormController({ children, ...props }) {
28407
28407
  }
28408
28408
 
28409
28409
  // src/components/forms/FormField.tsx
28410
- import { cloneElement as cloneElement2, Children, useId } from "react";
28410
+ import { cloneElement as cloneElement2, Children } from "react";
28411
28411
  var import_classnames7 = __toESM(require_classnames());
28412
28412
 
28413
+ // src/components/hooks/useFieldId.ts
28414
+ import { useId } from "react";
28415
+ function useFieldId(id) {
28416
+ const generatedId = useId();
28417
+ return id ?? generatedId;
28418
+ }
28419
+
28413
28420
  // css-modules:E:\dev\umami-react-zen\src\components\forms\FormField.module.css
28414
28421
  var FormField_default = { "field": "FormField_field__YTM1N", "description": "FormField_description__ZjFiM", "error": "FormField_error__NWZhM" };
28415
28422
 
@@ -28437,12 +28444,11 @@ function FormField({
28437
28444
  children,
28438
28445
  ...props
28439
28446
  }) {
28440
- const generatedId = useId();
28447
+ const fieldId = useFieldId(id);
28441
28448
  const context = useFormContext();
28442
28449
  const { control } = context;
28443
28450
  const { invalid, error } = context.getFieldState(name);
28444
- const fieldId = id ?? generatedId;
28445
- return /* @__PURE__ */ jsxs6("div", { ...props, id, className: (0, import_classnames7.default)(FormField_default.input, className), children: [
28451
+ return /* @__PURE__ */ jsxs6("div", { ...props, className: (0, import_classnames7.default)(FormField_default.input, className), children: [
28446
28452
  label && /* @__PURE__ */ jsx14(Label2, { htmlFor: fieldId, children: label }),
28447
28453
  /* @__PURE__ */ jsx14(FormController, { name, control, rules, children: ({ field }) => {
28448
28454
  return Children.map(
@@ -32241,13 +32247,13 @@ var createStoreImpl = (createState) => {
32241
32247
  }
32242
32248
  };
32243
32249
  const getState = () => state;
32244
- const getInitialState = () => initialState3;
32250
+ const getInitialState = () => initialState2;
32245
32251
  const subscribe = (listener) => {
32246
32252
  listeners.add(listener);
32247
32253
  return () => listeners.delete(listener);
32248
32254
  };
32249
32255
  const api = { setState, getState, getInitialState, subscribe };
32250
- const initialState3 = state = createState(setState, getState, api);
32256
+ const initialState2 = state = createState(setState, getState, api);
32251
32257
  return api;
32252
32258
  };
32253
32259
  var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
@@ -32385,26 +32391,41 @@ function useDebounce(value, delay) {
32385
32391
  }
32386
32392
 
32387
32393
  // src/components/hooks/useTheme.ts
32388
- import { useEffect as useEffect8 } from "react";
32389
- function getDefaultTheme() {
32390
- return typeof window !== "undefined" ? window?.matchMedia("(prefers-color-scheme: dark)")?.matches ? "dark" : "light" : "light";
32391
- }
32392
- var initialState2 = {
32393
- theme: getDefaultTheme()
32394
- };
32395
- var store2 = create(() => ({ ...initialState2 }));
32396
- function setTheme(theme) {
32397
- store2.setState({ theme });
32398
- document.documentElement.setAttribute("data-theme", theme);
32394
+ import { useLayoutEffect as useLayoutEffect2 } from "react";
32395
+ function resolveTheme(preferred, colorScheme) {
32396
+ if (preferred) {
32397
+ return preferred;
32398
+ }
32399
+ if (colorScheme === "light" || colorScheme === "dark") {
32400
+ return colorScheme;
32401
+ }
32402
+ if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches) {
32403
+ return "dark";
32404
+ }
32405
+ return "light";
32399
32406
  }
32400
- function useTheme(defaultTheme) {
32401
- const { theme } = store2();
32402
- useEffect8(() => {
32403
- if (defaultTheme) {
32404
- setTheme(defaultTheme);
32407
+ var useTheme = create((set2, get2) => ({
32408
+ theme: "light",
32409
+ setTheme: (theme) => {
32410
+ set2({ theme });
32411
+ if (typeof window !== "undefined") {
32412
+ localStorage.setItem("zen.theme", theme);
32413
+ document.documentElement.setAttribute("data-theme", theme);
32405
32414
  }
32406
- }, [defaultTheme]);
32407
- return { theme, setTheme };
32415
+ },
32416
+ initTheme: (preferred, colorScheme) => {
32417
+ if (typeof window === "undefined") return;
32418
+ const stored = localStorage.getItem("zen.theme");
32419
+ const initial = resolveTheme(preferred || stored || void 0, colorScheme);
32420
+ set2({ theme: initial });
32421
+ document.documentElement.setAttribute("data-theme", initial);
32422
+ }
32423
+ }));
32424
+ function useInitTheme(preferred, colorScheme) {
32425
+ const initTheme = useTheme((s) => s.initTheme);
32426
+ useLayoutEffect2(() => {
32427
+ initTheme(preferred, colorScheme);
32428
+ }, [preferred, colorScheme, initTheme]);
32408
32429
  }
32409
32430
 
32410
32431
  // src/components/Accordion.tsx
@@ -32743,7 +32764,8 @@ var List_default = { "list": "List_list__ZTRlN", "separator": "List_separator__O
32743
32764
  // src/components/List.tsx
32744
32765
  import { Fragment as Fragment5, jsx as jsx33, jsxs as jsxs18 } from "react/jsx-runtime";
32745
32766
  function List({
32746
- items,
32767
+ id,
32768
+ items = [],
32747
32769
  idProperty = "id",
32748
32770
  labelProperty = "label",
32749
32771
  separatorProperty = "separatpr",
@@ -32766,11 +32788,13 @@ function List({
32766
32788
  onChange?.([...keys].map(String));
32767
32789
  }
32768
32790
  };
32791
+ const fieldId = useFieldId(id);
32769
32792
  return /* @__PURE__ */ jsxs18(Fragment5, { children: [
32770
- label && /* @__PURE__ */ jsx33(Label2, { children: label }),
32793
+ label && /* @__PURE__ */ jsx33(Label2, { htmlFor: fieldId, children: label }),
32771
32794
  /* @__PURE__ */ jsx33(
32772
32795
  $eed445e0843c11d0$export$41f133550aa26f48,
32773
32796
  {
32797
+ id: fieldId,
32774
32798
  "aria-label": "list",
32775
32799
  ...props,
32776
32800
  selectedKeys: value || selectedKeys,
@@ -32780,12 +32804,12 @@ function List({
32780
32804
  onSelectionChange: handleSelectionChange,
32781
32805
  style: { ...style, ...getHighlightColor(highlightColor) },
32782
32806
  children: children || items?.map((item) => {
32783
- const id = item[idProperty] || item.toString();
32807
+ const id2 = item[idProperty] || item.toString();
32784
32808
  const label2 = item[labelProperty] || item.toString();
32785
32809
  return /* @__PURE__ */ jsxs18(Fragment4, { children: [
32786
32810
  item[separatorProperty] && /* @__PURE__ */ jsx33($431f98aba6844401$export$1ff3c3f08ae963c0, { className: List_default.separator }),
32787
- /* @__PURE__ */ jsx33(ListItem, { id, className: List_default.item, children: label2 })
32788
- ] }, id);
32811
+ /* @__PURE__ */ jsx33(ListItem, { id: id2, className: List_default.item, children: label2 })
32812
+ ] }, id2);
32789
32813
  })
32790
32814
  }
32791
32815
  )
@@ -32906,7 +32930,7 @@ var import_classnames25 = __toESM(require_classnames());
32906
32930
  import { useState as useState10 } from "react";
32907
32931
 
32908
32932
  // src/components/TextField.tsx
32909
- import { useEffect as useEffect9, useState as useState9 } from "react";
32933
+ import { useEffect as useEffect8, useState as useState9 } from "react";
32910
32934
  var import_classnames24 = __toESM(require_classnames());
32911
32935
 
32912
32936
  // src/components/CopyButton.tsx
@@ -32959,7 +32983,7 @@ function TextField2({
32959
32983
  setInputValue(value2);
32960
32984
  return onChange?.(value2);
32961
32985
  };
32962
- useEffect9(() => {
32986
+ useEffect8(() => {
32963
32987
  setInputValue(value);
32964
32988
  }, [value]);
32965
32989
  return /* @__PURE__ */ jsxs20(Fragment6, { children: [
@@ -33178,7 +33202,7 @@ function Dots({ size = "md", className, ...props }) {
33178
33202
 
33179
33203
  // src/components/FloatingTooltip.tsx
33180
33204
  var import_classnames31 = __toESM(require_classnames());
33181
- import { useEffect as useEffect10, useState as useState11 } from "react";
33205
+ import { useEffect as useEffect9, useState as useState11 } from "react";
33182
33206
 
33183
33207
  // src/components/Tooltip.tsx
33184
33208
  var import_classnames30 = __toESM(require_classnames());
@@ -33205,7 +33229,7 @@ var FloatingTooltip_default = { "floating": "FloatingTooltip_floating__ZjM4N" };
33205
33229
  import { jsx as jsx45 } from "react/jsx-runtime";
33206
33230
  function FloatingTooltip({ className, style, children, ...props }) {
33207
33231
  const [position, setPosition] = useState11({ x: -1e3, y: -1e3 });
33208
- useEffect10(() => {
33232
+ useEffect9(() => {
33209
33233
  const handler = (e) => {
33210
33234
  setPosition({ x: e.clientX, y: e.clientY });
33211
33235
  };
@@ -33261,7 +33285,7 @@ function Heading2({
33261
33285
  }
33262
33286
 
33263
33287
  // src/components/HoverTrigger.tsx
33264
- import { useRef as useRef8, useState as useState12, useEffect as useEffect11 } from "react";
33288
+ import { useRef as useRef8, useState as useState12, useEffect as useEffect10 } from "react";
33265
33289
 
33266
33290
  // css-modules:E:\dev\umami-react-zen\src\components\HoverTrigger.module.css
33267
33291
  var HoverTrigger_default = { "wrapper": "HoverTrigger_wrapper__NGFlN" };
@@ -33282,7 +33306,7 @@ function HoverTrigger({
33282
33306
  const isOverMenu = useRef8(false);
33283
33307
  const isOverButton = useRef8(false);
33284
33308
  const timeout = useRef8(null);
33285
- useEffect11(() => {
33309
+ useEffect10(() => {
33286
33310
  if (isOpen !== open) {
33287
33311
  setOpen(isOpen);
33288
33312
  }
@@ -33762,7 +33786,7 @@ function Radio2({ children, className, ...props }) {
33762
33786
  }
33763
33787
 
33764
33788
  // src/components/SearchField.tsx
33765
- import { useState as useState17, useEffect as useEffect12 } from "react";
33789
+ import { useState as useState17, useEffect as useEffect11 } from "react";
33766
33790
  var import_classnames45 = __toESM(require_classnames());
33767
33791
  import { Fragment as Fragment12, jsx as jsx60, jsxs as jsxs35 } from "react/jsx-runtime";
33768
33792
  function SearchField2({
@@ -33790,7 +33814,7 @@ function SearchField2({
33790
33814
  onSearch?.("");
33791
33815
  onChange?.("");
33792
33816
  };
33793
- useEffect12(() => {
33817
+ useEffect11(() => {
33794
33818
  if (delay > 0) {
33795
33819
  onSearch?.(searchValue);
33796
33820
  }
@@ -34091,14 +34115,8 @@ var ThemeButton_default = { "button": "ThemeButton_button__MDUzN" };
34091
34115
 
34092
34116
  // src/components/ThemeButton.tsx
34093
34117
  import { jsx as jsx67, jsxs as jsxs41 } from "react/jsx-runtime";
34094
- function ThemeButton({
34095
- className,
34096
- variant = "quiet",
34097
- defaultTheme,
34098
- onPress,
34099
- ...props
34100
- }) {
34101
- const { theme, setTheme: setTheme2 } = useTheme(defaultTheme);
34118
+ function ThemeButton({ className, variant = "quiet", onPress, ...props }) {
34119
+ const { theme, setTheme } = useTheme();
34102
34120
  const transitions = useTransition(theme, {
34103
34121
  initial: { opacity: 1 },
34104
34122
  from: {
@@ -34112,7 +34130,7 @@ function ThemeButton({
34112
34130
  }
34113
34131
  });
34114
34132
  function handleClick(e) {
34115
- setTheme2(theme === "light" ? "dark" : "light");
34133
+ setTheme(theme === "light" ? "dark" : "light");
34116
34134
  onPress?.(e);
34117
34135
  }
34118
34136
  return /* @__PURE__ */ jsxs41(
@@ -34205,11 +34223,16 @@ function ToggleGroupItem({ className, children, ...props }) {
34205
34223
 
34206
34224
  // src/components/ZenProvider.tsx
34207
34225
  import { jsx as jsx70 } from "react/jsx-runtime";
34208
- var defaultToastCofig = {
34226
+ var defaultToastConfig = {
34209
34227
  duration: 3e3
34210
34228
  };
34211
- function ZenProvider({ children, ...props }) {
34212
- const { toast = defaultToastCofig } = props;
34229
+ function ZenProvider({
34230
+ children,
34231
+ theme,
34232
+ colorScheme,
34233
+ toast = defaultToastConfig
34234
+ }) {
34235
+ useInitTheme(theme, colorScheme);
34213
34236
  return /* @__PURE__ */ jsx70(ToastProvider, { ...toast, children });
34214
34237
  }
34215
34238
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umami/react-zen",
3
- "version": "0.181.0",
3
+ "version": "0.183.0",
4
4
  "description": "Modern, minimalist React component library",
5
5
  "author": "Umami <hello@umami.is>",
6
6
  "license": "MIT",