Skip to content

Commit 37cd8cf

Browse files
committed
feat(components): 添加通知弹出位置的设置项
1 parent bfdc0f2 commit 37cd8cf

10 files changed

Lines changed: 177 additions & 64 deletions

File tree

apps/docs/src/components/demo/config/options/api.zh-Hans.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@
4646
"type": "\"system\" | \"dark\" | \"light\" | undefined",
4747
"def": "'system'\n\n"
4848
},
49+
{
50+
"name": "palette",
51+
"summary": "默认的主题调色板,当在\n`config`\n中存在时,当前值将被忽略。\n\n",
52+
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"error\" | \"surface\" | undefined",
53+
"def": "'surface'\n\n"
54+
},
4955
{
5056
"name": "transitionDuration",
5157
"summary": "动画效果的时长,单位为 ms。当在\n`config`\n中存在时,当前值将被忽略。\n\n",

apps/docs/src/components/demo/notify/notify.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function (): JSX.Element {
2121
<>
2222
<div class="flex w-40 flex-col gap-2">
2323
<Choice
24+
closable
2425
placeholder="type"
2526
value={typ()}
2627
onChange={setTyp}
@@ -33,6 +34,7 @@ export default function (): JSX.Element {
3334
placeholder="position"
3435
value={pos()}
3536
onChange={setPos}
37+
closable
3638
options={Notify.positions.map(v => {
3739
return { type: 'item', value: v, label: v };
3840
})}

apps/docs/src/components/demo/wizard/tour/api.zh-Hans.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
{
1212
"name": "accentPalette",
1313
"summary": "突出元素的色盘\n\n",
14-
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"error\" | \"surface\" | undefined"
14+
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"error\" | \"surface\" | undefined",
15+
"reactive": true
1516
},
1617
{
1718
"name": "start",

apps/docs/src/docs/usage/api.zh-Hans.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,47 @@
2121
"type": "void"
2222
},
2323
"pkg": "@cmfx/core"
24+
},
25+
{
26+
"kind": "function",
27+
"name": "palette",
28+
"summary": "获取当前元素所属的色盘\n\n",
29+
"type": "function palette(elem: HTMLElement, next?: number): Palette | undefined",
30+
"params": [
31+
{
32+
"name": "elem",
33+
"summary": "查询的元素;\n\n",
34+
"type": "HTMLElement"
35+
},
36+
{
37+
"name": "next",
38+
"summary": "如果指定了该值,则表示当前色盘往后移动的数量;\n\n",
39+
"type": "number | undefined"
40+
}
41+
],
42+
"return": {
43+
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"error\" | \"surface\" | undefined"
44+
},
45+
"pkg": "@cmfx/themes"
46+
},
47+
{
48+
"kind": "function",
49+
"name": "nextPalette",
50+
"summary": "计算色盘 p 之后 next 的色盘\n\n",
51+
"type": "function nextPalette(p: Palette, next?: number): Palette",
52+
"params": [
53+
{
54+
"name": "p",
55+
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"error\" | \"surface\""
56+
},
57+
{
58+
"name": "next",
59+
"type": "number | undefined"
60+
}
61+
],
62+
"return": {
63+
"type": "\"primary\" | \"secondary\" | \"tertiary\" | \"error\" | \"surface\""
64+
},
65+
"pkg": "@cmfx/themes"
2466
}
2567
]

packages/components/src/context/options/context.tsx

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ import { createContext, type JSX, type ParentProps, splitProps, useContext } fro
88
import { createStore } from 'solid-js/store';
99

1010
import { LocaleProvider } from '@components/context/locale';
11-
import type { ReqOptions } from './options';
12-
13-
const localeKey = 'locale';
14-
const displayStyleKey = 'display-style';
15-
const schemeKey = 'scheme';
16-
const modeKey = 'mode';
17-
const tzKey = 'timezone';
18-
const staysKey = 'stays';
19-
const fontSizeKey = 'font-size';
20-
const transitionDurationKey = 'transition-duration';
11+
import type { ConfigurableOptions, NotifyPosition, ReqOptions } from './options';
12+
13+
const keys: Record<keyof ConfigurableOptions, string> = {
14+
fontSize: 'font-size',
15+
scheme: 'scheme',
16+
mode: 'mode',
17+
transitionDuration: 'transition-duration',
18+
locale: 'locale',
19+
displayStyle: 'display-style',
20+
timezone: 'timezone',
21+
stays: 'stays',
22+
notifyPosition: 'notify-position',
23+
} as const;
2124

2225
/**
2326
* 提供了对全局配置的存取功能
@@ -83,19 +86,21 @@ export function buildAccessor(o: ReqOptions) {
8386
stays: o.stays,
8487
fontSize: o.fontSize,
8588
transitionDuration: o.transitionDuration,
89+
notifyPosition: o.notifyPosition,
8690
});
8791

8892
const read = () => {
8993
// 从配置内容中读取
9094
set({
91-
scheme: conf.get(schemeKey) ?? val.scheme,
92-
mode: conf.get(modeKey) ?? val.mode,
93-
locale: conf.get(localeKey) ?? val.locale,
94-
displayStyle: conf.get(displayStyleKey) ?? val.displayStyle,
95-
timezone: conf.get(tzKey) ?? val.timezone,
96-
stays: conf.get(staysKey) ?? val.stays,
97-
fontSize: conf.get(fontSizeKey) ?? val.fontSize,
98-
transitionDuration: conf.get(transitionDurationKey) ?? val.transitionDuration,
95+
scheme: conf.get(keys.scheme) ?? val.scheme,
96+
mode: conf.get(keys.mode) ?? val.mode,
97+
locale: conf.get(keys.locale) ?? val.locale,
98+
displayStyle: conf.get(keys.displayStyle) ?? val.displayStyle,
99+
timezone: conf.get(keys.timezone) ?? val.timezone,
100+
stays: conf.get(keys.stays) ?? val.stays,
101+
fontSize: conf.get(keys.fontSize) ?? val.fontSize,
102+
transitionDuration: conf.get(keys.transitionDuration) ?? val.transitionDuration,
103+
notifyPosition: conf.get(keys.notifyPosition) ?? val.notifyPosition,
99104
});
100105

101106
if (val.fontSize !== document.documentElement.style.fontSize) {
@@ -150,7 +155,7 @@ export function buildAccessor(o: ReqOptions) {
150155
*/
151156
setFontSize(size: string): void {
152157
set({ fontSize: size });
153-
conf.set(fontSizeKey, size);
158+
conf.set(keys.fontSize, size);
154159
document.documentElement.style.fontSize = size;
155160
},
156161

@@ -163,7 +168,7 @@ export function buildAccessor(o: ReqOptions) {
163168
*/
164169
setTransitionDuration(duration: number): void {
165170
set({ transitionDuration: duration });
166-
conf.set(transitionDurationKey, duration);
171+
conf.set(keys.transitionDuration, duration);
167172
document.documentElement.style.setProperty('--default-transition-duration', `${duration}ms`);
168173
},
169174

@@ -178,7 +183,7 @@ export function buildAccessor(o: ReqOptions) {
178183
*/
179184
setLocale(id: string): void {
180185
set({ locale: id });
181-
conf.set(localeKey, id);
186+
conf.set(keys.locale, id);
182187
document.documentElement.lang = id;
183188
},
184189

@@ -191,7 +196,7 @@ export function buildAccessor(o: ReqOptions) {
191196
*/
192197
setDisplayStyle(style: DisplayStyle): void {
193198
set({ displayStyle: style });
194-
conf.set(displayStyleKey, style);
199+
conf.set(keys.displayStyle, style);
195200
},
196201

197202
getDisplayStyle(): DisplayStyle {
@@ -203,7 +208,7 @@ export function buildAccessor(o: ReqOptions) {
203208
*/
204209
setTimezone(tz: string): void {
205210
set({ timezone: tz });
206-
conf.set(tzKey, tz);
211+
conf.set(keys.timezone, tz);
207212
},
208213

209214
getTimezone(): string {
@@ -223,7 +228,7 @@ export function buildAccessor(o: ReqOptions) {
223228
}
224229

225230
set({ scheme: s });
226-
conf.set(schemeKey, s);
231+
conf.set(keys.scheme, s);
227232
},
228233

229234
getScheme(): Scheme {
@@ -235,7 +240,7 @@ export function buildAccessor(o: ReqOptions) {
235240
*/
236241
setMode(mode: Mode): void {
237242
set({ mode: mode });
238-
conf.set(modeKey, mode);
243+
conf.set(keys.mode, mode);
239244
},
240245

241246
getMode(): Mode {
@@ -247,13 +252,25 @@ export function buildAccessor(o: ReqOptions) {
247252
*/
248253
setStays(stay: number): void {
249254
set({ stays: stay });
250-
conf.set(staysKey, stay);
255+
conf.set(keys.stays, stay);
251256
},
252257

253258
getStays(): number {
254259
return val.stays;
255260
},
256261

262+
/**
263+
* 设置当前配置中通知的显示位置
264+
*/
265+
setNotifyPosition(position: NotifyPosition): void {
266+
set({ notifyPosition: position });
267+
conf.set(keys.notifyPosition, position);
268+
},
269+
270+
getNotifyPosition(): NotifyPosition {
271+
return val.notifyPosition;
272+
},
273+
257274
/**
258275
* 清除当前用户的配置
259276
*/

packages/components/src/context/options/options.tsx

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,14 @@ import { default as IconLoading } from '~icons/cmfx/loading';
1111
import { handleProblem, type ProblemHandler } from './problem';
1212
import styles from './style.module.css';
1313

14-
/**
15-
* 组件库的全局配置项
16-
*/
17-
export interface Options {
18-
/**
19-
* 提供用于保存配置项到 {@link Storage} 对象的接口
20-
*/
21-
config: Config;
22-
23-
/**
24-
* 项目的 LOGO
25-
*/
26-
logo: string;
14+
export const notifyPositions = ['top', 'bottom'] as const;
2715

28-
/**
29-
* 表示加载状态的组件
30-
*
31-
* @remarks
32-
* 在页面未加载完成之前会显示此组件的内容。一般为一个动态的图标组件。
33-
*
34-
* @defaultValue `~icons/cmfx/loading`
35-
*/
36-
loading?: Component<ThemeProps>;
16+
export type NotifyPosition = (typeof notifyPositions)[number];
3717

18+
/**
19+
* 可配置的配置项
20+
*/
21+
export interface ConfigurableOptions {
3822
/**
3923
* 字体大小,当在 {@link config} 中存在时,当前值将被忽略。
4024
*/
@@ -50,16 +34,6 @@ export interface Options {
5034
*/
5135
scheme?: string | Scheme;
5236

53-
/**
54-
* 支持的主题列表
55-
*
56-
* @remarks
57-
* {@link ../theme/schemes#schemes} 下定义部分主题可以直接在此处使用。
58-
*
59-
* @defaultValue `new Map()`
60-
*/
61-
schemes?: Map<string, Scheme>;
62-
6337
/**
6438
* 默认的主题模式,当在 {@link config} 中存在时,当前值将被忽略。
6539
*
@@ -102,6 +76,48 @@ export interface Options {
10276
*/
10377
stays?: number;
10478

79+
/**
80+
* 通知的显示位置
81+
*
82+
* @defaultValue 'top'
83+
*/
84+
notifyPosition?: NotifyPosition;
85+
}
86+
87+
/**
88+
* 组件库的全局配置项
89+
*/
90+
export interface Options extends ConfigurableOptions {
91+
/**
92+
* 提供用于保存配置项到 {@link Storage} 对象的接口
93+
*/
94+
config: Config;
95+
96+
/**
97+
* 项目的 LOGO
98+
*/
99+
logo: string;
100+
101+
/**
102+
* 表示加载状态的组件
103+
*
104+
* @remarks
105+
* 在页面未加载完成之前会显示此组件的内容。一般为一个动态的图标组件。
106+
*
107+
* @defaultValue `~icons/cmfx/loading`
108+
*/
109+
loading?: Component<ThemeProps>;
110+
111+
/**
112+
* 支持的主题列表
113+
*
114+
* @remarks
115+
* {@link ../theme/schemes#schemes} 下定义部分主题可以直接在此处使用。
116+
*
117+
* @defaultValue `new Map()`
118+
*/
119+
schemes?: Map<string, Scheme>;
120+
105121
/**
106122
* 当前支持的语言列表以及加载方法
107123
*/
@@ -162,6 +178,7 @@ export const presetOptions: PickOptional<Options> = {
162178
mode: 'system',
163179
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
164180
stays: 5000,
181+
notifyPosition: 'top',
165182
titleSeparator: ' - ',
166183
pageSizes: [10, 20, 50, 100],
167184
pageSize: 20,

packages/components/src/messages/en.lang.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ const messages = {
127127
transitionDuration: 'Transition duration',
128128
transitionDurationDesc:
129129
'Sets the duration of all animation effects. If animations are disabled in the operating system, this setting will not be available.',
130+
notifyPosition: 'Notify position',
131+
notifyPositionDesc: 'Set the position of the notify',
132+
topPosition: 'Top',
133+
bottomPosition: 'Bottom',
130134
},
131135
table: {
132136
nodata: 'No data',

packages/components/src/messages/zh-Hans.lang.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ const messages: Messages = {
128128
resetOptions: '重置设置项',
129129
transitionDuration: '动画时长',
130130
transitionDurationDesc: '设置所有动画效果的时长,如果操作系统禁用了动画,那么此处将无法设置!',
131+
notifyPosition: '通知位置',
132+
notifyPositionDesc: '设置通知出现的位置',
133+
topPosition: '顶部',
134+
bottomPosition: '底部',
131135
},
132136
table: {
133137
nodata: '没有数据',

0 commit comments

Comments
 (0)