@arcgis/components-utils 4.34.0-next.3 → 4.34.0-next.31

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/dom.d.cts CHANGED
@@ -63,3 +63,13 @@ export declare const focusElement: (el: FocusableElement | undefined) => Promise
63
63
  export declare const setFocusOnElement: (ref: (Element & {
64
64
  componentOnReady?: () => Promise<void>;
65
65
  }) | null | undefined, selector: string) => void;
66
+ /**
67
+ * This helper returns the Calcite "mode" of an element.
68
+ *
69
+ * **DISCLAIMER**: It is advised to consider alternative solutions before using this utility:
70
+ * - Calcite CSS variables. Benefits: makes styles more consistent, and variables are updated automatically to match dark/light theme.
71
+ * - Detect dark mode using CSS selectors and apply styles in CSS. Benefit: styles update automatically when the theme changes.
72
+ *
73
+ * @param {HTMLElement} el An element.
74
+ */
75
+ export declare function unsafeGetModeName(el: HTMLElement): "dark" | "light";
package/dist/dom.d.ts CHANGED
@@ -63,3 +63,13 @@ export declare const focusElement: (el: FocusableElement | undefined) => Promise
63
63
  export declare const setFocusOnElement: (ref: (Element & {
64
64
  componentOnReady?: () => Promise<void>;
65
65
  }) | null | undefined, selector: string) => void;
66
+ /**
67
+ * This helper returns the Calcite "mode" of an element.
68
+ *
69
+ * **DISCLAIMER**: It is advised to consider alternative solutions before using this utility:
70
+ * - Calcite CSS variables. Benefits: makes styles more consistent, and variables are updated automatically to match dark/light theme.
71
+ * - Detect dark mode using CSS selectors and apply styles in CSS. Benefit: styles update automatically when the theme changes.
72
+ *
73
+ * @param {HTMLElement} el An element.
74
+ */
75
+ export declare function unsafeGetModeName(el: HTMLElement): "dark" | "light";
package/dist/index.cjs CHANGED
@@ -168,6 +168,10 @@ const setFocusOnElement = (ref, selector) => {
168
168
  }
169
169
  void Promise.resolve(ref.componentOnReady?.()).then(() => setFocus(ref, selector));
170
170
  };
171
+ function unsafeGetModeName(el) {
172
+ const closestElWithMode = closestElement(el, `.calcite-mode-dark, .calcite-mode-light, .calcite-mode-auto`);
173
+ return closestElWithMode?.classList.contains("calcite-mode-dark") || closestElWithMode?.classList.contains("calcite-mode-auto") && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
174
+ }
171
175
  const isEsriInternalEnv = () => (
172
176
  /*
173
177
  * `globalThis.` is important here. Some bundlers remove the `typeof process`
@@ -431,3 +435,4 @@ exports.setValuesInString = setValuesInString;
431
435
  exports.startLocaleObserver = startLocaleObserver;
432
436
  exports.supportedLocales = supportedLocales;
433
437
  exports.uncapitalize = uncapitalize;
438
+ exports.unsafeGetModeName = unsafeGetModeName;
package/dist/index.js CHANGED
@@ -166,6 +166,10 @@ const setFocusOnElement = (ref, selector) => {
166
166
  }
167
167
  void Promise.resolve(ref.componentOnReady?.()).then(() => setFocus(ref, selector));
168
168
  };
169
+ function unsafeGetModeName(el) {
170
+ const closestElWithMode = closestElement(el, `.calcite-mode-dark, .calcite-mode-light, .calcite-mode-auto`);
171
+ return closestElWithMode?.classList.contains("calcite-mode-dark") || closestElWithMode?.classList.contains("calcite-mode-auto") && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
172
+ }
169
173
  const isEsriInternalEnv = () => (
170
174
  /*
171
175
  * `globalThis.` is important here. Some bundlers remove the `typeof process`
@@ -429,5 +433,6 @@ export {
429
433
  setValuesInString,
430
434
  startLocaleObserver,
431
435
  supportedLocales,
432
- uncapitalize
436
+ uncapitalize,
437
+ unsafeGetModeName
433
438
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/components-utils",
3
- "version": "4.34.0-next.3",
3
+ "version": "4.34.0-next.31",
4
4
  "description": "Collection of common internal patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "sideEffects": false,