@easyv/react-components 0.0.32 → 0.0.34

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.
@@ -4,15 +4,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
4
4
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
5
  function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
6
  function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
- import React, { forwardRef } from 'react';
7
+ import { forwardRef } from 'react';
8
8
  import { Menu } from '@arco-design/web-react';
9
9
  import { DownOutlined, RightOutlined } from '@easyv/react-icons';
10
10
  import "./index.less";
11
+ import { useTheme } from "../hooks/useTheme";
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  var XMenu = /*#__PURE__*/forwardRef(function (props, ref) {
14
+ var theme = useTheme();
13
15
  return /*#__PURE__*/_jsx(Menu, _objectSpread(_objectSpread({
14
16
  ref: ref
15
17
  }, props), {}, {
18
+ theme: theme,
16
19
  icons: {
17
20
  horizontalArrowDown: /*#__PURE__*/_jsx(DownOutlined, {
18
21
  style: {
@@ -1,2 +1,3 @@
1
1
  export * from "./useClickOutside";
2
- export * from "./useEventListener";
2
+ export * from "./useEventListener";
3
+ export * from "./useTheme";
@@ -0,0 +1 @@
1
+ export declare function useTheme(): "light" | "dark";
@@ -0,0 +1,41 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useState } from 'react';
8
+ import { getTheme } from "../util/util";
9
+ export function useTheme() {
10
+ var _useState = useState(getTheme()),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ theme = _useState2[0],
13
+ setTheme = _useState2[1];
14
+ useEffect(function () {
15
+ setTheme(getTheme());
16
+ }, []);
17
+ useEffect(function () {
18
+ var observer = new MutationObserver(function (mutationsList) {
19
+ mutationsList.forEach(function (mutation) {
20
+ if (mutation.type === 'attributes' && mutation.attributeName === 'arco-theme') {
21
+ // 处理属性变化的逻辑
22
+ var newTheme = mutation.target.getAttribute('arco-theme');
23
+ if (newTheme && ['light', 'dark'].includes(newTheme)) {
24
+ setTheme(newTheme);
25
+ }
26
+ }
27
+ });
28
+ });
29
+ var bodyElement = document.querySelector('body');
30
+ var config = {
31
+ attributes: true
32
+ };
33
+ if (bodyElement) {
34
+ observer.observe(bodyElement, config);
35
+ }
36
+ return function () {
37
+ observer.disconnect();
38
+ };
39
+ }, []);
40
+ return theme;
41
+ }
@@ -0,0 +1 @@
1
+ export declare function getTheme(): 'light' | 'dark';
@@ -0,0 +1,5 @@
1
+ export function getTheme() {
2
+ var _document$body$attrib;
3
+ var theme = typeof document !== 'undefined' ? ((_document$body$attrib = document.body.attributes['arco-theme']) === null || _document$body$attrib === void 0 ? void 0 : _document$body$attrib.value) || 'light' : 'light';
4
+ return ['light', 'dark'].includes(theme) ? theme : 'light';
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easyv/react-components",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "description": "a react component library base on arco design",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -1,17 +0,0 @@
1
- import React from 'react';
2
- import type { MenuProps } from './interface';
3
- import './index.less';
4
- declare const XMenu: React.ForwardRefExoticComponent<MenuProps & React.RefAttributes<unknown>> & {
5
- Item: React.ForwardRefExoticComponent<import("@arco-design/web-react").MenuItemProps & React.RefAttributes<unknown>> & {
6
- menuType: string;
7
- };
8
- ItemGroup: React.ForwardRefExoticComponent<import("@arco-design/web-react").MenuItemGroupProps & React.RefAttributes<unknown>> & {
9
- menuType: string;
10
- };
11
- SubMenu: React.ForwardRefExoticComponent<import("@arco-design/web-react").MenuSubMenuProps & React.RefAttributes<unknown>> & {
12
- menuType: string;
13
- };
14
- __ARCO_MENU__: boolean;
15
- };
16
- export default XMenu;
17
- export { MenuProps };
@@ -1,2 +0,0 @@
1
- export * from './useClickOutside';
2
- export * from './useEventListener';