@n1kname/components 0.8.0 → 0.10.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/package.json +2 -1
- package/src/DayStrips.astro +34 -14
- package/src/Legend.astro +9 -30
- package/src/SidePanel.astro +5 -3
- package/src/daystrips.js +19 -6
- package/src/marks.css +34 -0
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@n1kname/components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./*.astro": "./src/*.astro",
|
|
8
8
|
"./type.css": "./src/type.css",
|
|
9
|
+
"./marks.css": "./src/marks.css",
|
|
9
10
|
"./icons": "./src/icons.ts",
|
|
10
11
|
"./datatable.js": "./src/datatable.js",
|
|
11
12
|
"./dotrows.js": "./src/dotrows.js",
|
package/src/DayStrips.astro
CHANGED
|
@@ -7,6 +7,8 @@
|
|
|
7
7
|
* The strips arrive at runtime: fill them with setDayStrips from `@n1kname/components/daystrips.js`.
|
|
8
8
|
* `rows` is how many streams to hold room for until then, so nothing below moves when they come.
|
|
9
9
|
*/
|
|
10
|
+
import './marks.css';
|
|
11
|
+
|
|
10
12
|
interface Props {
|
|
11
13
|
id: string;
|
|
12
14
|
rows?: number;
|
|
@@ -59,6 +61,8 @@ const { id, rows = 0, class: className, style, ...rest } = Astro.props;
|
|
|
59
61
|
margin-bottom: 6px;
|
|
60
62
|
overflow: hidden;
|
|
61
63
|
border-radius: 3px;
|
|
64
|
+
/* Between a gap's stripes, the card, never the days under it. */
|
|
65
|
+
--mark-ground: var(--c-surface);
|
|
62
66
|
}
|
|
63
67
|
|
|
64
68
|
.day-strips :global(.strip i) {
|
|
@@ -66,6 +70,36 @@ const { id, rows = 0, class: className, style, ...rest } = Astro.props;
|
|
|
66
70
|
inset-block: 0;
|
|
67
71
|
}
|
|
68
72
|
|
|
73
|
+
/* A stream's first and last day are rounded, wherever in the strip it starts. */
|
|
74
|
+
.day-strips :global(.strip .start) {
|
|
75
|
+
border-start-start-radius: 3px;
|
|
76
|
+
border-end-start-radius: 3px;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
.day-strips :global(.strip .end) {
|
|
80
|
+
border-start-end-radius: 3px;
|
|
81
|
+
border-end-end-radius: 3px;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* A gap is cut into the strip: a hairline of card on each side keeps it apart from the days
|
|
85
|
+
around it. Too narrow for its stripes to show, it is drawn solid in its colour instead. */
|
|
86
|
+
.day-strips :global(.strip .gap) {
|
|
87
|
+
box-shadow:
|
|
88
|
+
-1px 0 0 var(--c-surface),
|
|
89
|
+
1px 0 0 var(--c-surface);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.day-strips :global(.strip .gap[data-mark='stripes']) {
|
|
93
|
+
box-shadow:
|
|
94
|
+
-1px 0 0 var(--c-surface),
|
|
95
|
+
1px 0 0 var(--c-surface),
|
|
96
|
+
inset 0 0 0 1px var(--mark);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.day-strips :global(.strip .gap.narrow) {
|
|
100
|
+
background: var(--mark);
|
|
101
|
+
}
|
|
102
|
+
|
|
69
103
|
.day-strips :global(.ticks) {
|
|
70
104
|
position: relative;
|
|
71
105
|
height: 16px;
|
|
@@ -139,18 +173,4 @@ const { id, rows = 0, class: className, style, ...rest } = Astro.props;
|
|
|
139
173
|
.day-strips :global(.tip .quiet) {
|
|
140
174
|
color: var(--c-text-muted);
|
|
141
175
|
}
|
|
142
|
-
|
|
143
|
-
/* The marks, the same as a Legend's, so a strip and its key look alike. */
|
|
144
|
-
.day-strips :global(.mark.fill) {
|
|
145
|
-
background: var(--mark);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
.day-strips :global(.mark.stripes) {
|
|
149
|
-
background: repeating-linear-gradient(135deg, var(--mark) 0 2px, transparent 2px 5px);
|
|
150
|
-
box-shadow: inset 0 0 0 1px var(--mark);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.day-strips :global(.mark.empty) {
|
|
154
|
-
box-shadow: inset 0 0 0 1px var(--c-border-strong);
|
|
155
|
-
}
|
|
156
176
|
</style>
|
package/src/Legend.astro
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* faint a paler swatch, for an estimate: no invoice or reading yet
|
|
13
13
|
* dashed paler still with a dashed edge, for a projection of something still running
|
|
14
14
|
*/
|
|
15
|
+
import './marks.css';
|
|
16
|
+
|
|
15
17
|
interface Key {
|
|
16
18
|
label: string;
|
|
17
19
|
/** Any CSS colour, best a chart token such as var(--c-chart-1). Not needed for `empty`. */
|
|
@@ -33,7 +35,7 @@ const { keys, label = 'Legend', class: className, ...rest } = Astro.props;
|
|
|
33
35
|
{
|
|
34
36
|
keys.map((k) => (
|
|
35
37
|
<li>
|
|
36
|
-
<i class
|
|
38
|
+
<i class="mark" data-mark={k.mark ?? 'fill'} style={k.color ? `--mark: ${k.color}` : undefined} />
|
|
37
39
|
{k.label}
|
|
38
40
|
</li>
|
|
39
41
|
))
|
|
@@ -66,48 +68,25 @@ const { keys, label = 'Legend', class: className, ...rest } = Astro.props;
|
|
|
66
68
|
border-radius: 3px;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
|
-
.
|
|
70
|
-
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
.line {
|
|
71
|
+
/* Shapes on .mark too, so a page's own .legend or i rule can't reach in and square them. */
|
|
72
|
+
.mark[data-mark='line'] {
|
|
74
73
|
height: 2px;
|
|
75
74
|
border-radius: 1px;
|
|
76
75
|
background: var(--mark);
|
|
77
76
|
}
|
|
78
77
|
|
|
79
|
-
.dot,
|
|
80
|
-
.hollow {
|
|
78
|
+
.mark[data-mark='dot'],
|
|
79
|
+
.mark[data-mark='hollow'] {
|
|
81
80
|
width: 10px;
|
|
82
81
|
height: 10px;
|
|
83
82
|
border-radius: 50%;
|
|
84
83
|
}
|
|
85
84
|
|
|
86
|
-
.dot {
|
|
85
|
+
.mark[data-mark='dot'] {
|
|
87
86
|
background: var(--mark);
|
|
88
87
|
}
|
|
89
88
|
|
|
90
|
-
.hollow {
|
|
89
|
+
.mark[data-mark='hollow'] {
|
|
91
90
|
border: 2px solid var(--mark);
|
|
92
91
|
}
|
|
93
|
-
|
|
94
|
-
.stripes {
|
|
95
|
-
background: repeating-linear-gradient(135deg, var(--mark) 0 2px, transparent 2px 5px);
|
|
96
|
-
box-shadow: inset 0 0 0 1px var(--mark);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.empty {
|
|
100
|
-
box-shadow: inset 0 0 0 1px var(--c-border-strong);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/* The same fades as a bar chart's unsettled rows, a little stronger so a small swatch still shows. */
|
|
104
|
-
.faint {
|
|
105
|
-
background: color-mix(in oklab, var(--mark) 65%, transparent);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
.dashed {
|
|
109
|
-
background: color-mix(in oklab, var(--mark) 37%, transparent);
|
|
110
|
-
outline: 1px dashed var(--mark);
|
|
111
|
-
outline-offset: -1px;
|
|
112
|
-
}
|
|
113
92
|
</style>
|
package/src/SidePanel.astro
CHANGED
|
@@ -65,14 +65,16 @@ const titleId = `${id}-title`;
|
|
|
65
65
|
display var(--motion-base) allow-discrete;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/* It arrives on the spring, so it settles instead of stopping. Tokens before 0.3.0 have no
|
|
69
|
+
spring, and it falls back to ease-out. */
|
|
68
70
|
.side-panel[open] {
|
|
69
71
|
opacity: 1;
|
|
70
72
|
transform: none;
|
|
71
73
|
transition:
|
|
72
74
|
opacity var(--motion-slow) var(--ease-out),
|
|
73
|
-
transform var(--motion-slow) var(--ease-out),
|
|
74
|
-
overlay var(--motion-slow) allow-discrete,
|
|
75
|
-
display var(--motion-slow) allow-discrete;
|
|
75
|
+
transform var(--motion-spring, var(--motion-slow)) var(--ease-spring, var(--ease-out)),
|
|
76
|
+
overlay var(--motion-spring, var(--motion-slow)) allow-discrete,
|
|
77
|
+
display var(--motion-spring, var(--motion-slow)) allow-discrete;
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
@starting-style {
|
package/src/daystrips.js
CHANGED
|
@@ -6,13 +6,16 @@
|
|
|
6
6
|
// `states` says how each state looks: { label, mark, color, gap }. `mark` is a Legend mark:
|
|
7
7
|
// fill, stripes, or empty (not drawn on the strip, only in the tooltip and the legend). A `gap`
|
|
8
8
|
// state is drawn on top of the rest and never thinner than MIN_GAP_PX, so a one-day gap is
|
|
9
|
-
// never missed
|
|
9
|
+
// never missed, and solid when too narrow for its stripes. The colours are best the record
|
|
10
|
+
// state tokens, --c-state-complete, -waiting, -set-aside and -missing. Each stream is { label, title?, days, summary }: `days` its state per day,
|
|
10
11
|
// `summary` what a screen reader hears for its strip. Hovering shows the date and every
|
|
11
12
|
// stream whose state that day is not `quiet`.
|
|
12
13
|
import { esc } from './datatable.js';
|
|
13
14
|
|
|
14
15
|
// A one-day gap is about a pixel wide at a few years' scale; never draw one thinner than this.
|
|
15
16
|
const MIN_GAP_PX = 4;
|
|
17
|
+
// Below this, stripes are noise: the gap is drawn solid in its colour instead.
|
|
18
|
+
const MIN_STRIPES_PX = 8;
|
|
16
19
|
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
17
20
|
|
|
18
21
|
const addDays = (iso, n) => {
|
|
@@ -34,7 +37,6 @@ const runs = (days) => {
|
|
|
34
37
|
export const setDayStrips = (box, { from, streams, states, quiet, quietText, date = (iso) => iso, month = (m) => MONTHS[m - 1] }) => {
|
|
35
38
|
const days = Math.max(...streams.map((s) => s.days.length));
|
|
36
39
|
const pct = (i) => `${(i / days) * 100}%`;
|
|
37
|
-
const mark = (state) => `mark ${states[state].mark}`;
|
|
38
40
|
const swatch = (state) => (states[state].color ? ` style="--mark: ${states[state].color}"` : '');
|
|
39
41
|
|
|
40
42
|
const rows = streams
|
|
@@ -42,10 +44,13 @@ export const setDayStrips = (box, { from, streams, states, quiet, quietText, dat
|
|
|
42
44
|
const list = runs(s.days).filter((x) => states[x.state].mark !== 'empty');
|
|
43
45
|
// Quiet states first, gaps on top.
|
|
44
46
|
const order = [...list.filter((x) => !states[x.state].gap), ...list.filter((x) => states[x.state].gap)];
|
|
47
|
+
const first = list[0];
|
|
48
|
+
const last = list[list.length - 1];
|
|
45
49
|
const bar = (x) => {
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
|
|
50
|
+
const { gap, mark, color } = states[x.state];
|
|
51
|
+
const cls = [gap && 'gap', x === first && 'start', x === last && 'end'].filter(Boolean).join(' ');
|
|
52
|
+
const style = `left: ${pct(x.from)}; width: ${pct(x.len)}${gap ? `; min-width: ${MIN_GAP_PX}px` : ''}${color ? `; --mark: ${color}` : ''}`;
|
|
53
|
+
return `<i${cls ? ` class="${cls}"` : ''} data-mark="${mark}" style="${style}"></i>`;
|
|
49
54
|
};
|
|
50
55
|
return `<div class="strip" role="img" aria-label="${esc(s.summary)}">${order.map(bar).join('')}</div>`;
|
|
51
56
|
})
|
|
@@ -67,6 +72,14 @@ export const setDayStrips = (box, { from, streams, states, quiet, quietText, dat
|
|
|
67
72
|
`<div class="area"><div class="rows">${rows}</div><div class="ticks" aria-hidden="true">${ticks.join('')}</div>` +
|
|
68
73
|
'<div class="cursor" hidden></div><div class="tip" hidden></div></div>';
|
|
69
74
|
|
|
75
|
+
// A gap too narrow for its stripes is drawn solid; how narrow depends on the width the strip has.
|
|
76
|
+
const gaps = [...box.querySelectorAll('.strip .gap')];
|
|
77
|
+
const fit = () => gaps.forEach((g) => g.classList.toggle('narrow', g.getBoundingClientRect().width < MIN_STRIPES_PX));
|
|
78
|
+
fit();
|
|
79
|
+
box.stripsObserver?.disconnect();
|
|
80
|
+
box.stripsObserver = new ResizeObserver(fit);
|
|
81
|
+
box.stripsObserver.observe(box);
|
|
82
|
+
|
|
70
83
|
// Hover for the date, and what was not quiet that day.
|
|
71
84
|
const area = box.querySelector('.area');
|
|
72
85
|
const cursor = box.querySelector('.cursor');
|
|
@@ -81,7 +94,7 @@ export const setDayStrips = (box, { from, streams, states, quiet, quietText, dat
|
|
|
81
94
|
`<strong>${esc(date(addDays(from, i)))}</strong>` +
|
|
82
95
|
(notable.length
|
|
83
96
|
? notable
|
|
84
|
-
.map((s) => `<span class="line"><i
|
|
97
|
+
.map((s) => `<span class="line"><i data-mark="${states[s.days[i]].mark}"${swatch(s.days[i])}></i>${esc(s.label)}<em>${esc(states[s.days[i]].label)}</em></span>`)
|
|
85
98
|
.join('')
|
|
86
99
|
: `<span class="quiet">${esc(quietText)}</span>`);
|
|
87
100
|
const right = i / days > 0.6;
|
package/src/marks.css
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* How each kind of mark is coloured, in one place, so a Legend's key and the chart it explains
|
|
3
|
+
* look alike. Legend and DayStrips import it; a page that draws its own marks can too.
|
|
4
|
+
*
|
|
5
|
+
* <i data-mark="stripes" style="--mark: var(--c-state-set-aside)"></i>
|
|
6
|
+
*
|
|
7
|
+
* --mark is the colour. --mark-ground is what shows between the stripes: transparent unless
|
|
8
|
+
* set, and set to the card where a stripe sits on other marks, so they never show through.
|
|
9
|
+
* Size and shape stay with the component.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
[data-mark='fill'] {
|
|
13
|
+
background: var(--mark);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[data-mark='stripes'] {
|
|
17
|
+
background: repeating-linear-gradient(135deg, var(--mark) 0 2px, var(--mark-ground, transparent) 2px 5px);
|
|
18
|
+
box-shadow: inset 0 0 0 1px var(--mark);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
[data-mark='empty'] {
|
|
22
|
+
box-shadow: inset 0 0 0 1px var(--c-border-strong);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* The same fades as a bar chart's unsettled rows, a little stronger so a small swatch still shows. */
|
|
26
|
+
[data-mark='faint'] {
|
|
27
|
+
background: color-mix(in oklab, var(--mark) 65%, transparent);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
[data-mark='dashed'] {
|
|
31
|
+
background: color-mix(in oklab, var(--mark) 37%, transparent);
|
|
32
|
+
outline: 1px dashed var(--mark);
|
|
33
|
+
outline-offset: -1px;
|
|
34
|
+
}
|