@nanahoshi/mona-ui 0.41.0 → 0.42.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/docs/api/auto-complete.md +2 -0
- package/docs/api/combo-box.md +2 -0
- package/docs/api/dropdowns.md +3 -1
- package/docs/api/i18n.md +20 -0
- package/docs/api/locales.md +14 -14
- package/docs/api/sparkline.md +85 -0
- package/docs/auto-complete.md +64 -0
- package/docs/combo-box.md +65 -0
- package/docs/sparkline.md +303 -0
- package/fesm2022/nanahoshi-mona-ui-auto-complete.mjs +95 -30
- package/fesm2022/nanahoshi-mona-ui-combo-box.mjs +58 -5
- package/fesm2022/nanahoshi-mona-ui-dropdowns.mjs +64 -29
- package/fesm2022/nanahoshi-mona-ui-i18n-icu.mjs +39 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ar-sa.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-de-de.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-es-es.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-fr-fr.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-id-id.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-it-it.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ja-jp.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ko-kr.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pl-pl.mjs +25 -0
- package/fesm2022/nanahoshi-mona-ui-locales-pt-br.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-ru-ru.mjs +25 -0
- package/fesm2022/nanahoshi-mona-ui-locales-tr-tr.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-cn.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-locales-zh-tw.mjs +5 -0
- package/fesm2022/nanahoshi-mona-ui-sparkline.mjs +573 -0
- package/i18n/catalogs/en-US.messages.json +5 -0
- package/llms.txt +3 -1
- package/locales/ar-sa/ar-sa.messages.json +5 -0
- package/locales/de-de/de-de.messages.json +5 -0
- package/locales/es-es/es-es.messages.json +5 -0
- package/locales/fr-fr/fr-fr.messages.json +5 -0
- package/locales/id-id/id-id.messages.json +5 -0
- package/locales/it-it/it-it.messages.json +5 -0
- package/locales/ja-jp/ja-jp.messages.json +5 -0
- package/locales/ko-kr/ko-kr.messages.json +5 -0
- package/locales/pl-pl/pl-pl.messages.json +5 -0
- package/locales/pt-br/pt-br.messages.json +5 -0
- package/locales/ru-ru/ru-ru.messages.json +5 -0
- package/locales/tr-tr/tr-tr.messages.json +5 -0
- package/locales/zh-cn/zh-cn.messages.json +5 -0
- package/locales/zh-tw/zh-tw.messages.json +5 -0
- package/package.json +5 -1
- package/sparkline/package.json +4 -0
- package/types/nanahoshi-mona-ui-auto-complete.d.ts +42 -1
- package/types/nanahoshi-mona-ui-combo-box.d.ts +37 -1
- package/types/nanahoshi-mona-ui-dropdowns.d.ts +54 -4
- package/types/nanahoshi-mona-ui-i18n.d.ts +12 -0
- package/types/nanahoshi-mona-ui-locales-ar-sa.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-de-de.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-es-es.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-fr-fr.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-id-id.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-it-it.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-ja-jp.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-ko-kr.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-pl-pl.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-pt-br.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-ru-ru.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-tr-tr.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-zh-cn.d.ts +5 -0
- package/types/nanahoshi-mona-ui-locales-zh-tw.d.ts +5 -0
- package/types/nanahoshi-mona-ui-sparkline.d.ts +228 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# `@nanahoshi/mona-ui/sparkline`
|
|
2
|
+
|
|
3
|
+
Everything `@nanahoshi/mona-ui/sparkline` exports.
|
|
4
|
+
|
|
5
|
+
**Guides:** [Sparkline](../sparkline.md)
|
|
6
|
+
|
|
7
|
+
## `SparklineComponent`
|
|
8
|
+
|
|
9
|
+
Component.
|
|
10
|
+
|
|
11
|
+
A word-sized chart of a series of values, to sit on a line of text or in a table cell: a line, an area, columns or
|
|
12
|
+
wins and losses. It's an image to assistive technology, which reads its name and a summary of its values: how many,
|
|
13
|
+
the first, the last, the lowest and the highest, or how many wins, losses and draws.
|
|
14
|
+
|
|
15
|
+
Values run from left to right, also in a right-to-left layout, as on a chart's axis.
|
|
16
|
+
|
|
17
|
+
**Selector:** `mona-sparkline`
|
|
18
|
+
|
|
19
|
+
### Inputs
|
|
20
|
+
|
|
21
|
+
| Name | Type | Default | Description |
|
|
22
|
+
| --- | --- | --- | --- |
|
|
23
|
+
| `aria-describedby` | `string` | `""` | Ids of elements that describe the sparkline further. The summary of its values is added after them when it has a name. |
|
|
24
|
+
| `aria-label` | `string` | `""` | The sparkline's name, what its values are, such as "Weekly sales". Assistive technology reads the summary of its values after it. Without a name, the summary is the name. |
|
|
25
|
+
| `class` | `string` | `""` | Additional CSS classes merged onto the host element via `tailwind-merge`, such as a size: it's 6rem wide and 1.5rem tall by default. |
|
|
26
|
+
| `color` | `string` | `""` | The color of the line, the area and the bars, as a CSS color. The first chart color when empty. The `--mona-sparkline-color` custom property sets it from a style sheet. |
|
|
27
|
+
| `curve` | `SparklineCurve` | `"linear"` | How a line or an area joins its values, as a chart's line series does: `"linear"`, `"monotone-x"` (smooth, never past the values), `"natural"` (smoother, but it can swing past them), `"step"` (changing halfway between values) or `"step-after"` (holding each value until the next). Columns and win-loss bars ignore it. |
|
|
28
|
+
| `data` | `Iterable<number \| null \| undefined>` | `[]` | The values, in order. A `null`, or anything that isn't a finite number, leaves a gap. |
|
|
29
|
+
| `decorative` | `boolean` | `false` | Hides the sparkline from assistive technology, for one beside text that already gives its values. |
|
|
30
|
+
| `format` | `Intl.NumberFormatOptions \| null` | `null` | How the values are formatted in the summary assistive technology reads, such as `{ style: "currency", currency: "EUR" }`. The locale's number format when `null`. |
|
|
31
|
+
| `markers` | `readonly SparklineMarker[]` | `[]` | Values a line or area sparkline marks with a dot: `"first"`, `"last"`, `"min"` and `"max"`. |
|
|
32
|
+
| `max` | `number \| null` | `null` | The value at the top of the sparkline. Give several sparklines the same `min` and `max` to compare them. When `null`, the highest value, or zero for columns, or the reference value when it's higher. |
|
|
33
|
+
| `min` | `number \| null` | `null` | The value at the bottom of the sparkline. When `null`, the lowest value, or zero for columns, or the reference value when it's lower. |
|
|
34
|
+
| `negativeColor` | `string` | `""` | The color of column bars below zero and of losses, as a CSS color. The error color when empty. The `--mona-sparkline-negative-color` custom property sets it from a style sheet. |
|
|
35
|
+
| `referenceValue` | `number \| null` | `null` | A value to draw a dashed line at, such as a target or an average. Not drawn on a win-loss sparkline. |
|
|
36
|
+
| `type` | `SparklineType` | `"line"` | How the values are drawn: `"line"`, `"area"`, `"column"` or `"win-loss"`. |
|
|
37
|
+
|
|
38
|
+
## `SPARKLINE_DEFAULT_MESSAGES`
|
|
39
|
+
|
|
40
|
+
Constant.
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
const SPARKLINE_DEFAULT_MESSAGES: MonaSparklineMessages;
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## `SparklineCurve`
|
|
47
|
+
|
|
48
|
+
Type alias.
|
|
49
|
+
|
|
50
|
+
How a line or an area sparkline joins its values, as a chart's line series does: `"linear"` with straight segments,
|
|
51
|
+
`"monotone-x"` with a smooth curve that never swings past the values, `"natural"` with a smoother curve that can,
|
|
52
|
+
`"step"` in steps that change halfway between values, and `"step-after"` in steps that hold each value until the
|
|
53
|
+
next one.
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
type SparklineCurve = "linear" | "monotone-x" | "natural" | "step" | "step-after";
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
**Used by:** [`SparklineComponent`](sparkline.md#sparklinecomponent)
|
|
60
|
+
|
|
61
|
+
## `SparklineMarker`
|
|
62
|
+
|
|
63
|
+
Type alias.
|
|
64
|
+
|
|
65
|
+
A value a line or area sparkline marks with a dot: its first, its last, its lowest or its highest.
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
type SparklineMarker = "first" | "last" | "max" | "min";
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Used by:** [`SparklineComponent`](sparkline.md#sparklinecomponent)
|
|
72
|
+
|
|
73
|
+
## `SparklineType`
|
|
74
|
+
|
|
75
|
+
Type alias.
|
|
76
|
+
|
|
77
|
+
How a sparkline draws its values: `"line"` joins them, `"area"` fills under the line, `"column"` draws a bar for
|
|
78
|
+
each from zero, and `"win-loss"` draws a bar up for each positive value, down for each negative one and a short tick
|
|
79
|
+
for each zero, all of one height.
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
type SparklineType = "area" | "column" | "line" | "win-loss";
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
**Used by:** [`SparklineComponent`](sparkline.md#sparklinecomponent)
|
package/docs/auto-complete.md
CHANGED
|
@@ -274,6 +274,58 @@ export class AutoCompleteFormsExampleComponent {
|
|
|
274
274
|
</div>
|
|
275
275
|
```
|
|
276
276
|
|
|
277
|
+
### A bottom sheet on a phone
|
|
278
|
+
|
|
279
|
+
With `adaptiveMode="auto"`, on a screen narrower than 640 pixels, the suggestions open as a sheet along the bottom of the screen, with a text box of its own at the top. Narrow the window to see it.
|
|
280
|
+
|
|
281
|
+
`adaptive-example.component.ts`
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import { Component, signal } from "@angular/core";
|
|
285
|
+
import { AutoCompleteComponent } from "@nanahoshi/mona-ui/auto-complete";
|
|
286
|
+
import { DropdownFilterableDirective } from "@nanahoshi/mona-ui/dropdowns";
|
|
287
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
288
|
+
|
|
289
|
+
@Component({
|
|
290
|
+
selector: "app-auto-complete-adaptive-example",
|
|
291
|
+
imports: [AutoCompleteComponent, DropdownFilterableDirective, FormFieldComponent],
|
|
292
|
+
templateUrl: "./adaptive-example.component.html"
|
|
293
|
+
})
|
|
294
|
+
export class AutoCompleteAdaptiveExampleComponent {
|
|
295
|
+
protected readonly cities = [
|
|
296
|
+
"Amsterdam",
|
|
297
|
+
"Barcelona",
|
|
298
|
+
"Berlin",
|
|
299
|
+
"Istanbul",
|
|
300
|
+
"Kraków",
|
|
301
|
+
"Lisbon",
|
|
302
|
+
"Osaka",
|
|
303
|
+
"Seoul",
|
|
304
|
+
"Sydney",
|
|
305
|
+
"Toronto",
|
|
306
|
+
"Vienna"
|
|
307
|
+
];
|
|
308
|
+
protected readonly city = signal<string | null>(null);
|
|
309
|
+
}
|
|
310
|
+
```
|
|
311
|
+
|
|
312
|
+
`adaptive-example.component.html`
|
|
313
|
+
|
|
314
|
+
```html
|
|
315
|
+
<mona-form-field
|
|
316
|
+
class="max-w-sm"
|
|
317
|
+
label="City"
|
|
318
|
+
hint="On a phone, suggestions open along the bottom of the screen, with a box to type in.">
|
|
319
|
+
<mona-auto-complete
|
|
320
|
+
adaptiveMode="auto"
|
|
321
|
+
class="w-full"
|
|
322
|
+
monaDropDownFilterable
|
|
323
|
+
placeholder="Type a city"
|
|
324
|
+
[data]="cities"
|
|
325
|
+
[(value)]="city" />
|
|
326
|
+
</mona-form-field>
|
|
327
|
+
```
|
|
328
|
+
|
|
277
329
|
### Highlight the first match while typing
|
|
278
330
|
|
|
279
331
|
`highlightFirst` (default `true`) highlights the first option whose text matches the typed text as the consumer types, so `Enter` can commit it immediately. Set it to `false` to require the consumer to navigate to an option explicitly before `Enter` commits it.
|
|
@@ -335,6 +387,16 @@ Blurring the input while the popup is closed commits the typed text as `value`,
|
|
|
335
387
|
|
|
336
388
|
`open` and `close` emit event objects with `preventDefault()` and `isDefaultPrevented()`. Calling `preventDefault()` in an `open` handler stops the popup from opening; calling it in a `close` handler stops the popup from closing. `close`'s event object also exposes `via`, describing what triggered the close attempt.
|
|
337
389
|
|
|
390
|
+
### The bottom sheet
|
|
391
|
+
|
|
392
|
+
With `adaptiveMode="auto"`, the popup opens as a bottom sheet when the screen is narrower than 640 pixels as it opens; it doesn't switch while open. On such a screen, the field raises no on-screen keyboard. Pressing it opens the sheet, with the matches for the field's text, or the whole list when it has none. Typing into the field with a keyboard opens it too, and carries the text along.
|
|
393
|
+
|
|
394
|
+
The sheet covers the page with a dimmed backdrop and has a header with the field's name (or `adaptiveTitle`) and a close button. Below it is a text box, which takes focus and is named by that header, then the list, whose options are 44 pixels tall.
|
|
395
|
+
|
|
396
|
+
The text box works as the field does: typing suggests, the arrow keys highlight, `Enter` commits and `Escape` closes. Deleting its text keeps the sheet open, with the whole list. The sheet keeps its height while the list filters, so the text box stays put, and it sits above an on-screen keyboard.
|
|
397
|
+
|
|
398
|
+
When the sheet closes, focus goes back to the field, with the typed text, which becomes the value when focus leaves, as usual. Without `adaptiveMode`, or with `"none"`, the popup always opens under the field.
|
|
399
|
+
|
|
338
400
|
### `DropdownFieldSelectorType`, `DropdownFieldPredicateType`, and `ListSizeInputType` are not exported
|
|
339
401
|
|
|
340
402
|
`textField`, `valueField`, `itemDisabled`, `popupHeight`, and `popupWidth` are typed with these generic aliases internally, but none of the three types are re-exported from `@nanahoshi/mona-ui`. Inline values (as in the examples above) still type-check structurally; only a standalone typed variable would require an import.
|
|
@@ -362,6 +424,8 @@ Blurring the input while the popup is closed commits the typed text as `value`,
|
|
|
362
424
|
|
|
363
425
|
The host element itself is not a Tab stop (`tabindex="-1"`); the inner `<input>` element receives focus and is the actual Tab stop. Arrow-key navigation moves an internal highlighted-option pointer, reflected through `aria-activedescendant` on the input, instead of moving DOM focus into the popup.
|
|
364
426
|
|
|
427
|
+
In a bottom sheet (`adaptiveMode="auto"` on a small screen), focus moves to the sheet's text box, which has the same role and states as the input, and comes back to the input when the sheet closes.
|
|
428
|
+
|
|
365
429
|
### ARIA
|
|
366
430
|
|
|
367
431
|
| Element | Attribute | When present | Value |
|
package/docs/combo-box.md
CHANGED
|
@@ -295,6 +295,59 @@ export class ComboBoxFormsExampleComponent {
|
|
|
295
295
|
</div>
|
|
296
296
|
```
|
|
297
297
|
|
|
298
|
+
### A bottom sheet on a phone
|
|
299
|
+
|
|
300
|
+
With `adaptiveMode="auto"`, on a screen narrower than 640 pixels, the popup opens as a sheet along the bottom of the screen, with a text box of its own at the top. Narrow the window to see it.
|
|
301
|
+
|
|
302
|
+
`adaptive-example.component.ts`
|
|
303
|
+
|
|
304
|
+
```typescript
|
|
305
|
+
import { Component, signal } from "@angular/core";
|
|
306
|
+
import { ComboBoxComponent } from "@nanahoshi/mona-ui/combo-box";
|
|
307
|
+
import { DropdownFilterableDirective } from "@nanahoshi/mona-ui/dropdowns";
|
|
308
|
+
import { FormFieldComponent } from "@nanahoshi/mona-ui/form-field";
|
|
309
|
+
|
|
310
|
+
@Component({
|
|
311
|
+
selector: "app-combo-box-adaptive-example",
|
|
312
|
+
imports: [ComboBoxComponent, DropdownFilterableDirective, FormFieldComponent],
|
|
313
|
+
templateUrl: "./adaptive-example.component.html"
|
|
314
|
+
})
|
|
315
|
+
export class ComboBoxAdaptiveExampleComponent {
|
|
316
|
+
protected readonly countries = [
|
|
317
|
+
"Argentina",
|
|
318
|
+
"Australia",
|
|
319
|
+
"Brazil",
|
|
320
|
+
"Canada",
|
|
321
|
+
"Germany",
|
|
322
|
+
"Indonesia",
|
|
323
|
+
"Italy",
|
|
324
|
+
"Japan",
|
|
325
|
+
"Poland",
|
|
326
|
+
"South Korea",
|
|
327
|
+
"Spain",
|
|
328
|
+
"Türkiye"
|
|
329
|
+
];
|
|
330
|
+
protected readonly country = signal<string | null>("Japan");
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
`adaptive-example.component.html`
|
|
335
|
+
|
|
336
|
+
```html
|
|
337
|
+
<mona-form-field
|
|
338
|
+
class="max-w-sm"
|
|
339
|
+
label="Country"
|
|
340
|
+
hint="On a phone, the list opens along the bottom of the screen, with a box to type in.">
|
|
341
|
+
<mona-combo-box
|
|
342
|
+
adaptiveMode="auto"
|
|
343
|
+
class="w-full"
|
|
344
|
+
monaDropDownFilterable
|
|
345
|
+
placeholder="Type a country"
|
|
346
|
+
[data]="countries"
|
|
347
|
+
[(value)]="country" />
|
|
348
|
+
</mona-form-field>
|
|
349
|
+
```
|
|
350
|
+
|
|
298
351
|
### Grouping
|
|
299
352
|
|
|
300
353
|
`monaDropDownGroupable` groups options under a header row, driven by `groupBy`.
|
|
@@ -365,6 +418,16 @@ While the popup is open, `Escape` reverts the displayed text to the currently se
|
|
|
365
418
|
|
|
366
419
|
`open` and `close` emit event objects with `preventDefault()` and `isDefaultPrevented()`. Calling `preventDefault()` in an `open` handler stops the popup from opening; calling it in a `close` handler stops the popup from closing. `close`'s event object also exposes `via`, describing what triggered the close attempt.
|
|
367
420
|
|
|
421
|
+
### The bottom sheet
|
|
422
|
+
|
|
423
|
+
With `adaptiveMode="auto"`, the popup opens as a bottom sheet when the screen is narrower than 640 pixels as it opens; it doesn't switch while open. On such a screen, the field raises no on-screen keyboard. Pressing it opens the sheet, and so does typing into it with a keyboard, which carries the text along.
|
|
424
|
+
|
|
425
|
+
The sheet covers the page with a dimmed backdrop and has a header with the field's name (or `adaptiveTitle`) and a close button. Below it is a text box, which takes focus and is named by that header, then the list, whose options are 44 pixels tall.
|
|
426
|
+
|
|
427
|
+
The text box works as the field does: it filters the list, the arrow keys move through it, `Enter` resolves the text as described in [Enter key resolution](#enter-key-resolution), and `Escape` reverts it. The sheet keeps its height while the list filters, so the text box stays put, and it sits above an on-screen keyboard.
|
|
428
|
+
|
|
429
|
+
When the sheet closes, focus goes back to the field. Pressing the backdrop or the close button leaves the typed text in the field, which resolves it when focus leaves, as usual. Without `adaptiveMode`, or with `"none"`, the popup always opens under the field.
|
|
430
|
+
|
|
368
431
|
### `DropdownFieldSelectorType`, `DropdownFieldPredicateType`, and `ListSizeInputType` are not exported
|
|
369
432
|
|
|
370
433
|
`textField`, `valueField`, `itemDisabled`, `popupHeight`, and `popupWidth` are typed with these generic aliases internally, but none of the three types are re-exported from `@nanahoshi/mona-ui`. Inline values (as in the examples above) still type-check structurally; only a standalone typed variable would require an import.
|
|
@@ -390,6 +453,8 @@ While the popup is open, `Escape` reverts the displayed text to the currently se
|
|
|
390
453
|
|
|
391
454
|
The host element itself is not a Tab stop (`tabindex="-1"`); the inner `<input>` element receives focus and is the actual Tab stop. Arrow-key navigation moves an internal highlighted-option pointer, reflected through `aria-activedescendant` on the input, instead of moving DOM focus into the popup.
|
|
392
455
|
|
|
456
|
+
In a bottom sheet (`adaptiveMode="auto"` on a small screen), focus moves to the sheet's text box, which has the same role and states as the input, and comes back to the input when the sheet closes.
|
|
457
|
+
|
|
393
458
|
### ARIA
|
|
394
459
|
|
|
395
460
|
| Element | Attribute | When present | Value |
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# Sparkline
|
|
2
|
+
|
|
3
|
+
> A word-sized line, area, column or win-loss chart, for a table cell or a line of text.
|
|
4
|
+
|
|
5
|
+
Entry point: `@nanahoshi/mona-ui/sparkline`
|
|
6
|
+
|
|
7
|
+
**Selector:** `mona-sparkline`
|
|
8
|
+
|
|
9
|
+
`SparklineComponent` draws a series of values as a chart the size of a word, to sit on a line of text or in a table cell: a line, an area, columns or wins and losses. It has no axes, legend or tooltips; it shows a trend at a glance, next to the numbers that give it.
|
|
10
|
+
|
|
11
|
+
Screen readers read it as an image, with its name and a summary of its values: how many, the first, the last, the lowest and the highest.
|
|
12
|
+
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
Give the sparkline its values and a name. It draws them from left to right, scaled to fill its box, which is 6rem wide and 1.5rem tall unless a class sizes it.
|
|
16
|
+
|
|
17
|
+
**Use Sparkline when:**
|
|
18
|
+
|
|
19
|
+
- A trend matters more than its values: in a table row, a dashboard tile or a sentence.
|
|
20
|
+
- Many small charts should compare at a glance, on one scale.
|
|
21
|
+
|
|
22
|
+
To read values off axes, see a tooltip or interact with the data, use a [chart](chart.md).
|
|
23
|
+
|
|
24
|
+
## Import & Quick Start
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { SparklineComponent } from "@nanahoshi/mona-ui/sparkline";
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
<mona-sparkline aria-label="Visitors per day" [data]="visitors" />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
protected readonly visitors = [320, 410, 380, 520, 490, 610, 580, 720];
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Examples
|
|
39
|
+
|
|
40
|
+
### Line, area, column and win-loss
|
|
41
|
+
|
|
42
|
+
`type` sets how the values are drawn. A column sparkline stands its bars on zero, in the error color below it. A win-loss sparkline draws a bar up for each positive value, down for each negative one, and a short tick for each zero, all of one height.
|
|
43
|
+
|
|
44
|
+
`types-example.component.ts`
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { Component } from "@angular/core";
|
|
48
|
+
import { SparklineComponent } from "@nanahoshi/mona-ui/sparkline";
|
|
49
|
+
|
|
50
|
+
@Component({
|
|
51
|
+
selector: "app-sparkline-types-example",
|
|
52
|
+
imports: [SparklineComponent],
|
|
53
|
+
templateUrl: "./types-example.component.html"
|
|
54
|
+
})
|
|
55
|
+
export class SparklineTypesExampleComponent {
|
|
56
|
+
protected readonly results = [1, 1, -1, 0, 1, -1, -1, 1, 1, 0, 1, 1];
|
|
57
|
+
protected readonly revenueChange = [4, 7, -2, 5, 9, -6, 3, 8, -3, 6];
|
|
58
|
+
protected readonly signUps = [12, 15, 14, 22, 28, 24, 31, 36, 33, 41];
|
|
59
|
+
protected readonly visitors = [320, 410, 380, 520, 490, 610, 580, 720, 690, 840];
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
`types-example.component.html`
|
|
64
|
+
|
|
65
|
+
```html
|
|
66
|
+
<dl class="grid max-w-md grid-cols-[8rem_auto] items-center gap-x-6 gap-y-4 text-sm">
|
|
67
|
+
<dt class="text-muted-foreground">Line</dt>
|
|
68
|
+
<dd><mona-sparkline aria-label="Visitors per day" [data]="visitors" /></dd>
|
|
69
|
+
|
|
70
|
+
<dt class="text-muted-foreground">Area</dt>
|
|
71
|
+
<dd><mona-sparkline aria-label="Sign-ups per day" type="area" [data]="signUps" /></dd>
|
|
72
|
+
|
|
73
|
+
<dt class="text-muted-foreground">Column</dt>
|
|
74
|
+
<dd><mona-sparkline aria-label="Change in revenue per month" type="column" [data]="revenueChange" /></dd>
|
|
75
|
+
|
|
76
|
+
<dt class="text-muted-foreground">Win-loss</dt>
|
|
77
|
+
<dd><mona-sparkline aria-label="Results of the last 12 matches" type="win-loss" [data]="results" /></dd>
|
|
78
|
+
</dl>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Smooth and stepped lines
|
|
82
|
+
|
|
83
|
+
`curve` sets how a line or an area joins its values, with the same choices as a chart's line series:
|
|
84
|
+
|
|
85
|
+
- `"linear"`, the default, joins them with straight segments.
|
|
86
|
+
- `"monotone-x"` draws a smooth curve that never swings past the values, so none looks higher or lower than it is.
|
|
87
|
+
- `"natural"` is smoother still, but it can overshoot where the values rise and fall sharply.
|
|
88
|
+
- `"step"` changes halfway between values.
|
|
89
|
+
- `"step-after"` holds each value until the next, for something that changes at a moment, such as a price, a plan or a stock level.
|
|
90
|
+
|
|
91
|
+
Columns and win-loss bars ignore it.
|
|
92
|
+
|
|
93
|
+
`curves-example.component.ts`
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { Component } from "@angular/core";
|
|
97
|
+
import { SparklineComponent } from "@nanahoshi/mona-ui/sparkline";
|
|
98
|
+
|
|
99
|
+
@Component({
|
|
100
|
+
selector: "app-sparkline-curves-example",
|
|
101
|
+
imports: [SparklineComponent],
|
|
102
|
+
templateUrl: "./curves-example.component.html"
|
|
103
|
+
})
|
|
104
|
+
export class SparklineCurvesExampleComponent {
|
|
105
|
+
protected readonly orders = [14, 22, 18, 30, 26, 41, 35, 38, 52, 47];
|
|
106
|
+
protected readonly plan = [10, 10, 10, 25, 25, 25, 25, 50, 50, 50];
|
|
107
|
+
}
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`curves-example.component.html`
|
|
111
|
+
|
|
112
|
+
```html
|
|
113
|
+
<dl class="grid max-w-md grid-cols-[8rem_auto] items-center gap-x-6 gap-y-4 text-sm">
|
|
114
|
+
<dt class="text-muted-foreground">Linear</dt>
|
|
115
|
+
<dd><mona-sparkline aria-label="Orders per day" [data]="orders" /></dd>
|
|
116
|
+
|
|
117
|
+
<dt class="text-muted-foreground">Monotone</dt>
|
|
118
|
+
<dd><mona-sparkline aria-label="Orders per day" curve="monotone-x" [data]="orders" /></dd>
|
|
119
|
+
|
|
120
|
+
<dt class="text-muted-foreground">Natural</dt>
|
|
121
|
+
<dd><mona-sparkline aria-label="Orders per day" curve="natural" [data]="orders" /></dd>
|
|
122
|
+
|
|
123
|
+
<dt class="text-muted-foreground">Step</dt>
|
|
124
|
+
<dd><mona-sparkline aria-label="Orders per day" curve="step" type="area" [data]="orders" /></dd>
|
|
125
|
+
|
|
126
|
+
<dt class="text-muted-foreground">Step after</dt>
|
|
127
|
+
<dd><mona-sparkline aria-label="Plan limit per month" curve="step-after" type="area" [data]="plan" /></dd>
|
|
128
|
+
</dl>
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### In a table
|
|
132
|
+
|
|
133
|
+
Give every row's sparkline the same `min` and `max`, and they share a scale, so their heights compare. `markers` puts a dot on the latest week.
|
|
134
|
+
|
|
135
|
+
`table-example.component.ts`
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
import { Component } from "@angular/core";
|
|
139
|
+
import { SparklineComponent } from "@nanahoshi/mona-ui/sparkline";
|
|
140
|
+
|
|
141
|
+
interface Product {
|
|
142
|
+
readonly name: string;
|
|
143
|
+
readonly total: number;
|
|
144
|
+
readonly weeks: readonly number[];
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function product(name: string, weeks: readonly number[]): Product {
|
|
148
|
+
return { name, total: weeks.reduce((sum, units) => sum + units, 0), weeks };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
@Component({
|
|
152
|
+
selector: "app-sparkline-table-example",
|
|
153
|
+
imports: [SparklineComponent],
|
|
154
|
+
templateUrl: "./table-example.component.html"
|
|
155
|
+
})
|
|
156
|
+
export class SparklineTableExampleComponent {
|
|
157
|
+
protected readonly products: readonly Product[] = [
|
|
158
|
+
product("Desk lamp", [42, 38, 45, 51, 48, 56, 61, 58, 66, 72, 69, 78]),
|
|
159
|
+
product("Notebook", [80, 76, 71, 74, 68, 65, 62, 66, 59, 55, 57, 52]),
|
|
160
|
+
product("Water bottle", [20, 24, 31, 45, 62, 70, 74, 69, 51, 38, 29, 24]),
|
|
161
|
+
product("Headphones", [33, 35, 34, 36, 35, 37, 36, 38, 37, 39, 38, 40])
|
|
162
|
+
];
|
|
163
|
+
/** One scale for every row, so the sparklines compare. */
|
|
164
|
+
protected readonly highest = Math.max(...this.products.flatMap(item => item.weeks));
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
`table-example.component.html`
|
|
169
|
+
|
|
170
|
+
```html
|
|
171
|
+
<table class="w-full max-w-lg text-sm">
|
|
172
|
+
<thead class="text-muted-foreground">
|
|
173
|
+
<tr>
|
|
174
|
+
<th scope="col" class="pb-2 text-start font-medium">Product</th>
|
|
175
|
+
<th scope="col" class="pb-2 text-start font-medium">Last 12 weeks</th>
|
|
176
|
+
<th scope="col" class="pb-2 text-end font-medium">Units</th>
|
|
177
|
+
</tr>
|
|
178
|
+
</thead>
|
|
179
|
+
<tbody>
|
|
180
|
+
@for (product of products; track product.name) {
|
|
181
|
+
<tr class="border-t border-border">
|
|
182
|
+
<th scope="row" class="py-2 text-start font-medium">{{ product.name }}</th>
|
|
183
|
+
<td class="py-2">
|
|
184
|
+
<mona-sparkline
|
|
185
|
+
class="w-32"
|
|
186
|
+
[aria-label]="'Weekly units of ' + product.name"
|
|
187
|
+
[data]="product.weeks"
|
|
188
|
+
[markers]="['last']"
|
|
189
|
+
[max]="highest"
|
|
190
|
+
[min]="0" />
|
|
191
|
+
</td>
|
|
192
|
+
<td class="py-2 text-end tabular-nums">{{ product.total }}</td>
|
|
193
|
+
</tr>
|
|
194
|
+
}
|
|
195
|
+
</tbody>
|
|
196
|
+
</table>
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Markers and a reference line
|
|
200
|
+
|
|
201
|
+
`markers` marks the first, the last, the lowest and the highest values with dots. `referenceValue` draws a dashed line at a target or an average, and the range widens to show it. `color` sets the sparkline's color, and `format` how the summary reads its values.
|
|
202
|
+
|
|
203
|
+
`reference-example.component.ts`
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
import { Component } from "@angular/core";
|
|
207
|
+
import { SparklineComponent } from "@nanahoshi/mona-ui/sparkline";
|
|
208
|
+
|
|
209
|
+
@Component({
|
|
210
|
+
selector: "app-sparkline-reference-example",
|
|
211
|
+
imports: [SparklineComponent],
|
|
212
|
+
templateUrl: "./reference-example.component.html"
|
|
213
|
+
})
|
|
214
|
+
export class SparklineReferenceExampleComponent {
|
|
215
|
+
protected readonly milliseconds: Intl.NumberFormatOptions = { style: "unit", unit: "millisecond" };
|
|
216
|
+
protected readonly responseTimes = [172, 168, 181, 195, 214, 231, 208, 193, 188, 179, 191, 186];
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
`reference-example.component.html`
|
|
221
|
+
|
|
222
|
+
```html
|
|
223
|
+
<div class="flex max-w-md flex-col gap-1 rounded-lg border border-border p-4">
|
|
224
|
+
<span class="text-sm text-muted-foreground">Response time, target 200 ms</span>
|
|
225
|
+
<div class="flex items-center gap-4">
|
|
226
|
+
<span class="text-2xl font-semibold tabular-nums">186 ms</span>
|
|
227
|
+
<mona-sparkline
|
|
228
|
+
aria-label="Response time per hour, against a target of 200 ms"
|
|
229
|
+
class="h-10 w-48"
|
|
230
|
+
color="var(--color-chart-3)"
|
|
231
|
+
type="area"
|
|
232
|
+
[data]="responseTimes"
|
|
233
|
+
[format]="milliseconds"
|
|
234
|
+
[markers]="['min', 'max', 'last']"
|
|
235
|
+
[referenceValue]="200" />
|
|
236
|
+
</div>
|
|
237
|
+
</div>
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
## Appearance & Styling
|
|
241
|
+
|
|
242
|
+
The sparkline is an inline block, aligned to the middle of the text around it. Size it with a class, such as `class="h-8 w-40"`.
|
|
243
|
+
|
|
244
|
+
Its colors are custom properties, so a class or a style sheet can set them too:
|
|
245
|
+
|
|
246
|
+
| Custom property | Input | Default | Colors |
|
|
247
|
+
| --- | --- | --- | --- |
|
|
248
|
+
| `--mona-sparkline-color` | `color` | The first chart color, `--color-chart-1` | The line, the area, columns above zero and wins |
|
|
249
|
+
| `--mona-sparkline-negative-color` | `negativeColor` | The error color, `--color-error` | Columns below zero and losses |
|
|
250
|
+
|
|
251
|
+
The line is 1.5 pixels wide and markers are 5 pixels across, whatever the sparkline's size. An area under the line is a wash of its color, with the line carrying the shape. Keep a color you choose at 3:1 against the background, as the default chart colors are. In forced colors, the sparkline is drawn in the system's text color.
|
|
252
|
+
|
|
253
|
+
## Behavior
|
|
254
|
+
|
|
255
|
+
### Values and gaps
|
|
256
|
+
|
|
257
|
+
`data` takes the values in order. A `null`, or anything that isn't a finite number, leaves a gap: the line breaks there, and a value alone between gaps shows as a dot. Gaps keep their place, so the values on either side stay where they'd be. A curve joins each run of values between gaps on its own.
|
|
258
|
+
|
|
259
|
+
### The range
|
|
260
|
+
|
|
261
|
+
Without `min` and `max`, the lowest value is at the bottom and the highest at the top. Columns always take zero into the range, as they stand on it, and so does a reference value. Values outside a range you set are drawn at its edge. When all the values are the same, the line runs across the middle. A `"natural"` curve can swing a little past the lowest and highest values, and out of the box; `"monotone-x"` stays inside it.
|
|
262
|
+
|
|
263
|
+
An area fills down to zero when the values cross it, and to the bottom edge when they're all above it.
|
|
264
|
+
|
|
265
|
+
### Direction
|
|
266
|
+
|
|
267
|
+
Values run from left to right in right-to-left layouts too, as on a chart's axis.
|
|
268
|
+
|
|
269
|
+
## Accessibility
|
|
270
|
+
|
|
271
|
+
The sparkline is an image (`role="img"`) to assistive technology. `aria-label` names it, and a summary of its values describes it: "12 values, first 6, last 15, lowest 4, highest 18", or for a win-loss sparkline, "7 wins, 3 losses, 1 draw". Without a name, the summary is its name. `format` sets how the summary formats values, such as a currency, in the locale's number format.
|
|
272
|
+
|
|
273
|
+
When the text beside a sparkline already gives its values, set `decorative` to hide it from assistive technology.
|
|
274
|
+
|
|
275
|
+
The sparkline isn't focusable and has no keyboard interaction.
|
|
276
|
+
|
|
277
|
+
### ARIA
|
|
278
|
+
|
|
279
|
+
| Attribute | When present | Value |
|
|
280
|
+
| --- | --- | --- |
|
|
281
|
+
| `role` | Unless `decorative` | `"img"` |
|
|
282
|
+
| `aria-label` | Unless `decorative` | The `aria-label` input, or the summary without one |
|
|
283
|
+
| `aria-describedby` | With a name, or `aria-describedby` given | The ids given, then the summary's |
|
|
284
|
+
| `aria-hidden` | `decorative` is set | `"true"` |
|
|
285
|
+
|
|
286
|
+
## API
|
|
287
|
+
|
|
288
|
+
Everything below is imported from `@nanahoshi/mona-ui/sparkline`. Each name links to its reference page, with every input, output, property and method.
|
|
289
|
+
|
|
290
|
+
| Name | Kind | Description |
|
|
291
|
+
| --- | --- | --- |
|
|
292
|
+
| [`SparklineComponent`](api/sparkline.md#sparklinecomponent) | Component | A word-sized chart of a series of values, to sit on a line of text or in a table cell: a line, an area, columns or wins and losses. |
|
|
293
|
+
|
|
294
|
+
### Types
|
|
295
|
+
|
|
296
|
+
| Type | Kind | Description |
|
|
297
|
+
| --- | --- | --- |
|
|
298
|
+
| [`SPARKLINE_DEFAULT_MESSAGES`](api/sparkline.md#sparkline-default-messages) | Constant | |
|
|
299
|
+
| [`SparklineCurve`](api/sparkline.md#sparklinecurve) | Type alias | How a line or an area sparkline joins its values, as a chart's line series does: `"linear"` with straight segments, `"monotone-x"` with a smooth curve that never swings past the values, `"natural"` with a smoother curve that can, `"step"` in steps that change halfway between values, and `"step-after"` in steps that hold each value until the next one. |
|
|
300
|
+
| [`SparklineMarker`](api/sparkline.md#sparklinemarker) | Type alias | A value a line or area sparkline marks with a dot: its first, its last, its lowest or its highest. |
|
|
301
|
+
| [`SparklineType`](api/sparkline.md#sparklinetype) | Type alias | How a sparkline draws its values: `"line"` joins them, `"area"` fills under the line, `"column"` draws a bar for each from zero, and `"win-loss"` draws a bar up for each positive value, down for each negative one and a short tick for each zero, all of one height. |
|
|
302
|
+
|
|
303
|
+
**Related types:** [`MonaSparklineMessages`](api/i18n.md#monasparklinemessages)
|