wx-svelte-core 1.3.0
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/license.txt +21 -0
- package/package.json +35 -0
- package/src/Locale.svelte +17 -0
- package/src/components/Area.svelte +70 -0
- package/src/components/Button.svelte +187 -0
- package/src/components/Calendar.svelte +42 -0
- package/src/components/Checkbox.svelte +132 -0
- package/src/components/CheckboxGroup.svelte +52 -0
- package/src/components/ColorBoard.svelte +311 -0
- package/src/components/ColorPicker.svelte +110 -0
- package/src/components/ColorSelect.svelte +204 -0
- package/src/components/Combo.svelte +228 -0
- package/src/components/Counter.svelte +178 -0
- package/src/components/DatePicker.svelte +115 -0
- package/src/components/DateRangePicker.svelte +138 -0
- package/src/components/Dropdown.svelte +125 -0
- package/src/components/Field.svelte +91 -0
- package/src/components/Globals.svelte +53 -0
- package/src/components/Icon.svelte +31 -0
- package/src/components/Modal.svelte +115 -0
- package/src/components/ModalArea.svelte +32 -0
- package/src/components/MultiCombo.svelte +279 -0
- package/src/components/Notice.svelte +145 -0
- package/src/components/Notices.svelte +20 -0
- package/src/components/Pager.svelte +131 -0
- package/src/components/Popup.svelte +53 -0
- package/src/components/Portal.svelte +42 -0
- package/src/components/RadioButton.svelte +129 -0
- package/src/components/RadioButtonGroup.svelte +50 -0
- package/src/components/RangeCalendar.svelte +134 -0
- package/src/components/RichSelect.svelte +149 -0
- package/src/components/Segmented.svelte +115 -0
- package/src/components/Select.svelte +124 -0
- package/src/components/SideArea.svelte +33 -0
- package/src/components/Slider.svelte +242 -0
- package/src/components/Switch.svelte +88 -0
- package/src/components/Tabs.svelte +163 -0
- package/src/components/Text.svelte +185 -0
- package/src/components/Timepicker.svelte +217 -0
- package/src/components/TwoState.svelte +60 -0
- package/src/components/calendar/Button.svelte +40 -0
- package/src/components/calendar/Duodecade.svelte +97 -0
- package/src/components/calendar/Header.svelte +105 -0
- package/src/components/calendar/Month.svelte +189 -0
- package/src/components/calendar/Panel.svelte +119 -0
- package/src/components/calendar/Year.svelte +89 -0
- package/src/components/calendar/helpers.js +56 -0
- package/src/components/helpers/SuggestDropdown.svelte +79 -0
- package/src/components/helpers/colorTransformator.js +146 -0
- package/src/components/helpers/colorValidation.js +21 -0
- package/src/components/helpers/listnav.js +85 -0
- package/src/components/helpers/sliderMove.js +42 -0
- package/src/components/helpers.js +6 -0
- package/src/index.js +50 -0
- package/src/themes/FontOpenSans.svelte +36 -0
- package/src/themes/FonttRoboto.svelte +19 -0
- package/src/themes/Material.svelte +321 -0
- package/src/themes/Willow.svelte +323 -0
- package/src/themes/WillowDark.svelte +320 -0
- package/whatsnew.md +97 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Field from "./Field.svelte";
|
|
3
|
+
import Text from "./Text.svelte";
|
|
4
|
+
import Dropdown from "./Dropdown.svelte";
|
|
5
|
+
import Slider from "./Slider.svelte";
|
|
6
|
+
import TwoState from "./TwoState.svelte";
|
|
7
|
+
|
|
8
|
+
import { getContext } from "svelte";
|
|
9
|
+
import { dateToString, uid } from "wx-lib-dom";
|
|
10
|
+
|
|
11
|
+
export let value = new Date(0, 0, 0, 0, 0);
|
|
12
|
+
export let id = uid();
|
|
13
|
+
export let title;
|
|
14
|
+
export let css;
|
|
15
|
+
export let disabled = false;
|
|
16
|
+
export let error = false;
|
|
17
|
+
export let format;
|
|
18
|
+
|
|
19
|
+
const { calendar: calendarLocale, formats } =
|
|
20
|
+
getContext("wx-i18n").getRaw();
|
|
21
|
+
const h12 = calendarLocale.clockFormat == 12;
|
|
22
|
+
let f, timeFormat, zeroBased;
|
|
23
|
+
$: {
|
|
24
|
+
f = format || formats.timeFormat;
|
|
25
|
+
timeFormat =
|
|
26
|
+
typeof f === "function" ? f : dateToString(f, calendarLocale);
|
|
27
|
+
zeroBased = timeFormat(new Date(0, 0, 0, 1)).indexOf("01") != -1;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const maxH = 23;
|
|
31
|
+
const maxM = 59;
|
|
32
|
+
|
|
33
|
+
const update = (v, max) => {
|
|
34
|
+
v = getNumber(v);
|
|
35
|
+
return Math.min(v, max);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
let popup;
|
|
39
|
+
|
|
40
|
+
let hText = "",
|
|
41
|
+
mText = "";
|
|
42
|
+
let h = 0;
|
|
43
|
+
let m = 0;
|
|
44
|
+
let pm = false;
|
|
45
|
+
|
|
46
|
+
$: initTime(value);
|
|
47
|
+
function initTime(value) {
|
|
48
|
+
if (value) {
|
|
49
|
+
h = update(value.getHours(), maxH);
|
|
50
|
+
m = update(value.getMinutes(), maxM);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
let textValue;
|
|
55
|
+
$: updateTime(h, m);
|
|
56
|
+
function updateTime(h, m) {
|
|
57
|
+
pm = h > 11;
|
|
58
|
+
hText = formatH(h);
|
|
59
|
+
mText = formatM(m);
|
|
60
|
+
textValue = timeFormat(new Date(0, 0, 0, h, m));
|
|
61
|
+
|
|
62
|
+
if (
|
|
63
|
+
(value && (value.getHours() !== h || value.getMinutes() !== m)) ||
|
|
64
|
+
(!value && (h || m))
|
|
65
|
+
) {
|
|
66
|
+
const next = new Date(value);
|
|
67
|
+
next.setMinutes(m);
|
|
68
|
+
next.setHours(h);
|
|
69
|
+
value = next;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function click() {
|
|
74
|
+
popup = true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function togglePM() {
|
|
78
|
+
h = (h + 12) % 24;
|
|
79
|
+
}
|
|
80
|
+
function formatH(v) {
|
|
81
|
+
if (h12) {
|
|
82
|
+
v = v % 12;
|
|
83
|
+
if (v === 0) return "12";
|
|
84
|
+
}
|
|
85
|
+
return formatTime(v, zeroBased);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function formatM(v) {
|
|
89
|
+
return formatTime(v, true);
|
|
90
|
+
}
|
|
91
|
+
function updateH(v) {
|
|
92
|
+
v = update(v, maxH);
|
|
93
|
+
if (h12) {
|
|
94
|
+
v = v * 1;
|
|
95
|
+
if (v === 12) v = 0;
|
|
96
|
+
if (pm) v += 12;
|
|
97
|
+
}
|
|
98
|
+
return v;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function getNumber(v) {
|
|
102
|
+
return `${v}`.replace(/[^\d]/g, "") || 0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function formatTime(v, zeroBased) {
|
|
106
|
+
return (v < 10 && zeroBased ? `0${v}` : `${v}`).slice(-2);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function cancel() {
|
|
110
|
+
popup = null;
|
|
111
|
+
}
|
|
112
|
+
</script>
|
|
113
|
+
|
|
114
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
115
|
+
<div
|
|
116
|
+
class="wx-timepicker"
|
|
117
|
+
class:wx-error={error}
|
|
118
|
+
class:wx-disabled={disabled}
|
|
119
|
+
on:click={click}
|
|
120
|
+
>
|
|
121
|
+
<Text
|
|
122
|
+
{id}
|
|
123
|
+
{css}
|
|
124
|
+
{title}
|
|
125
|
+
value={textValue}
|
|
126
|
+
readonly={true}
|
|
127
|
+
{disabled}
|
|
128
|
+
{error}
|
|
129
|
+
icon="wxi-clock"
|
|
130
|
+
inputStyle="cursor: pointer; width: 100%; padding-right: calc(var(--wx-input-icon-size) + var(--wx-input-icon-indent) * 2);"
|
|
131
|
+
/>
|
|
132
|
+
|
|
133
|
+
{#if popup && !disabled}
|
|
134
|
+
<Dropdown {cancel} width={"unset"}>
|
|
135
|
+
<div class="wx-wrapper">
|
|
136
|
+
<div class="wx-timer">
|
|
137
|
+
<input
|
|
138
|
+
class="wx-digit"
|
|
139
|
+
bind:value={hText}
|
|
140
|
+
on:blur={() => (h = updateH(hText))}
|
|
141
|
+
/>
|
|
142
|
+
<div class="wx-separator">:</div>
|
|
143
|
+
<input
|
|
144
|
+
class="wx-digit"
|
|
145
|
+
bind:value={mText}
|
|
146
|
+
on:blur={() => (m = update(mText, maxM))}
|
|
147
|
+
/>
|
|
148
|
+
{#if h12}
|
|
149
|
+
<TwoState value={pm} click={togglePM}>
|
|
150
|
+
<span>am</span>
|
|
151
|
+
<span slot="active">pm</span>
|
|
152
|
+
</TwoState>
|
|
153
|
+
{/if}
|
|
154
|
+
</div>
|
|
155
|
+
<Field width={"unset"}>
|
|
156
|
+
<Slider
|
|
157
|
+
label={calendarLocale.hours}
|
|
158
|
+
width={"unset"}
|
|
159
|
+
bind:value={h}
|
|
160
|
+
max={maxH}
|
|
161
|
+
/>
|
|
162
|
+
</Field>
|
|
163
|
+
<Field width={"unset"}>
|
|
164
|
+
<Slider
|
|
165
|
+
label={calendarLocale.minutes}
|
|
166
|
+
width={"unset"}
|
|
167
|
+
bind:value={m}
|
|
168
|
+
max={maxM}
|
|
169
|
+
/>
|
|
170
|
+
</Field>
|
|
171
|
+
</div>
|
|
172
|
+
</Dropdown>
|
|
173
|
+
{/if}
|
|
174
|
+
</div>
|
|
175
|
+
|
|
176
|
+
<style>
|
|
177
|
+
.wx-timepicker {
|
|
178
|
+
position: relative;
|
|
179
|
+
width: var(--wx-input-width);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.wx-wrapper {
|
|
183
|
+
padding: 10px 20px;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.wx-timer {
|
|
187
|
+
display: flex;
|
|
188
|
+
text-align: center;
|
|
189
|
+
justify-content: center;
|
|
190
|
+
margin-bottom: 10px;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.wx-digit {
|
|
194
|
+
display: block;
|
|
195
|
+
width: 50px;
|
|
196
|
+
height: 38px;
|
|
197
|
+
border: none;
|
|
198
|
+
border-bottom: var(--wx-input-border);
|
|
199
|
+
font-family: var(--wx-input-font-family);
|
|
200
|
+
font-size: 24px;
|
|
201
|
+
line-height: 28px;
|
|
202
|
+
padding: 5px;
|
|
203
|
+
text-align: center;
|
|
204
|
+
color: var(--wx-input-font-color);
|
|
205
|
+
background-color: transparent;
|
|
206
|
+
outline: none;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.wx-digit:focus {
|
|
210
|
+
border-bottom: var(--wx-input-border-focus);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.wx-separator {
|
|
214
|
+
font-size: 24px;
|
|
215
|
+
line-height: 38px;
|
|
216
|
+
}
|
|
217
|
+
</style>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Button from "./Button.svelte";
|
|
3
|
+
|
|
4
|
+
export let value = false;
|
|
5
|
+
export let type = "";
|
|
6
|
+
export let icon = null;
|
|
7
|
+
export let disabled = null;
|
|
8
|
+
export let iconActive = null;
|
|
9
|
+
export let click;
|
|
10
|
+
export let title = "";
|
|
11
|
+
export let css = "";
|
|
12
|
+
export let text = "";
|
|
13
|
+
export let textActive = "";
|
|
14
|
+
|
|
15
|
+
let typeStr = type;
|
|
16
|
+
$: typeStr = (value ? "pressed" : "") + (type ? " " + type : "");
|
|
17
|
+
|
|
18
|
+
function handleClick(ev) {
|
|
19
|
+
if (click) click(ev);
|
|
20
|
+
if (!ev.defaultPrevented) value = !value;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const SLOTS = $$props.$$slots;
|
|
24
|
+
</script>
|
|
25
|
+
|
|
26
|
+
{#if value && SLOTS && SLOTS.active}
|
|
27
|
+
<Button
|
|
28
|
+
{title}
|
|
29
|
+
text={(value && textActive) || text}
|
|
30
|
+
{css}
|
|
31
|
+
type={typeStr}
|
|
32
|
+
icon={(value && iconActive) || icon}
|
|
33
|
+
click={handleClick}
|
|
34
|
+
{disabled}
|
|
35
|
+
>
|
|
36
|
+
<slot name="active" />
|
|
37
|
+
</Button>
|
|
38
|
+
{:else if SLOTS && SLOTS.default}
|
|
39
|
+
<Button
|
|
40
|
+
{title}
|
|
41
|
+
text={(value && textActive) || text}
|
|
42
|
+
{css}
|
|
43
|
+
type={typeStr}
|
|
44
|
+
icon={(value && iconActive) || icon}
|
|
45
|
+
click={handleClick}
|
|
46
|
+
{disabled}
|
|
47
|
+
>
|
|
48
|
+
<slot />
|
|
49
|
+
</Button>
|
|
50
|
+
{:else}
|
|
51
|
+
<Button
|
|
52
|
+
{title}
|
|
53
|
+
text={(value && textActive) || text}
|
|
54
|
+
{css}
|
|
55
|
+
type={typeStr}
|
|
56
|
+
icon={(value && iconActive) || icon}
|
|
57
|
+
click={handleClick}
|
|
58
|
+
{disabled}
|
|
59
|
+
/>
|
|
60
|
+
{/if}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let click;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<button on:click={click}>
|
|
6
|
+
<slot />
|
|
7
|
+
</button>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
button {
|
|
11
|
+
display: inline-block;
|
|
12
|
+
vertical-align: top;
|
|
13
|
+
text-decoration: none;
|
|
14
|
+
text-align: center;
|
|
15
|
+
letter-spacing: normal;
|
|
16
|
+
font-family: var(--wx-calendar-controls-font-family);
|
|
17
|
+
font-size: var(--wx-calendar-controls-font-size);
|
|
18
|
+
line-height: var(--wx-calendar-controls-line-height);
|
|
19
|
+
font-weight: var(--wx-calendar-controls-font-weight);
|
|
20
|
+
text-transform: none;
|
|
21
|
+
padding: 0;
|
|
22
|
+
border: none;
|
|
23
|
+
border-radius: 0;
|
|
24
|
+
background: transparent;
|
|
25
|
+
color: var(--wx-calendar-controls-font-color);
|
|
26
|
+
cursor: pointer;
|
|
27
|
+
box-shadow: none;
|
|
28
|
+
transition: none;
|
|
29
|
+
max-width: 100%;
|
|
30
|
+
user-select: none;
|
|
31
|
+
}
|
|
32
|
+
button,
|
|
33
|
+
button:focus,
|
|
34
|
+
button:active {
|
|
35
|
+
outline: none;
|
|
36
|
+
}
|
|
37
|
+
button:active {
|
|
38
|
+
opacity: 0.8;
|
|
39
|
+
}
|
|
40
|
+
</style>
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { delegateClick } from "wx-lib-dom";
|
|
4
|
+
import Button from "./Button.svelte";
|
|
5
|
+
|
|
6
|
+
const _ = getContext("wx-i18n").getRaw().calendar;
|
|
7
|
+
|
|
8
|
+
export let value;
|
|
9
|
+
export let current;
|
|
10
|
+
export let cancel;
|
|
11
|
+
export let part;
|
|
12
|
+
|
|
13
|
+
let years;
|
|
14
|
+
let year;
|
|
15
|
+
$: {
|
|
16
|
+
year = current.getFullYear();
|
|
17
|
+
|
|
18
|
+
const start = year - (year % 10) - 1;
|
|
19
|
+
const end = start + 12;
|
|
20
|
+
years = [];
|
|
21
|
+
for (let y = start; y < end; ++y) {
|
|
22
|
+
years.push(y);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const selectYears = {
|
|
27
|
+
click: selectYear,
|
|
28
|
+
};
|
|
29
|
+
function selectYear(year, e) {
|
|
30
|
+
if (year) {
|
|
31
|
+
e.stopPropagation();
|
|
32
|
+
current.setFullYear(year);
|
|
33
|
+
current = current;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (part === "normal") value = new Date(current);
|
|
37
|
+
|
|
38
|
+
cancel();
|
|
39
|
+
}
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
<div class="wx-years" use:delegateClick={selectYears}>
|
|
43
|
+
{#each years as y, i}
|
|
44
|
+
<div
|
|
45
|
+
class="wx-year"
|
|
46
|
+
class:wx-current={year == y}
|
|
47
|
+
class:wx-prev-decade={i === 0}
|
|
48
|
+
class:wx-next-decade={i === 11}
|
|
49
|
+
data-id={y}
|
|
50
|
+
>
|
|
51
|
+
{y}
|
|
52
|
+
</div>
|
|
53
|
+
{/each}
|
|
54
|
+
</div>
|
|
55
|
+
<div class="wx-buttons">
|
|
56
|
+
<Button click={cancel}>{_.done}</Button>
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<style>
|
|
60
|
+
.wx-years {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-wrap: wrap;
|
|
63
|
+
margin: var(--wx-calendar-gap);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.wx-year {
|
|
67
|
+
flex: 0 0 calc(100% / 4 - var(--wx-calendar-gap) * 2);
|
|
68
|
+
max-width: calc(100% / 4 - var(--wx-calendar-gap) * 2);
|
|
69
|
+
margin: calc(var(--wx-calendar-gap) * 2) var(--wx-calendar-gap);
|
|
70
|
+
text-align: center;
|
|
71
|
+
cursor: pointer;
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-wrap: nowrap;
|
|
74
|
+
align-items: center;
|
|
75
|
+
justify-content: center;
|
|
76
|
+
height: var(--wx-calendar-cell-size);
|
|
77
|
+
border-radius: var(--wx-calendar-border-radius);
|
|
78
|
+
}
|
|
79
|
+
.wx-year.wx-current {
|
|
80
|
+
background: var(--wx-color-primary);
|
|
81
|
+
color: var(--wx-color-primary-font);
|
|
82
|
+
}
|
|
83
|
+
.wx-year:not(.wx-current):hover {
|
|
84
|
+
background-color: var(--wx-background-hover);
|
|
85
|
+
}
|
|
86
|
+
.wx-prev-decade,
|
|
87
|
+
.wx-next-decade {
|
|
88
|
+
color: var(--wx-color-font-disabled);
|
|
89
|
+
}
|
|
90
|
+
.wx-buttons {
|
|
91
|
+
display: flex;
|
|
92
|
+
flex-wrap: nowrap;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: center;
|
|
95
|
+
margin-top: var(--wx-calendar-gap);
|
|
96
|
+
}
|
|
97
|
+
</style>
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getContext, createEventDispatcher } from "svelte";
|
|
3
|
+
const dispatch = createEventDispatcher();
|
|
4
|
+
|
|
5
|
+
const locale = getContext("wx-i18n").getRaw().calendar;
|
|
6
|
+
const monthNames = locale.monthFull;
|
|
7
|
+
|
|
8
|
+
export let date;
|
|
9
|
+
export let type;
|
|
10
|
+
|
|
11
|
+
export let part;
|
|
12
|
+
|
|
13
|
+
let month, year, label;
|
|
14
|
+
$: {
|
|
15
|
+
month = date.getMonth();
|
|
16
|
+
year = date.getFullYear();
|
|
17
|
+
|
|
18
|
+
switch (type) {
|
|
19
|
+
case "month":
|
|
20
|
+
label = `${monthNames[month]} ${year}`;
|
|
21
|
+
break;
|
|
22
|
+
case "year":
|
|
23
|
+
label = year;
|
|
24
|
+
break;
|
|
25
|
+
case "duodecade": {
|
|
26
|
+
const start = year - (year % 10);
|
|
27
|
+
const end = start + 9;
|
|
28
|
+
|
|
29
|
+
label = `${start} - ${end}`;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function changeType() {
|
|
36
|
+
dispatch("shift", { diff: 0, type });
|
|
37
|
+
}
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<div class="wx-header">
|
|
41
|
+
{#if part != "right"}
|
|
42
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
43
|
+
<i
|
|
44
|
+
class="wx-pager wxi-angle-left"
|
|
45
|
+
on:click={() => dispatch("shift", { diff: -1, type })}
|
|
46
|
+
/>
|
|
47
|
+
{:else}<span class="wx-spacer" />{/if}
|
|
48
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
49
|
+
<span class="wx-label" on:click={changeType}>{label}</span>
|
|
50
|
+
{#if part != "left"}
|
|
51
|
+
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
52
|
+
<i
|
|
53
|
+
class="wx-pager wxi-angle-right"
|
|
54
|
+
on:click={() => dispatch("shift", { diff: 1, type })}
|
|
55
|
+
/>
|
|
56
|
+
{:else}<span class="wx-spacer" />{/if}
|
|
57
|
+
</div>
|
|
58
|
+
|
|
59
|
+
<style>
|
|
60
|
+
.wx-header {
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-wrap: nowrap;
|
|
63
|
+
align-items: center;
|
|
64
|
+
margin-bottom: calc(var(--wx-calendar-gap) * 2);
|
|
65
|
+
font-size: var(--wx-calendar-header-font-size);
|
|
66
|
+
line-height: var(--wx-calendar-header-line-height);
|
|
67
|
+
font-weight: var(--wx-calendar-header-font-weight);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.wx-spacer,
|
|
71
|
+
.wx-pager {
|
|
72
|
+
width: var(--wx-calendar-cell-size);
|
|
73
|
+
height: var(--wx-calendar-cell-size);
|
|
74
|
+
flex-shrink: 0;
|
|
75
|
+
}
|
|
76
|
+
.wx-pager {
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
border-radius: 50%;
|
|
79
|
+
line-height: 1;
|
|
80
|
+
display: flex;
|
|
81
|
+
flex-wrap: nowrap;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
user-select: none;
|
|
85
|
+
color: var(--wx-calendar-icon-color);
|
|
86
|
+
font-size: var(--wx-calendar-icon-size);
|
|
87
|
+
}
|
|
88
|
+
.wx-pager:before {
|
|
89
|
+
display: block;
|
|
90
|
+
}
|
|
91
|
+
.wx-pager:hover {
|
|
92
|
+
background-color: var(--wx-background-hover);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
.wx-label {
|
|
96
|
+
flex: 0 0 calc(100% - var(--wx-calendar-cell-size) * 2);
|
|
97
|
+
max-width: calc(100% - var(--wx-calendar-cell-size) * 2);
|
|
98
|
+
text-align: center;
|
|
99
|
+
color: var(--wx-color-link);
|
|
100
|
+
cursor: pointer;
|
|
101
|
+
overflow: hidden;
|
|
102
|
+
white-space: nowrap;
|
|
103
|
+
text-overflow: ellipsis;
|
|
104
|
+
}
|
|
105
|
+
</style>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { getContext } from "svelte";
|
|
3
|
+
import { delegateClick } from "wx-lib-dom";
|
|
4
|
+
|
|
5
|
+
export let value;
|
|
6
|
+
export let current;
|
|
7
|
+
export let cancel;
|
|
8
|
+
export let select;
|
|
9
|
+
export let part;
|
|
10
|
+
export let markers = null;
|
|
11
|
+
|
|
12
|
+
const locale = getContext("wx-i18n").getRaw().calendar;
|
|
13
|
+
const weekStart = (locale.weekStart || 7) % 7;
|
|
14
|
+
const weekdays = locale.dayShort
|
|
15
|
+
.slice(weekStart)
|
|
16
|
+
.concat(locale.dayShort.slice(0, weekStart));
|
|
17
|
+
|
|
18
|
+
let days;
|
|
19
|
+
let date;
|
|
20
|
+
|
|
21
|
+
const dv = (d, dm, dd) =>
|
|
22
|
+
new Date(
|
|
23
|
+
d.getFullYear(),
|
|
24
|
+
d.getMonth() + (dm || 0),
|
|
25
|
+
d.getDate() + (dd || 0)
|
|
26
|
+
);
|
|
27
|
+
let ranges = part !== "normal";
|
|
28
|
+
$: {
|
|
29
|
+
if (part == "normal") date = [value ? dv(value).valueOf() : 0];
|
|
30
|
+
else
|
|
31
|
+
date = value
|
|
32
|
+
? [
|
|
33
|
+
value.start ? dv(value.start).valueOf() : 0,
|
|
34
|
+
value.end ? dv(value.end).valueOf() : 0,
|
|
35
|
+
]
|
|
36
|
+
: [0, 0];
|
|
37
|
+
|
|
38
|
+
const start = getStart();
|
|
39
|
+
const end = getEnd();
|
|
40
|
+
const curMonth = current.getMonth();
|
|
41
|
+
days = [];
|
|
42
|
+
for (let d = start; d <= end; d.setDate(d.getDate() + 1)) {
|
|
43
|
+
const day = {
|
|
44
|
+
day: d.getDate(),
|
|
45
|
+
in: d.getMonth() === curMonth,
|
|
46
|
+
date: d.valueOf(),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
let css = "";
|
|
50
|
+
css += !day.in ? " wx-inactive" : "";
|
|
51
|
+
css += date.indexOf(day.date) > -1 ? " wx-selected" : "";
|
|
52
|
+
|
|
53
|
+
if (ranges) {
|
|
54
|
+
const s = day.date == date[0];
|
|
55
|
+
const e = day.date == date[1];
|
|
56
|
+
if (s && !e) css += " wx-left";
|
|
57
|
+
else if (e && !s) css += " wx-right";
|
|
58
|
+
|
|
59
|
+
if (day.date > date[0] && day.date < date[1])
|
|
60
|
+
css += " wx-inrange";
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
css += isWeekEnd(d) ? " wx-weekend" : "";
|
|
64
|
+
if (markers) {
|
|
65
|
+
const mark = markers(d);
|
|
66
|
+
if (mark) css += " " + mark;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
days.push({ ...day, css });
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function isWeekEnd(date) {
|
|
74
|
+
const d = date.getDay();
|
|
75
|
+
return d === 0 || d === 6;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function getStart() {
|
|
79
|
+
const start = dv(current, 0, 1 - current.getDate());
|
|
80
|
+
start.setDate(
|
|
81
|
+
start.getDate() - ((start.getDay() - (weekStart - 7)) % 7)
|
|
82
|
+
);
|
|
83
|
+
return start;
|
|
84
|
+
}
|
|
85
|
+
function getEnd() {
|
|
86
|
+
const end = dv(current, 1, -current.getDate());
|
|
87
|
+
end.setDate(end.getDate() + ((6 - end.getDay() + weekStart) % 7));
|
|
88
|
+
return end;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const selectDates = {
|
|
92
|
+
click: selectDate,
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
function selectDate(date, e) {
|
|
96
|
+
if (select) {
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
select(new Date(new Date(date)));
|
|
99
|
+
}
|
|
100
|
+
if (cancel) cancel();
|
|
101
|
+
}
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<div>
|
|
105
|
+
<div class="wx-weekdays">
|
|
106
|
+
{#each weekdays as day}
|
|
107
|
+
<div class="wx-weekday">{day}</div>
|
|
108
|
+
{/each}
|
|
109
|
+
</div>
|
|
110
|
+
<div class="wx-days" use:delegateClick={selectDates}>
|
|
111
|
+
{#each days as day (day.date)}
|
|
112
|
+
<div
|
|
113
|
+
class="wx-day {day.css}"
|
|
114
|
+
class:wx-out={!day.in}
|
|
115
|
+
data-id={day.date}
|
|
116
|
+
>
|
|
117
|
+
{day.day}
|
|
118
|
+
</div>
|
|
119
|
+
{/each}
|
|
120
|
+
</div>
|
|
121
|
+
</div>
|
|
122
|
+
|
|
123
|
+
<style>
|
|
124
|
+
.wx-weekdays {
|
|
125
|
+
display: flex;
|
|
126
|
+
flex-wrap: nowrap;
|
|
127
|
+
margin-bottom: calc(var(--wx-calendar-gap) * 1.5);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.wx-weekday {
|
|
131
|
+
flex: 0 0 calc(100% / 7);
|
|
132
|
+
max-width: calc(100% / 7);
|
|
133
|
+
font-size: var(--wx-font-size-sm);
|
|
134
|
+
line-height: var(--wx-line-height-sm);
|
|
135
|
+
color: var(--wx-color-font-alt);
|
|
136
|
+
text-align: center;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.wx-days {
|
|
140
|
+
display: flex;
|
|
141
|
+
flex-wrap: wrap;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.wx-day {
|
|
145
|
+
border-radius: var(--wx-calendar-border-radius);
|
|
146
|
+
flex: 0 0 calc(100% / 7);
|
|
147
|
+
max-width: calc(100% / 7);
|
|
148
|
+
height: calc(
|
|
149
|
+
var(--wx-calendar-cell-size) - var(--wx-calendar-line-gap) * 2
|
|
150
|
+
);
|
|
151
|
+
margin: calc(var(--wx-calendar-line-gap) / 2) 0;
|
|
152
|
+
display: flex;
|
|
153
|
+
flex-wrap: nowrap;
|
|
154
|
+
align-items: center;
|
|
155
|
+
justify-content: center;
|
|
156
|
+
text-align: center;
|
|
157
|
+
}
|
|
158
|
+
.wx-day:not(.wx-out):not(.wx-selected) {
|
|
159
|
+
cursor: pointer;
|
|
160
|
+
}
|
|
161
|
+
.wx-day:not(.wx-out):not(.wx-selected):hover {
|
|
162
|
+
background: var(--wx-background-hover);
|
|
163
|
+
}
|
|
164
|
+
.wx-day.wx-out {
|
|
165
|
+
color: var(--wx-color-font-disabled);
|
|
166
|
+
}
|
|
167
|
+
.wx-day.wx-selected:not(.wx-out) {
|
|
168
|
+
background: var(--wx-color-primary);
|
|
169
|
+
color: var(--wx-color-primary-font);
|
|
170
|
+
}
|
|
171
|
+
.wx-day.wx-selected.wx-left:not(.wx-out) {
|
|
172
|
+
border-radius: calc(var(--wx-calendar-border-radius)) 0 0
|
|
173
|
+
calc(var(--wx-calendar-border-radius));
|
|
174
|
+
}
|
|
175
|
+
.wx-day.wx-selected.wx-right:not(.wx-out) {
|
|
176
|
+
border-radius: 0 calc(var(--wx-calendar-border-radius))
|
|
177
|
+
calc(var(--wx-calendar-border-radius)) 0;
|
|
178
|
+
}
|
|
179
|
+
.wx-day.wx-inrange:not(.wx-out) {
|
|
180
|
+
border-radius: 0;
|
|
181
|
+
background: var(--wx-color-primary-selected);
|
|
182
|
+
}
|
|
183
|
+
.wx-day.wx-weekend:not(.wx-selected):not(.wx-out) {
|
|
184
|
+
color: var(--wx-color-primary);
|
|
185
|
+
}
|
|
186
|
+
.wx-day.wx-inactive {
|
|
187
|
+
pointer-events: none;
|
|
188
|
+
}
|
|
189
|
+
</style>
|