cdui-js 1.0.21 → 1.0.23
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/css/datewidget.css +8 -0
- package/demo/src/App.tsx +0 -2
- package/demo/src/pages/Canlendar.tsx +4 -4
- package/demo/src/pages/Form.tsx +19 -0
- package/package.json +1 -1
- package/src/components/Canlendar.tsx +91 -48
- package/src/components/ComboBox.tsx +8 -6
- package/src/components/DatePicker.tsx +30 -45
- package/src/components/Form.tsx +1 -0
- package/src/components/MonthPicker.tsx +1 -1
- package/src/components/MonthWidget.tsx +65 -36
- package/src/components/Popup.tsx +43 -10
- package/src/components/YearPicker.tsx +1 -1
- package/src/components/YearWidget.tsx +62 -138
- package/src/{components/Dialog.ts → dialog.ts} +5 -2
- package/src/i18n/index.ts +2 -2
- package/src/index.ts +2 -1
- package/src/location.ts +7 -5
- package/src/popup.ts +33 -0
- package/src/reactive.ts +3 -0
- package/src/ssr/render.ts +5 -5
- package/demo/src/pages/MobileDatePicker.tsx +0 -5
- package/src/components/MobileDatePicker.tsx +0 -444
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { JSX } from '../jsx';
|
|
2
2
|
import { MonthWidget as i18n } from '../i18n';
|
|
3
3
|
import { replaceTemplate } from '../template';
|
|
4
|
-
import { createSignal, combineClass } from '../reactive';
|
|
4
|
+
import { createSignal, combineClass, omitProps, render } from '../reactive';
|
|
5
5
|
import { For } from './For';
|
|
6
|
-
|
|
7
|
-
const getCurrentMonth = () => {
|
|
8
|
-
let date = new Date();
|
|
9
|
-
return [date.getFullYear(), date.getMonth() + 1] as [year: number, month: number];
|
|
10
|
-
};
|
|
6
|
+
import { YearWidget } from './YearWidget';
|
|
11
7
|
|
|
12
8
|
const MONTH_LIST = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
|
|
13
9
|
|
|
14
10
|
const MonthItem = (props: {
|
|
15
11
|
value: number;
|
|
16
12
|
selectedValue: [year: number, month: number];
|
|
17
|
-
currentValue:
|
|
13
|
+
currentValue: number;
|
|
18
14
|
onclick: (event: Event) => void;
|
|
19
15
|
disableFn?: (year: number, month: number) => boolean;
|
|
20
16
|
}) => {
|
|
@@ -28,23 +24,21 @@ const MonthItem = (props: {
|
|
|
28
24
|
|
|
29
25
|
const checkCurrent = () => {
|
|
30
26
|
const today = new Date();
|
|
31
|
-
const currentValue = props.currentValue;
|
|
32
27
|
|
|
33
|
-
return today.getFullYear() === currentValue
|
|
28
|
+
return today.getFullYear() === props.currentValue + year && today.getMonth() + 1 === month;
|
|
34
29
|
};
|
|
35
30
|
|
|
36
31
|
const checkSelected = () => {
|
|
37
32
|
let selectedValue = props.selectedValue;
|
|
38
|
-
const currentValue = props.currentValue;
|
|
39
33
|
|
|
40
|
-
return selectedValue && selectedValue[0] === currentValue
|
|
34
|
+
return selectedValue && selectedValue[0] === props.currentValue + year && selectedValue[1] === month;
|
|
41
35
|
};
|
|
42
36
|
|
|
43
37
|
return (
|
|
44
38
|
<span
|
|
45
39
|
class={`datewidget-item${year ? ' next-block' : ''}${checkCurrent() ? ' today' : ''}${
|
|
46
40
|
checkSelected() ? ' selected' : ''
|
|
47
|
-
}${props.disableFn && props.disableFn(props.currentValue
|
|
41
|
+
}${props.disableFn && props.disableFn(props.currentValue + year, month) ? ' disabled' : ''}`}
|
|
48
42
|
data-month={`${year}|${month}`}
|
|
49
43
|
onclick={props.onclick}
|
|
50
44
|
>
|
|
@@ -53,11 +47,38 @@ const MonthItem = (props: {
|
|
|
53
47
|
);
|
|
54
48
|
};
|
|
55
49
|
|
|
50
|
+
const showYearWidget = (
|
|
51
|
+
dom: HTMLElement,
|
|
52
|
+
setCurrentValue: (value) => void,
|
|
53
|
+
selectedValue?: [year: number, month: number],
|
|
54
|
+
) => {
|
|
55
|
+
render(
|
|
56
|
+
() => (
|
|
57
|
+
<YearWidget
|
|
58
|
+
value={selectedValue && selectedValue[0]}
|
|
59
|
+
style={{ position: 'absolute', top: '0', left: '0', width: '100%', border: 'none' }}
|
|
60
|
+
onchange={(event) => {
|
|
61
|
+
let result = event.detail;
|
|
62
|
+
|
|
63
|
+
dom.removeChild(event.target as HTMLElement);
|
|
64
|
+
|
|
65
|
+
if (!selectedValue || result !== selectedValue[0]) {
|
|
66
|
+
setCurrentValue(result);
|
|
67
|
+
}
|
|
68
|
+
}}
|
|
69
|
+
></YearWidget>
|
|
70
|
+
),
|
|
71
|
+
dom,
|
|
72
|
+
);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const OMIT_PROPS = ['class', 'value', 'disableFn'] as const;
|
|
76
|
+
|
|
56
77
|
/**
|
|
57
78
|
* 月份组件
|
|
58
79
|
*/
|
|
59
80
|
export const MonthWidget = (
|
|
60
|
-
props: Omit<JSX.HTMLAttributes<never>, 'children'> & {
|
|
81
|
+
props: Omit<JSX.HTMLAttributes<never>, 'children' | 'onchange'> & {
|
|
61
82
|
/**
|
|
62
83
|
* 年月值
|
|
63
84
|
*/
|
|
@@ -65,55 +86,63 @@ export const MonthWidget = (
|
|
|
65
86
|
/**
|
|
66
87
|
* 值变更事件
|
|
67
88
|
*/
|
|
68
|
-
|
|
89
|
+
onchange?: (value: CustomEvent<[year: number, month: number]>) => void;
|
|
69
90
|
/**
|
|
70
91
|
* 禁用函数
|
|
71
92
|
*/
|
|
72
93
|
disableFn?: (year: number, month: number) => boolean;
|
|
73
94
|
},
|
|
74
95
|
) => {
|
|
75
|
-
let
|
|
76
|
-
let domBody: HTMLElement;
|
|
96
|
+
let dom: HTMLElement;
|
|
77
97
|
|
|
78
98
|
const [selectedValue, setSelectedValue] = createSignal(props.value);
|
|
79
|
-
const [currentValue, setCurrentValue] = createSignal(selectedValue()
|
|
99
|
+
const [currentValue, setCurrentValue] = createSignal(selectedValue() ? selectedValue()[0] : new Date().getFullYear());
|
|
80
100
|
|
|
81
101
|
const onclick = (event: Event) => {
|
|
82
102
|
let target = event.currentTarget as HTMLElement;
|
|
83
103
|
let month = target.dataset.month as any;
|
|
84
104
|
|
|
85
105
|
// 没有选中
|
|
86
|
-
if (month
|
|
87
|
-
|
|
88
|
-
|
|
106
|
+
if (month) {
|
|
107
|
+
// 父节点
|
|
108
|
+
let parent = dom.parentNode as HTMLElement;
|
|
109
|
+
// 是否嵌入到日历组件中
|
|
110
|
+
let inline = parent.classList.contains('datewidget');
|
|
89
111
|
|
|
90
|
-
|
|
91
|
-
|
|
112
|
+
if (inline || !target.classList.contains('selected')) {
|
|
113
|
+
month = month.split('|');
|
|
114
|
+
month = [currentValue() + (month[0] | 0), month[1] | 0];
|
|
115
|
+
|
|
116
|
+
setSelectedValue(month);
|
|
117
|
+
|
|
118
|
+
dom.dispatchEvent(
|
|
119
|
+
new CustomEvent('change', {
|
|
120
|
+
detail: month,
|
|
121
|
+
bubbles: !inline, // 允许事件冒泡
|
|
122
|
+
}),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
92
125
|
}
|
|
93
126
|
};
|
|
94
127
|
|
|
95
128
|
return (
|
|
96
|
-
<div
|
|
129
|
+
<div
|
|
130
|
+
ref={dom as any}
|
|
131
|
+
class={combineClass('monthwidget datewidget', props.class)}
|
|
132
|
+
{...(omitProps(props, OMIT_PROPS) as any)}
|
|
133
|
+
>
|
|
97
134
|
<div class="datewidget-header">
|
|
98
|
-
<div
|
|
99
|
-
{replaceTemplate(i18n.Title, currentValue()
|
|
135
|
+
<div class="datewidget-title" onclick={() => showYearWidget(dom, setCurrentValue, selectedValue())}>
|
|
136
|
+
{replaceTemplate(i18n.Title, currentValue())}
|
|
100
137
|
</div>
|
|
101
|
-
<svg
|
|
102
|
-
class="icon icon-s"
|
|
103
|
-
aria-hidden={true}
|
|
104
|
-
onclick={() => setCurrentValue([currentValue()[0] - 1, currentValue()[1]])}
|
|
105
|
-
>
|
|
138
|
+
<svg class="icon icon-s" aria-hidden={true} onclick={() => setCurrentValue(currentValue() - 1)}>
|
|
106
139
|
<use href="#icon-backward"></use>
|
|
107
140
|
</svg>
|
|
108
|
-
<svg
|
|
109
|
-
class="icon icon-s"
|
|
110
|
-
aria-hidden={true}
|
|
111
|
-
onclick={() => setCurrentValue([currentValue()[0] + 1, currentValue()[1]])}
|
|
112
|
-
>
|
|
141
|
+
<svg class="icon icon-s" aria-hidden={true} onclick={() => setCurrentValue(currentValue() + 1)}>
|
|
113
142
|
<use href="#icon-forward"></use>
|
|
114
143
|
</svg>
|
|
115
144
|
</div>
|
|
116
|
-
<div
|
|
145
|
+
<div class="datewidget-body">
|
|
117
146
|
<For each={MONTH_LIST}>
|
|
118
147
|
{(item) => (
|
|
119
148
|
<MonthItem
|
package/src/components/Popup.tsx
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { JSX } from '../jsx';
|
|
2
2
|
import { layout } from '../layout';
|
|
3
|
-
import { omitProps } from '../reactive';
|
|
3
|
+
import { omitProps, onMount } from '../reactive';
|
|
4
4
|
import { disableAutoCloseEvent, hideMaskLayer, registerAutoClose, showMaskLayer } from '../dom';
|
|
5
|
+
import { createRoot } from 'solid-js';
|
|
5
6
|
|
|
6
7
|
const POPUP_TOP_CLASS = 'popup-top';
|
|
7
8
|
const POPUP_RIGHT_CLASS = 'popup-right';
|
|
@@ -75,7 +76,7 @@ const showPopup = (dom: HTMLElement, onPopup?: (dom: HTMLElement) => void | fals
|
|
|
75
76
|
let host = dom.parentNode as HTMLElement;
|
|
76
77
|
|
|
77
78
|
// 先显示
|
|
78
|
-
style.width = host.offsetWidth + 'px';
|
|
79
|
+
// style.width = host.offsetWidth + 'px';
|
|
79
80
|
style.height = 'auto';
|
|
80
81
|
style.display = 'block';
|
|
81
82
|
|
|
@@ -85,7 +86,7 @@ const showPopup = (dom: HTMLElement, onPopup?: (dom: HTMLElement) => void | fals
|
|
|
85
86
|
let rect = host.getBoundingClientRect();
|
|
86
87
|
|
|
87
88
|
// 同步子组件宽度
|
|
88
|
-
style.width = width + 'px';
|
|
89
|
+
// style.width = width + 'px';
|
|
89
90
|
|
|
90
91
|
if (windowHeight - rect.top - rect.height < height + 4 && rect.top >= height) {
|
|
91
92
|
classList.add(POPUP_TOP_CLASS);
|
|
@@ -195,13 +196,15 @@ export const Popup = (props?: JSX.HTMLAttributes<never> & PopupProps) => {
|
|
|
195
196
|
|
|
196
197
|
// 初始化外部调用接口
|
|
197
198
|
props.api &&
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
199
|
+
onMount(() => {
|
|
200
|
+
props.api({
|
|
201
|
+
get popup() {
|
|
202
|
+
return currentPopup.dom === popup;
|
|
203
|
+
},
|
|
204
|
+
openPopup: () => showPopup(popup, props.onPopup),
|
|
205
|
+
closePopup: () => currentPopup.dom === popup && hidePopup(),
|
|
206
|
+
togglePopup: () => togglePopup(popup, props.onPopup),
|
|
207
|
+
});
|
|
205
208
|
});
|
|
206
209
|
|
|
207
210
|
return (
|
|
@@ -226,3 +229,33 @@ export const closePopup = () => {
|
|
|
226
229
|
|
|
227
230
|
// 注册点击关闭弹出层的方法
|
|
228
231
|
registerAutoClose(closePopup);
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 弹出层
|
|
235
|
+
*/
|
|
236
|
+
export type Popup = HTMLElement & {
|
|
237
|
+
/**
|
|
238
|
+
* 关闭对话框方法
|
|
239
|
+
*/
|
|
240
|
+
close(): void;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
export const showPopup1 = (component: () => JSX.Element): Popup => {
|
|
244
|
+
return createRoot((dispose) => {
|
|
245
|
+
let body = document.body;
|
|
246
|
+
let popup = component() as Popup;
|
|
247
|
+
let style = popup.style;
|
|
248
|
+
|
|
249
|
+
style.position = 'fixed';
|
|
250
|
+
style.zIndex = '9';
|
|
251
|
+
|
|
252
|
+
body.appendChild(popup);
|
|
253
|
+
|
|
254
|
+
popup.close = () => {
|
|
255
|
+
body.removeChild(popup);
|
|
256
|
+
dispose();
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
return popup;
|
|
260
|
+
});
|
|
261
|
+
};
|
|
@@ -1,188 +1,112 @@
|
|
|
1
1
|
import { JSX } from '../jsx';
|
|
2
2
|
import { YearWidget as i18n } from '../i18n';
|
|
3
3
|
import { replaceTemplate } from '../template';
|
|
4
|
-
import { createSignal, combineClass } from '../reactive';
|
|
5
|
-
import { For } from './For';
|
|
4
|
+
import { createSignal, combineClass, omitProps } from '../reactive';
|
|
6
5
|
|
|
7
|
-
//
|
|
8
|
-
const
|
|
6
|
+
// 渲染年项
|
|
7
|
+
const renderYears = (
|
|
9
8
|
items: string[],
|
|
10
|
-
year: number,
|
|
11
|
-
month: number,
|
|
12
9
|
from: number,
|
|
13
10
|
to: number,
|
|
14
11
|
className: string,
|
|
15
|
-
todayValue:
|
|
16
|
-
selectedValue?:
|
|
17
|
-
disableFn?: (year: number
|
|
12
|
+
todayValue: number,
|
|
13
|
+
selectedValue?: number,
|
|
14
|
+
disableFn?: (year: number) => boolean,
|
|
18
15
|
) => {
|
|
19
|
-
let
|
|
20
|
-
let selected =
|
|
21
|
-
selectedValue && selectedValue.getFullYear() === year && selectedValue.getMonth() === month
|
|
22
|
-
? selectedValue.getDate()
|
|
23
|
-
: -1;
|
|
24
|
-
|
|
25
|
-
for (let i = from; i <= to; i++) {
|
|
16
|
+
for (let i = from; i < to; i++) {
|
|
26
17
|
items.push(
|
|
27
|
-
`<span class="datewidget-item${className}${
|
|
28
|
-
disableFn && disableFn(
|
|
29
|
-
}" data-
|
|
18
|
+
`<span class="datewidget-item${className}${todayValue === i ? ' today' : ''}${selectedValue === i ? ' selected' : ''}${
|
|
19
|
+
disableFn && disableFn(i) ? ' disabled' : ''
|
|
20
|
+
}" data-year="${i}">${i}</span>`,
|
|
30
21
|
);
|
|
31
22
|
}
|
|
32
23
|
};
|
|
33
24
|
|
|
34
|
-
|
|
35
|
-
const renderPrevMonthItems = (
|
|
36
|
-
items: string[],
|
|
37
|
-
year: number,
|
|
38
|
-
month: number,
|
|
39
|
-
index: number,
|
|
40
|
-
todayValue: Date,
|
|
41
|
-
selectedValue?: Date,
|
|
42
|
-
disableFn?: (year: number, month: number, date: number) => boolean,
|
|
43
|
-
) => {
|
|
44
|
-
// 获取上月天数
|
|
45
|
-
let days = new Date(year, month, 0).getDate();
|
|
46
|
-
|
|
47
|
-
if (month > 0) {
|
|
48
|
-
month--;
|
|
49
|
-
} else {
|
|
50
|
-
year--;
|
|
51
|
-
month = 11;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
renderDates(items, year, month, days - index + 1, days, ' prev-block', todayValue, selectedValue, disableFn);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const renderNextMonthItems = (
|
|
58
|
-
items: string[],
|
|
59
|
-
year: number,
|
|
60
|
-
month: number,
|
|
61
|
-
days: number,
|
|
62
|
-
todayValue: Date,
|
|
63
|
-
selectedValue?: Date,
|
|
64
|
-
disableFn?: (year: number, month: number, date: number) => boolean,
|
|
65
|
-
) => {
|
|
66
|
-
if (month < 11) {
|
|
67
|
-
month++;
|
|
68
|
-
} else {
|
|
69
|
-
year++;
|
|
70
|
-
month = 0;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
renderDates(items, year, month, 1, days, ' next-block', todayValue, selectedValue, disableFn);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const renderItems = (
|
|
77
|
-
currentValue: Date,
|
|
78
|
-
selectedValue?: Date,
|
|
79
|
-
disableFn?: (year: number, month: number, date: number) => boolean,
|
|
80
|
-
) => {
|
|
25
|
+
const renderItems = (currentValue: number, selectedValue?: number, disableFn?: (year: number) => boolean) => {
|
|
81
26
|
let today = new Date();
|
|
82
|
-
let year = currentValue.getFullYear();
|
|
83
|
-
let month = currentValue.getMonth();
|
|
84
|
-
let firstDate = new Date(year, month, 1); // 获取当前月的第一天
|
|
85
|
-
|
|
86
|
-
let firstWeek = firstDate.getDay();
|
|
87
27
|
let items = [];
|
|
88
|
-
let index = 0;
|
|
89
|
-
let days;
|
|
90
|
-
|
|
91
|
-
// 当前月第一天不是周一,渲染上月数据
|
|
92
|
-
if (firstWeek !== 1) {
|
|
93
|
-
index = firstWeek > 0 ? firstWeek - 1 : 6;
|
|
94
|
-
renderPrevMonthItems(items, year, month, index, today, selectedValue, disableFn);
|
|
95
|
-
}
|
|
96
28
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
29
|
+
// 渲染前面 10 年
|
|
30
|
+
renderYears(items, currentValue, currentValue + 10, '', today.getFullYear(), selectedValue, disableFn);
|
|
31
|
+
|
|
32
|
+
// 渲染后面 6 年
|
|
33
|
+
renderYears(
|
|
34
|
+
items,
|
|
35
|
+
currentValue + 10,
|
|
36
|
+
currentValue + 16,
|
|
37
|
+
' next-block',
|
|
38
|
+
today.getFullYear(),
|
|
39
|
+
selectedValue,
|
|
40
|
+
disableFn,
|
|
41
|
+
);
|
|
106
42
|
|
|
107
43
|
return items.join('');
|
|
108
44
|
};
|
|
109
45
|
|
|
46
|
+
const OMIT_PROPS = ['class', 'value', 'disableFn'] as const;
|
|
47
|
+
|
|
110
48
|
/**
|
|
111
49
|
* 年份组件
|
|
112
50
|
*/
|
|
113
51
|
export const YearWidget = (
|
|
114
|
-
props: Omit<JSX.HTMLAttributes<never>, 'children'> & {
|
|
52
|
+
props: Omit<JSX.HTMLAttributes<never>, 'children' | 'onchange'> & {
|
|
115
53
|
/**
|
|
116
|
-
*
|
|
54
|
+
* 年值
|
|
117
55
|
*/
|
|
118
|
-
value?:
|
|
56
|
+
value?: number;
|
|
119
57
|
/**
|
|
120
58
|
* 值变更事件
|
|
121
59
|
*/
|
|
122
|
-
|
|
60
|
+
onchange?: (event: CustomEvent<number>) => void;
|
|
123
61
|
/**
|
|
124
62
|
* 禁用函数
|
|
125
63
|
*/
|
|
126
|
-
disableFn?: (year: number
|
|
64
|
+
disableFn?: (year: number) => boolean;
|
|
127
65
|
},
|
|
128
66
|
) => {
|
|
129
|
-
let
|
|
130
|
-
let domBody: HTMLElement;
|
|
131
|
-
|
|
132
|
-
// const [selectedValue, setSelectedValue] = createSignal(props.value);
|
|
133
|
-
// const [currentValue, setCurrentValue] = createSignal(selectedValue() || getCurrentMonth());
|
|
134
|
-
|
|
135
|
-
// const onclick = (event: Event) => {
|
|
136
|
-
// let target = event.currentTarget as HTMLElement;
|
|
137
|
-
// let month = target.dataset.month as any;
|
|
67
|
+
let dom: HTMLElement;
|
|
138
68
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// month = month.split('|');
|
|
142
|
-
// month = [currentValue()[0] + (month[0] | 0), month[1] | 0];
|
|
143
|
-
|
|
144
|
-
// setSelectedValue(month);
|
|
145
|
-
// props.onValueChange && props.onValueChange(month);
|
|
146
|
-
// }
|
|
147
|
-
// };
|
|
69
|
+
const [selectedValue, setSelectedValue] = createSignal(props.value);
|
|
70
|
+
const [currentValue, setCurrentValue] = createSignal((((selectedValue() || new Date().getFullYear()) / 10) | 0) * 10);
|
|
148
71
|
|
|
149
72
|
return (
|
|
150
|
-
<div
|
|
151
|
-
{
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
onclick={() => setCurrentValue([currentValue()[0] - 1, currentValue()[1]])}
|
|
159
|
-
>
|
|
73
|
+
<div
|
|
74
|
+
ref={dom as any}
|
|
75
|
+
class={combineClass('yearwidget datewidget', props.class)}
|
|
76
|
+
{...(omitProps(props, OMIT_PROPS) as any)}
|
|
77
|
+
>
|
|
78
|
+
<div class="datewidget-header">
|
|
79
|
+
<div class="datewidget-title">{replaceTemplate(i18n.Title, currentValue(), currentValue() + 9)}</div>
|
|
80
|
+
<svg class="icon icon-s" aria-hidden={true} onclick={() => setCurrentValue(currentValue() - 10)}>
|
|
160
81
|
<use href="#icon-backward"></use>
|
|
161
82
|
</svg>
|
|
162
|
-
<svg
|
|
163
|
-
class="icon icon-s"
|
|
164
|
-
aria-hidden={true}
|
|
165
|
-
onclick={() => setCurrentValue([currentValue()[0] + 1, currentValue()[1]])}
|
|
166
|
-
>
|
|
83
|
+
<svg class="icon icon-s" aria-hidden={true} onclick={() => setCurrentValue(currentValue() + 10)}>
|
|
167
84
|
<use href="#icon-forward"></use>
|
|
168
85
|
</svg>
|
|
169
86
|
</div>
|
|
170
87
|
<div
|
|
171
|
-
|
|
172
|
-
class="datewidget-body canlendar-body"
|
|
88
|
+
class="datewidget-body yearwidget-body"
|
|
173
89
|
onclick={(event) => {
|
|
174
90
|
let target = event.target as HTMLElement;
|
|
175
|
-
let
|
|
91
|
+
let year;
|
|
176
92
|
|
|
177
|
-
while (target && target !==
|
|
178
|
-
if ((
|
|
179
|
-
//
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
93
|
+
while (target && target !== dom) {
|
|
94
|
+
if ((year = +target.dataset.year)) {
|
|
95
|
+
// 父节点
|
|
96
|
+
let parent = dom.parentNode as HTMLElement;
|
|
97
|
+
// 是否嵌入到年月组件中
|
|
98
|
+
let inline = parent.classList.contains('datewidget');
|
|
183
99
|
|
|
184
|
-
|
|
185
|
-
|
|
100
|
+
// 没有选中
|
|
101
|
+
if (inline || !target.classList.contains('selected')) {
|
|
102
|
+
setSelectedValue(year);
|
|
103
|
+
|
|
104
|
+
dom.dispatchEvent(
|
|
105
|
+
new CustomEvent('change', {
|
|
106
|
+
detail: year,
|
|
107
|
+
bubbles: !inline, // 允许事件冒泡
|
|
108
|
+
}),
|
|
109
|
+
);
|
|
186
110
|
}
|
|
187
111
|
|
|
188
112
|
break;
|
|
@@ -192,7 +116,7 @@ export const YearWidget = (
|
|
|
192
116
|
}
|
|
193
117
|
}}
|
|
194
118
|
innerHTML={renderItems(currentValue(), selectedValue(), props.disableFn)}
|
|
195
|
-
></div>
|
|
119
|
+
></div>
|
|
196
120
|
</div>
|
|
197
121
|
);
|
|
198
122
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createRoot } from 'solid-js';
|
|
2
2
|
|
|
3
|
-
import { JSX } from '
|
|
3
|
+
import { JSX } from './jsx';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 对话框
|
|
@@ -22,8 +22,11 @@ export const showDialog = (component: () => JSX.Element): Dialog => {
|
|
|
22
22
|
return createRoot((dispose) => {
|
|
23
23
|
let body = document.body;
|
|
24
24
|
let dialog = component() as Dialog;
|
|
25
|
+
let style= dialog.style;
|
|
26
|
+
|
|
27
|
+
style.position = 'fixed';
|
|
28
|
+
style.zIndex = '9';
|
|
25
29
|
|
|
26
|
-
dialog.style.cssText = 'position:fixed;z-index:9';
|
|
27
30
|
body.appendChild(dialog);
|
|
28
31
|
|
|
29
32
|
dialog.close = () => {
|
package/src/i18n/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export let MonthWidget = i18n.MonthWidget;
|
|
|
13
13
|
/**
|
|
14
14
|
* 日历
|
|
15
15
|
*/
|
|
16
|
-
export let
|
|
16
|
+
export let Canlendar = i18n.Canlendar;
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* 表单
|
|
@@ -28,6 +28,6 @@ export let Form = i18n.Form;
|
|
|
28
28
|
export const switchLanguage = (data: typeof i18n) => {
|
|
29
29
|
YearWidget = i18n.YearWidget;
|
|
30
30
|
MonthWidget = i18n.MonthWidget;
|
|
31
|
-
|
|
31
|
+
Canlendar = i18n.Canlendar;
|
|
32
32
|
Form = i18n.Form;
|
|
33
33
|
};
|
package/src/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from './components/CollapsiblePanel';
|
|
|
27
27
|
export * from './components/Carousel';
|
|
28
28
|
export * from './components/KeepAlive';
|
|
29
29
|
export * from './components/Popup';
|
|
30
|
-
|
|
30
|
+
|
|
31
|
+
export * from './dialog';
|
|
31
32
|
|
|
32
33
|
export * from './ssr/render';
|
package/src/location.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isBrowser } from './dom';
|
|
2
|
-
import { reactive } from './reactive';
|
|
2
|
+
import { batch, reactive } from './reactive';
|
|
3
3
|
|
|
4
4
|
export interface Location {
|
|
5
5
|
/**
|
|
@@ -98,10 +98,12 @@ export const updateURL = (path: string, search?: string, hash?: string) => {
|
|
|
98
98
|
location.hash = hash || '';
|
|
99
99
|
|
|
100
100
|
if (location.path !== path || location.search !== search) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
batch(() => {
|
|
102
|
+
location.path = path;
|
|
103
|
+
location.paths = path.match(/\/[^/]*/g) || [];
|
|
104
|
+
location.search = search || '';
|
|
105
|
+
location.query = search ? parseQuery(search) : {};
|
|
106
|
+
});
|
|
105
107
|
}
|
|
106
108
|
};
|
|
107
109
|
|
package/src/popup.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createRoot } from 'solid-js';
|
|
2
|
+
|
|
3
|
+
import { JSX } from './jsx';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 弹出层
|
|
7
|
+
*/
|
|
8
|
+
export type Popup = HTMLElement & {
|
|
9
|
+
/**
|
|
10
|
+
* 关闭对话框方法
|
|
11
|
+
*/
|
|
12
|
+
close(): void;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const showPopup1 = (component: () => JSX.Element): Popup => {
|
|
16
|
+
return createRoot((dispose) => {
|
|
17
|
+
let body = document.body;
|
|
18
|
+
let popup = component() as Popup;
|
|
19
|
+
let style = popup.style;
|
|
20
|
+
|
|
21
|
+
style.position = 'fixed';
|
|
22
|
+
style.zIndex = '9';
|
|
23
|
+
|
|
24
|
+
body.appendChild(popup);
|
|
25
|
+
|
|
26
|
+
popup.close = () => {
|
|
27
|
+
body.removeChild(popup);
|
|
28
|
+
dispose();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
return popup;
|
|
32
|
+
});
|
|
33
|
+
};
|
package/src/reactive.ts
CHANGED