@apliteni/apliteni-ui 0.25.3 → 0.27.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/README.md +2 -2
- package/package.json +1 -1
- package/react/README.md +92 -2
- package/react/dist/index.css +0 -12
- package/react/dist/index.d.ts +73 -6
- package/react/dist/index.js +380 -114
- package/src/components/pagination.js +344 -0
- package/src/index.css +1 -0
- package/src/index.js +1 -0
- package/src/inline.js +2 -0
- package/src/styles/button.css +14 -0
- package/src/styles/input.css +6 -0
- package/src/styles/pagination.css +124 -0
- package/src/tokens/tokens.css +6 -0
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// Pagination — the strip under a table or a list, as an HTML string.
|
|
2
|
+
//
|
|
3
|
+
// It renders a page the CALLER computed. Rows never come in here: `page`,
|
|
4
|
+
// `pageSize` and `total` are numbers, so a page counted by a server and a page
|
|
5
|
+
// sliced out of an array in memory produce the same markup.
|
|
6
|
+
//
|
|
7
|
+
// `total: null` is the honest shape for an API that cannot count what it has not
|
|
8
|
+
// fetched. The component then knows no last page, so it draws Prev and Next and
|
|
9
|
+
// nothing else — see `ui-pager--open` below.
|
|
10
|
+
import { esc } from './index.js';
|
|
11
|
+
|
|
12
|
+
// The sizes a table offers, and the one it starts on. Named here so no call site
|
|
13
|
+
// writes either number: both moved once already and would have moved in thirteen
|
|
14
|
+
// files. MUI's DataGrid ships exactly this pair (default 100, options 25/50/100),
|
|
15
|
+
// AG Grid defaults to 100, and the finance portal's two data-heavy surfaces
|
|
16
|
+
// already page at 100. A 250 step was in the first draft of this component and
|
|
17
|
+
// no surveyed kit offers one, so it went rather than being invented.
|
|
18
|
+
export const PAGE_SIZES = [25, 50, 100];
|
|
19
|
+
export const DEFAULT_PAGE_SIZE = 100;
|
|
20
|
+
|
|
21
|
+
// The classes button({ variant: 'ghost', size: 'sm' }) emits, written out because
|
|
22
|
+
// button() takes no extra class and every control here needs one of its own for
|
|
23
|
+
// the React component to key on. src/components/pagination.test.js asserts the
|
|
24
|
+
// two agree, so a change to button()'s class list fails there instead of drifting.
|
|
25
|
+
const GHOST_SM = 'ui-btn ui-btn--ghost ui-btn--sm';
|
|
26
|
+
|
|
27
|
+
const VARIANTS = ['steps', 'numbered', 'jump'];
|
|
28
|
+
|
|
29
|
+
// The id seeds a <label for> and the control it names, so two pagers that share
|
|
30
|
+
// one are two labels pointing at one control: the second table's "Rows" label
|
|
31
|
+
// focuses the FIRST table's select, and the second select has no accessible name
|
|
32
|
+
// at all. `tabs()` states the same requirement in words and leaves it there; a
|
|
33
|
+
// pager is dropped under a table by a caller who is not thinking about ids, and
|
|
34
|
+
// two tables on a page is the ordinary case rather than the exotic one. So an
|
|
35
|
+
// omitted id is unique by construction instead. A caller who needs a stable id —
|
|
36
|
+
// a server rendering the same page twice, a test — passes one.
|
|
37
|
+
let seq = 0;
|
|
38
|
+
const cx = (...a) => a.filter(Boolean).join(' ');
|
|
39
|
+
|
|
40
|
+
// Every number here arrives from a URL in real use — `?page=-2`, `?page=abc`,
|
|
41
|
+
// `?page=` — so each is coerced before it is clamped, and nothing that is not a
|
|
42
|
+
// finite integer reaches the markup.
|
|
43
|
+
//
|
|
44
|
+
// `Number()` alone is not that check, and the first draft of this used it. It
|
|
45
|
+
// reads '', ' ', null, [] and false as 0, all of which are finite: `?total=` then
|
|
46
|
+
// meant "this result holds zero rows" and erased the whole component, and
|
|
47
|
+
// `?pageSize=` meant one row per page. Only a number, or a string with something
|
|
48
|
+
// in it, is a number here. A Symbol is refused rather than thrown on — a string
|
|
49
|
+
// factory that raises a TypeError is a worse answer than a pager.
|
|
50
|
+
//
|
|
51
|
+
// The cap is Number.MAX_SAFE_INTEGER because above it arithmetic stops moving:
|
|
52
|
+
// `at - 1 === at === at + 1`, so Prev and Next would carry the same target while
|
|
53
|
+
// both rendered live, and a page past 1e21 prints as `1e+21`, which parseInt reads
|
|
54
|
+
// back as 1.
|
|
55
|
+
const CAP = Number.MAX_SAFE_INTEGER;
|
|
56
|
+
const int = (v, fallback) => {
|
|
57
|
+
const raw = typeof v === 'number' ? v
|
|
58
|
+
: (typeof v === 'string' && v.trim() !== '') ? Number(v)
|
|
59
|
+
: NaN;
|
|
60
|
+
if (!Number.isFinite(raw)) return fallback;
|
|
61
|
+
return Math.min(Math.max(Math.trunc(raw), -CAP), CAP);
|
|
62
|
+
};
|
|
63
|
+
const fmt = (n) => n.toLocaleString('en-US');
|
|
64
|
+
|
|
65
|
+
// A control at an end is DISABLED, never removed. Polaris states the rule as
|
|
66
|
+
// "Hint when merchants are at the first or the last page by disabling the
|
|
67
|
+
// corresponding button": removing it slides the next control sideways under a
|
|
68
|
+
// pointer already travelling toward it, and takes away the only evidence a
|
|
69
|
+
// screen-reader user has that they are at the start.
|
|
70
|
+
//
|
|
71
|
+
// An <a> has no disabled state, so an end that is off renders as
|
|
72
|
+
// <button disabled> even when `href` was given — a link that goes nowhere reads
|
|
73
|
+
// as available right up until it is followed.
|
|
74
|
+
function control({ cls, page, label, href, disabled = false, current = false }) {
|
|
75
|
+
const attrs = `class="${cls}" data-page="${page}"${current ? ' aria-current="page"' : ''}`;
|
|
76
|
+
return href && !disabled
|
|
77
|
+
? `<a href="${esc(href(page))}" ${attrs}>${esc(label)}</a>`
|
|
78
|
+
: `<button type="button" ${attrs}${disabled ? ' disabled aria-disabled="true"' : ''}>${esc(label)}</button>`;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The page numbers a `numbered` pager shows, with `null` where a run was cut.
|
|
83
|
+
*
|
|
84
|
+
* Seven slots at most: page 1, the last page, the current page with one
|
|
85
|
+
* neighbour each side, and a gap for each run removed between them. Two rules
|
|
86
|
+
* keep the strip honest — no two gaps side by side, and no gap standing in for a
|
|
87
|
+
* single page, because an ellipsis hiding one number is wider than the number
|
|
88
|
+
* and costs a click to find out what it was.
|
|
89
|
+
*/
|
|
90
|
+
function slotsFor(page, pageCount) {
|
|
91
|
+
const wanted = [1, pageCount, page - 1, page, page + 1]
|
|
92
|
+
.filter((n) => n >= 1 && n <= pageCount);
|
|
93
|
+
const shown = [...new Set(wanted)].sort((a, b) => a - b);
|
|
94
|
+
const out = [];
|
|
95
|
+
for (const n of shown) {
|
|
96
|
+
const prev = out.length ? out[out.length - 1] : null;
|
|
97
|
+
if (prev != null) {
|
|
98
|
+
if (n - prev === 2) out.push(prev + 1); // one page hidden — draw it, not a gap
|
|
99
|
+
else if (n - prev > 2) out.push(null);
|
|
100
|
+
}
|
|
101
|
+
out.push(n);
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* pagination({ … }) → the <nav> a caller drops under a table.
|
|
108
|
+
*
|
|
109
|
+
* A pager for a single page draws no steps: GOV.UK's guidance is "Do not show
|
|
110
|
+
* pagination if there's only one page of content", and the kit was rendering
|
|
111
|
+
* two permanently dead buttons under every short table. With no size control to
|
|
112
|
+
* offer, such a pager has no job at all and returns the empty string; with one,
|
|
113
|
+
* the <nav> stays for the size control alone — somebody looking at 25 of 25 rows
|
|
114
|
+
* may still want 100 per page — and carries `ui-pager--single`.
|
|
115
|
+
*/
|
|
116
|
+
export function pagination({
|
|
117
|
+
page = 1,
|
|
118
|
+
pageSize = DEFAULT_PAGE_SIZE,
|
|
119
|
+
total = null,
|
|
120
|
+
hasMore = false,
|
|
121
|
+
pageSizes = null,
|
|
122
|
+
variant = 'steps',
|
|
123
|
+
label = 'Pagination',
|
|
124
|
+
loading = false,
|
|
125
|
+
href = null,
|
|
126
|
+
id,
|
|
127
|
+
} = {}) {
|
|
128
|
+
const uid = esc(String(id ?? `pager-${++seq}`));
|
|
129
|
+
const kind = VARIANTS.includes(variant) ? variant : 'steps';
|
|
130
|
+
// A size of zero or less is not a size, so it is read as absent rather than
|
|
131
|
+
// clamped to 1 — clamping turns `?pageSize=0` into 4,812 pages of one row.
|
|
132
|
+
const asked = int(pageSize, DEFAULT_PAGE_SIZE);
|
|
133
|
+
const size = asked > 0 ? asked : DEFAULT_PAGE_SIZE;
|
|
134
|
+
// A total that is not a number is a total nobody knows — the open shape is the
|
|
135
|
+
// truthful answer to it, and it is the same answer `total: null` asks for.
|
|
136
|
+
const asRows = int(total, null);
|
|
137
|
+
const counted = total != null && asRows !== null;
|
|
138
|
+
const rows = counted ? Math.max(0, asRows) : null;
|
|
139
|
+
const last = counted ? Math.max(1, Math.ceil(rows / size)) : null;
|
|
140
|
+
// One below the cap when nothing is counted, because the open shape emits
|
|
141
|
+
// `at + 1` as Next's target and MAX_SAFE_INTEGER + 1 is not representable — it
|
|
142
|
+
// rounds back onto its neighbour, so Prev and Next would carry one page again.
|
|
143
|
+
const at = counted
|
|
144
|
+
? Math.min(Math.max(1, int(page, 1)), last)
|
|
145
|
+
: Math.min(Math.max(1, int(page, 1)), CAP - 1);
|
|
146
|
+
|
|
147
|
+
// The current size is offered even when the caller's list forgot it: a select
|
|
148
|
+
// whose value is not among its options renders as the first one, which reports
|
|
149
|
+
// a page size the table is not using.
|
|
150
|
+
// Capped: this is a string factory, and a caller who hands it a hundred thousand
|
|
151
|
+
// sizes gets a hundred thousand <option>s and megabytes of HTML rather than an
|
|
152
|
+
// error. Twelve is past any real size menu — MUI ships four.
|
|
153
|
+
const offered = (Array.isArray(pageSizes) ? pageSizes : [])
|
|
154
|
+
.slice(0, 12)
|
|
155
|
+
.map((s) => int(s, 0))
|
|
156
|
+
.filter((s) => s > 0);
|
|
157
|
+
const sizes = offered.length
|
|
158
|
+
? [...new Set([...offered, size])].sort((a, b) => a - b)
|
|
159
|
+
: [];
|
|
160
|
+
|
|
161
|
+
const single = counted && last === 1;
|
|
162
|
+
if (single && !sizes.length) return '';
|
|
163
|
+
|
|
164
|
+
const from = (at - 1) * size + 1;
|
|
165
|
+
const to = counted ? Math.min(at * size, rows) : null;
|
|
166
|
+
// Not "1–0 of 0" for an empty result, and not "7–7 of 7" for a single row:
|
|
167
|
+
// both are arithmetic a reader has to undo.
|
|
168
|
+
const status = !counted ? `Page ${fmt(at)}`
|
|
169
|
+
: rows === 0 ? '0 of 0'
|
|
170
|
+
: from === to ? `${fmt(from)} of ${fmt(rows)}`
|
|
171
|
+
: `${fmt(from)}–${fmt(to)} of ${fmt(rows)}`;
|
|
172
|
+
|
|
173
|
+
const sizeBlock = sizes.length
|
|
174
|
+
? `<div class="ui-pager__size">`
|
|
175
|
+
+ `<label class="ui-pager__size-label" for="${uid}-size">Rows</label>`
|
|
176
|
+
+ `<select class="ui-select ui-pager__size-select" id="${uid}-size"${loading ? ' disabled' : ''}>`
|
|
177
|
+
+ sizes.map((s) => `<option value="${s}"${s === size ? ' selected' : ''}>${fmt(s)}</option>`).join('')
|
|
178
|
+
+ `</select></div>`
|
|
179
|
+
: '';
|
|
180
|
+
|
|
181
|
+
const step = (spec) => control({ cls: `${GHOST_SM} ui-pager__step`, href, ...spec, disabled: loading || spec.disabled });
|
|
182
|
+
const atStart = at === 1;
|
|
183
|
+
const atEnd = counted && at === last;
|
|
184
|
+
|
|
185
|
+
let steps = '';
|
|
186
|
+
if (single) {
|
|
187
|
+
steps = ''; // GOV.UK: no pagination for one page of content.
|
|
188
|
+
} else if (!counted) {
|
|
189
|
+
// The open shape: no last page exists, so no control may claim to reach one.
|
|
190
|
+
// Next is off when the caller says there is nothing after this page.
|
|
191
|
+
steps = `<div class="ui-pager__steps">`
|
|
192
|
+
+ step({ page: Math.max(1, at - 1), label: 'Prev', disabled: atStart })
|
|
193
|
+
+ step({ page: at + 1, label: 'Next', disabled: !hasMore })
|
|
194
|
+
+ `</div>`;
|
|
195
|
+
} else {
|
|
196
|
+
let middle = '';
|
|
197
|
+
if (kind === 'numbered') {
|
|
198
|
+
middle = slotsFor(at, last).map((n) => (n == null
|
|
199
|
+
? '<span class="ui-pager__gap" aria-hidden="true">…</span>'
|
|
200
|
+
: control({
|
|
201
|
+
cls: cx(`${GHOST_SM} ui-pager__page`, n === at && 'is-current'),
|
|
202
|
+
href,
|
|
203
|
+
page: n,
|
|
204
|
+
label: fmt(n),
|
|
205
|
+
current: n === at,
|
|
206
|
+
disabled: loading,
|
|
207
|
+
}))).join('');
|
|
208
|
+
} else if (kind === 'jump') {
|
|
209
|
+
middle = `<span class="ui-pager__jump"><label for="${uid}-jump">Page</label>`
|
|
210
|
+
+ `<input class="ui-input ui-pager__jump-input" id="${uid}-jump" type="number"`
|
|
211
|
+
+ ` min="1" max="${last}" value="${at}"${loading ? ' disabled' : ''}>`
|
|
212
|
+
+ `<span class="ui-pager__jump-of">of ${fmt(last)}</span></span>`;
|
|
213
|
+
}
|
|
214
|
+
// First and Last are the numbered variant's own job — its first and last
|
|
215
|
+
// slots are always those two pages, so a second pair of controls for them
|
|
216
|
+
// would be the same jump written twice.
|
|
217
|
+
const ends = kind !== 'numbered';
|
|
218
|
+
steps = `<div class="ui-pager__steps">`
|
|
219
|
+
+ (ends ? step({ page: 1, label: 'First', disabled: atStart }) : '')
|
|
220
|
+
+ step({ page: Math.max(1, at - 1), label: 'Prev', disabled: atStart })
|
|
221
|
+
+ middle
|
|
222
|
+
+ step({ page: Math.min(last, at + 1), label: 'Next', disabled: atEnd })
|
|
223
|
+
+ (ends ? step({ page: last, label: 'Last', disabled: atEnd }) : '')
|
|
224
|
+
+ `</div>`;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// The status line is the only live region in the component: a strip where the
|
|
228
|
+
// numbers, the size control and four buttons all announced would read the same
|
|
229
|
+
// change out four times.
|
|
230
|
+
return `<nav class="${cx('ui-pager', `ui-pager--${kind}`, !counted && 'ui-pager--open', single && 'ui-pager--single')}"`
|
|
231
|
+
+ ` aria-label="${esc(label)}"${loading ? ' aria-busy="true"' : ''}>`
|
|
232
|
+
+ `<p class="ui-pager__status" aria-live="polite" aria-atomic="true">${esc(status)}</p>`
|
|
233
|
+
+ sizeBlock
|
|
234
|
+
+ steps
|
|
235
|
+
+ `</nav>`;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Make a rendered pager work.
|
|
240
|
+
*
|
|
241
|
+
* Every control the factory draws is inert markup until this runs: the steps
|
|
242
|
+
* carry `data-page` and nothing reads it, the size control is a `<select>` with
|
|
243
|
+
* no handler, and the jump input is an `<input>` with no handler. Shipping the
|
|
244
|
+
* `jump` variant without this meant shipping the one control that reaches an
|
|
245
|
+
* arbitrary page and having it do nothing.
|
|
246
|
+
*
|
|
247
|
+
* It reads the class contract rather than hooks of its own — `.ui-pager__step`,
|
|
248
|
+
* `.ui-pager__page`, `.ui-pager__size-select`, `.ui-pager__jump-input` — so the
|
|
249
|
+
* markup is exactly what `pagination()` already returns and the React component
|
|
250
|
+
* is still class-for-class identical to it.
|
|
251
|
+
*
|
|
252
|
+
* const pager = wirePagination(root, {
|
|
253
|
+
* onPage: (page) => load({ page }),
|
|
254
|
+
* onPageSize: (size) => load({ page: 1, size }),
|
|
255
|
+
* });
|
|
256
|
+
*
|
|
257
|
+
* Listeners are delegated from `root`, so a pager re-rendered underneath stays
|
|
258
|
+
* wired. Returns a function that removes them.
|
|
259
|
+
*
|
|
260
|
+
* A step rendered as an `<a href>` is left alone: it is a link, the browser owns
|
|
261
|
+
* it, and calling it back as well would navigate twice.
|
|
262
|
+
*/
|
|
263
|
+
export function wirePagination(root = document, { onPage, onPageSize } = {}) {
|
|
264
|
+
const scope = typeof root === 'string' ? document.querySelector(root) : root;
|
|
265
|
+
if (!scope || typeof scope.addEventListener !== 'function') return () => {};
|
|
266
|
+
|
|
267
|
+
const pageOf = (el) => int(el.getAttribute('data-page'), null);
|
|
268
|
+
const inPager = (el) => el && el.closest && el.closest('.ui-pager');
|
|
269
|
+
|
|
270
|
+
const onClick = (e) => {
|
|
271
|
+
const step = e.target.closest?.('.ui-pager__step, .ui-pager__page');
|
|
272
|
+
if (!step || !inPager(step) || step.tagName === 'A' || step.disabled) return;
|
|
273
|
+
const page = pageOf(step);
|
|
274
|
+
if (page !== null) onPage?.(page);
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
const onChange = (e) => {
|
|
278
|
+
const select = e.target.closest?.('.ui-pager__size-select');
|
|
279
|
+
if (!select || !inPager(select)) return;
|
|
280
|
+
const size = int(select.value, null);
|
|
281
|
+
if (size !== null && size > 0) onPageSize?.(size);
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
// Enter commits; so does leaving the box. A value the input cannot parse — it
|
|
285
|
+
// is type="number", so a rejected keystroke leaves it empty — is not a page,
|
|
286
|
+
// and the box goes back to the one it was showing rather than to page 1.
|
|
287
|
+
const commit = (box) => {
|
|
288
|
+
const asked = int(box.value, null);
|
|
289
|
+
const max = int(box.getAttribute('max'), null);
|
|
290
|
+
if (asked === null || asked < 1) {
|
|
291
|
+
box.value = box.defaultValue;
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
const page = max === null ? asked : Math.min(asked, max);
|
|
295
|
+
box.value = String(page);
|
|
296
|
+
if (String(page) !== box.defaultValue) onPage?.(page);
|
|
297
|
+
};
|
|
298
|
+
const onKeydown = (e) => {
|
|
299
|
+
const box = e.target.closest?.('.ui-pager__jump-input');
|
|
300
|
+
if (!box || !inPager(box) || e.key !== 'Enter') return;
|
|
301
|
+
// A lone number input inside a <form> submits it on Enter, which reloads the
|
|
302
|
+
// page the reader was trying to move within.
|
|
303
|
+
e.preventDefault();
|
|
304
|
+
commit(box);
|
|
305
|
+
};
|
|
306
|
+
const onBlur = (e) => {
|
|
307
|
+
const box = e.target.closest?.('.ui-pager__jump-input');
|
|
308
|
+
if (box && inPager(box)) commit(box);
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
scope.addEventListener('click', onClick);
|
|
312
|
+
scope.addEventListener('change', onChange);
|
|
313
|
+
scope.addEventListener('keydown', onKeydown);
|
|
314
|
+
scope.addEventListener('focusout', onBlur);
|
|
315
|
+
return () => {
|
|
316
|
+
scope.removeEventListener('click', onClick);
|
|
317
|
+
scope.removeEventListener('change', onChange);
|
|
318
|
+
scope.removeEventListener('keydown', onKeydown);
|
|
319
|
+
scope.removeEventListener('focusout', onBlur);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Rewrite a pager's row range, in place. THIS is the announcement.
|
|
325
|
+
*
|
|
326
|
+
* The factory returns a whole `<nav>`, so the obvious way to show a new page is
|
|
327
|
+
* to replace it — which inserts a brand-new live region that already contains its
|
|
328
|
+
* text, and several screen readers say nothing at all about a region that arrived
|
|
329
|
+
* with its content. The kit has met this before and answered it the same way:
|
|
330
|
+
* `setBusy()` rewrites the line its region already holds rather than inserting a
|
|
331
|
+
* new one. why: docs/specification.md#pending-and-denied-states
|
|
332
|
+
*
|
|
333
|
+
* So a consumer re-rendering a pager should hand the new range here instead of
|
|
334
|
+
* relying on the replacement to speak. Returns the status element, or null when
|
|
335
|
+
* there is nothing to update — safe against a torn-down view.
|
|
336
|
+
*/
|
|
337
|
+
export function setPagerStatus(root, text) {
|
|
338
|
+
const el = typeof root === 'string' ? document.querySelector(root) : root;
|
|
339
|
+
if (!el || typeof el.querySelector !== 'function') return null;
|
|
340
|
+
const status = el.matches?.('.ui-pager__status') ? el : el.querySelector('.ui-pager__status');
|
|
341
|
+
if (!status) return null;
|
|
342
|
+
if (status.textContent !== String(text)) status.textContent = String(text);
|
|
343
|
+
return status;
|
|
344
|
+
}
|
package/src/index.css
CHANGED
package/src/index.js
CHANGED
|
@@ -13,6 +13,7 @@ export * from './components/feedback.js';
|
|
|
13
13
|
export * from './components/toasts.js';
|
|
14
14
|
export * from './components/success.js';
|
|
15
15
|
export * from './components/loading.js';
|
|
16
|
+
export * from './components/pagination.js';
|
|
16
17
|
export * from './assets/icons.js';
|
|
17
18
|
export * from './assets/brand.js';
|
|
18
19
|
export * from './motion.js';
|
package/src/inline.js
CHANGED
|
@@ -41,6 +41,7 @@ export const styles = {
|
|
|
41
41
|
drawer: read('styles/drawer.css'),
|
|
42
42
|
confirm: read('styles/confirm.css'),
|
|
43
43
|
table: read('styles/table.css'),
|
|
44
|
+
pagination: read('styles/pagination.css'),
|
|
44
45
|
empty: read('styles/empty.css'),
|
|
45
46
|
callout: read('styles/callout.css'),
|
|
46
47
|
code: read('styles/code.css'),
|
|
@@ -69,6 +70,7 @@ export const cssText = [
|
|
|
69
70
|
styles.drawer,
|
|
70
71
|
styles.confirm,
|
|
71
72
|
styles.table,
|
|
73
|
+
styles.pagination,
|
|
72
74
|
styles.empty,
|
|
73
75
|
styles.callout,
|
|
74
76
|
styles.code,
|
package/src/styles/button.css
CHANGED
|
@@ -100,7 +100,21 @@
|
|
|
100
100
|
.ui-btn--ghost[aria-disabled="true"] {
|
|
101
101
|
background: transparent;
|
|
102
102
|
border-color: transparent;
|
|
103
|
+
color: var(--disabled-ink-bare);
|
|
103
104
|
}
|
|
105
|
+
/* With no box, the ink is read on whatever is behind it. --disabled-ink read
|
|
106
|
+
5.18:1 on a card and 4.66:1 on --surface-3 in dark, under #220's 5.56, so the
|
|
107
|
+
ghost takes an ink set for the dullest ground: in dark 7.00 / 6.24 / 6.69 /
|
|
108
|
+
5.62 on --bg / --surface / --surface-2 / --surface-3, in light 6.50 / 6.50 /
|
|
109
|
+
6.01 / 5.60. The enabled ghost's --dim reads 1.5 times that in dark, 1.6 in light.
|
|
110
|
+
|
|
111
|
+
#273 got here the long way. It first gave the ghost the flat disabled box
|
|
112
|
+
instead, on the claim that nothing would get less readable. That was false:
|
|
113
|
+
--bg and --surface lost up to 0.46. Then the box was rendered in a pager at
|
|
114
|
+
page 1, and the boxed First and Prev read heavier than the boxless Next and
|
|
115
|
+
Last beside them: the controls that were off looked like the live ones. No
|
|
116
|
+
contrast table shows that. The box was reverted and this ink shipped.
|
|
117
|
+
Held by src/styles/button-disabled.test.js. */
|
|
104
118
|
|
|
105
119
|
/* Busy: keep the label, run an indeterminate accent shimmer along the base, and
|
|
106
120
|
the button is disabled (not clickable). Pass busy + the .ui-btn__bars markup.
|
package/src/styles/input.css
CHANGED
|
@@ -49,7 +49,13 @@
|
|
|
49
49
|
|
|
50
50
|
/* The value a reader typed is still the value; it goes quiet, it does not fade
|
|
51
51
|
into the field under it the way an opacity would take both down together. #220 */
|
|
52
|
+
/* `.ui-select` joins these two in #273. It had no disabled rule at all, and it
|
|
53
|
+
sets `background: var(--surface-2)` as an author declaration — which outranks
|
|
54
|
+
the UA's own grey-out — so a disabled select rendered pixel-identical to a live
|
|
55
|
+
one. A pager marked busy showed every button and the jump input visibly off
|
|
56
|
+
beside a size control that still looked available. */
|
|
52
57
|
.ui-input:disabled,
|
|
58
|
+
.ui-select:disabled,
|
|
53
59
|
.ui-textarea:disabled {
|
|
54
60
|
background: var(--disabled-surface);
|
|
55
61
|
border-color: var(--disabled-border);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/* ============================================================================
|
|
2
|
+
* Pagination — .ui-pager (variants: --steps / --numbered / --jump)
|
|
3
|
+
* --open total unknown: Prev and Next only, no last page to reach
|
|
4
|
+
* --single one page of content: the size control alone, no steps
|
|
5
|
+
* The controls are .ui-btn ghost/sm and the size control is a .ui-select, so
|
|
6
|
+
* everything here is layout and the two states those sheets do not own.
|
|
7
|
+
* ========================================================================== */
|
|
8
|
+
|
|
9
|
+
.ui-pager {
|
|
10
|
+
display: flex;
|
|
11
|
+
flex-wrap: wrap;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: var(--space-3) var(--space-4);
|
|
14
|
+
font-size: var(--text-sm);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/* The status is the only thing anchored to the start of the strip: it is read,
|
|
18
|
+
not aimed at, and pushing the controls to the far end keeps the pointer's
|
|
19
|
+
target group in one place as the row count changes width. */
|
|
20
|
+
.ui-pager__status {
|
|
21
|
+
margin: 0 auto 0 0;
|
|
22
|
+
color: var(--muted);
|
|
23
|
+
font-variant-numeric: tabular-nums;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.ui-pager__size {
|
|
27
|
+
display: flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
gap: var(--space-2);
|
|
30
|
+
}
|
|
31
|
+
.ui-pager__size-label { color: var(--muted); }
|
|
32
|
+
|
|
33
|
+
/* .ui-select is a form field sized for a form — full width, 12px/15px padding.
|
|
34
|
+
In a pager it sits in a row of sm buttons, so it takes their scale. Two things
|
|
35
|
+
travel with that: the chevron .ui-select paints is positioned from the right
|
|
36
|
+
edge, so the padding on that side has to stay clear of it, and the height is
|
|
37
|
+
declared so this control and the jump input beside it agree on one box. */
|
|
38
|
+
.ui-pager__size-select {
|
|
39
|
+
width: auto;
|
|
40
|
+
min-height: var(--space-8);
|
|
41
|
+
padding: var(--space-1) var(--space-6) var(--space-1) var(--space-2);
|
|
42
|
+
font-size: var(--text-sm);
|
|
43
|
+
border-radius: var(--radius-sm);
|
|
44
|
+
background-position: right var(--space-2) center;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.ui-pager__steps {
|
|
48
|
+
display: flex;
|
|
49
|
+
flex-wrap: wrap;
|
|
50
|
+
align-items: center;
|
|
51
|
+
gap: var(--space-1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/* Page numbers are read as a row of equal cells, and .ui-btn--sm's padding makes
|
|
55
|
+
"1" narrower than "49" — so a strip re-flows under the pointer as the reader
|
|
56
|
+
walks into three-digit pages. The number is WCAG 2.5.8's 24px: an equalised
|
|
57
|
+
cell should not be narrower than a target is allowed to be. */
|
|
58
|
+
.ui-pager__page {
|
|
59
|
+
min-width: var(--space-6);
|
|
60
|
+
font-variant-numeric: tabular-nums;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* The page you are on. Guarded, because this weighs the same as `.ui-btn:disabled`
|
|
64
|
+
and is imported after it: written plainly it would repaint the current page of
|
|
65
|
+
a `loading` pager as though it were live, which is the one thing the busy state
|
|
66
|
+
must not leave behind. Spelled `[disabled]` rather than `:disabled` — the same
|
|
67
|
+
selector for the markup this component emits, and the spelling that keeps a
|
|
68
|
+
rule about an ENABLED control out of the disabled-rule sweep in
|
|
69
|
+
stories/guidelines/accessibility-floor.test.js, which reads selector text. */
|
|
70
|
+
.ui-pager__page.is-current:not([disabled]) {
|
|
71
|
+
background: var(--surface-3);
|
|
72
|
+
border-color: var(--border);
|
|
73
|
+
color: var(--strong);
|
|
74
|
+
font-weight: var(--weight-semibold);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.ui-pager__gap {
|
|
78
|
+
padding: 0 var(--space-1);
|
|
79
|
+
color: var(--muted);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.ui-pager__jump {
|
|
83
|
+
display: inline-flex;
|
|
84
|
+
align-items: center;
|
|
85
|
+
gap: var(--space-2);
|
|
86
|
+
color: var(--muted);
|
|
87
|
+
padding: 0 var(--space-1);
|
|
88
|
+
}
|
|
89
|
+
/* Wide enough for four digits and the spinner a number input draws beside them;
|
|
90
|
+
in ch so it follows the type rather than a measured pixel. The height is
|
|
91
|
+
declared rather than left to the line box, because an <input> holds its value
|
|
92
|
+
in a property: it is the one control in the strip with no text of its own, and
|
|
93
|
+
nothing else gives it the 24px WCAG 2.5.8 asks of a pointer target. */
|
|
94
|
+
.ui-pager__jump-input {
|
|
95
|
+
width: 8ch;
|
|
96
|
+
min-height: var(--space-8);
|
|
97
|
+
padding: var(--space-1) var(--space-2);
|
|
98
|
+
font-size: var(--text-sm);
|
|
99
|
+
border-radius: var(--radius-sm);
|
|
100
|
+
text-align: center;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* A pager directly after a table stands off it. The strip owns no margin of its
|
|
104
|
+
own — it is dropped under lists and cards too, and a component that carries
|
|
105
|
+
spacing everywhere is one every caller has to cancel somewhere — so the gap is
|
|
106
|
+
declared on the one adjacency the kit can see. `.rx-pager` carried a bare
|
|
107
|
+
`margin-top: 16px` for this, which is --space-4; the number moves to the scale
|
|
108
|
+
with it rather than travelling as a literal.
|
|
109
|
+
why: docs/specification.md#spacing-and-rhythm */
|
|
110
|
+
.ui-table + .ui-pager { margin-top: var(--space-4); }
|
|
111
|
+
|
|
112
|
+
/* A step given an `href` is an anchor, and a host stylesheet's `a:link` is
|
|
113
|
+
(0,1,1) — which outranks `.ui-btn--ghost` at (0,1,0) and paints the enabled
|
|
114
|
+
steps in the host's link colour while the disabled ends keep --disabled-ink-bare.
|
|
115
|
+
One strip, reading as two different controls. The kit has paid for this twice
|
|
116
|
+
already and both fixes are the same shape: see the (0,2,0) note on
|
|
117
|
+
`.ui-nav .ui-nav__item` in nav.css. Storybook ships no `a:link`, so the "Pages
|
|
118
|
+
as links" story cannot show it — which is why the rule is stated rather than
|
|
119
|
+
discovered.
|
|
120
|
+
why: docs/specification.md#pagination */
|
|
121
|
+
a.ui-pager__step,
|
|
122
|
+
a.ui-pager__page { color: var(--dim); }
|
|
123
|
+
a.ui-pager__step:hover,
|
|
124
|
+
a.ui-pager__page:hover { color: var(--strong); }
|
package/src/tokens/tokens.css
CHANGED
|
@@ -158,6 +158,11 @@
|
|
|
158
158
|
--disabled-ink: var(--muted);
|
|
159
159
|
--disabled-surface: var(--surface-2);
|
|
160
160
|
--disabled-border: var(--border);
|
|
161
|
+
/* The ink of a disabled control that paints no box of its own — a ghost button. With
|
|
162
|
+
no surface beside it, it is read on whatever is behind it, so it is set to clear the
|
|
163
|
+
floor on the dullest ground there is (--surface-3). #273
|
|
164
|
+
why: docs/specification.md#colour-and-contrast */
|
|
165
|
+
--disabled-ink-bare: #a39eb7;
|
|
161
166
|
|
|
162
167
|
/* Lifted from #9b5dff, which cleared the flat surfaces and failed on its own wash over
|
|
163
168
|
a card; the value was already in the ramp. --ring is var(--accent) and follows by
|
|
@@ -271,6 +276,7 @@
|
|
|
271
276
|
--disabled-ink: var(--muted);
|
|
272
277
|
--disabled-surface: var(--surface-2);
|
|
273
278
|
--disabled-border: var(--border);
|
|
279
|
+
--disabled-ink-bare: #585e6c;
|
|
274
280
|
|
|
275
281
|
--accent: #6a2dcc;
|
|
276
282
|
--accent-strong: #6a2dcc; /* already dark enough for white text */
|