@aortl/admin-css 0.13.2 → 0.14.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.
@@ -0,0 +1,311 @@
1
+ @layer components {
2
+ /*
3
+ * Charts — three pure-CSS primitives driven entirely by inline custom
4
+ * properties (never data-* attributes: CSS can't read an attribute as a
5
+ * number for calc() cross-browser yet). No JS, no axes/ticks/gridlines.
6
+ * They serve two altitudes: dense inline micro-viz (a swatch in a table
7
+ * cell) and compact dashboard cards.
8
+ *
9
+ * Data contract:
10
+ * - bars: container `--chart-max` (default 100), each bar `--value`;
11
+ * the fill sizes to `var(--value) / var(--chart-max) * 100%`.
12
+ * - stack: each segment `--value`, sized by `flex` (no max — the ratios
13
+ * are intrinsic to the flex grow factors).
14
+ * - donut: one pre-built cumulative conic-gradient stop string in
15
+ * `--donut-segments` (CSS can't sum a variable-length sibling
16
+ * list, so the string arrives whole).
17
+ *
18
+ * Colour: single-series follows `currentColor` (default `--color-primary`,
19
+ * recoloured by the `.chart-success`/etc. variants like `.progress`).
20
+ * Multi-series colours are set inline per bar/segment (`--bar-color` /
21
+ * `--segment-color` / legend `--legend-color`); there is no chart token
22
+ * layer. role="img" + aria-label carries the semantics; a native `title`
23
+ * on each bar/segment gives a hover read-out.
24
+ */
25
+
26
+ /* Shared base — sizing knobs + the single-series fill colour. Any chart
27
+ type reads these; size modifiers below just remap them. */
28
+ .chart {
29
+ --chart-max: 100;
30
+ --chart-height: 8rem; /* bar track cross-axis size (md) */
31
+ --chart-size: 8rem; /* donut diameter (md) */
32
+ --chart-gap: 0.25rem;
33
+ color: var(--color-primary);
34
+ }
35
+
36
+ /* Single-series semantic variants — recolour currentColor, like progress. */
37
+ .chart-success {
38
+ color: var(--color-success);
39
+ }
40
+ .chart-warning {
41
+ color: var(--color-warning);
42
+ }
43
+ .chart-danger {
44
+ color: var(--color-danger);
45
+ }
46
+ .chart-info {
47
+ color: var(--color-info);
48
+ }
49
+
50
+ /* --------------------------------------------------------------------- *
51
+ * BAR CHART — horizontal (default) *
52
+ * --------------------------------------------------------------------- *
53
+ * Three-column grid: [label | track (1fr) | value]. Each `.chart-bar` is
54
+ * a `subgrid` spanning all three, so the label gutter and the value column
55
+ * stay aligned across every row. The fill lives in the `1fr` track — a
56
+ * definite width once the grid resolves, which is exactly what lets its
57
+ * `inline-size: %` transition (see the transition note). Values sit in the
58
+ * trailing column, so a short bar never clips its number and a full bar
59
+ * never overflows. */
60
+ .chart-bars {
61
+ display: grid;
62
+ grid-template-columns: auto 1fr auto;
63
+ row-gap: var(--chart-gap);
64
+ align-items: center;
65
+ inline-size: 100%;
66
+ }
67
+
68
+ .chart-bar {
69
+ display: grid;
70
+ grid-template-columns: subgrid;
71
+ grid-column: 1 / -1;
72
+ align-items: center;
73
+ }
74
+
75
+ /* Category label — only emitted when the datum carries one. The empty
76
+ `auto` column collapses to 0 when no bar has a label. */
77
+ .chart-bar-label {
78
+ @apply text-xs text-text-muted;
79
+ grid-column: 1;
80
+ text-align: end;
81
+ padding-inline-end: 0.5rem;
82
+ white-space: nowrap;
83
+ }
84
+
85
+ .chart-bar-track {
86
+ grid-column: 2;
87
+ min-inline-size: 0;
88
+ }
89
+
90
+ .chart-bar-fill {
91
+ block-size: 0.75rem;
92
+ inline-size: calc(var(--value) / var(--chart-max) * 100%);
93
+ background: var(--bar-color, currentColor);
94
+ border-radius: 2px;
95
+ /* Transition the resolved length (NOT --value, which isn't registered):
96
+ a percentage length transitions because the track has a definite size.
97
+ Both axes are listed so the vertical fill animates too. */
98
+ transition:
99
+ inline-size 200ms ease,
100
+ block-size 200ms ease;
101
+ }
102
+
103
+ /* Value label — trailing aligned column. Opt-in via `.chart-values`. */
104
+ .chart-bar-value {
105
+ @apply text-xs text-text-muted tabular-nums;
106
+ grid-column: 3;
107
+ text-align: end;
108
+ padding-inline-start: 0.5rem;
109
+ white-space: nowrap;
110
+ }
111
+ .chart:not(.chart-values) .chart-bar-value {
112
+ display: none;
113
+ }
114
+
115
+ /* --------------------------------------------------------------------- *
116
+ * BAR CHART — vertical modifier *
117
+ * --------------------------------------------------------------------- *
118
+ * Flex row of equal columns inside a fixed-height box. Each column is a
119
+ * flex column [value | track | label]; the track (`flex: 1`) gets a
120
+ * definite block-size so the fill's `block-size: %` resolves and animates.
121
+ * Bars grow up from the floor (`justify-content: end`). */
122
+ .chart-bars-vertical {
123
+ display: flex;
124
+ flex-direction: row;
125
+ align-items: stretch;
126
+ gap: var(--chart-gap);
127
+ block-size: var(--chart-height);
128
+ inline-size: 100%;
129
+ }
130
+
131
+ .chart-bars-vertical .chart-bar {
132
+ display: flex;
133
+ flex-direction: column;
134
+ flex: 1 1 0;
135
+ min-inline-size: 0;
136
+ align-items: stretch;
137
+ gap: 0.25rem;
138
+ }
139
+
140
+ .chart-bars-vertical .chart-bar-value {
141
+ order: 0;
142
+ grid-column: auto;
143
+ text-align: center;
144
+ padding: 0;
145
+ }
146
+
147
+ .chart-bars-vertical .chart-bar-track {
148
+ order: 1;
149
+ flex: 1 1 auto;
150
+ min-block-size: 0;
151
+ display: flex;
152
+ flex-direction: column;
153
+ justify-content: end;
154
+ }
155
+
156
+ .chart-bars-vertical .chart-bar-fill {
157
+ inline-size: 100%;
158
+ block-size: calc(var(--value) / var(--chart-max) * 100%);
159
+ }
160
+
161
+ .chart-bars-vertical .chart-bar-label {
162
+ order: 2;
163
+ text-align: center;
164
+ padding: 0;
165
+ }
166
+
167
+ /* --------------------------------------------------------------------- *
168
+ * STACKED / PROPORTION BAR *
169
+ * --------------------------------------------------------------------- *
170
+ * A single rounded track partitioned by `flex: var(--value)`. No max
171
+ * needed — proportions are the flex-grow ratios. A hairline in the
172
+ * surface colour separates adjacent segments. */
173
+ .chart-stack {
174
+ display: flex;
175
+ flex-direction: row;
176
+ inline-size: 100%;
177
+ block-size: 0.75rem;
178
+ border-radius: 9999px;
179
+ overflow: hidden;
180
+ background: var(--color-surface-strong);
181
+ }
182
+
183
+ .chart-segment {
184
+ flex: var(--value) 1 0;
185
+ min-inline-size: 0;
186
+ background: var(--segment-color, currentColor);
187
+ transition: flex-grow 200ms ease;
188
+ }
189
+ .chart-segment + .chart-segment {
190
+ box-shadow: -1px 0 0 0 var(--color-surface);
191
+ }
192
+
193
+ /* --------------------------------------------------------------------- *
194
+ * DONUT / PIE *
195
+ * --------------------------------------------------------------------- *
196
+ * A conic-gradient circle with the centre punched out by a radial-gradient
197
+ * mask. `--donut-thickness` is the ring width as a % of the diameter; the
198
+ * hole's inner radius is `50% - thickness`, so thickness=50% leaves no hole
199
+ * (a solid pie). The same stop position twice gives a crisp ring edge.
200
+ *
201
+ * The centre label must NOT be a child of the ring — `mask` clips the whole
202
+ * subtree, so a child sitting in the hole would be invisible. It's a sibling
203
+ * overlay: the figure is an inline-grid and both the ring and the label
204
+ * occupy the same cell. */
205
+ .chart-donut-figure {
206
+ position: relative;
207
+ inline-size: var(--chart-size);
208
+ aspect-ratio: 1;
209
+ display: inline-grid;
210
+ place-items: center;
211
+ }
212
+
213
+ .chart-donut {
214
+ --donut-thickness: 33%;
215
+ inline-size: var(--chart-size);
216
+ aspect-ratio: 1;
217
+ border-radius: 50%;
218
+ background: conic-gradient(var(--donut-segments, currentColor 0 100%));
219
+ -webkit-mask: radial-gradient(
220
+ circle at center,
221
+ transparent calc(50% - var(--donut-thickness)),
222
+ #000 calc(50% - var(--donut-thickness))
223
+ );
224
+ mask: radial-gradient(
225
+ circle at center,
226
+ transparent calc(50% - var(--donut-thickness)),
227
+ #000 calc(50% - var(--donut-thickness))
228
+ );
229
+ }
230
+
231
+ .chart-donut-figure > .chart-donut {
232
+ grid-area: 1 / 1;
233
+ inline-size: 100%;
234
+ }
235
+
236
+ /* Solid pie — no hole. */
237
+ .chart-donut-pie {
238
+ --donut-thickness: 50%;
239
+ }
240
+
241
+ .chart-donut-center {
242
+ @apply text-center text-sm font-semibold tabular-nums leading-tight;
243
+ grid-area: 1 / 1;
244
+ z-index: 1;
245
+ pointer-events: none;
246
+ }
247
+
248
+ /* --------------------------------------------------------------------- *
249
+ * LEGEND (donut + stack) *
250
+ * --------------------------------------------------------------------- */
251
+ .chart-legend {
252
+ @apply flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-text-muted;
253
+ list-style: none;
254
+ margin: 0;
255
+ padding: 0;
256
+ }
257
+
258
+ .chart-legend-item {
259
+ @apply inline-flex items-center gap-1.5;
260
+ }
261
+ .chart-legend-item::before {
262
+ content: "";
263
+ inline-size: 0.625rem;
264
+ block-size: 0.625rem;
265
+ border-radius: 2px;
266
+ background: var(--legend-color, currentColor);
267
+ flex-shrink: 0;
268
+ }
269
+
270
+ /* --------------------------------------------------------------------- *
271
+ * SIZES — remap the cross-axis / diameter knobs *
272
+ * --------------------------------------------------------------------- */
273
+ .chart-sm {
274
+ --chart-height: 4rem;
275
+ --chart-size: 4rem;
276
+ }
277
+ .chart-lg {
278
+ --chart-height: 12rem;
279
+ --chart-size: 12rem;
280
+ }
281
+
282
+ /* --------------------------------------------------------------------- *
283
+ * INLINE — micro-viz that sits in running text / a table cell *
284
+ * --------------------------------------------------------------------- *
285
+ * Inline-flex, baseline-nudged, and em-relative so the swatch tracks the
286
+ * surrounding font size. */
287
+ .chart-inline {
288
+ display: inline-flex;
289
+ vertical-align: middle;
290
+ --chart-height: 1em;
291
+ --chart-size: 1.25em;
292
+ }
293
+ .chart-inline .chart-stack {
294
+ inline-size: 6em;
295
+ block-size: 0.5em;
296
+ }
297
+ .chart-inline .chart-bars,
298
+ .chart-inline.chart-bars {
299
+ inline-size: 6em;
300
+ }
301
+
302
+ /* --------------------------------------------------------------------- *
303
+ * REDUCED MOTION *
304
+ * --------------------------------------------------------------------- */
305
+ @media (prefers-reduced-motion: reduce) {
306
+ .chart-bar-fill,
307
+ .chart-segment {
308
+ transition: none;
309
+ }
310
+ }
311
+ }
@@ -34,3 +34,4 @@
34
34
  @import "./table.css";
35
35
  @import "./tooltip.css";
36
36
  @import "./code-block.css";
37
+ @import "./chart.css";