UNPKG

@easyx.ai/dumi-theme-easyxai

Version:

@easyx.ai/dumi-theme-easyxai 是为 dumi2 打造的一款文档站主题包,提供了更加美观、易用的研发与阅读体验

105 lines 4.73 kB
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["value", "onChange", "options", "className", "style"]; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } import { memo } from 'react'; import { Flexbox } from 'react-layout-kit'; import NativeSelect from "../NativeSelect"; import { jsx as _jsx } from "react/jsx-runtime"; import { jsxs as _jsxs } from "react/jsx-runtime"; var IconDark = function IconDark() { return /*#__PURE__*/_jsx("svg", { viewBox: "0 0 16 16", width: "1em", height: "1em", fill: "currentColor", children: /*#__PURE__*/_jsx("path", { d: "M8.218 1.455c3.527.109 6.327 3.018 6.327 6.545 0 3.6-2.945 6.545-6.545 6.545a6.562 6.562 0 0 1-6.036-4h.218c3.6 0 6.545-2.945 6.545-6.545 0-.91-.182-1.745-.509-2.545m0-1.455c-.473 0-.909.218-1.2.618-.29.4-.327.946-.145 1.382.254.655.4 1.31.4 2 0 2.8-2.291 5.09-5.091 5.09h-.218c-.473 0-.91.22-1.2.62-.291.4-.328.945-.146 1.38C1.891 14.074 4.764 16 8 16c4.4 0 8-3.6 8-8a7.972 7.972 0 0 0-7.745-8h-.037Z" }) }); }; var IconLight = function IconLight() { return /*#__PURE__*/_jsx("svg", { viewBox: "0 0 16 16", width: "1em", height: "1em", fill: "currentColor", children: /*#__PURE__*/_jsx("path", { d: "M8 13a1 1 0 0 1 1 1v1a1 1 0 1 1-2 0v-1a1 1 0 0 1 1-1ZM8 3a1 1 0 0 1-1-1V1a1 1 0 1 1 2 0v1a1 1 0 0 1-1 1Zm7 4a1 1 0 1 1 0 2h-1a1 1 0 1 1 0-2h1ZM3 8a1 1 0 0 1-1 1H1a1 1 0 1 1 0-2h1a1 1 0 0 1 1 1Zm9.95 3.536.707.707a1 1 0 0 1-1.414 1.414l-.707-.707a1 1 0 0 1 1.414-1.414Zm-9.9-7.072-.707-.707a1 1 0 0 1 1.414-1.414l.707.707A1 1 0 0 1 3.05 4.464Zm9.9 0a1 1 0 0 1-1.414-1.414l.707-.707a1 1 0 0 1 1.414 1.414l-.707.707Zm-9.9 7.072a1 1 0 0 1 1.414 1.414l-.707.707a1 1 0 0 1-1.414-1.414l.707-.707ZM8 4a4 4 0 1 0 0 8 4 4 0 0 0 0-8Zm0 6.5a2.5 2.5 0 1 1 0-5 2.5 2.5 0 0 1 0 5Z" }) }); }; var IconAuto = function IconAuto() { return /*#__PURE__*/_jsx("svg", { viewBox: "0 0 16 16", width: "1em", height: "1em", fill: "currentColor", children: /*#__PURE__*/_jsx("path", { d: "M14.595 8a6.595 6.595 0 1 1-13.19 0 6.595 6.595 0 0 1 13.19 0ZM8 0a8 8 0 1 0 0 16A8 8 0 0 0 8 0Zm0 2.014v11.972A5.986 5.986 0 0 0 8 2.014Z" }) }); }; var Option = function Option(_ref) { var icon = _ref.icon, label = _ref.label; return /*#__PURE__*/_jsxs(Flexbox, { horizontal: true, gap: 12, align: 'center', children: [/*#__PURE__*/_jsxs("span", { style: { width: 12 }, children: [icon, " "] }), label] }); }; var defaultOptions = [{ label: '跟随系统', icon: /*#__PURE__*/_jsx(IconAuto, {}), value: 'auto' }, { label: '亮色模式', icon: /*#__PURE__*/_jsx(IconLight, {}), value: 'light' }, { label: '暗色模式', icon: /*#__PURE__*/_jsx(IconDark, {}), value: 'dark' }]; var ThemeSwitch = function ThemeSwitch(_ref2) { var value = _ref2.value, _onChange = _ref2.onChange, _ref2$options = _ref2.options, options = _ref2$options === void 0 ? defaultOptions : _ref2$options, className = _ref2.className, style = _ref2.style, props = _objectWithoutProperties(_ref2, _excluded); return /*#__PURE__*/_jsx("span", _objectSpread(_objectSpread({}, props), {}, { children: /*#__PURE__*/_jsx(NativeSelect, { options: options, value: options.findIndex(function (o) { return o.value === value; }), onChange: function onChange(index) { var mode = options[index].value; _onChange(mode); }, renderValue: function renderValue(index) { var _options$index; return (_options$index = options[index]) === null || _options$index === void 0 ? void 0 : _options$index.icon; }, renderItem: function renderItem(item) { return item && /*#__PURE__*/_jsx(Option, { label: item.label, icon: item.icon }); }, className: className, style: style }) })); }; export default /*#__PURE__*/memo(ThemeSwitch);