@hozo/semantics 0.2.0 → 0.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/CHANGELOG.md +27 -0
- package/README.md +39 -0
- package/dist/generated/badge.d.ts +2 -0
- package/dist/generated/badge.d.ts.map +1 -0
- package/dist/generated/badge.js +2 -0
- package/dist/generated/badge.js.map +1 -0
- package/dist/generated/badge.native.d.ts +2 -0
- package/dist/generated/badge.native.d.ts.map +1 -0
- package/dist/generated/badge.native.js +2 -0
- package/dist/generated/badge.native.js.map +1 -0
- package/dist/generated/meter.d.ts +2 -0
- package/dist/generated/meter.d.ts.map +1 -0
- package/dist/generated/meter.js +2 -0
- package/dist/generated/meter.js.map +1 -0
- package/dist/generated/meter.native.d.ts +2 -0
- package/dist/generated/meter.native.d.ts.map +1 -0
- package/dist/generated/meter.native.js +2 -0
- package/dist/generated/meter.native.js.map +1 -0
- package/dist/generated/table.d.ts +2 -0
- package/dist/generated/table.d.ts.map +1 -0
- package/dist/generated/table.js +2 -0
- package/dist/generated/table.js.map +1 -0
- package/dist/generated/table.native.d.ts +2 -0
- package/dist/generated/table.native.d.ts.map +1 -0
- package/dist/generated/table.native.js +2 -0
- package/dist/generated/table.native.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +74 -16
- package/dist/index.js.map +1 -1
- package/dist/index.native.d.ts +60 -0
- package/dist/index.native.d.ts.map +1 -1
- package/dist/index.native.js +83 -6
- package/dist/index.native.js.map +1 -1
- package/dist/meter-gauge.d.ts +30 -0
- package/dist/meter-gauge.d.ts.map +1 -0
- package/dist/meter-gauge.js +36 -0
- package/dist/meter-gauge.js.map +1 -0
- package/dist/table.d.ts +45 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +31 -0
- package/dist/table.js.map +1 -0
- package/dist/table.native.d.ts +92 -0
- package/dist/table.native.d.ts.map +1 -0
- package/dist/table.native.js +207 -0
- package/dist/table.native.js.map +1 -0
- package/package.json +27 -3
- package/src/generated/badge.native.ts +1 -0
- package/src/generated/badge.ts +1 -0
- package/src/generated/meter.native.ts +1 -0
- package/src/generated/meter.ts +1 -0
- package/src/generated/table.native.ts +7 -0
- package/src/generated/table.ts +7 -0
- package/src/index.native.tsx +151 -6
- package/src/index.tsx +255 -45
- package/src/meter-gauge.ts +54 -0
- package/src/table.native.tsx +446 -0
- package/src/table.tsx +144 -0
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { useHozoMessage } from '@hozo/behaviors'
|
|
2
|
+
import { hozoViewBase, hozoViewClassName } from '@hozo/engine'
|
|
1
3
|
import type { CSSProperties, ReactNode } from 'react'
|
|
4
|
+
import { meterGauge } from './meter-gauge.ts'
|
|
2
5
|
|
|
3
6
|
export interface SemanticsUniversalProps {
|
|
4
7
|
className?: string
|
|
@@ -31,65 +34,89 @@ function domProps(props: Omit<SemanticsUniversalProps, 'style' | 'className' | '
|
|
|
31
34
|
|
|
32
35
|
export function Main({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
33
36
|
return (
|
|
34
|
-
|
|
35
|
-
{
|
|
36
|
-
|
|
37
|
+
<>
|
|
38
|
+
{hozoViewBase()}
|
|
39
|
+
<main className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
40
|
+
{children}
|
|
41
|
+
</main>
|
|
42
|
+
</>
|
|
37
43
|
)
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
export function Header({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
41
47
|
return (
|
|
42
|
-
|
|
43
|
-
{
|
|
44
|
-
|
|
48
|
+
<>
|
|
49
|
+
{hozoViewBase()}
|
|
50
|
+
<header className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
51
|
+
{children}
|
|
52
|
+
</header>
|
|
53
|
+
</>
|
|
45
54
|
)
|
|
46
55
|
}
|
|
47
56
|
|
|
48
57
|
export function Footer({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
49
58
|
return (
|
|
50
|
-
|
|
51
|
-
{
|
|
52
|
-
|
|
59
|
+
<>
|
|
60
|
+
{hozoViewBase()}
|
|
61
|
+
<footer className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
62
|
+
{children}
|
|
63
|
+
</footer>
|
|
64
|
+
</>
|
|
53
65
|
)
|
|
54
66
|
}
|
|
55
67
|
|
|
56
68
|
export function Aside({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
57
69
|
return (
|
|
58
|
-
|
|
59
|
-
{
|
|
60
|
-
|
|
70
|
+
<>
|
|
71
|
+
{hozoViewBase()}
|
|
72
|
+
<aside className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
73
|
+
{children}
|
|
74
|
+
</aside>
|
|
75
|
+
</>
|
|
61
76
|
)
|
|
62
77
|
}
|
|
63
78
|
|
|
64
79
|
export function Search({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
65
80
|
return (
|
|
66
|
-
|
|
67
|
-
{
|
|
68
|
-
|
|
81
|
+
<>
|
|
82
|
+
{hozoViewBase()}
|
|
83
|
+
<search className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
84
|
+
{children}
|
|
85
|
+
</search>
|
|
86
|
+
</>
|
|
69
87
|
)
|
|
70
88
|
}
|
|
71
89
|
|
|
72
90
|
export function Section({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
73
91
|
return (
|
|
74
|
-
|
|
75
|
-
{
|
|
76
|
-
|
|
92
|
+
<>
|
|
93
|
+
{hozoViewBase()}
|
|
94
|
+
<section className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
95
|
+
{children}
|
|
96
|
+
</section>
|
|
97
|
+
</>
|
|
77
98
|
)
|
|
78
99
|
}
|
|
79
100
|
|
|
80
101
|
export function Article({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
81
102
|
return (
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
|
|
103
|
+
<>
|
|
104
|
+
{hozoViewBase()}
|
|
105
|
+
<article className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
106
|
+
{children}
|
|
107
|
+
</article>
|
|
108
|
+
</>
|
|
85
109
|
)
|
|
86
110
|
}
|
|
87
111
|
|
|
88
112
|
export function Nav({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
89
113
|
return (
|
|
90
|
-
|
|
91
|
-
{
|
|
92
|
-
|
|
114
|
+
<>
|
|
115
|
+
{hozoViewBase()}
|
|
116
|
+
<nav className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
117
|
+
{children}
|
|
118
|
+
</nav>
|
|
119
|
+
</>
|
|
93
120
|
)
|
|
94
121
|
}
|
|
95
122
|
|
|
@@ -100,25 +127,34 @@ export interface ListProps extends SemanticsUniversalProps {
|
|
|
100
127
|
export function List({ ordered = false, className, children, style, ...props }: ListProps) {
|
|
101
128
|
const Tag = ordered ? 'ol' : 'ul'
|
|
102
129
|
return (
|
|
103
|
-
|
|
104
|
-
{
|
|
105
|
-
|
|
130
|
+
<>
|
|
131
|
+
{hozoViewBase()}
|
|
132
|
+
<Tag className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
133
|
+
{children}
|
|
134
|
+
</Tag>
|
|
135
|
+
</>
|
|
106
136
|
)
|
|
107
137
|
}
|
|
108
138
|
|
|
109
139
|
export function ListItem({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
110
140
|
return (
|
|
111
|
-
|
|
112
|
-
{
|
|
113
|
-
|
|
141
|
+
<>
|
|
142
|
+
{hozoViewBase()}
|
|
143
|
+
<li className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
144
|
+
{children}
|
|
145
|
+
</li>
|
|
146
|
+
</>
|
|
114
147
|
)
|
|
115
148
|
}
|
|
116
149
|
|
|
117
150
|
export function Figure({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
118
151
|
return (
|
|
119
|
-
|
|
120
|
-
{
|
|
121
|
-
|
|
152
|
+
<>
|
|
153
|
+
{hozoViewBase()}
|
|
154
|
+
<figure className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
155
|
+
{children}
|
|
156
|
+
</figure>
|
|
157
|
+
</>
|
|
122
158
|
)
|
|
123
159
|
}
|
|
124
160
|
|
|
@@ -140,17 +176,23 @@ export function Time({ className, children, style, dateTime, datetime, ...props
|
|
|
140
176
|
|
|
141
177
|
export function Address({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
142
178
|
return (
|
|
143
|
-
|
|
144
|
-
{
|
|
145
|
-
|
|
179
|
+
<>
|
|
180
|
+
{hozoViewBase()}
|
|
181
|
+
<address className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
182
|
+
{children}
|
|
183
|
+
</address>
|
|
184
|
+
</>
|
|
146
185
|
)
|
|
147
186
|
}
|
|
148
187
|
|
|
149
188
|
export function Fieldset({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
150
189
|
return (
|
|
151
|
-
|
|
152
|
-
{
|
|
153
|
-
|
|
190
|
+
<>
|
|
191
|
+
{hozoViewBase()}
|
|
192
|
+
<fieldset className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
193
|
+
{children}
|
|
194
|
+
</fieldset>
|
|
195
|
+
</>
|
|
154
196
|
)
|
|
155
197
|
}
|
|
156
198
|
|
|
@@ -192,17 +234,23 @@ export function Term({ className, children, style, ...props }: SemanticsUniversa
|
|
|
192
234
|
|
|
193
235
|
export function Description({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
194
236
|
return (
|
|
195
|
-
|
|
196
|
-
{
|
|
197
|
-
|
|
237
|
+
<>
|
|
238
|
+
{hozoViewBase()}
|
|
239
|
+
<dd className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
240
|
+
{children}
|
|
241
|
+
</dd>
|
|
242
|
+
</>
|
|
198
243
|
)
|
|
199
244
|
}
|
|
200
245
|
|
|
201
246
|
export function TermList({ className, children, style, ...props }: SemanticsUniversalProps) {
|
|
202
247
|
return (
|
|
203
|
-
|
|
204
|
-
{
|
|
205
|
-
|
|
248
|
+
<>
|
|
249
|
+
{hozoViewBase()}
|
|
250
|
+
<dl className={hozoViewClassName(className)} style={style} {...domProps(props)}>
|
|
251
|
+
{children}
|
|
252
|
+
</dl>
|
|
253
|
+
</>
|
|
206
254
|
)
|
|
207
255
|
}
|
|
208
256
|
|
|
@@ -241,6 +289,147 @@ export interface ProgressProps extends SemanticsUniversalProps {
|
|
|
241
289
|
children?: ReactNode
|
|
242
290
|
}
|
|
243
291
|
|
|
292
|
+
export interface BadgeProps extends SemanticsUniversalProps {
|
|
293
|
+
/**
|
|
294
|
+
* A number to show. With it, the badge reads as its `accessibilityLabel`
|
|
295
|
+
* ("3 unread messages") rather than as the bare digit; without one, the
|
|
296
|
+
* children are the badge, a word that already says what it means.
|
|
297
|
+
*/
|
|
298
|
+
count?: number
|
|
299
|
+
/** The largest number shown; above it the badge shows `99+`. */
|
|
300
|
+
max?: number
|
|
301
|
+
children?: ReactNode
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Off screen and still in the accessibility tree. */
|
|
305
|
+
const VISUALLY_HIDDEN = {
|
|
306
|
+
position: 'absolute',
|
|
307
|
+
width: 1,
|
|
308
|
+
height: 1,
|
|
309
|
+
margin: -1,
|
|
310
|
+
padding: 0,
|
|
311
|
+
overflow: 'hidden',
|
|
312
|
+
clipPath: 'inset(50%)',
|
|
313
|
+
whiteSpace: 'nowrap',
|
|
314
|
+
border: 0,
|
|
315
|
+
} as const
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* A short status label -- "Draft", or a count.
|
|
319
|
+
*
|
|
320
|
+
* A count is the case with something to get right. The digit alone is read
|
|
321
|
+
* as "three", which says nothing about what there are three of, and a
|
|
322
|
+
* `<span>` cannot carry an accessible name to say it instead: `generic` is
|
|
323
|
+
* one of the roles ARIA prohibits naming. So the digit is hidden from
|
|
324
|
+
* assistive technology and the sentence is beside it, off screen -- the
|
|
325
|
+
* same arrangement a screen reader would hear from `"3" + " unread messages"`
|
|
326
|
+
* written out, with only the first part drawn.
|
|
327
|
+
*/
|
|
328
|
+
export function Badge({ count, max, className, style, children, ...props }: BadgeProps) {
|
|
329
|
+
const message = useHozoMessage()
|
|
330
|
+
const { 'aria-label': named, ...dom } = domProps(props)
|
|
331
|
+
if (count === undefined) {
|
|
332
|
+
return (
|
|
333
|
+
<span className={className} style={style} aria-label={named} {...dom}>
|
|
334
|
+
{children}
|
|
335
|
+
</span>
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
const over = max !== undefined && count > max
|
|
339
|
+
const shown = over ? `${max}+` : String(count)
|
|
340
|
+
const label = named ?? (over ? message('hozo.badge.overflow', { max: max as number }) : shown)
|
|
341
|
+
return (
|
|
342
|
+
<span className={className} style={style} {...dom}>
|
|
343
|
+
<span aria-hidden="true">{shown}</span>
|
|
344
|
+
<span style={VISUALLY_HIDDEN}>{label}</span>
|
|
345
|
+
</span>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
export interface SkeletonProps extends SemanticsUniversalProps {
|
|
350
|
+
children?: ReactNode
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* A loading placeholder.
|
|
355
|
+
*
|
|
356
|
+
* Hidden from assistive technology, because a grey box has nothing to say;
|
|
357
|
+
* the region being loaded is what says so, with `aria-busy`. Marked with
|
|
358
|
+
* `data-hozo-skeleton`, so the compiler's base CSS stops any animation on it
|
|
359
|
+
* or inside it under reduced motion -- whatever class started it
|
|
360
|
+
* (decision 007, section 5). The look, pulse included, is the caller's.
|
|
361
|
+
*/
|
|
362
|
+
export function Skeleton({ className, style, children, ...props }: SkeletonProps) {
|
|
363
|
+
return (
|
|
364
|
+
<>
|
|
365
|
+
{hozoViewBase()}
|
|
366
|
+
<div
|
|
367
|
+
className={hozoViewClassName(className)}
|
|
368
|
+
style={style}
|
|
369
|
+
{...domProps(props)}
|
|
370
|
+
aria-hidden={true}
|
|
371
|
+
data-hozo-skeleton=""
|
|
372
|
+
>
|
|
373
|
+
{children}
|
|
374
|
+
</div>
|
|
375
|
+
</>
|
|
376
|
+
)
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export interface MeterProps extends SemanticsUniversalProps {
|
|
380
|
+
/** Where in the range the amount is. */
|
|
381
|
+
value: number
|
|
382
|
+
/** The range, 0 to 1 when left out, as `<meter>` reads it. */
|
|
383
|
+
min?: number
|
|
384
|
+
max?: number
|
|
385
|
+
/**
|
|
386
|
+
* Where the range counts as low, high and best. The browser colours the
|
|
387
|
+
* bar by them; nothing announces them, on either platform.
|
|
388
|
+
*/
|
|
389
|
+
low?: number
|
|
390
|
+
high?: number
|
|
391
|
+
optimum?: number
|
|
392
|
+
children?: ReactNode
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* An amount within a known range -- a disk's fill, a password's strength.
|
|
397
|
+
* Not `Progress`, which is how far a task has got: a reader says "meter"
|
|
398
|
+
* for this and "progress bar" for that, and they mean different things.
|
|
399
|
+
*/
|
|
400
|
+
export function Meter({
|
|
401
|
+
value,
|
|
402
|
+
min,
|
|
403
|
+
max,
|
|
404
|
+
low,
|
|
405
|
+
high,
|
|
406
|
+
optimum,
|
|
407
|
+
className,
|
|
408
|
+
children,
|
|
409
|
+
style,
|
|
410
|
+
...props
|
|
411
|
+
}: MeterProps) {
|
|
412
|
+
return (
|
|
413
|
+
<meter
|
|
414
|
+
value={value}
|
|
415
|
+
min={min}
|
|
416
|
+
max={max}
|
|
417
|
+
low={low}
|
|
418
|
+
high={high}
|
|
419
|
+
optimum={optimum}
|
|
420
|
+
className={className}
|
|
421
|
+
style={style}
|
|
422
|
+
// The amount as a percentage, as Native reads it: without this NVDA
|
|
423
|
+
// says "progress bar, 0.6" and VoiceOver "0.6". Before the spread, so
|
|
424
|
+
// an author's own `aria-valuetext` wins.
|
|
425
|
+
aria-valuetext={`${Math.round(meterGauge({ value, min, max }).fraction * 100)}%`}
|
|
426
|
+
{...domProps(props)}
|
|
427
|
+
>
|
|
428
|
+
{children}
|
|
429
|
+
</meter>
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
|
|
244
433
|
export function Progress({ value, max, className, children, style, ...props }: ProgressProps) {
|
|
245
434
|
return (
|
|
246
435
|
<progress value={value} max={max} className={className} style={style} {...domProps(props)}>
|
|
@@ -248,3 +437,24 @@ export function Progress({ value, max, className, children, style, ...props }: P
|
|
|
248
437
|
</progress>
|
|
249
438
|
)
|
|
250
439
|
}
|
|
440
|
+
|
|
441
|
+
export {
|
|
442
|
+
HozoTable,
|
|
443
|
+
HozoTableCaption,
|
|
444
|
+
HozoTableCell,
|
|
445
|
+
HozoTableRow,
|
|
446
|
+
HozoTableSection,
|
|
447
|
+
Table,
|
|
448
|
+
TableBody,
|
|
449
|
+
TableCaption,
|
|
450
|
+
type TableCaptionProps,
|
|
451
|
+
TableCell,
|
|
452
|
+
type TableCellProps,
|
|
453
|
+
TableFooter,
|
|
454
|
+
TableHead,
|
|
455
|
+
TableHeader,
|
|
456
|
+
type TableProps,
|
|
457
|
+
TableRow,
|
|
458
|
+
type TableRowProps,
|
|
459
|
+
type TableSectionProps,
|
|
460
|
+
} from './table.tsx'
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a `<meter>`'s amount sits and which of its three colours it gets,
|
|
3
|
+
* worked out the way the browser does, so React Native can draw the bar the
|
|
4
|
+
* Web is given for free.
|
|
5
|
+
*
|
|
6
|
+
* The clamping follows the HTML standard's `<meter>` attributes: the range is
|
|
7
|
+
* 0 to 1 when left out, `max` is never below `min`, `value` and `optimum` sit
|
|
8
|
+
* inside the range, `low` inside it, and `high` between `low` and `max`. The
|
|
9
|
+
* regions are the browser's: an optimum between `low` and `high` makes that
|
|
10
|
+
* middle stretch good and both sides fair; an optimum beyond either boundary
|
|
11
|
+
* makes its own end good, the middle fair and the far end poor. A boundary
|
|
12
|
+
* belongs to the better side, every time -- read off Chromium's own pixels
|
|
13
|
+
* for 110 combinations, which is what the tests' edge cases are.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export type MeterRegion = 'optimum' | 'suboptimal' | 'even-less-good'
|
|
17
|
+
|
|
18
|
+
export interface MeterGauge {
|
|
19
|
+
/** How far along the range the amount is, 0 to 1. */
|
|
20
|
+
fraction: number
|
|
21
|
+
region: MeterRegion
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface MeterRange {
|
|
25
|
+
value: number
|
|
26
|
+
min?: number
|
|
27
|
+
max?: number
|
|
28
|
+
low?: number
|
|
29
|
+
high?: number
|
|
30
|
+
optimum?: number
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const clamp = (value: number, lowest: number, highest: number) =>
|
|
34
|
+
Math.min(Math.max(value, lowest), highest)
|
|
35
|
+
|
|
36
|
+
export function meterGauge({ value, min, max, low, high, optimum }: MeterRange): MeterGauge {
|
|
37
|
+
const start = min ?? 0
|
|
38
|
+
const end = Math.max(start, max ?? 1)
|
|
39
|
+
const amount = clamp(value, start, end)
|
|
40
|
+
const lowBound = clamp(low ?? start, start, end)
|
|
41
|
+
const highBound = clamp(high ?? end, lowBound, end)
|
|
42
|
+
const best = clamp(optimum ?? (start + end) / 2, start, end)
|
|
43
|
+
const fraction = end === start ? 0 : (amount - start) / (end - start)
|
|
44
|
+
|
|
45
|
+
let region: MeterRegion
|
|
46
|
+
if (lowBound <= best && best <= highBound) {
|
|
47
|
+
region = lowBound <= amount && amount <= highBound ? 'optimum' : 'suboptimal'
|
|
48
|
+
} else if (highBound < best) {
|
|
49
|
+
region = highBound <= amount ? 'optimum' : lowBound <= amount ? 'suboptimal' : 'even-less-good'
|
|
50
|
+
} else {
|
|
51
|
+
region = amount <= lowBound ? 'optimum' : amount <= highBound ? 'suboptimal' : 'even-less-good'
|
|
52
|
+
}
|
|
53
|
+
return { fraction, region }
|
|
54
|
+
}
|