@blocklet/pages-kit 0.6.99 → 0.6.100
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/lib/cjs/builtin/color-picker.js +7 -2
- package/lib/cjs/contexts/color.js +22 -3
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/common.js +1 -1
- package/lib/cjs/utils/style.js +16 -2
- package/lib/esm/builtin/color-picker.js +8 -3
- package/lib/esm/contexts/color.js +22 -4
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/common.js +1 -1
- package/lib/esm/utils/style.js +14 -1
- package/lib/types/contexts/color.d.ts +13 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/style.d.ts +5 -0
- package/package.json +2 -2
package/lib/cjs/utils/common.js
CHANGED
|
@@ -13,7 +13,7 @@ exports.isBrowserEnv = isBrowserEnv;
|
|
|
13
13
|
*/
|
|
14
14
|
function isMuiColorKey(value) {
|
|
15
15
|
// special case
|
|
16
|
-
if (value === 'transparent' || value === 'divider') {
|
|
16
|
+
if (value === 'transparent' || value === 'divider' || value === 'auto') {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
19
|
return /^(primary|secondary|error|warning|info|success|grey|background|text|action|common)\.[a-zA-Z0-9]+$/.test(value);
|
package/lib/cjs/utils/style.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isMuiColorKey = void 0;
|
|
6
|
+
exports.isMuiColorKey = exports.gradientFromPrimary = void 0;
|
|
7
7
|
exports.isGradient = isGradient;
|
|
8
8
|
exports.isColorString = isColorString;
|
|
9
9
|
exports.getSafeGradient = getSafeGradient;
|
|
@@ -51,7 +51,7 @@ function isColorString(color) {
|
|
|
51
51
|
if (typeof color !== 'string') {
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
|
-
if (isGradient(color)) {
|
|
54
|
+
if (isGradient(color) || color === 'auto') {
|
|
55
55
|
return true;
|
|
56
56
|
}
|
|
57
57
|
const currentColor = (0, tinycolor2_1.default)(color);
|
|
@@ -141,6 +141,20 @@ function parseColor(color = '') {
|
|
|
141
141
|
}
|
|
142
142
|
return color;
|
|
143
143
|
}
|
|
144
|
+
const gradientFromPrimary = (opts = {}) => (theme) => {
|
|
145
|
+
const { angle = '135deg', hueShift = 35 } = opts;
|
|
146
|
+
// 取 primary.main -> HSL(tinycolor 的 s/l 为 0~1)
|
|
147
|
+
const base = (0, tinycolor2_1.default)(theme.palette.primary.main).toHsl();
|
|
148
|
+
const clampHue = (h) => ((h % 360) + 360) % 360;
|
|
149
|
+
const h1 = clampHue(base.h);
|
|
150
|
+
const h2 = clampHue(base.h - hueShift);
|
|
151
|
+
const alpha = theme.palette.mode === 'light' ? 0.12 : 0.24;
|
|
152
|
+
// 生成两端色(只改 H,S/L 不变;统一用目标 alpha)
|
|
153
|
+
const c1 = (0, tinycolor2_1.default)({ h: h1, s: base.s, l: base.l, a: alpha }).toHslString(); // hsla(h, s%, l%, a)
|
|
154
|
+
const c2 = (0, tinycolor2_1.default)({ h: h2, s: base.s, l: base.l, a: alpha }).toHslString();
|
|
155
|
+
return `linear-gradient(${angle}, ${c1} 0%, ${c2} 100%)`;
|
|
156
|
+
};
|
|
157
|
+
exports.gradientFromPrimary = gradientFromPrimary;
|
|
144
158
|
/**
|
|
145
159
|
* 转换颜色
|
|
146
160
|
* @param color - 颜色字符串
|
|
@@ -5,7 +5,7 @@ import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, ButtonG
|
|
|
5
5
|
import { useBoolean, useLocalStorageState, useReactive } from 'ahooks';
|
|
6
6
|
import { Suspense, lazy, useCallback, useImperativeHandle, useRef } from 'react';
|
|
7
7
|
import tinycolor from 'tinycolor2';
|
|
8
|
-
import { useMuiColorPalette } from '../contexts/color';
|
|
8
|
+
import { useBackgroundColorStyle, useMuiColorPalette } from '../contexts/color';
|
|
9
9
|
import { isColorString, isGradient, getSafeGradient, getTransparentBackground } from '../utils/style';
|
|
10
10
|
const ColorPickerLib = lazy(() => import('react-best-gradient-color-picker'));
|
|
11
11
|
const HEIGHT = 400;
|
|
@@ -123,6 +123,7 @@ export function ColorItem({ color, sx = {}, ...props }) {
|
|
|
123
123
|
const MuiThemeTab = ({ value, onChange, }) => {
|
|
124
124
|
const { t } = useLocaleContext();
|
|
125
125
|
const muiPalette = useMuiColorPalette();
|
|
126
|
+
const { getBackgroundColorStyle } = useBackgroundColorStyle();
|
|
126
127
|
const mode = muiPalette?.theme?.palette?.mode;
|
|
127
128
|
const isDark = mode === 'dark';
|
|
128
129
|
const { groupedMuiColors } = muiPalette;
|
|
@@ -139,6 +140,9 @@ const MuiThemeTab = ({ value, onChange, }) => {
|
|
|
139
140
|
selectedColor = 'rgba(0,0,0,0.7)';
|
|
140
141
|
}
|
|
141
142
|
}
|
|
143
|
+
else if (item.colorKey === 'auto') {
|
|
144
|
+
selectedColor = 'rgba(0,0,0,0.7)';
|
|
145
|
+
}
|
|
142
146
|
// 是否有另一种模式的颜色值
|
|
143
147
|
const hasAlternateColor = !!item.alternateColorValue;
|
|
144
148
|
return (_jsx(Tooltip, { title: `${item.colorKey}${hasAlternateColor ? t('maker.configColorMuiThemeWithAlternateColor') : ''}`, sx: {
|
|
@@ -170,7 +174,7 @@ const MuiThemeTab = ({ value, onChange, }) => {
|
|
|
170
174
|
left: 0,
|
|
171
175
|
...(item.colorValue === 'transparent'
|
|
172
176
|
? { background: getTransparentBackground() }
|
|
173
|
-
:
|
|
177
|
+
: getBackgroundColorStyle(item.colorValue)),
|
|
174
178
|
} }), hasAlternateColor && _jsx(AlternateColorIndicator, { value: item.alternateColorValue }), value?.originalMuiKey === item.colorKey && (_jsx("i", { className: "i-mdi:check", style: {
|
|
175
179
|
color: selectedColor,
|
|
176
180
|
fontSize: '1.2rem',
|
|
@@ -204,6 +208,7 @@ export const ConfigColorDialog = function ConfigColorDialog({ ref, onSave, enabl
|
|
|
204
208
|
defaultValue: 0,
|
|
205
209
|
});
|
|
206
210
|
const muiPalette = useMuiColorPalette();
|
|
211
|
+
const { getBackgroundColorStyle } = useBackgroundColorStyle();
|
|
207
212
|
const mode = muiPalette?.theme?.palette?.mode;
|
|
208
213
|
const isDark = mode === 'dark';
|
|
209
214
|
// Create default tabs
|
|
@@ -241,7 +246,7 @@ export const ConfigColorDialog = function ConfigColorDialog({ ref, onSave, enabl
|
|
|
241
246
|
previewStyle.backgroundImage = state.value;
|
|
242
247
|
}
|
|
243
248
|
else {
|
|
244
|
-
previewStyle
|
|
249
|
+
Object.assign(previewStyle, getBackgroundColorStyle(state.value));
|
|
245
250
|
}
|
|
246
251
|
}
|
|
247
252
|
else {
|
|
@@ -2,7 +2,7 @@ import { createTheme } from '@arcblock/ux/lib/Theme';
|
|
|
2
2
|
import { useTheme } from '@mui/material/styles';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { useCallback, useMemo } from 'react';
|
|
5
|
-
import { isMuiColorKey, colorConvert } from '../utils/style';
|
|
5
|
+
import { isMuiColorKey, colorConvert, gradientFromPrimary, isGradient } from '../utils/style';
|
|
6
6
|
/**
|
|
7
7
|
* Hook 用于获取和操作 MUI 主题色
|
|
8
8
|
*/
|
|
@@ -23,10 +23,10 @@ export function useMuiColorPalette() {
|
|
|
23
23
|
// 特殊颜色组
|
|
24
24
|
{
|
|
25
25
|
type: 'special',
|
|
26
|
-
keys: ['transparent'],
|
|
26
|
+
keys: ['transparent', 'auto'],
|
|
27
27
|
variants: null,
|
|
28
|
-
format: () =>
|
|
29
|
-
accessor: () => ({
|
|
28
|
+
format: (key) => key,
|
|
29
|
+
accessor: (key) => ({ [key]: key }),
|
|
30
30
|
},
|
|
31
31
|
// common 颜色
|
|
32
32
|
{
|
|
@@ -184,3 +184,21 @@ export function useColorConvert() {
|
|
|
184
184
|
return colorConvert(color, theme);
|
|
185
185
|
}, [theme, colorConvert]);
|
|
186
186
|
}
|
|
187
|
+
export function useBackgroundColorStyle() {
|
|
188
|
+
const getBackgroundColor = useCallback((color = '') => {
|
|
189
|
+
if (color === 'auto') {
|
|
190
|
+
return gradientFromPrimary();
|
|
191
|
+
}
|
|
192
|
+
return color;
|
|
193
|
+
}, []);
|
|
194
|
+
const getBackgroundColorStyle = useCallback((color = '') => {
|
|
195
|
+
if (color === 'auto') {
|
|
196
|
+
return { backgroundImage: gradientFromPrimary() };
|
|
197
|
+
}
|
|
198
|
+
if (isGradient(color)) {
|
|
199
|
+
return { backgroundImage: color };
|
|
200
|
+
}
|
|
201
|
+
return { bgcolor: color };
|
|
202
|
+
}, []);
|
|
203
|
+
return { getBackgroundColorStyle, getBackgroundColor };
|
|
204
|
+
}
|