@robert-stackflow/oneui 0.6.52 → 0.6.53

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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.6.53
2
+
3
+ - ContributionCalendar 的月份、星期、提示与图例随 locale 显示,保留中文默认文案并支持英文日历。
4
+
1
5
  ## 0.6.48
2
6
 
3
7
  - TableOfContents 新增 railAlign="start",支持左侧目录的短线左对齐及从左侧展开长度变化;默认 end 保持原行为。
@@ -12,6 +12,30 @@ import {
12
12
  parseCalendarDay
13
13
  } from "./contribution.js";
14
14
  import s from "./ContributionCalendar.module.css";
15
+ const calendarCopy = {
16
+ zh: {
17
+ label: "\u6D3B\u52A8\u8BB0\u5F55",
18
+ unit: "\u6B21\u6D3B\u52A8",
19
+ invalidRange: "\u65E5\u671F\u8303\u56F4\u65E0\u6548\u3002",
20
+ future: "\u672A\u6765\u65E5\u671F",
21
+ missing: "\u6682\u65E0\u6570\u636E",
22
+ legend: "\u6D3B\u52A8\u6B21\u6570\u7531\u5C11\u5230\u591A",
23
+ less: "\u5C11",
24
+ more: "\u591A",
25
+ separator: "\uFF0C"
26
+ },
27
+ en: {
28
+ label: "Activity",
29
+ unit: "activities",
30
+ invalidRange: "Invalid date range.",
31
+ future: "Future date",
32
+ missing: "No data",
33
+ legend: "Activity from less to more",
34
+ less: "Less",
35
+ more: "More",
36
+ separator: ", "
37
+ }
38
+ };
15
39
  function ContributionCalendar({
16
40
  data,
17
41
  year = (/* @__PURE__ */ new Date()).getFullYear(),
@@ -20,8 +44,8 @@ function ContributionCalendar({
20
44
  weekStartsOn = 1,
21
45
  value,
22
46
  onChange,
23
- label = "\u6D3B\u52A8\u8BB0\u5F55",
24
- unit = "\u6B21\u6D3B\u52A8",
47
+ label,
48
+ unit,
25
49
  locale = "zh-CN",
26
50
  color = "var(--success)",
27
51
  emptyMode = "zero",
@@ -32,6 +56,10 @@ function ContributionCalendar({
32
56
  source,
33
57
  fill = false
34
58
  }) {
59
+ const chinese = new Intl.Locale(locale).language === "zh";
60
+ const copy = calendarCopy[chinese ? "zh" : "en"];
61
+ const calendarLabel = label ?? copy.label;
62
+ const calendarUnit = unit ?? copy.unit;
35
63
  const current = /* @__PURE__ */ new Date(), todayKey = today || [
36
64
  current.getFullYear(),
37
65
  String(current.getMonth() + 1).padStart(2, "0"),
@@ -69,6 +97,20 @@ function ContributionCalendar({
69
97
  }),
70
98
  [locale]
71
99
  ), numbers = useMemo(() => new Intl.NumberFormat(locale), [locale]);
100
+ const months = useMemo(
101
+ () => new Intl.DateTimeFormat(locale, { month: "short", timeZone: "UTC" }),
102
+ [locale]
103
+ );
104
+ const weekdays = useMemo(() => {
105
+ const format = new Intl.DateTimeFormat(locale, {
106
+ weekday: chinese ? "narrow" : "short",
107
+ timeZone: "UTC"
108
+ });
109
+ return Array.from(
110
+ { length: 7 },
111
+ (_, day) => format.format(new Date(Date.UTC(2024, 0, 7 + day)))
112
+ );
113
+ }, [locale, chinese]);
72
114
  const choose = useCallback((date) => onChange?.(date), [onChange]);
73
115
  const move = useCallback(
74
116
  (event, day) => {
@@ -105,11 +147,12 @@ function ContributionCalendar({
105
147
  },
106
148
  [model]
107
149
  );
108
- if (!model.valid) return /* @__PURE__ */ jsx("p", { role: "alert", children: "\u65E5\u671F\u8303\u56F4\u65E0\u6548\u3002" });
150
+ if (!model.valid) return /* @__PURE__ */ jsx("p", { role: "alert", lang: locale, children: copy.invalidRange });
109
151
  return /* @__PURE__ */ jsxs(
110
152
  "div",
111
153
  {
112
154
  className: s.calendar,
155
+ lang: locale,
113
156
  style: {
114
157
  "--calendar-color": color,
115
158
  "--calendar-cell-max": fill ? "24px" : "13px",
@@ -117,11 +160,11 @@ function ContributionCalendar({
117
160
  },
118
161
  children: [
119
162
  /* @__PURE__ */ jsxs("header", { className: s.header, children: [
120
- /* @__PURE__ */ jsx("h3", { children: label }),
163
+ /* @__PURE__ */ jsx("h3", { children: calendarLabel }),
121
164
  /* @__PURE__ */ jsxs("span", { children: [
122
165
  numbers.format(model.total),
123
166
  " ",
124
- unit
167
+ calendarUnit
125
168
  ] })
126
169
  ] }),
127
170
  /* @__PURE__ */ jsxs("div", { className: s.scroll, ref: root, children: [
@@ -136,11 +179,8 @@ function ContributionCalendar({
136
179
  children: [
137
180
  /* @__PURE__ */ jsx("span", {}),
138
181
  model.months.filter(
139
- (month, index, months) => !months[index + 1] || months[index + 1].column - month.column >= 2
140
- ).map((month) => /* @__PURE__ */ jsxs("span", { style: { gridColumn: month.column + 2 }, children: [
141
- month.month,
142
- "\u6708"
143
- ] }, month.key))
182
+ (month, index, headings) => !headings[index + 1] || headings[index + 1].column - month.column >= 2
183
+ ).map((month) => /* @__PURE__ */ jsx("span", { style: { gridColumn: month.column + 2 }, children: months.format(new Date(Date.UTC(month.year, month.month - 1, 1))) }, month.key))
144
184
  ]
145
185
  }
146
186
  ),
@@ -148,7 +188,7 @@ function ContributionCalendar({
148
188
  "div",
149
189
  {
150
190
  role: "grid",
151
- "aria-label": label,
191
+ "aria-label": calendarLabel,
152
192
  "aria-rowcount": 7,
153
193
  "aria-colcount": model.weeks,
154
194
  children: Array.from({ length: 7 }, (_, row) => /* @__PURE__ */ jsxs(
@@ -160,10 +200,10 @@ function ContributionCalendar({
160
200
  gridTemplateColumns: "28px repeat(" + model.weeks + ",var(--calendar-cell))"
161
201
  },
162
202
  children: [
163
- /* @__PURE__ */ jsx("span", { className: s.weekday, role: "rowheader", children: ["\u65E5", "\u4E00", "\u4E8C", "\u4E09", "\u56DB", "\u4E94", "\u516D"][(row + weekStartsOn) % 7] }),
203
+ /* @__PURE__ */ jsx("span", { className: s.weekday, role: "rowheader", children: weekdays[(row + weekStartsOn) % 7] }),
164
204
  Array.from({ length: model.weeks }, (_2, column) => {
165
205
  const day = model.cells[column * 7 + row];
166
- const text = formatter.format(parseCalendarDay(day.date)) + (day.future ? "\uFF0C\u672A\u6765\u65E5\u671F" : emptyMode === "missing" && day.missing ? "\uFF0C\u6682\u65E0\u6570\u636E" : "\uFF0C" + numbers.format(day.count) + " " + unit);
206
+ const text = formatter.format(parseCalendarDay(day.date)) + copy.separator + (day.future ? copy.future : emptyMode === "missing" && day.missing ? copy.missing : numbers.format(day.count) + " " + calendarUnit);
167
207
  return /* @__PURE__ */ jsx(
168
208
  ContributionCell,
169
209
  {
@@ -188,8 +228,8 @@ function ContributionCalendar({
188
228
  ] }),
189
229
  /* @__PURE__ */ jsxs("footer", { className: s.footer, children: [
190
230
  source ?? (value && /* @__PURE__ */ jsx("span", { children: value })),
191
- /* @__PURE__ */ jsxs("div", { className: s.legend, "aria-label": "\u6D3B\u52A8\u6B21\u6570\u7531\u5C11\u5230\u591A", children: [
192
- /* @__PURE__ */ jsx("span", { children: "\u5C11" }),
231
+ /* @__PURE__ */ jsxs("div", { className: s.legend, "aria-label": copy.legend, children: [
232
+ /* @__PURE__ */ jsx("span", { children: copy.less }),
193
233
  [0, 1, 2, 3, 4].map((level) => /* @__PURE__ */ jsx(
194
234
  "i",
195
235
  {
@@ -199,7 +239,7 @@ function ContributionCalendar({
199
239
  },
200
240
  level
201
241
  )),
202
- /* @__PURE__ */ jsx("span", { children: "\u591A" })
242
+ /* @__PURE__ */ jsx("span", { children: copy.more })
203
243
  ] })
204
244
  ] }),
205
245
  footer && /* @__PURE__ */ jsx("div", { className: s.extraFooter, children: footer })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.52",
3
+ "version": "0.6.53",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [