@ysgroup/ui 0.1.57 → 0.1.58

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ysgroup/ui",
3
- "version": "0.1.57",
3
+ "version": "0.1.58",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -25,7 +25,7 @@
25
25
  "access": "public"
26
26
  },
27
27
  "devDependencies": {
28
- "@ysgroup/contracts": "^0.1.51",
28
+ "@ysgroup/contracts": "^0.1.52",
29
29
  "@ysgroup/core": "^0.1.32",
30
30
  "@ysgroup/theme": "^0.3.3",
31
31
  "docx-preview": "^0.4.1"
@@ -1,12 +1,18 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
- * 月历:两种视图——「休班」标放假、调休上班和节日名;「交易日」只回答开不开市:交易日左侧主色竖条、右上角写本月
4
- * 第几个交易日,节前最后、节后首日、月初、月末这几个关键交易日加小标签,休市日(周末、放假、调休上班的周末)斜纹底写「休市」。
3
+ * 月历:每天右上角一个状态标签,底色跟着状态走,一眼分清能不能交易、要不要上班。
5
4
  *
5
+ * - mark="trading" 交易日视图:交易日浅绿底、蓝色「交易日」标签(showOrdinal 时旁边写本月第几个,默认不写);
6
+ * 休市日(周末、放假、法定补班的周末)不上底色,写灰色「休市」。
7
+ * - mark="work" 工作日视图:工作日和法定补班(调休上班的周末)浅绿底,分别写「工作日」「法定补班」
8
+ * (实心标签,最醒目);周末不上底色写「休息」,法定放假浅橙底写「放假」和节日名。
9
+ * - 不传 mark(或 mark="none")是默认视图:只当普通月历用,只显示日期和事件。
10
+ * - 上月、下月的格子只留淡底色和日期,不写标签。
11
+ * - 标签文字可以用 labels 改(如把「法定补班」改成「调休上班」);showLabel、showOrdinal 控制标签和序号显不显示。
6
12
  * - 日期信息(days)由服务端 ys_base.calendar 下发,组件只显示,不自己按周一到周五猜;某天 covered 为 false 表示这一年
7
- * 还没有放假安排,顶部写明、格子不标休班也不标交易日。交易日标记由 @ysgroup/core 的 ysTradingMarks 按 trading 字段推出。
13
+ * 还没有放假安排,顶部写明、格子不标状态。序号由 @ysgroup/core 的 ysTradingMarks 按 trading 字段推出,只对完整月份标。
14
+ * - 图例可以点:悬停或点一项,只突出这一类日子,再点一次取消。
8
15
  * - v-model 是选中日期,v-model:month 是显示的月份(`YYYY-MM`);翻月后按 ysMonthRange(month) 取这一屏的日期信息。
9
- * - mark="work" | "trading" 选视图(旧的 trading 属性等于 mark="trading");summary 在顶部显示本月统计。
10
16
  * - 键盘:方向键移动一天或一周,PageUp / PageDown 翻月,Home / End 到本周一 / 周日,Enter 或空格选中;跨月自动翻页。
11
17
  * - 事件条(events)每格最多 maxEvents 条,其余收成「+N」(触发 more);要完全自定义格子内容用 #day 插槽。
12
18
  */
@@ -37,6 +43,26 @@ export interface YsCalendarEvent {
37
43
  tone?: "primary" | "success" | "warning" | "danger" | "info";
38
44
  }
39
45
 
46
+ /** 格子状态:交易日视图 trading / closed,工作日视图 workday / adjusted / weekend / holiday。 */
47
+ export type YsCalendarStatus =
48
+ | "trading"
49
+ | "closed"
50
+ | "workday"
51
+ | "adjusted"
52
+ | "weekend"
53
+ | "holiday";
54
+ /** 各状态标签上的文字。 */
55
+ export type YsCalendarLabels = Record<YsCalendarStatus, string>;
56
+
57
+ const DEFAULT_LABELS: YsCalendarLabels = {
58
+ trading: "交易日",
59
+ closed: "休市",
60
+ workday: "工作日",
61
+ adjusted: "法定补班",
62
+ weekend: "休息",
63
+ holiday: "放假",
64
+ };
65
+
40
66
  const props = withDefaults(
41
67
  defineProps<{
42
68
  modelValue?: string;
@@ -46,11 +72,17 @@ const props = withDefaults(
46
72
  today?: string;
47
73
  loading?: boolean;
48
74
  size?: "default" | "small";
49
- /** 视图:work 休班(默认)、trading 交易日。 */
50
- mark?: "work" | "trading";
75
+ /** 视图:none 默认(不标状态)、work 工作日、trading 交易日。 */
76
+ mark?: "work" | "trading" | "none";
51
77
  /** 旧写法,等于 mark="trading"。 */
52
78
  trading?: boolean;
53
- /** 顶部显示本月统计(休班视图:工作日、放假、调休上班;交易日视图:交易日、休市)。 */
79
+ /** 改标签文字,只写要改的几项,如 { adjusted: "调休上班" }。 */
80
+ labels?: Partial<YsCalendarLabels>;
81
+ /** 每格右上角显示状态标签(迷你模式不显示,只留底色)。 */
82
+ showLabel?: boolean;
83
+ /** 交易日视图在标签旁写本月第几个交易日(默认不写,选中日详情里写)。 */
84
+ showOrdinal?: boolean;
85
+ /** 顶部显示本月统计(工作日视图:工作日、法定补班、放假;交易日视图:交易日、休市)。 */
54
86
  summary?: boolean;
55
87
  maxEvents?: number;
56
88
  /** 不能选的日期(如非交易日):变淡、点了不选中。 */
@@ -68,6 +100,9 @@ const props = withDefaults(
68
100
  size: "default",
69
101
  mark: undefined,
70
102
  trading: false,
103
+ labels: () => ({}),
104
+ showLabel: true,
105
+ showOrdinal: false,
71
106
  summary: false,
72
107
  maxEvents: 3,
73
108
  disabledDate: undefined,
@@ -112,9 +147,12 @@ const eventMap = computed(() => {
112
147
  return map;
113
148
  });
114
149
  const small = computed(() => props.size === "small");
115
- const tradingView = computed(
116
- () => (props.mark ?? (props.trading ? "trading" : "work")) === "trading",
117
- );
150
+ const view = computed(() => props.mark ?? (props.trading ? "trading" : "none"));
151
+ const tradingView = computed(() => view.value === "trading");
152
+ const labelText = computed<YsCalendarLabels>(() => ({
153
+ ...DEFAULT_LABELS,
154
+ ...props.labels,
155
+ }));
118
156
  const marks = computed(() =>
119
157
  tradingView.value
120
158
  ? ysTradingMarks(props.days)
@@ -129,26 +167,29 @@ const missingYears = computed(() => {
129
167
  years.add(cell.date.slice(0, 4));
130
168
  return [...years].sort();
131
169
  });
132
- const showLegend = computed(
133
- () => !small.value && (props.legend ?? props.days.length > 0),
134
- );
135
170
  const todayVisible = computed(() =>
136
171
  cells.value.some((cell) => cell.date === todayText.value),
137
172
  );
138
173
 
139
174
  /** 顶部统计:拆成「名称 + 数字」几段,数字加粗。月份信息不全时不显示。 */
140
175
  const summaryParts = computed(() => {
141
- if (!props.summary || small.value) return [];
176
+ if (!props.summary || small.value || view.value === "none") return [];
142
177
  const value = ysMonthSummary(props.days, shownMonth.value);
143
178
  if (!value.complete) return [];
179
+ const labels = labelText.value;
144
180
  if (tradingView.value)
145
181
  return [
146
- { label: "交易日", value: value.trading },
147
- { label: "休市", value: value.closed },
182
+ { label: labels.trading, value: value.trading },
183
+ { label: labels.closed, value: value.closed },
148
184
  ];
149
- const parts = [{ label: "工作日", value: value.workdays }];
150
- if (value.holidays) parts.push({ label: "放假", value: value.holidays });
151
- if (value.adjusted) parts.push({ label: "调休上班", value: value.adjusted });
185
+ // 和图例一致:工作日不含法定补班,法定补班单列
186
+ const parts = [
187
+ { label: labels.workday, value: value.workdays - value.adjusted },
188
+ ];
189
+ if (value.adjusted)
190
+ parts.push({ label: labels.adjusted, value: value.adjusted });
191
+ if (value.holidays)
192
+ parts.push({ label: labels.holiday, value: value.holidays });
152
193
  return parts;
153
194
  });
154
195
 
@@ -169,30 +210,48 @@ function covered(date: string): boolean {
169
210
  const item = info(date);
170
211
  return Boolean(item) && item?.covered !== false;
171
212
  }
172
- function badge(date: string): "休" | "班" | "" {
173
- if (tradingView.value || !covered(date)) return "";
174
- const kind = info(date)?.kind;
175
- return kind === "holiday" ? "休" : kind === "adjusted" ? "班" : "";
213
+ /** 这一天的状态;没有日期信息、这一年没有放假安排或 mark="none" 时为空。 */
214
+ function status(date: string): YsCalendarStatus | "" {
215
+ if (view.value === "none" || !covered(date)) return "";
216
+ const item = info(date);
217
+ if (!item) return "";
218
+ if (tradingView.value) return item.trading ? "trading" : "closed";
219
+ return item.kind;
176
220
  }
177
- function isRest(cell: YsMonthCell): boolean {
178
- const item = info(cell.date);
179
- if (item && item.covered !== false)
180
- return item.kind === "holiday" || item.kind === "weekend";
181
- return cell.weekday >= 5;
221
+ /** 上月、下月的格子只留淡底色和日期,标签、序号、节日名只在本月写。 */
222
+ function inShownMonth(date: string): boolean {
223
+ return date.startsWith(shownMonth.value);
182
224
  }
183
- function isTrading(date: string): boolean {
184
- return tradingView.value && covered(date) && Boolean(info(date)?.trading);
225
+ function statusLabel(date: string): string {
226
+ if (!inShownMonth(date)) return "";
227
+ const value = status(date);
228
+ return value ? labelText.value[value] : "";
185
229
  }
186
- function isClosed(date: string): boolean {
187
- return tradingView.value && covered(date) && !info(date)?.trading;
230
+ /** 迷你模式工作日视图在数字右上角挂「休」「班」小角标。 */
231
+ function badge(date: string): "休" | "班" | "" {
232
+ if (!inShownMonth(date)) return "";
233
+ const value = status(date);
234
+ return value === "holiday" ? "休" : value === "adjusted" ? "班" : "";
188
235
  }
189
- /** 格子第二行:休班视图写节日名;交易日视图休市日写「休市」或「端午节 · 休市」。 */
236
+ function isWeekendCell(cell: YsMonthCell): boolean {
237
+ const value = status(cell.date);
238
+ if (value) return value === "weekend" || value === "holiday";
239
+ return cell.weekday >= 5;
240
+ }
241
+ /** 状态标签下面那一行:节日名;交易日视图休市日写「国庆节 · 休市」,法定补班写「国庆节调休」。 */
190
242
  function subline(date: string): string {
191
- if (!covered(date)) return "";
192
- const item = info(date);
193
- if (tradingView.value)
194
- return isClosed(date) ? (item?.name ? `${item.name} · 休市` : "休市") : "";
195
- return item?.name ?? "";
243
+ if (!inShownMonth(date)) return "";
244
+ const value = status(date);
245
+ const name = info(date)?.name ?? "";
246
+ if (!value || !name) return "";
247
+ if (value === "closed") return `${name} · ${labelText.value.closed}`;
248
+ if (value === "adjusted") return `${name}调休`;
249
+ return name;
250
+ }
251
+ function ordinalOf(date: string): number | undefined {
252
+ return props.showOrdinal && inShownMonth(date)
253
+ ? marks.value.get(date)?.ordinal
254
+ : undefined;
196
255
  }
197
256
  function markOf(date: string): YsTradingMark | undefined {
198
257
  return marks.value.get(date);
@@ -204,7 +263,7 @@ function ariaLabel(cell: YsMonthCell): string {
204
263
  const item = info(cell.date);
205
264
  const parts = [ysDateTitle(cell.date)];
206
265
  if (item?.covered === false) parts.push("放假安排还没有");
207
- else if (item) {
266
+ else if (item && view.value !== "none") {
208
267
  parts.push(
209
268
  item.name
210
269
  ? `${YS_DAY_KIND_LABELS[item.kind]} ${item.name}`
@@ -230,6 +289,43 @@ function ariaLabel(cell: YsMonthCell): string {
230
289
  return parts.join(",");
231
290
  }
232
291
 
292
+ // ---------- 图例:悬停或点一项,只突出这一类 ----------
293
+ const legendItems = computed<{ key: YsCalendarStatus; text: string }[]>(() => {
294
+ if (tradingView.value)
295
+ return [
296
+ { key: "trading", text: props.showOrdinal ? "旁边是本月第几个" : "" },
297
+ { key: "closed", text: `周末、放假和${labelText.value.adjusted}的周末` },
298
+ ];
299
+ if (view.value === "work")
300
+ return [
301
+ { key: "workday", text: "" },
302
+ { key: "adjusted", text: "调休上班的周末" },
303
+ { key: "weekend", text: "" },
304
+ { key: "holiday", text: "法定节假日" },
305
+ ];
306
+ return [];
307
+ });
308
+ const showLegend = computed(
309
+ () =>
310
+ !small.value &&
311
+ (props.legend ?? props.days.length > 0) &&
312
+ (legendItems.value.length > 0 || todayVisible.value),
313
+ );
314
+ const legendHover = ref<YsCalendarStatus | "">("");
315
+ const legendPinned = ref<YsCalendarStatus | "">("");
316
+ const focusStatus = computed(() => legendHover.value || legendPinned.value);
317
+ watch(view, () => {
318
+ legendHover.value = "";
319
+ legendPinned.value = "";
320
+ });
321
+ function togglePinned(key: YsCalendarStatus) {
322
+ legendPinned.value = legendPinned.value === key ? "" : key;
323
+ }
324
+ function legendCount(key: YsCalendarStatus): number {
325
+ return cells.value.filter((cell) => cell.inMonth && status(cell.date) === key)
326
+ .length;
327
+ }
328
+
233
329
  // ---------- 选择与键盘 ----------
234
330
  const grid = ref<HTMLElement | null>(null);
235
331
  const focusDate = ref(
@@ -306,7 +402,11 @@ function goToday() {
306
402
  <template>
307
403
  <div
308
404
  class="ys-calendar"
309
- :class="{ 'is-small': small, 'is-trading-view': tradingView }"
405
+ :class="{
406
+ 'is-small': small,
407
+ 'is-trading-view': tradingView,
408
+ 'is-focusing': Boolean(focusStatus),
409
+ }"
310
410
  >
311
411
  <header class="ys-calendar__head">
312
412
  <div class="ys-calendar__nav">
@@ -366,7 +466,7 @@ function goToday() {
366
466
  role="status"
367
467
  >
368
468
  {{ missingYears.join("、") }} 年的放假安排还没有(国务院办公厅一般在上一年
369
- 10–11 月发布),这些日期暂不标休班和交易日。
469
+ 10–11 月发布),这些日期暂不标工作日和交易日。
370
470
  </p>
371
471
 
372
472
  <div
@@ -404,25 +504,20 @@ function goToday() {
404
504
  :aria-selected="cell.date === modelValue"
405
505
  :aria-disabled="disabled(cell.date) || undefined"
406
506
  :aria-label="ariaLabel(cell)"
407
- :title="small ? ariaLabel(cell) : undefined"
408
- :class="{
409
- 'is-outside': !cell.inMonth,
410
- 'is-today': cell.date === todayText,
411
- 'is-selected': cell.date === modelValue,
412
- 'is-rest': isRest(cell),
413
- 'is-holiday':
414
- !tradingView &&
415
- covered(cell.date) &&
416
- info(cell.date)?.kind === 'holiday',
417
- 'is-adjusted':
418
- !tradingView &&
419
- covered(cell.date) &&
420
- info(cell.date)?.kind === 'adjusted',
421
- 'is-trading': isTrading(cell.date),
422
- 'is-closed': isClosed(cell.date),
423
- 'is-uncovered': info(cell.date)?.covered === false,
424
- 'is-disabled': disabled(cell.date),
425
- }"
507
+ :title="ariaLabel(cell)"
508
+ :class="[
509
+ status(cell.date) ? `is-${status(cell.date)}` : '',
510
+ {
511
+ 'is-outside': !cell.inMonth,
512
+ 'is-today': cell.date === todayText,
513
+ 'is-selected': cell.date === modelValue,
514
+ 'is-weekend-day': isWeekendCell(cell),
515
+ 'is-uncovered': info(cell.date)?.covered === false,
516
+ 'is-disabled': disabled(cell.date),
517
+ 'is-dimmed':
518
+ Boolean(focusStatus) && status(cell.date) !== focusStatus,
519
+ },
520
+ ]"
426
521
  @click="select(cell.date)"
427
522
  @focus="focusDate = cell.date"
428
523
  >
@@ -432,40 +527,44 @@ function goToday() {
432
527
  :info="info(cell.date)"
433
528
  :events="eventsOf(cell.date)"
434
529
  :mark="markOf(cell.date)"
530
+ :status="status(cell.date)"
435
531
  >
436
532
  <div class="ys-calendar__top">
437
533
  <span class="ys-calendar__date">{{
438
534
  Number(cell.date.slice(8))
439
535
  }}</span>
440
536
  <span
441
- v-if="badge(cell.date)"
537
+ v-if="small && badge(cell.date)"
442
538
  class="ys-calendar__badge"
443
539
  :class="badge(cell.date) === '休' ? 'is-off' : 'is-work'"
444
540
  >{{ badge(cell.date) }}</span
445
541
  >
446
542
  <span
447
- v-else-if="!small && markOf(cell.date)?.ordinal"
448
- class="ys-calendar__ordinal"
449
- aria-hidden="true"
450
- >{{ markOf(cell.date)?.ordinal }}</span
543
+ v-else-if="
544
+ !small &&
545
+ (ordinalOf(cell.date) ||
546
+ (showLabel && statusLabel(cell.date)))
547
+ "
548
+ class="ys-calendar__status"
451
549
  >
550
+ <span
551
+ v-if="ordinalOf(cell.date)"
552
+ class="ys-calendar__ordinal"
553
+ aria-hidden="true"
554
+ >第 {{ ordinalOf(cell.date) }} 个</span
555
+ >
556
+ <span
557
+ v-if="showLabel && statusLabel(cell.date)"
558
+ class="ys-calendar__label"
559
+ aria-hidden="true"
560
+ >{{ statusLabel(cell.date) }}</span
561
+ >
562
+ </span>
452
563
  </div>
453
564
  <template v-if="!small">
454
565
  <div v-if="subline(cell.date)" class="ys-calendar__name">
455
566
  {{ subline(cell.date) }}
456
567
  </div>
457
- <div
458
- v-if="markOf(cell.date)?.tags.length"
459
- class="ys-calendar__tags"
460
- >
461
- <span
462
- v-for="tag in markOf(cell.date)?.tags"
463
- :key="tag"
464
- class="ys-calendar__tag"
465
- :class="`is-${tag}`"
466
- >{{ YS_TRADING_TAG_LABELS[tag].short }}</span
467
- >
468
- </div>
469
568
  <ul v-if="eventsOf(cell.date).length" class="ys-calendar__events">
470
569
  <li
471
570
  v-for="item in eventsOf(cell.date).slice(0, maxEvents)"
@@ -498,27 +597,26 @@ function goToday() {
498
597
  </div>
499
598
 
500
599
  <footer v-if="showLegend" class="ys-calendar__legend">
501
- <template v-if="tradingView">
502
- <span
503
- ><i
504
- class="ys-calendar__swatch is-trading"
505
- />交易日(右上角是本月第几个)</span
506
- >
507
- <span
508
- ><i
509
- class="ys-calendar__swatch is-closed"
510
- />休市:周末、放假和调休上班的周末</span
511
- >
512
- <span
513
- ><i class="ys-calendar__tag is-pre-holiday">节前最后</i
514
- ><i class="ys-calendar__tag is-month-last">月末最后</i
515
- >关键交易日</span
516
- >
517
- </template>
518
- <template v-else>
519
- <span><i class="ys-calendar__badge is-off">休</i>放假</span>
520
- <span><i class="ys-calendar__badge is-work">班</i>调休上班</span>
521
- </template>
600
+ <button
601
+ v-for="item in legendItems"
602
+ :key="item.key"
603
+ type="button"
604
+ class="ys-calendar__legend-item"
605
+ :class="[`is-${item.key}`, { 'is-active': legendPinned === item.key }]"
606
+ :aria-pressed="legendPinned === item.key"
607
+ :title="`只突出${labelText[item.key]},再点一次取消`"
608
+ @mouseenter="legendHover = item.key"
609
+ @mouseleave="legendHover = ''"
610
+ @focus="legendHover = item.key"
611
+ @blur="legendHover = ''"
612
+ @click="togglePinned(item.key)"
613
+ >
614
+ <i class="ys-calendar__swatch">{{ labelText[item.key] }}</i>
615
+ <strong>{{ legendCount(item.key) }}</strong>
616
+ <span v-if="item.text" class="ys-calendar__legend-note">{{
617
+ item.text
618
+ }}</span>
619
+ </button>
522
620
  <span v-if="todayVisible" class="ys-calendar__legend-today">今天</span>
523
621
  </footer>
524
622
  </div>
@@ -526,27 +624,52 @@ function goToday() {
526
624
 
527
625
  <style scoped>
528
626
  .ys-calendar {
529
- --cal-rest: color-mix(
627
+ /* 每种状态一个色调:交易日、工作日和法定补班绿,放假橙,休息、休市灰 */
628
+ --cal-trading: var(--ys-color-success);
629
+ --cal-workday: var(--ys-color-success);
630
+ --cal-holiday: var(--ys-color-warning);
631
+ --cal-rest: var(--ys-color-text-3);
632
+ /* 底色:不支持相对颜色的浏览器用混色兜底 */
633
+ --cal-open-bg: color-mix(
530
634
  in srgb,
531
- var(--ys-color-success) 82%,
532
- var(--ys-color-text-1)
635
+ var(--ys-color-success) 6%,
636
+ var(--ys-color-bg-elevated)
533
637
  );
534
- --cal-work: color-mix(
638
+ --cal-open-hover: color-mix(
535
639
  in srgb,
536
- var(--ys-color-warning) 80%,
537
- var(--ys-color-text-1)
640
+ var(--ys-color-success) 10%,
641
+ var(--ys-color-bg-elevated)
642
+ );
643
+ --cal-holiday-bg: color-mix(
644
+ in srgb,
645
+ var(--ys-color-warning) 6%,
646
+ var(--ys-color-bg-elevated)
538
647
  );
539
- --cal-bar: color-mix(in srgb, var(--ys-color-primary) 75%, transparent);
540
- --cal-stripe: repeating-linear-gradient(
541
- 135deg,
542
- color-mix(in srgb, var(--ys-color-text-3) 10%, transparent) 0 5px,
543
- transparent 5px 11px
648
+ --cal-holiday-hover: color-mix(
649
+ in srgb,
650
+ var(--ys-color-warning) 10%,
651
+ var(--ys-color-bg-elevated)
544
652
  );
545
653
  display: flex;
546
654
  flex-direction: column;
547
655
  gap: 8px;
548
656
  min-width: 0;
549
657
  }
658
+ /* 支持相对颜色时,底色固定亮度和饱和度:柔和的浅绿和浅橙,不发灰也不刺眼 */
659
+ @supports (color: oklch(from red l c h)) {
660
+ .ys-calendar {
661
+ --cal-open-bg: oklch(from var(--ys-color-success) 0.976 0.018 h);
662
+ --cal-open-hover: oklch(from var(--ys-color-success) 0.952 0.03 h);
663
+ --cal-holiday-bg: oklch(from var(--ys-color-warning) 0.975 0.02 h);
664
+ --cal-holiday-hover: oklch(from var(--ys-color-warning) 0.952 0.032 h);
665
+ }
666
+ html[data-theme="dark"] .ys-calendar {
667
+ --cal-open-bg: oklch(from var(--ys-color-success) 0.25 0.028 h);
668
+ --cal-open-hover: oklch(from var(--ys-color-success) 0.29 0.04 h);
669
+ --cal-holiday-bg: oklch(from var(--ys-color-warning) 0.25 0.028 h);
670
+ --cal-holiday-hover: oklch(from var(--ys-color-warning) 0.29 0.04 h);
671
+ }
672
+ }
550
673
  .ys-calendar__head {
551
674
  display: flex;
552
675
  flex-wrap: wrap;
@@ -598,7 +721,6 @@ function goToday() {
598
721
  .ys-calendar__missing {
599
722
  margin: 0;
600
723
  padding: 6px 10px;
601
- border-left: 3px solid var(--ys-color-warning);
602
724
  border-radius: var(--ys-radius-s);
603
725
  color: var(--ys-color-text-2);
604
726
  background: color-mix(in srgb, var(--ys-color-warning) 8%, transparent);
@@ -634,11 +756,14 @@ function goToday() {
634
756
  font-weight: 600;
635
757
  }
636
758
  .ys-calendar__weekday.is-weekend {
637
- color: var(--cal-rest);
759
+ color: var(--ys-color-text-3);
638
760
  }
761
+
762
+ /* 格子:--tone 是状态色调(标签、节日名用),--bg 是底色 */
639
763
  .ys-calendar__cell {
640
- --cal-ring: 0 0 0 0 transparent;
641
- --cal-left: 0 0 0 0 transparent;
764
+ --tone: transparent;
765
+ --bg: transparent;
766
+ --ring: 0 0 0 0 transparent;
642
767
  position: relative;
643
768
  display: flex;
644
769
  flex-direction: column;
@@ -646,60 +771,62 @@ function goToday() {
646
771
  min-width: 0;
647
772
  /* 格子随宽度略微变高,大屏不显得扁 */
648
773
  min-height: clamp(88px, 6.8vw, 128px);
649
- padding: 6px 6px 6px 8px;
774
+ padding: 6px;
650
775
  cursor: pointer;
651
776
  outline: none;
652
- box-shadow: var(--cal-left), var(--cal-ring);
653
- transition:
654
- background-color 0.15s ease,
655
- box-shadow 0.15s ease;
777
+ background-color: var(--bg);
778
+ box-shadow: var(--ring);
779
+ transition: box-shadow 0.15s ease;
656
780
  }
657
781
  .ys-calendar__cell + .ys-calendar__cell {
658
782
  border-left: 1px solid var(--ys-color-border);
659
783
  }
660
784
  .ys-calendar__cell:hover {
661
- background-color: color-mix(in srgb, var(--ys-color-primary) 4%, transparent);
785
+ --bg: color-mix(in srgb, var(--ys-color-primary) 5%, transparent);
662
786
  }
663
- .ys-calendar__cell:focus-visible {
664
- --cal-ring: inset 0 0 0 2px var(--ys-color-primary);
665
- }
666
- .ys-calendar__cell.is-rest:not(.is-selected) {
667
- background-color: color-mix(in srgb, var(--ys-color-text-3) 4%, transparent);
787
+ /* 能上班、能交易的日子浅绿底;放假浅橙底;休息、休市白底,和绿色一深一浅 */
788
+ .ys-calendar__cell.is-trading,
789
+ .ys-calendar__cell.is-workday,
790
+ .ys-calendar__cell.is-adjusted {
791
+ --tone: var(--cal-workday);
792
+ --bg: var(--cal-open-bg);
668
793
  }
669
- .ys-calendar__cell.is-holiday:not(.is-selected) {
670
- background-color: color-mix(in srgb, var(--ys-color-success) 7%, transparent);
794
+ .ys-calendar__cell.is-holiday {
795
+ --tone: var(--cal-holiday);
796
+ --bg: var(--cal-holiday-bg);
671
797
  }
672
- .ys-calendar__cell.is-adjusted:not(.is-selected) {
673
- background-color: color-mix(in srgb, var(--ys-color-warning) 7%, transparent);
798
+ .ys-calendar__cell.is-closed,
799
+ .ys-calendar__cell.is-weekend {
800
+ --tone: var(--cal-rest);
801
+ --bg: transparent;
674
802
  }
675
- /* 交易日视图:交易日左侧竖条,休市斜纹 */
676
- .ys-calendar__cell.is-trading {
677
- --cal-left: inset 3px 0 0 var(--cal-bar);
803
+ .ys-calendar__cell.is-trading:hover,
804
+ .ys-calendar__cell.is-workday:hover,
805
+ .ys-calendar__cell.is-adjusted:hover {
806
+ --bg: var(--cal-open-hover);
678
807
  }
679
- .ys-calendar__cell.is-closed {
680
- background-image: var(--cal-stripe);
681
- }
682
- .ys-calendar__cell.is-closed .ys-calendar__date {
683
- color: var(--ys-color-text-3);
808
+ .ys-calendar__cell.is-holiday:hover {
809
+ --bg: var(--cal-holiday-hover);
684
810
  }
685
- .ys-calendar__cell.is-selected {
686
- --cal-ring: inset 0 0 0 1px
687
- color-mix(in srgb, var(--ys-color-primary) 60%, transparent);
688
- background-color: color-mix(
689
- in srgb,
690
- var(--ys-color-primary) 11%,
691
- transparent
692
- );
811
+ .ys-calendar__cell.is-closed:hover,
812
+ .ys-calendar__cell.is-weekend:hover {
813
+ --bg: color-mix(in srgb, var(--cal-rest) 7%, transparent);
693
814
  }
694
- .ys-calendar__cell.is-selected:focus-visible {
695
- --cal-ring: inset 0 0 0 2px var(--ys-color-primary);
815
+ /* 上月、下月的日期:底色减半、内容变淡 */
816
+ .ys-calendar__cell.is-outside {
817
+ background-color: color-mix(in srgb, var(--bg) 45%, transparent);
696
818
  }
697
819
  .ys-calendar__cell.is-outside > * {
698
820
  opacity: 0.42;
699
821
  }
700
- .ys-calendar__cell.is-outside.is-trading {
701
- --cal-left: inset 3px 0 0
702
- color-mix(in srgb, var(--ys-color-primary) 28%, transparent);
822
+ .ys-calendar__cell:focus-visible {
823
+ --ring: inset 0 0 0 2px var(--ys-color-primary);
824
+ }
825
+ .ys-calendar__cell.is-selected {
826
+ --ring: inset 0 0 0 1.5px var(--ys-color-primary);
827
+ }
828
+ .ys-calendar__cell.is-selected:focus-visible {
829
+ --ring: inset 0 0 0 2px var(--ys-color-primary);
703
830
  }
704
831
  .ys-calendar__cell.is-disabled {
705
832
  cursor: not-allowed;
@@ -707,14 +834,24 @@ function goToday() {
707
834
  .ys-calendar__cell.is-disabled > * {
708
835
  opacity: 0.38;
709
836
  }
837
+ /* 图例突出某一类时,其余格子去掉底色、内容变淡 */
838
+ .ys-calendar__cell.is-dimmed {
839
+ background-color: transparent;
840
+ }
841
+ .ys-calendar__cell.is-dimmed > * {
842
+ opacity: 0.22;
843
+ }
844
+
710
845
  .ys-calendar__top {
711
846
  display: flex;
712
847
  gap: 4px;
713
848
  align-items: center;
714
849
  justify-content: space-between;
850
+ min-width: 0;
715
851
  }
716
852
  .ys-calendar__date {
717
853
  display: inline-flex;
854
+ flex: none;
718
855
  align-items: center;
719
856
  justify-content: center;
720
857
  min-width: 24px;
@@ -722,12 +859,14 @@ function goToday() {
722
859
  padding: 0 4px;
723
860
  border-radius: 999px;
724
861
  color: var(--ys-color-text-1);
725
- font-size: 13px;
862
+ font-size: 14px;
726
863
  font-variant-numeric: tabular-nums;
727
864
  font-weight: 600;
728
865
  }
729
- .ys-calendar__cell.is-rest:not(.is-closed) .ys-calendar__date {
730
- color: var(--cal-rest);
866
+ .ys-calendar__cell.is-weekend-day .ys-calendar__date,
867
+ .ys-calendar__cell.is-closed .ys-calendar__date {
868
+ color: var(--ys-color-text-2);
869
+ font-weight: 500;
731
870
  }
732
871
  .ys-calendar__cell.is-uncovered .ys-calendar__date {
733
872
  text-decoration: underline dotted var(--ys-color-text-3);
@@ -737,73 +876,88 @@ function goToday() {
737
876
  color: var(--ys-color-on-solid);
738
877
  background: var(--ys-color-primary);
739
878
  }
740
- .ys-calendar__badge {
879
+ .ys-calendar__status {
741
880
  display: inline-flex;
881
+ gap: 4px;
742
882
  align-items: center;
743
- justify-content: center;
744
- width: 18px;
745
- height: 18px;
883
+ min-width: 0;
884
+ overflow: hidden;
885
+ }
886
+ .ys-calendar__ordinal {
887
+ overflow: hidden;
888
+ color: var(--ys-color-text-2);
889
+ font-size: 11px;
890
+ font-variant-numeric: tabular-nums;
891
+ white-space: nowrap;
892
+ }
893
+ /* 状态标签:白底同色调描边深字,在有底色的格子上也清楚;法定补班是实心,最醒目 */
894
+ .ys-calendar__label,
895
+ .ys-calendar__swatch {
896
+ flex: none;
897
+ padding: 0 5px;
898
+ border: 1px solid color-mix(in srgb, var(--tone) 60%, transparent);
746
899
  border-radius: var(--ys-radius-s);
900
+ color: color-mix(in srgb, var(--tone) 88%, var(--ys-color-text-1));
901
+ background: var(--ys-color-bg-elevated);
747
902
  font-size: 11px;
748
903
  font-style: normal;
749
904
  font-weight: 600;
750
- line-height: 1;
751
- }
752
- .ys-calendar__badge.is-off {
753
- color: var(--cal-rest);
754
- background: color-mix(in srgb, var(--ys-color-success) 16%, transparent);
905
+ line-height: 16px;
906
+ white-space: nowrap;
755
907
  }
756
- .ys-calendar__badge.is-work {
757
- color: var(--cal-work);
758
- background: color-mix(in srgb, var(--ys-color-warning) 18%, transparent);
908
+ .ys-calendar__cell.is-closed .ys-calendar__label,
909
+ .ys-calendar__cell.is-weekend .ys-calendar__label,
910
+ .ys-calendar__legend-item.is-closed .ys-calendar__swatch,
911
+ .ys-calendar__legend-item.is-weekend .ys-calendar__swatch {
912
+ border-color: transparent;
913
+ color: var(--ys-color-text-2);
914
+ background: color-mix(in srgb, var(--cal-rest) 14%, transparent);
759
915
  }
760
- .ys-calendar__ordinal {
761
- min-width: 20px;
916
+ /* 「交易日」标签用主色蓝,格子仍是浅绿底 */
917
+ .ys-calendar__cell.is-trading .ys-calendar__label,
918
+ .ys-calendar__legend-item.is-trading .ys-calendar__swatch {
762
919
  color: color-mix(
763
920
  in srgb,
764
- var(--ys-color-primary) 70%,
765
- var(--ys-color-text-3)
921
+ var(--ys-color-primary) 85%,
922
+ var(--ys-color-text-1)
766
923
  );
767
- font-size: 11px;
768
- font-variant-numeric: tabular-nums;
769
- font-weight: 600;
770
- text-align: right;
924
+ border-color: color-mix(in srgb, var(--ys-color-primary) 60%, transparent);
925
+ background: var(--ys-color-bg-elevated);
926
+ }
927
+ .ys-calendar__cell.is-adjusted .ys-calendar__label,
928
+ .ys-calendar__legend-item.is-adjusted .ys-calendar__swatch {
929
+ border-color: var(--cal-workday);
930
+ color: var(--ys-color-on-solid);
931
+ background: var(--cal-workday);
771
932
  }
772
933
  .ys-calendar__name {
773
934
  overflow: hidden;
774
- color: var(--cal-rest);
935
+ color: color-mix(in srgb, var(--tone) 75%, var(--ys-color-text-1));
775
936
  font-size: 11px;
776
937
  line-height: 1.5;
777
938
  white-space: nowrap;
778
939
  text-overflow: ellipsis;
779
940
  }
780
- .ys-calendar__cell.is-adjusted .ys-calendar__name {
781
- color: var(--cal-work);
782
- }
783
- .ys-calendar__cell.is-closed .ys-calendar__name {
941
+ .ys-calendar__cell.is-closed .ys-calendar__name,
942
+ .ys-calendar__cell.is-weekend .ys-calendar__name {
784
943
  color: var(--ys-color-text-3);
785
944
  }
786
- .ys-calendar__tags {
787
- display: flex;
788
- flex-wrap: wrap;
789
- gap: 3px;
790
- }
791
- .ys-calendar__tag {
792
- --tone: var(--ys-color-primary);
793
- padding: 0 5px;
945
+ .ys-calendar__badge {
946
+ display: inline-flex;
947
+ align-items: center;
948
+ justify-content: center;
794
949
  border-radius: var(--ys-radius-s);
795
- color: color-mix(in srgb, var(--tone) 82%, var(--ys-color-text-1));
796
- background: color-mix(in srgb, var(--tone) 13%, transparent);
797
- font-size: 11px;
798
950
  font-style: normal;
799
- line-height: 17px;
800
- white-space: nowrap;
951
+ font-weight: 600;
952
+ line-height: 1;
801
953
  }
802
- .ys-calendar__tag.is-pre-holiday {
803
- --tone: var(--ys-color-warning);
954
+ .ys-calendar__badge.is-off {
955
+ color: color-mix(in srgb, var(--cal-holiday) 80%, var(--ys-color-text-1));
956
+ background: color-mix(in srgb, var(--cal-holiday) 20%, transparent);
804
957
  }
805
- .ys-calendar__tag.is-post-holiday {
806
- --tone: var(--ys-color-success);
958
+ .ys-calendar__badge.is-work {
959
+ color: var(--ys-color-on-solid);
960
+ background: var(--cal-workday);
807
961
  }
808
962
  .ys-calendar__events {
809
963
  display: flex;
@@ -821,7 +975,7 @@ function goToday() {
821
975
  border-left: 3px solid var(--tone);
822
976
  border-radius: var(--ys-radius-s);
823
977
  color: var(--ys-color-text-1);
824
- background: color-mix(in srgb, var(--tone) 10%, transparent);
978
+ background: color-mix(in srgb, var(--tone) 10%, var(--ys-color-bg-elevated));
825
979
  font-size: 12px;
826
980
  line-height: 18px;
827
981
  white-space: nowrap;
@@ -854,33 +1008,58 @@ function goToday() {
854
1008
  background: color-mix(in srgb, var(--ys-color-primary) 10%, transparent);
855
1009
  }
856
1010
 
857
- /* 图例 */
1011
+ /* 图例:每项是按钮,悬停或点一下只突出这一类 */
858
1012
  .ys-calendar__legend {
859
1013
  display: flex;
860
1014
  flex-wrap: wrap;
861
- gap: 4px 18px;
1015
+ gap: 4px 6px;
862
1016
  align-items: center;
863
1017
  color: var(--ys-color-text-3);
864
1018
  font-size: 12px;
865
1019
  }
866
- .ys-calendar__legend > span {
1020
+ .ys-calendar__legend-item {
1021
+ --tone: var(--cal-rest);
867
1022
  display: inline-flex;
868
1023
  gap: 5px;
869
1024
  align-items: center;
1025
+ padding: 2px 8px 2px 3px;
1026
+ border: 1px solid transparent;
1027
+ border-radius: var(--ys-radius-s);
1028
+ color: inherit;
1029
+ background: none;
1030
+ font: inherit;
1031
+ cursor: pointer;
870
1032
  }
871
- .ys-calendar__swatch {
872
- display: inline-block;
873
- width: 18px;
874
- height: 14px;
875
- border: 1px solid var(--ys-color-border);
876
- border-radius: 3px;
877
- background: var(--ys-color-bg-elevated);
1033
+ .ys-calendar__legend-item:hover,
1034
+ .ys-calendar__legend-item:focus-visible {
1035
+ border-color: var(--ys-color-border);
1036
+ outline: none;
1037
+ }
1038
+ .ys-calendar__legend-item.is-active {
1039
+ border-color: color-mix(in srgb, var(--tone) 50%, var(--ys-color-border));
1040
+ color: var(--ys-color-text-1);
1041
+ background: color-mix(in srgb, var(--tone) 8%, transparent);
1042
+ }
1043
+ .ys-calendar__legend-item strong {
1044
+ color: var(--ys-color-text-1);
1045
+ font-variant-numeric: tabular-nums;
1046
+ font-weight: 600;
878
1047
  }
879
- .ys-calendar__swatch.is-trading {
880
- box-shadow: inset 3px 0 0 var(--cal-bar);
1048
+ .ys-calendar__legend-item.is-trading {
1049
+ --tone: var(--cal-trading);
881
1050
  }
882
- .ys-calendar__swatch.is-closed {
883
- background-image: var(--cal-stripe);
1051
+ .ys-calendar__legend-item.is-workday,
1052
+ .ys-calendar__legend-item.is-adjusted {
1053
+ --tone: var(--cal-workday);
1054
+ }
1055
+ .ys-calendar__legend-item.is-holiday {
1056
+ --tone: var(--cal-holiday);
1057
+ }
1058
+ .ys-calendar__legend-today {
1059
+ display: inline-flex;
1060
+ gap: 5px;
1061
+ align-items: center;
1062
+ margin-left: 6px;
884
1063
  }
885
1064
  .ys-calendar__legend-today::before {
886
1065
  display: inline-block;
@@ -891,7 +1070,7 @@ function goToday() {
891
1070
  content: "";
892
1071
  }
893
1072
 
894
- /* 迷你模式:只有日期、休班角标(交易日视图为休市斜纹)和事件圆点,悬停看完整信息 */
1073
+ /* 迷你模式:只有日期、底色、休、班角标和事件圆点,悬停看完整信息 */
895
1074
  .ys-calendar.is-small .ys-calendar__weekday {
896
1075
  padding: 4px 0;
897
1076
  text-align: center;
@@ -902,9 +1081,6 @@ function goToday() {
902
1081
  min-height: 36px;
903
1082
  padding: 2px;
904
1083
  }
905
- .ys-calendar.is-small .ys-calendar__cell.is-trading {
906
- --cal-left: 0 0 0 0 transparent;
907
- }
908
1084
  .ys-calendar.is-small .ys-calendar__cell + .ys-calendar__cell {
909
1085
  border-left: 0;
910
1086
  }
package/src/index.ts CHANGED
@@ -4,7 +4,11 @@ export { default as YsCrudTable } from "./components/YsCrudTable.vue";
4
4
  export { default as YsTableToolbar } from "./components/YsTableToolbar.vue";
5
5
  export { default as YsStatusFilter } from "./components/YsStatusFilter.vue";
6
6
  export { default as YsCalendar } from "./components/YsCalendar.vue";
7
- export type { YsCalendarEvent } from "./components/YsCalendar.vue";
7
+ export type {
8
+ YsCalendarEvent,
9
+ YsCalendarLabels,
10
+ YsCalendarStatus,
11
+ } from "./components/YsCalendar.vue";
8
12
  export { default as YsTablePagination } from "./components/YsTablePagination.vue";
9
13
  export { default as YsRowActionMenu } from "./components/YsRowActionMenu.vue";
10
14
  export type { YsRowAction } from "./components/YsRowActionMenu.vue";