@robert-stackflow/oneui 0.6.51 → 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 +4 -0
- package/README.md +4 -0
- package/components/ContributionCalendar.js +56 -16
- package/components/Pagination.js +38 -9
- package/components/Pagination.module.css +11 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -353,3 +353,7 @@ Closing returns a visible source image with Hero motion. Missing/offscreen sourc
|
|
|
353
353
|
已有 React 事件表单可改为 `<Form onSubmit={submit}>`,保留事件处理、受控值和业务请求。Form 统一处理 required、type、pattern、范围、自定义有效性、首个错误焦点和异步提交锁;错误通过 FormField / Input 的 FieldMessages 展示。未包裹的原生字段使用可聚焦的错误摘要。`validationMode="blur"` 在离开字段后检查,默认提交时检查;出错后修改会更新反馈。内部自动使用 noValidate,不出现原生气泡。
|
|
354
354
|
|
|
355
355
|
`validateForm(formRef.current, false)` 检查并展示字段错误但不抢焦点,适合自动保存;省略第二个参数则聚焦首个错误。保留自定义业务错误、身份验证、并发和请求重试策略。字段使用稳定 id 或 name,并通过 OneUI FormField / 控件提供标签。`controller={useFormState(...)}` 模式保持兼容,用于显式规则与异步字段校验。
|
|
356
|
+
|
|
357
|
+
### 窄屏分页(0.6.52)
|
|
358
|
+
|
|
359
|
+
650px 及以下保留上一页、下一页、首页页码、末页页码和当前页;省略相邻页码与重复的首尾双箭头,用省略号标明页码间隔。44px 触屏目标保持不变,320px 视口中分页无需折到第二行。全部页码仍使用同一套按钮/原生链接和回调逻辑。
|
|
@@ -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
|
|
24
|
-
unit
|
|
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:
|
|
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:
|
|
163
|
+
/* @__PURE__ */ jsx("h3", { children: calendarLabel }),
|
|
121
164
|
/* @__PURE__ */ jsxs("span", { children: [
|
|
122
165
|
numbers.format(model.total),
|
|
123
166
|
" ",
|
|
124
|
-
|
|
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,
|
|
140
|
-
).map((month) => /* @__PURE__ */
|
|
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":
|
|
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: [
|
|
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 ?
|
|
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":
|
|
192
|
-
/* @__PURE__ */ jsx("span", { children:
|
|
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:
|
|
242
|
+
/* @__PURE__ */ jsx("span", { children: copy.more })
|
|
203
243
|
] })
|
|
204
244
|
] }),
|
|
205
245
|
footer && /* @__PURE__ */ jsx("div", { className: s.extraFooter, children: footer })
|
package/components/Pagination.js
CHANGED
|
@@ -57,10 +57,14 @@ function Pagination({
|
|
|
57
57
|
pages
|
|
58
58
|
])
|
|
59
59
|
].sort((a, b) => a - b);
|
|
60
|
+
const compactVisible = [.../* @__PURE__ */ new Set([1, current, pages])].sort(
|
|
61
|
+
(a, b) => a - b
|
|
62
|
+
);
|
|
60
63
|
function pageControl(target, options) {
|
|
61
64
|
const props = {
|
|
62
65
|
className: options.className,
|
|
63
66
|
"aria-label": options.label,
|
|
67
|
+
"data-pagination-boundary": options.boundary || void 0,
|
|
64
68
|
"aria-current": options.current ? "page" : void 0,
|
|
65
69
|
variant: options.current ? "primary" : options.className === s.page ? "ghost" : "secondary"
|
|
66
70
|
};
|
|
@@ -123,6 +127,7 @@ function Pagination({
|
|
|
123
127
|
/* @__PURE__ */ jsxs("div", { className: s.pages, children: [
|
|
124
128
|
pageControl(1, {
|
|
125
129
|
className: s.arrow,
|
|
130
|
+
boundary: true,
|
|
126
131
|
label: text("\u7B2C\u4E00\u9875", "First page", "\u7B2C\u4E00\u9801"),
|
|
127
132
|
disabled: current === 1,
|
|
128
133
|
children: /* @__PURE__ */ jsx(ChevronsLeft, {})
|
|
@@ -133,15 +138,38 @@ function Pagination({
|
|
|
133
138
|
disabled: current === 1,
|
|
134
139
|
children: /* @__PURE__ */ jsx(ChevronLeft, {})
|
|
135
140
|
}),
|
|
136
|
-
visible.map((n, i) => /* @__PURE__ */ jsxs(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
className: s.
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
141
|
+
visible.map((n, i) => /* @__PURE__ */ jsxs(
|
|
142
|
+
"span",
|
|
143
|
+
{
|
|
144
|
+
className: s.number,
|
|
145
|
+
"data-compact-hidden": !compactVisible.includes(n) || void 0,
|
|
146
|
+
children: [
|
|
147
|
+
i > 0 && n - visible[i - 1] > 1 && /* @__PURE__ */ jsx(
|
|
148
|
+
"span",
|
|
149
|
+
{
|
|
150
|
+
className: `${s.ellipsis} ${s.expandedEllipsis}`,
|
|
151
|
+
"aria-hidden": "true",
|
|
152
|
+
children: "\u2026"
|
|
153
|
+
}
|
|
154
|
+
),
|
|
155
|
+
compactVisible.indexOf(n) > 0 && n - compactVisible[compactVisible.indexOf(n) - 1] > 1 && /* @__PURE__ */ jsx(
|
|
156
|
+
"span",
|
|
157
|
+
{
|
|
158
|
+
className: `${s.ellipsis} ${s.compactEllipsis}`,
|
|
159
|
+
"aria-hidden": "true",
|
|
160
|
+
children: "\u2026"
|
|
161
|
+
}
|
|
162
|
+
),
|
|
163
|
+
pageControl(n, {
|
|
164
|
+
className: s.page,
|
|
165
|
+
label: english ? "Page " + n : "\u7B2C " + n + text(" \u9875", "", " \u9801"),
|
|
166
|
+
current: n === current,
|
|
167
|
+
children: n
|
|
168
|
+
})
|
|
169
|
+
]
|
|
170
|
+
},
|
|
171
|
+
n
|
|
172
|
+
)),
|
|
145
173
|
pageControl(current + 1, {
|
|
146
174
|
className: s.arrow,
|
|
147
175
|
label: nextLabel ?? text("\u4E0B\u4E00\u9875", "Next", "\u4E0B\u4E00\u9801"),
|
|
@@ -150,6 +178,7 @@ function Pagination({
|
|
|
150
178
|
}),
|
|
151
179
|
pageControl(pages, {
|
|
152
180
|
className: s.arrow,
|
|
181
|
+
boundary: true,
|
|
153
182
|
label: text("\u6700\u540E\u4E00\u9875", "Last page", "\u6700\u5F8C\u4E00\u9801"),
|
|
154
183
|
disabled: current === pages,
|
|
155
184
|
children: /* @__PURE__ */ jsx(ChevronsRight, {})
|
|
@@ -56,6 +56,9 @@
|
|
|
56
56
|
padding: 0 3px;
|
|
57
57
|
color: var(--muted);
|
|
58
58
|
}
|
|
59
|
+
.compactEllipsis {
|
|
60
|
+
display: none;
|
|
61
|
+
}
|
|
59
62
|
.jump {
|
|
60
63
|
display: flex;
|
|
61
64
|
align-items: center;
|
|
@@ -70,6 +73,14 @@
|
|
|
70
73
|
color: var(--fg);
|
|
71
74
|
}
|
|
72
75
|
@media (max-width: 650px) {
|
|
76
|
+
.pages [data-pagination-boundary],
|
|
77
|
+
.number[data-compact-hidden],
|
|
78
|
+
.expandedEllipsis {
|
|
79
|
+
display: none;
|
|
80
|
+
}
|
|
81
|
+
.compactEllipsis {
|
|
82
|
+
display: inline;
|
|
83
|
+
}
|
|
73
84
|
.controls {
|
|
74
85
|
gap: 10px;
|
|
75
86
|
width: 100%;
|