ochreui 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +153 -2
- package/cli/ochreui.mjs +601 -0
- package/mcp/core.mjs +126 -0
- package/mcp/docs.json +906 -0
- package/mcp/server.mjs +23 -0
- package/package.json +393 -3
- package/registry/agent-team.ts +350 -0
- package/registry/avatar.ts +300 -0
- package/registry/badge.ts +207 -0
- package/registry/breadcrumb.ts +435 -0
- package/registry/button.ts +238 -0
- package/registry/card.ts +221 -0
- package/registry/change-summary.ts +200 -0
- package/registry/checkbox.ts +204 -0
- package/registry/code-block.ts +332 -0
- package/registry/color-picker.ts +720 -0
- package/registry/comment-thread.ts +503 -0
- package/registry/context-menu.ts +281 -0
- package/registry/cover-flow.ts +623 -0
- package/registry/date-picker.ts +799 -0
- package/registry/decision-inbox.ts +340 -0
- package/registry/dialog.ts +577 -0
- package/registry/dropdown-menu.ts +864 -0
- package/registry/email-draft.ts +916 -0
- package/registry/empty-calendar.ts +199 -0
- package/registry/empty-state.ts +164 -0
- package/registry/enrichment-orbit.ts +164 -0
- package/registry/filter-menu.ts +541 -0
- package/registry/form-field.ts +308 -0
- package/registry/frost-cloud.ts +381 -0
- package/registry/ghosted-chat.ts +210 -0
- package/registry/glow-cloud.ts +402 -0
- package/registry/grid-background.ts +164 -0
- package/registry/hover-card.ts +401 -0
- package/registry/icon-button.ts +133 -0
- package/registry/index.json +2124 -0
- package/registry/integration-beam.ts +588 -0
- package/registry/integration-grid.ts +209 -0
- package/registry/kbd.ts +176 -0
- package/registry/layer-stack.ts +351 -0
- package/registry/lead-sourcing.ts +285 -0
- package/registry/logo-cluster.ts +239 -0
- package/registry/logo-marquee.ts +505 -0
- package/registry/message-actions.ts +833 -0
- package/registry/model-orbit.ts +583 -0
- package/registry/model-wheel.ts +372 -0
- package/registry/notification-stack.ts +301 -0
- package/registry/number-input.ts +552 -0
- package/registry/number-ticker.ts +261 -0
- package/registry/ochre.css +917 -0
- package/registry/otp-input.ts +704 -0
- package/registry/overlay.ts +312 -0
- package/registry/pagination.ts +362 -0
- package/registry/popover.ts +296 -0
- package/registry/profile-menu.ts +332 -0
- package/registry/progress-tracker.ts +291 -0
- package/registry/rating.ts +461 -0
- package/registry/reaction-bar.ts +322 -0
- package/registry/region-map.ts +537 -0
- package/registry/resizable.ts +489 -0
- package/registry/scroll-area.ts +271 -0
- package/registry/segmented-control.ts +433 -0
- package/registry/select.ts +769 -0
- package/registry/separator.ts +97 -0
- package/registry/shimmer-loader.ts +211 -0
- package/registry/side-folder.ts +152 -0
- package/registry/skeleton.ts +136 -0
- package/registry/skill/INSTRUCTIONS.md +11 -0
- package/registry/skill/SKILL.md +65 -0
- package/registry/skill/checklist.md +45 -0
- package/registry/skill/references/agent-team.md +105 -0
- package/registry/skill/references/avatar.md +88 -0
- package/registry/skill/references/badge.md +92 -0
- package/registry/skill/references/breadcrumb.md +99 -0
- package/registry/skill/references/button.md +82 -0
- package/registry/skill/references/card.md +111 -0
- package/registry/skill/references/catalog.md +114 -0
- package/registry/skill/references/change-summary.md +103 -0
- package/registry/skill/references/checkbox.md +105 -0
- package/registry/skill/references/code-block.md +109 -0
- package/registry/skill/references/color-picker.md +138 -0
- package/registry/skill/references/comment-thread.md +164 -0
- package/registry/skill/references/context-menu.md +205 -0
- package/registry/skill/references/cover-flow.md +128 -0
- package/registry/skill/references/date-picker.md +154 -0
- package/registry/skill/references/decision-inbox.md +126 -0
- package/registry/skill/references/dialog.md +155 -0
- package/registry/skill/references/dropdown-menu.md +144 -0
- package/registry/skill/references/email-draft.md +182 -0
- package/registry/skill/references/empty-calendar.md +74 -0
- package/registry/skill/references/empty-state.md +118 -0
- package/registry/skill/references/enrichment-orbit.md +71 -0
- package/registry/skill/references/filter-menu.md +143 -0
- package/registry/skill/references/form-field.md +118 -0
- package/registry/skill/references/frost-cloud.md +80 -0
- package/registry/skill/references/ghosted-chat.md +75 -0
- package/registry/skill/references/glow-cloud.md +84 -0
- package/registry/skill/references/grid-background.md +76 -0
- package/registry/skill/references/hover-card.md +125 -0
- package/registry/skill/references/icon-button.md +99 -0
- package/registry/skill/references/integration-beam.md +107 -0
- package/registry/skill/references/integration-grid.md +100 -0
- package/registry/skill/references/kbd.md +65 -0
- package/registry/skill/references/layer-stack.md +115 -0
- package/registry/skill/references/lead-sourcing.md +92 -0
- package/registry/skill/references/logo-cluster.md +92 -0
- package/registry/skill/references/logo-marquee.md +123 -0
- package/registry/skill/references/message-actions.md +146 -0
- package/registry/skill/references/model-orbit.md +106 -0
- package/registry/skill/references/model-wheel.md +84 -0
- package/registry/skill/references/notification-stack.md +138 -0
- package/registry/skill/references/number-input.md +117 -0
- package/registry/skill/references/number-ticker.md +73 -0
- package/registry/skill/references/otp-input.md +142 -0
- package/registry/skill/references/pagination.md +112 -0
- package/registry/skill/references/popover.md +143 -0
- package/registry/skill/references/profile-menu.md +123 -0
- package/registry/skill/references/progress-tracker.md +122 -0
- package/registry/skill/references/rating.md +111 -0
- package/registry/skill/references/reaction-bar.md +128 -0
- package/registry/skill/references/region-map.md +109 -0
- package/registry/skill/references/resizable.md +127 -0
- package/registry/skill/references/scroll-area.md +113 -0
- package/registry/skill/references/segmented-control.md +96 -0
- package/registry/skill/references/select.md +122 -0
- package/registry/skill/references/separator.md +69 -0
- package/registry/skill/references/shimmer-loader.md +83 -0
- package/registry/skill/references/side-folder.md +75 -0
- package/registry/skill/references/skeleton.md +95 -0
- package/registry/skill/references/smart-recommendation.md +132 -0
- package/registry/skill/references/spinner.md +84 -0
- package/registry/skill/references/switch.md +79 -0
- package/registry/skill/references/tab-overload.md +70 -0
- package/registry/skill/references/tag-input.md +126 -0
- package/registry/skill/references/team-invite.md +94 -0
- package/registry/skill/references/testimonial-wall.md +110 -0
- package/registry/skill/references/text-area.md +115 -0
- package/registry/skill/references/text-field.md +126 -0
- package/registry/skill/references/text-reveal.md +71 -0
- package/registry/skill/references/thinking-loader.md +87 -0
- package/registry/skill/references/time-picker.md +122 -0
- package/registry/skill/references/tips-panel.md +115 -0
- package/registry/skill/references/toggle-group.md +98 -0
- package/registry/skill/references/tool-call-card.md +151 -0
- package/registry/skill/references/tooltip.md +94 -0
- package/registry/skill/references/tree-view.md +172 -0
- package/registry/skill/theming.md +57 -0
- package/registry/smart-recommendation.ts +415 -0
- package/registry/spinner.ts +67 -0
- package/registry/switch.ts +146 -0
- package/registry/tab-overload.ts +211 -0
- package/registry/tag-input.ts +620 -0
- package/registry/team-invite.ts +248 -0
- package/registry/testimonial-wall.ts +521 -0
- package/registry/text-area.ts +432 -0
- package/registry/text-field.ts +415 -0
- package/registry/text-reveal.ts +175 -0
- package/registry/theme.ts +68 -0
- package/registry/thinking-loader.ts +302 -0
- package/registry/time-picker.ts +828 -0
- package/registry/tips-panel.ts +312 -0
- package/registry/toggle-group.ts +357 -0
- package/registry/tool-call-card.ts +578 -0
- package/registry/tooltip.ts +486 -0
- package/registry/tree-view.ts +454 -0
- package/styles/base.css +500 -0
- package/styles/tokens.css +415 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Button, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (tokens and the ui-spin / ui-shimmer keyframes), added once by `npx ochreui init`.
|
|
5
|
+
*
|
|
6
|
+
* <button uiButton> is a native button in four variants and three sizes, with an icon before the label
|
|
7
|
+
* (<svg uiButtonIcon>) or after it (<svg uiButtonIconEnd>), and a loading state that stays focusable.
|
|
8
|
+
*
|
|
9
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
10
|
+
* --ui-button-radius corners (default 6px; Classic 10, 12 and 14px)
|
|
11
|
+
* --ui-button-press scale while held (default 0.97)
|
|
12
|
+
*/
|
|
13
|
+
import {
|
|
14
|
+
Component,
|
|
15
|
+
DOCUMENT,
|
|
16
|
+
DestroyRef,
|
|
17
|
+
Directive,
|
|
18
|
+
ElementRef,
|
|
19
|
+
afterNextRender,
|
|
20
|
+
booleanAttribute,
|
|
21
|
+
inject,
|
|
22
|
+
input,
|
|
23
|
+
isDevMode,
|
|
24
|
+
} from '@angular/core';
|
|
25
|
+
|
|
26
|
+
export type ButtonVariant = 'primary' | 'secondary' | 'ghost' | 'destructive';
|
|
27
|
+
export type ButtonSize = 'sm' | 'md' | 'lg';
|
|
28
|
+
|
|
29
|
+
const space = (n: string) => `var(--ui-space-${n})`;
|
|
30
|
+
/** Per size: height, padding, gap, icon, radius growth and type in Clean, and how much each grows in Classic. */
|
|
31
|
+
const SIZES: Record<ButtonSize, Record<string, string>> = {
|
|
32
|
+
sm: {
|
|
33
|
+
'--_h': space('6'), '--_hx': space('2'), '--_p': space('2'), '--_px': space('1'), '--_g': space('1'), '--_gx': space('0-5'),
|
|
34
|
+
'--_i0': 'var(--ui-icon-sm)', '--_rx': space('1'), '--_fs': 'var(--ui-text-sm)', '--_fx': '1px', '--_lh': space('4'),
|
|
35
|
+
},
|
|
36
|
+
md: {
|
|
37
|
+
'--_h': `calc(${space('6')} + ${space('1')})`, '--_hx': space('3'), '--_p': space('2-5'), '--_px': space('1-5'), '--_g': space('1-5'),
|
|
38
|
+
'--_gx': space('0-5'), '--_i0': 'var(--ui-icon-md)', '--_rx': space('1-5'), '--_fs': 'var(--ui-text-base)', '--_fx': '1px', '--_lh': 'var(--ui-leading-base)',
|
|
39
|
+
},
|
|
40
|
+
lg: {
|
|
41
|
+
'--_h': space('8'), '--_hx': space('4'), '--_p': space('3'), '--_px': space('2'), '--_g': space('1-5'), '--_gx': space('1'),
|
|
42
|
+
'--_i0': 'var(--ui-icon-md)', '--_rx': space('2'), '--_fs': 'var(--ui-text-base)', '--_fx': '2px', '--_lh': 'var(--ui-leading-base)',
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
@Component({
|
|
47
|
+
selector: 'button[uiButton]',
|
|
48
|
+
host: {
|
|
49
|
+
'[attr.data-variant]': 'variant()',
|
|
50
|
+
'[attr.data-size]': 'size()',
|
|
51
|
+
'[style]': 'sizes[size()]',
|
|
52
|
+
'[attr.aria-busy]': 'loading() || null',
|
|
53
|
+
'[attr.aria-disabled]': 'loading() || null',
|
|
54
|
+
},
|
|
55
|
+
template: `<span class="lead">@if (loading()) {<svg class="spin" style="width: var(--_i); height: var(--_i)" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><circle cx="8" cy="8" r="6" stroke-dasharray="26 100" /></svg>} @else {<ng-content select="[uiButtonIcon]" />}</span><span class="label"><ng-content /></span><span class="trail"><ng-content select="[uiButtonIconEnd]" /></span>`,
|
|
56
|
+
styles: `
|
|
57
|
+
:host {
|
|
58
|
+
--_t: var(--ui-look-tray, 0);
|
|
59
|
+
--_hh: calc(var(--_h) + var(--_hx) * var(--_t));
|
|
60
|
+
--_pad: calc(var(--_p) + (var(--_px) + 1px) * var(--_t) - 1px);
|
|
61
|
+
--_i: calc(var(--_i0) + var(--ui-space-0-5) * var(--_t));
|
|
62
|
+
--_m: calc(var(--ui-space-0-5) * (var(--_t) - 1));
|
|
63
|
+
--_a: 96%;
|
|
64
|
+
--_f0: var(--ui-text-on-neutral);
|
|
65
|
+
--_b0: color-mix(in srgb, var(--ui-bg-neutral-solid) calc(var(--_a) + (100% - var(--_a)) * var(--_t)), transparent);
|
|
66
|
+
--_f: var(--_f0);
|
|
67
|
+
--_b: var(--_b0);
|
|
68
|
+
--_f1: var(--_f0);
|
|
69
|
+
--_b1: var(--_b0);
|
|
70
|
+
--_edge: transparent;
|
|
71
|
+
--_img: none;
|
|
72
|
+
--_sh: none;
|
|
73
|
+
--_ic: currentColor;
|
|
74
|
+
--_hi: 14%;
|
|
75
|
+
display: inline-flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: center;
|
|
78
|
+
gap: calc(var(--_g) + var(--_gx) * var(--_t));
|
|
79
|
+
box-sizing: border-box;
|
|
80
|
+
block-size: var(--_hh);
|
|
81
|
+
padding: 0 var(--_pad);
|
|
82
|
+
border: 1px solid var(--_edge);
|
|
83
|
+
border-radius: var(--ui-button-radius, calc(var(--ui-radius-sm) + var(--_rx) * var(--_t)));
|
|
84
|
+
background: var(--_img) var(--_b);
|
|
85
|
+
box-shadow: var(--_sh);
|
|
86
|
+
color: var(--_f);
|
|
87
|
+
font: var(--ui-weight-medium) calc(var(--_fs) + var(--_fx) * var(--_t)) / calc(var(--_lh) * (1 - var(--_t)) + 1em * var(--_t)) var(--ui-font-sans);
|
|
88
|
+
letter-spacing: calc(-0.01em * var(--_t));
|
|
89
|
+
white-space: nowrap;
|
|
90
|
+
overflow: clip;
|
|
91
|
+
user-select: none;
|
|
92
|
+
cursor: pointer;
|
|
93
|
+
transition: var(--ui-duration-2) var(--ui-ease-out);
|
|
94
|
+
transition-property: background, color, box-shadow, opacity, transform;
|
|
95
|
+
}
|
|
96
|
+
:host([data-variant='primary']) {
|
|
97
|
+
--_sh: 0 calc(2px * var(--_t)) calc(4px * var(--_t)) color-mix(in srgb, var(--ui-gray-1000) calc(16% * var(--_t)), transparent);
|
|
98
|
+
--_img: linear-gradient(color-mix(in srgb, var(--ui-gray-0) calc(var(--_hi) * var(--_t)), transparent), transparent);
|
|
99
|
+
}
|
|
100
|
+
:host([data-variant='secondary']) {
|
|
101
|
+
--_f0: var(--ui-text);
|
|
102
|
+
--_b0: var(--ui-bg-surface);
|
|
103
|
+
--_b1: color-mix(in srgb, var(--ui-bg-subtle) calc(var(--_t) * 100%), var(--_b0));
|
|
104
|
+
--_edge: color-mix(in srgb, var(--ui-border) calc(var(--_t) * 100%), transparent);
|
|
105
|
+
--_sh: var(--ui-shadow-sm);
|
|
106
|
+
--_ic: color-mix(in srgb, var(--ui-icon) calc(100% - 100% * var(--_t)), var(--_f0));
|
|
107
|
+
}
|
|
108
|
+
:host([data-variant='ghost']) {
|
|
109
|
+
--_f0: var(--ui-text-muted);
|
|
110
|
+
--_f1: var(--ui-text);
|
|
111
|
+
--_b0: transparent;
|
|
112
|
+
--_b1: color-mix(in srgb, var(--ui-text) 5%, transparent);
|
|
113
|
+
}
|
|
114
|
+
:host([data-variant='destructive']) {
|
|
115
|
+
--_f0: var(--ui-danger);
|
|
116
|
+
--_b0: var(--ui-danger-soft);
|
|
117
|
+
--_b1: color-mix(in srgb, var(--ui-danger) 15%, transparent);
|
|
118
|
+
}
|
|
119
|
+
@media (hover: hover) {
|
|
120
|
+
:host(:hover:not(:disabled, [aria-busy])) {
|
|
121
|
+
--_f: var(--_f1);
|
|
122
|
+
--_b: var(--_b1);
|
|
123
|
+
--_ic: currentColor;
|
|
124
|
+
--_a: 88%;
|
|
125
|
+
--_hi: 22%;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
129
|
+
:host(:active:not(:disabled, [aria-busy])) { transform: scale(var(--ui-button-press, 0.97)); }
|
|
130
|
+
.spin { animation: ui-spin 900ms linear infinite; }
|
|
131
|
+
:host([aria-busy]) .label {
|
|
132
|
+
background: linear-gradient(100deg, #0000 40%, var(--_f) 50%, #0000 60%) 0 0 / 250% 100%;
|
|
133
|
+
-webkit-background-clip: text;
|
|
134
|
+
background-clip: text;
|
|
135
|
+
animation: ui-shimmer 1040ms linear infinite;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
@container style(--ui-motion-scale: 0) {
|
|
139
|
+
:host(:active) { transform: none; }
|
|
140
|
+
.spin, .label { animation: none; background: none; }
|
|
141
|
+
}
|
|
142
|
+
@media (pointer: coarse) {
|
|
143
|
+
:host { block-size: max(var(--_hh), var(--ui-space-8) + (var(--_h) - var(--ui-space-6)) / 2); }
|
|
144
|
+
}
|
|
145
|
+
:host(:focus-visible) { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
146
|
+
:host(:disabled) { opacity: var(--ui-disabled-opacity); }
|
|
147
|
+
:host(:is(:disabled, [aria-busy])) { cursor: default; }
|
|
148
|
+
:host(:has(> .label:empty)) { inline-size: var(--_hh); padding: 0; --_m: 0; }
|
|
149
|
+
.lead, .trail { display: inline-flex; color: var(--_ic); }
|
|
150
|
+
.lead { margin-inline-start: var(--_m); }
|
|
151
|
+
.trail { margin-inline-end: var(--_m); }
|
|
152
|
+
span:empty { display: none; }
|
|
153
|
+
:host([aria-busy]) .label { color: color-mix(in srgb, var(--_f) 70%, transparent); }
|
|
154
|
+
@media (forced-colors: active) {
|
|
155
|
+
:host(:disabled) { color: GrayText; border-color: GrayText; }
|
|
156
|
+
}
|
|
157
|
+
`,
|
|
158
|
+
})
|
|
159
|
+
export class UiButton {
|
|
160
|
+
/** Primary for the main action, secondary next to it, ghost for quiet ones, destructive for deleting. */
|
|
161
|
+
readonly variant = input<ButtonVariant>('primary');
|
|
162
|
+
/** 24, 28 or 32px tall; Classic 32, 40 or 48px. Taller on touch screens. */
|
|
163
|
+
readonly size = input<ButtonSize>('md');
|
|
164
|
+
/** Shows a spinner in place of the leading icon, shimmers the label and ignores clicks. Stays focusable. */
|
|
165
|
+
readonly loading = input(false, { transform: booleanAttribute });
|
|
166
|
+
|
|
167
|
+
protected readonly sizes = SIZES;
|
|
168
|
+
|
|
169
|
+
constructor() {
|
|
170
|
+
const el = inject<ElementRef<HTMLButtonElement>>(ElementRef).nativeElement;
|
|
171
|
+
const view = inject(DOCUMENT).defaultView;
|
|
172
|
+
const destroy = inject(DestroyRef);
|
|
173
|
+
|
|
174
|
+
el.addEventListener('click', (e) => {
|
|
175
|
+
if (this.loading()) {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
e.stopImmediatePropagation();
|
|
178
|
+
}
|
|
179
|
+
}, true);
|
|
180
|
+
|
|
181
|
+
afterNextRender(() => {
|
|
182
|
+
const label = el.querySelector(':scope > .label')!;
|
|
183
|
+
if (isDevMode() && !label.textContent?.trim() && !el.ariaLabel && !el.hasAttribute('aria-labelledby')) {
|
|
184
|
+
console.warn('uiButton: a button with only an icon needs an aria-label.', el);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (!view?.ResizeObserver || !view.MutationObserver || !el.animate) return;
|
|
188
|
+
const glide = () => el.getAnimations().find((a) => a.id === 'ui-glide');
|
|
189
|
+
let width = el.offsetWidth;
|
|
190
|
+
const resize = new view.ResizeObserver(() => !glide() && (width = el.offsetWidth));
|
|
191
|
+
const change = new view.MutationObserver((records) => {
|
|
192
|
+
const running = glide();
|
|
193
|
+
const style = view.getComputedStyle(el);
|
|
194
|
+
const from = running ? parseFloat(style.width) : width;
|
|
195
|
+
running?.cancel();
|
|
196
|
+
width = el.offsetWidth;
|
|
197
|
+
const still = view.matchMedia('(prefers-reduced-motion: reduce)').matches || style.getPropertyValue('--ui-motion-scale').trim() === '0';
|
|
198
|
+
if (still) return;
|
|
199
|
+
const ease = style.getPropertyValue('--ui-ease-out').trim() || 'ease-out';
|
|
200
|
+
if (from && width && from !== width) {
|
|
201
|
+
el.animate([{ width: `${from}px` }, { width: `${width}px` }], { duration: 480, easing: ease, id: 'ui-glide' });
|
|
202
|
+
}
|
|
203
|
+
if (records.some((r) => label.contains(r.target))) {
|
|
204
|
+
label.animate([{ opacity: 0.33, filter: 'blur(2px)' }, { opacity: 1, filter: 'none' }], { duration: 480, easing: ease });
|
|
205
|
+
}
|
|
206
|
+
for (const r of records) {
|
|
207
|
+
if (r.target === label || label.contains(r.target)) continue;
|
|
208
|
+
for (const node of r.addedNodes) {
|
|
209
|
+
if (node instanceof Element) {
|
|
210
|
+
node.animate(
|
|
211
|
+
[{ opacity: 0.3, transform: 'scale(0.75)', filter: 'blur(1.4px)' }, { opacity: 1, transform: 'none', filter: 'none' }],
|
|
212
|
+
{ duration: 520, easing: ease },
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
resize.observe(el);
|
|
219
|
+
change.observe(el, { childList: true, characterData: true, subtree: true });
|
|
220
|
+
destroy.onDestroy(() => {
|
|
221
|
+
resize.disconnect();
|
|
222
|
+
change.disconnect();
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Marks an icon inside a button: `<svg uiButtonIcon>` before the label, `<svg uiButtonIconEnd>` after it. Sized to the button and hidden from screen readers. */
|
|
229
|
+
@Directive({
|
|
230
|
+
selector: '[uiButtonIcon], [uiButtonIconEnd]',
|
|
231
|
+
host: {
|
|
232
|
+
'aria-hidden': 'true',
|
|
233
|
+
'[style.flex]': '"none"',
|
|
234
|
+
'[style.width]': '"var(--_i)"',
|
|
235
|
+
'[style.height]': '"var(--_i)"',
|
|
236
|
+
},
|
|
237
|
+
})
|
|
238
|
+
export class UiButtonIcon {}
|
package/registry/card.ts
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Card, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (`npx ochreui init`).
|
|
5
|
+
*
|
|
6
|
+
* <section uiCard> <ui-card-header> <h3 uiCardTitle>…</h3> <p uiCardDescription>…</p> </ui-card-header>
|
|
7
|
+
* <div uiCardContent>…</div> <div uiCardFooter>Status <button uiCardEnd>Open</button></div> </section>
|
|
8
|
+
* Put uiCard on your own element so the semantics stay yours. `interactive` stretches the title's
|
|
9
|
+
* uiCardLink over the whole card; `selected` shows it as picked.
|
|
10
|
+
*
|
|
11
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
12
|
+
* --ui-card-radius corners (default 10px; Classic 16px panel in a 20px tray)
|
|
13
|
+
* --ui-card-padding inner space (default 16px)
|
|
14
|
+
* --ui-card-gap space between header, content and footer (default 12px)
|
|
15
|
+
* --ui-card-bg fill (default --ui-bg-surface)
|
|
16
|
+
* --ui-card-bg-selected selected fill (default a step grayer; Classic: the tray around the panel)
|
|
17
|
+
* --ui-card-edge resting edge (default a soft grey ring; on grey surfaces use var(--ui-hairline))
|
|
18
|
+
* --ui-card-edge-hover edge while the pointer is over an interactive card
|
|
19
|
+
* --ui-card-edge-selected edge of a selected card
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
Component,
|
|
23
|
+
Directive,
|
|
24
|
+
ElementRef,
|
|
25
|
+
ViewEncapsulation,
|
|
26
|
+
afterNextRender,
|
|
27
|
+
booleanAttribute,
|
|
28
|
+
computed,
|
|
29
|
+
contentChild,
|
|
30
|
+
inject,
|
|
31
|
+
input,
|
|
32
|
+
isDevMode,
|
|
33
|
+
signal,
|
|
34
|
+
} from '@angular/core';
|
|
35
|
+
|
|
36
|
+
let nextId = 0;
|
|
37
|
+
|
|
38
|
+
/** The title, inside `<ui-card-header>`: an `h2`–`h4`, or a `p` in a list of choices. */
|
|
39
|
+
@Directive({
|
|
40
|
+
selector: '[uiCardTitle]',
|
|
41
|
+
host: {
|
|
42
|
+
class: 'ui-card-title',
|
|
43
|
+
style: 'overflow-wrap: anywhere',
|
|
44
|
+
'[id]': 'id()',
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
export class UiCardTitle {
|
|
48
|
+
readonly id = input(`ui-card-title-${nextId++}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A quiet line or two under the title. An empty one takes no room. */
|
|
52
|
+
@Directive({
|
|
53
|
+
selector: '[uiCardDescription]',
|
|
54
|
+
host: { class: 'ui-card-description', style: 'overflow-wrap: anywhere', '[id]': 'id()' },
|
|
55
|
+
})
|
|
56
|
+
export class UiCardDescription {
|
|
57
|
+
readonly id = input(`ui-card-description-${nextId++}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Something small before the title: an icon, a logo, an avatar or a tile. */
|
|
61
|
+
@Directive({ selector: '[uiCardIcon]', host: { class: 'ui-card-icon', style: 'flex: none' } })
|
|
62
|
+
export class UiCardIcon {}
|
|
63
|
+
|
|
64
|
+
/** At the end of the title line, centred on it: an icon button, a menu, a badge. */
|
|
65
|
+
@Directive({ selector: '[uiCardAction]', host: { class: 'ui-card-action', style: 'flex: none' } })
|
|
66
|
+
export class UiCardAction {}
|
|
67
|
+
|
|
68
|
+
/** The body. */
|
|
69
|
+
@Directive({ selector: '[uiCardContent]', host: { class: 'ui-card-content', style: 'min-width: 0' } })
|
|
70
|
+
export class UiCardContent {}
|
|
71
|
+
|
|
72
|
+
/** A bottom row in small quiet text: status at the start, buttons at the end. Last inside the card. */
|
|
73
|
+
@Directive({
|
|
74
|
+
selector: '[uiCardFooter]',
|
|
75
|
+
host: {
|
|
76
|
+
class: 'ui-card-footer',
|
|
77
|
+
style: 'display: flex; flex-wrap: wrap; align-items: center; gap: var(--ui-space-2); box-sizing: border-box; min-height: var(--_fh); padding: calc(var(--ui-space-1) * var(--_t)) 0 0; padding-inline: calc(var(--_p) * var(--_t)) calc(var(--ui-space-0-5) * var(--_t)); color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + .5px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 2px * var(--_t))',
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
export class UiCardFooter {}
|
|
81
|
+
|
|
82
|
+
/** Pushes a footer item, and everything after it, to the end of the row. */
|
|
83
|
+
@Directive({ selector: '[uiCardEnd]', host: { class: 'ui-card-end', style: 'margin-inline-start: auto' } })
|
|
84
|
+
export class UiCardEnd {}
|
|
85
|
+
|
|
86
|
+
/** The title's link or button. On an interactive card it covers the whole card and carries its focus ring. */
|
|
87
|
+
@Directive({
|
|
88
|
+
selector: 'a[uiCardLink], button[uiCardLink]',
|
|
89
|
+
host: { class: 'ui-card-link', '[attr.aria-describedby]': 'describedBy()' },
|
|
90
|
+
})
|
|
91
|
+
export class UiCardLink {
|
|
92
|
+
/** Your own descriptions, kept alongside the card's. Set it as `aria-describedby="…"`. */
|
|
93
|
+
readonly ariaDescribedby = input<string>(undefined, { alias: 'aria-describedby' });
|
|
94
|
+
|
|
95
|
+
readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
96
|
+
private readonly card = inject(UiCard, { optional: true });
|
|
97
|
+
protected readonly describedBy = computed(() => {
|
|
98
|
+
const desc = this.card?.interactive() ? this.card.description()?.id() : '';
|
|
99
|
+
return [this.ariaDescribedby(), desc].filter(Boolean).join(' ') || null;
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The top row: `[uiCardIcon]`, then title, description and anything more, then `[uiCardAction]`. */
|
|
104
|
+
@Component({
|
|
105
|
+
selector: 'ui-card-header',
|
|
106
|
+
host: { style: 'display: flex; align-items: flex-start; gap: var(--ui-space-3); min-width: 0' },
|
|
107
|
+
template: `<ng-content select="[uiCardIcon]" /><div class="ui-card-text" style="display: grid; gap: var(--ui-space-0-5); flex: 1; min-width: 0"><ng-content select="[uiCardTitle]" /><ng-content select="[uiCardDescription]" /><ng-content /></div><div class="ui-card-actions" style="display: flex; align-items: center; gap: var(--ui-space-1); flex: none; height: var(--ui-leading-base); margin-inline-end: calc(-1 * var(--ui-space-1-5) - var(--ui-space-0-5) * var(--_t))"><ng-content select="[uiCardAction]" /></div>`,
|
|
108
|
+
})
|
|
109
|
+
export class UiCardHeader {}
|
|
110
|
+
|
|
111
|
+
@Component({
|
|
112
|
+
selector: '[uiCard]',
|
|
113
|
+
encapsulation: ViewEncapsulation.None,
|
|
114
|
+
host: {
|
|
115
|
+
class: 'ui-card',
|
|
116
|
+
'[attr.data-interactive]': 'interactive() ? "" : null',
|
|
117
|
+
'[attr.data-selected]': 'selected() ? "" : null',
|
|
118
|
+
'[attr.data-hover]': 'interactive() && hover() ? "" : null',
|
|
119
|
+
'[attr.aria-labelledby]': 'labelledBy()',
|
|
120
|
+
'[attr.aria-label]': 'label()',
|
|
121
|
+
'(pointerenter)': 'hover.set($event.pointerType === "mouse")',
|
|
122
|
+
'(pointerleave)': 'hover.set(false)',
|
|
123
|
+
},
|
|
124
|
+
template: `<div class="ui-card-panel" style="display: flex; flex-direction: column; flex: 1; gap: var(--_g); padding: calc(var(--_p) * var(--_t)); border-radius: var(--_r); background: color-mix(in srgb, var(--_bg) calc(var(--_t) * 100%), transparent); box-shadow: 0 0 0 calc(1px * var(--_t)) var(--_e), 0 calc(var(--_y) * var(--_t)) calc(var(--_b) * var(--_t)) calc(var(--_x) * var(--_t)) var(--_s), 0 calc(1px * var(--_t)) calc(2px * var(--_t)) var(--_s)"><ng-content /></div><ng-content select="[uiCardFooter]" />`,
|
|
125
|
+
styles: `
|
|
126
|
+
.ui-card {
|
|
127
|
+
--_t: var(--ui-look-tray, 0);
|
|
128
|
+
--_f: calc(1 - var(--_t));
|
|
129
|
+
--_k: 1;
|
|
130
|
+
--_r: var(--ui-card-radius, calc(var(--ui-radius-md) + 2px + 6px * var(--_t)));
|
|
131
|
+
--_ro: calc(var(--_r) + var(--ui-tray-padding));
|
|
132
|
+
--_p: var(--ui-card-padding, var(--ui-space-4));
|
|
133
|
+
--_g: var(--ui-card-gap, var(--ui-space-3));
|
|
134
|
+
--_e: var(--ui-card-edge, color-mix(in srgb, var(--ui-bg-muted) 88%, var(--ui-bg-surface)));
|
|
135
|
+
--_s: color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
|
|
136
|
+
--_bg: var(--ui-card-bg, var(--ui-bg-surface));
|
|
137
|
+
--_h0: color-mix(in srgb, var(--ui-tray-bg) calc(var(--_t) * 100%), var(--_bg));
|
|
138
|
+
--_h: var(--_h0);
|
|
139
|
+
--_y: calc(1px * var(--_f) * var(--_k));
|
|
140
|
+
--_b: var(--_y);
|
|
141
|
+
--_x: calc(-1 * var(--_y));
|
|
142
|
+
--_fh: calc(var(--ui-space-6) + var(--ui-space-1) + var(--ui-space-3) * var(--_t));
|
|
143
|
+
position: relative;
|
|
144
|
+
display: flex;
|
|
145
|
+
flex-direction: column;
|
|
146
|
+
gap: calc(var(--_g) * var(--_f));
|
|
147
|
+
box-sizing: border-box;
|
|
148
|
+
min-width: 0;
|
|
149
|
+
padding: calc(var(--_p) * var(--_f) + var(--ui-tray-padding));
|
|
150
|
+
border-radius: var(--_ro);
|
|
151
|
+
background: var(--_h);
|
|
152
|
+
box-shadow: 0 0 0 calc(.5px * var(--_f)) var(--_e), 0 calc(var(--_y) * var(--_f)) calc(var(--_b) * var(--_f)) calc(var(--_x) * var(--_f)) var(--_s), 0 calc(1px * var(--_f)) calc(2px * var(--_f)) var(--_s);
|
|
153
|
+
color: var(--ui-text);
|
|
154
|
+
font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
|
|
155
|
+
}
|
|
156
|
+
.ui-card, .ui-card-panel { transition: calc(160ms * var(--ui-motion-scale)); transition-property: box-shadow, background-color; }
|
|
157
|
+
.ui-card[data-interactive] { cursor: pointer; }
|
|
158
|
+
.ui-card[data-hover]:not(:has(.ui-card-link:disabled)) { --_y: calc(2px * var(--_k)); --_b: calc(6px * var(--_k)); --_x: calc(-1px * var(--_k)); }
|
|
159
|
+
.ui-card[data-hover]:not([data-selected]) { --_e: var(--ui-card-edge-hover, color-mix(in srgb, var(--ui-text) 5%, var(--ui-bg-muted))); }
|
|
160
|
+
.ui-card[data-selected] {
|
|
161
|
+
--_k: var(--_t);
|
|
162
|
+
--_e: var(--ui-card-edge-selected, color-mix(in srgb, var(--ui-text) 9%, var(--ui-bg-muted)));
|
|
163
|
+
--_h: var(--ui-card-bg-selected, color-mix(in srgb, var(--ui-text) calc(5% * var(--_t)), color-mix(in srgb, var(--ui-bg-muted) calc(45% * var(--_f)), light-dark(var(--_h0), color-mix(in srgb, var(--ui-text) calc(5% * var(--_t)), var(--_h0))))));
|
|
164
|
+
}
|
|
165
|
+
.ui-card:has(.ui-card-link:disabled), .ui-card-link:disabled { cursor: default; }
|
|
166
|
+
.ui-card-description:empty, .ui-card-actions:empty { display: none; }
|
|
167
|
+
:where(.ui-card-title, .ui-card-description):not(z):not(z) { margin: 0; color: var(--ui-text-muted); }
|
|
168
|
+
:where(.ui-card-title):not(z):not(z) { color: var(--ui-text); font: var(--ui-weight-medium) calc(var(--ui-text-base) + 1px * var(--_t)) / var(--ui-leading-base) var(--ui-font-sans); letter-spacing: calc(-.01em * var(--_t)); }
|
|
169
|
+
.ui-card-link { all: unset; cursor: pointer; text-align: start; -webkit-tap-highlight-color: transparent; }
|
|
170
|
+
.ui-card[data-interactive] .ui-card-link::after { content: ''; position: absolute; inset: 0; z-index: 0; border-radius: var(--_ro); }
|
|
171
|
+
.ui-card-link:focus-visible::after, .ui-card:not([data-interactive]) .ui-card-link:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
172
|
+
.ui-card[data-interactive] :is(a, button, input, select, textarea, label, [tabindex]):not(.ui-card-link) { position: relative; z-index: 1; }
|
|
173
|
+
@media (pointer: coarse) {
|
|
174
|
+
.ui-card { --_fh: calc(var(--ui-space-8) + var(--ui-space-1) + var(--ui-space-1) * var(--_t)); }
|
|
175
|
+
}
|
|
176
|
+
@media (forced-colors: active) {
|
|
177
|
+
.ui-card { outline: calc(1px * var(--_f)) solid CanvasText; outline-offset: -1px; }
|
|
178
|
+
.ui-card-panel { outline: calc(1px * var(--_t)) solid CanvasText; outline-offset: -1px; }
|
|
179
|
+
.ui-card[data-selected] { outline: 2px solid Highlight; outline-offset: -2px; }
|
|
180
|
+
}
|
|
181
|
+
`,
|
|
182
|
+
})
|
|
183
|
+
export class UiCard {
|
|
184
|
+
/** The whole card is one click target: the `uiCardLink` in its title stretches over it. Other buttons inside stay their own targets. */
|
|
185
|
+
readonly interactive = input(false, { transform: booleanAttribute });
|
|
186
|
+
/** Shown as picked: a grayer fill and a firmer edge. Say it with aria-pressed or aria-current on the title's link too. */
|
|
187
|
+
readonly selected = input(false, { transform: booleanAttribute });
|
|
188
|
+
/** Your own label reference. Without one, a `section` or `article` card is labelled by its title. */
|
|
189
|
+
readonly ariaLabelledby = input<string>(undefined, { alias: 'aria-labelledby' });
|
|
190
|
+
/** Your own name for the card. A `section` or `article` card with one is not labelled by its title. */
|
|
191
|
+
readonly ariaLabel = input<string>(undefined, { alias: 'aria-label' });
|
|
192
|
+
|
|
193
|
+
readonly title = contentChild(UiCardTitle);
|
|
194
|
+
readonly description = contentChild(UiCardDescription);
|
|
195
|
+
private readonly link = contentChild(UiCardLink);
|
|
196
|
+
protected readonly hover = signal(false);
|
|
197
|
+
|
|
198
|
+
private readonly el = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
199
|
+
private readonly region = /^(SECTION|ARTICLE)$/.test(this.el.tagName);
|
|
200
|
+
protected label() {
|
|
201
|
+
return this.ariaLabel() ?? this.el.getAttribute('aria-label');
|
|
202
|
+
}
|
|
203
|
+
protected labelledBy() {
|
|
204
|
+
return this.ariaLabelledby() ?? ((this.region && !this.label() && this.title()?.id()) || null);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
constructor() {
|
|
208
|
+
afterNextRender(() => {
|
|
209
|
+
if (!isDevMode()) return;
|
|
210
|
+
const link = this.link()?.el;
|
|
211
|
+
if (this.region && !this.labelledBy() && !this.label()) console.warn('ui-card: a section or article card needs a [uiCardTitle] or an aria-label.', this.el);
|
|
212
|
+
if (this.interactive() && !link) console.warn('ui-card: an interactive card needs an <a uiCardLink> or <button uiCardLink> in its title.', this.el);
|
|
213
|
+
if (link && !link.textContent?.trim() && !link.ariaLabel && !link.hasAttribute('aria-labelledby')) {
|
|
214
|
+
console.warn('ui-card: the card link has no name. Give it text or an aria-label.', link);
|
|
215
|
+
}
|
|
216
|
+
if (this.selected() && link && !link.hasAttribute('aria-pressed') && !link.hasAttribute('aria-current')) {
|
|
217
|
+
console.warn('ui-card: say that the card is selected with aria-pressed or aria-current on its link.', link);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Change Summary, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens), which `npx ochreui init` adds once.
|
|
5
|
+
*
|
|
6
|
+
* <ui-change-summary period="This week" [changes]="changes" />
|
|
7
|
+
* A read-only card of what changed, one metric per row: `tone` colors the tile, `direction` picks the arrow
|
|
8
|
+
* (default from the tone). The arrow is decorative, so write the direction in the text too.
|
|
9
|
+
*
|
|
10
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
11
|
+
* --ui-change-summary-good / -good-bg arrow and tile of a good change (default: green on a green wash)
|
|
12
|
+
* --ui-change-summary-bad / -bad-bg arrow and tile of a bad change (default: red on a red wash)
|
|
13
|
+
* --ui-change-summary-neutral / -neutral-bg arrow and tile of a neutral change (default: grey on a grey wash)
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
Component,
|
|
17
|
+
DestroyRef,
|
|
18
|
+
Directive,
|
|
19
|
+
ElementRef,
|
|
20
|
+
afterNextRender,
|
|
21
|
+
afterRenderEffect,
|
|
22
|
+
booleanAttribute,
|
|
23
|
+
computed,
|
|
24
|
+
inject,
|
|
25
|
+
input,
|
|
26
|
+
isDevMode,
|
|
27
|
+
} from '@angular/core';
|
|
28
|
+
|
|
29
|
+
export type ChangeTone = 'good' | 'bad' | 'neutral';
|
|
30
|
+
export type ChangeDirection = 'up' | 'down' | 'flat';
|
|
31
|
+
export type ChangeSummaryHeadingLevel = 2 | 3 | 4 | 5 | 6;
|
|
32
|
+
|
|
33
|
+
export interface MetricChange {
|
|
34
|
+
/** The metric: "Active users". */
|
|
35
|
+
label: string;
|
|
36
|
+
/** What happened, in words, direction included: "Up 6.1% to 18.2K". A `\n` starts a new line. */
|
|
37
|
+
change: string;
|
|
38
|
+
tone: ChangeTone;
|
|
39
|
+
/** The arrow. Left out: up for good, down for bad, flat for neutral. */
|
|
40
|
+
direction?: ChangeDirection;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Words screen readers hear after each change. An empty string says nothing. */
|
|
44
|
+
export interface ChangeSummaryLabels {
|
|
45
|
+
good: string;
|
|
46
|
+
bad: string;
|
|
47
|
+
neutral: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const LABELS: ChangeSummaryLabels = { good: 'good', bad: 'needs attention', neutral: '' };
|
|
51
|
+
const DIRECTION: Record<ChangeTone, ChangeDirection> = { good: 'up', bad: 'down', neutral: 'flat' };
|
|
52
|
+
|
|
53
|
+
let nextId = 0;
|
|
54
|
+
|
|
55
|
+
/** Your own icon in front of the title, in place of the summary glyph: `<svg uiChangeSummaryIcon>`. */
|
|
56
|
+
@Directive({
|
|
57
|
+
selector: '[uiChangeSummaryIcon]',
|
|
58
|
+
host: { 'aria-hidden': 'true', style: 'flex: none; inline-size: var(--ui-icon-md); block-size: var(--ui-icon-md)' },
|
|
59
|
+
})
|
|
60
|
+
export class UiChangeSummaryIcon {}
|
|
61
|
+
|
|
62
|
+
@Component({
|
|
63
|
+
selector: 'ui-change-summary',
|
|
64
|
+
host: {
|
|
65
|
+
role: 'region',
|
|
66
|
+
'[attr.aria-labelledby]': 'titleId',
|
|
67
|
+
'[attr.title]': 'null',
|
|
68
|
+
'[attr.data-static]': 'animate() ? null : ""',
|
|
69
|
+
},
|
|
70
|
+
template: `
|
|
71
|
+
<div class="q">
|
|
72
|
+
<div class="head" style="display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-3); box-sizing: border-box; min-block-size: calc(44px * var(--_f))">
|
|
73
|
+
<div class="name" style="display: flex; align-items: center; gap: var(--ui-space-2); min-inline-size: 0; color: color-mix(in srgb, var(--_tc) calc(100% * var(--_t)), var(--ui-text)); font-weight: var(--ui-weight-medium)">
|
|
74
|
+
<span style="display: flex; flex: none; color: color-mix(in srgb, var(--_tc) calc(100% * var(--_t)), var(--ui-icon))"><ng-content select="[uiChangeSummaryIcon]"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-linecap="round" aria-hidden="true" style="inline-size: var(--ui-icon-md); block-size: var(--ui-icon-md); stroke-width: calc(1.1px + .4px * var(--_t))"><path d="M2.5 4h7M2.5 8h11M2.5 12h4.5" /></svg></ng-content></span>
|
|
75
|
+
<p class="clip" dir="auto" style="margin: 0" [id]="titleId" [attr.role]="headingLevel() ? 'heading' : null" [attr.aria-level]="headingLevel()">{{ title() }}</p>
|
|
76
|
+
</div>
|
|
77
|
+
@if (period()) {
|
|
78
|
+
<span class="clip" dir="auto" style="flex: none; max-inline-size: 50%; color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 1px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 4px * var(--_t))">{{ period() }}</span>
|
|
79
|
+
}
|
|
80
|
+
</div>
|
|
81
|
+
@if (changes().length) {
|
|
82
|
+
<dl style="container-type: inline-size; overflow: clip; margin: 0; border: calc(1px * var(--_t)) solid var(--ui-border); border-radius: calc(16px * var(--_t)); background: var(--ui-bg-surface); box-shadow: 0 calc(1px * var(--_t)) calc(2px * var(--_t)) var(--_s)">
|
|
83
|
+
@for (c of changes(); track c.label; let i = $index) {
|
|
84
|
+
<div class="row" [style.--_i]="i < 7 ? i : 7">
|
|
85
|
+
<dt class="clip" dir="auto" style="font-weight: var(--ui-weight-medium)">{{ c.label }}</dt>
|
|
86
|
+
<dd style="display: flex; align-items: center; gap: var(--ui-space-2); min-inline-size: 0; margin: 0">
|
|
87
|
+
<span class="tile" [attr.data-tone]="c.tone" aria-hidden="true" style="display: grid; flex: none; place-items: center; inline-size: 20px; block-size: 20px; border-radius: calc(5px + 1px * var(--_t)); background: var(--_b); color: var(--_c)"
|
|
88
|
+
><svg viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" [style.rotate]="turn[c.direction ?? direction[c.tone]]" style="inline-size: var(--ui-icon-xs); block-size: var(--ui-icon-xs); stroke-width: calc(1.25px + .35px * var(--_t))"><path d="M6 9.5v-7M3 5.5l3-3 3 3" /></svg
|
|
89
|
+
></span>
|
|
90
|
+
<span dir="auto" style="position: relative; min-inline-size: 0; color: var(--ui-text-muted); white-space: pre-line; overflow-wrap: anywhere">{{ c.change }}@if (words()[c.tone]; as w) {<span class="ui-sr">, {{ w }}</span>}</span>
|
|
91
|
+
</dd>
|
|
92
|
+
</div>
|
|
93
|
+
}
|
|
94
|
+
</dl>
|
|
95
|
+
}
|
|
96
|
+
</div>
|
|
97
|
+
`,
|
|
98
|
+
styles: `
|
|
99
|
+
:host {
|
|
100
|
+
--_t: var(--ui-look-tray, 0);
|
|
101
|
+
--_f: calc(1 - var(--_t));
|
|
102
|
+
--_s: color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
|
|
103
|
+
--_tc: light-dark(oklch(from var(--ui-hue-blue) calc(l - .07) calc(c - .06) calc(h - 13)), var(--ui-info));
|
|
104
|
+
--_r: 1;
|
|
105
|
+
--_c: var(--ui-change-summary-neutral, var(--ui-icon));
|
|
106
|
+
--_b: var(--ui-change-summary-neutral-bg, var(--ui-bg-muted));
|
|
107
|
+
display: block;
|
|
108
|
+
overflow: clip;
|
|
109
|
+
padding: calc(6px * var(--_t));
|
|
110
|
+
border-radius: calc(var(--ui-radius-md) + 2px + 12px * var(--_t));
|
|
111
|
+
background: color-mix(in srgb, var(--ui-tray-bg) calc(100% * var(--_t)), var(--ui-bg-surface));
|
|
112
|
+
box-shadow: 0 0 0 calc(.5px * var(--_f)) color-mix(in srgb, var(--ui-bg-muted) 88%, var(--ui-bg-surface)), 0 calc(1px * var(--_f)) calc(1px * var(--_f)) calc(-1px * var(--_f)) var(--_s), 0 calc(1px * var(--_f)) calc(2px * var(--_f)) var(--_s);
|
|
113
|
+
color: var(--ui-text);
|
|
114
|
+
font: calc(var(--ui-text-base) + 1px * var(--_t)) / var(--ui-leading-base) var(--ui-font-sans);
|
|
115
|
+
}
|
|
116
|
+
:host(:dir(rtl)) { --_r: -1; }
|
|
117
|
+
:host::before { content: 'x x x x x x x x' / ''; display: block; block-size: 0; overflow: hidden; font-size: 0; word-spacing: calc(480px / 7); }
|
|
118
|
+
.q { container-type: inline-size; }
|
|
119
|
+
.head { padding: calc(11px * var(--_t)) calc(var(--ui-space-4) + 2px * var(--_t)) calc(10px * var(--_t)); }
|
|
120
|
+
.clip { overflow: hidden; min-inline-size: 0; text-overflow: ellipsis; white-space: nowrap; }
|
|
121
|
+
.row {
|
|
122
|
+
--ui-rise-distance: 4px;
|
|
123
|
+
display: grid;
|
|
124
|
+
grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
|
|
125
|
+
align-items: center;
|
|
126
|
+
column-gap: var(--ui-space-4);
|
|
127
|
+
box-sizing: border-box;
|
|
128
|
+
min-block-size: calc(var(--ui-space-12) + 4px * var(--_t));
|
|
129
|
+
padding: 0 calc(var(--ui-space-4) + 4px * var(--_t));
|
|
130
|
+
border-block-start: 1px solid light-dark(color-mix(in srgb, var(--ui-border) 60%, var(--ui-bg-surface)), var(--ui-border));
|
|
131
|
+
animation: ui-rise calc(520ms * var(--ui-motion-scale)) var(--ui-ease-out) calc((120ms + 70ms * var(--_i)) * var(--ui-motion-scale)) both;
|
|
132
|
+
transition: background-color calc(140ms * var(--ui-motion-scale));
|
|
133
|
+
}
|
|
134
|
+
.row:first-child { border-block-start-width: calc(1px * var(--_f)); }
|
|
135
|
+
:host([data-static]) .row { animation: none; }
|
|
136
|
+
[data-tone='good'] { --_c: var(--ui-change-summary-good, color-mix(in srgb, var(--ui-success) 70%, var(--ui-hue-green))); --_b: var(--ui-change-summary-good-bg, var(--ui-success-soft)); }
|
|
137
|
+
[data-tone='bad'] { --_c: var(--ui-change-summary-bad, var(--ui-hue-red)); --_b: var(--ui-change-summary-bad-bg, var(--ui-danger-soft)); }
|
|
138
|
+
@media (hover: hover) {
|
|
139
|
+
.row:hover { background: light-dark(color-mix(in srgb, var(--ui-text) calc(1.5% + .5% * var(--_t)), transparent), color-mix(in srgb, var(--ui-text) calc(2.5% + 1% * var(--_t)), transparent)); }
|
|
140
|
+
}
|
|
141
|
+
@container (max-width: 400px) {
|
|
142
|
+
.head { padding-inline: calc(14px + 4px * var(--_t)); }
|
|
143
|
+
.row { grid-template-columns: minmax(0, 1fr); row-gap: var(--ui-space-1); padding: calc(10px + 1px * var(--_t)) calc(14px + 2px * var(--_t)); }
|
|
144
|
+
}
|
|
145
|
+
@media (prefers-reduced-motion: reduce) {
|
|
146
|
+
.row { animation: none; }
|
|
147
|
+
}
|
|
148
|
+
@media (forced-colors: active) {
|
|
149
|
+
:host { outline: calc(1px * var(--_f)) solid CanvasText; outline-offset: -1px; }
|
|
150
|
+
.tile { outline: 1px solid CanvasText; outline-offset: -1px; }
|
|
151
|
+
}
|
|
152
|
+
`,
|
|
153
|
+
})
|
|
154
|
+
export class UiChangeSummary {
|
|
155
|
+
/** One row per metric, in order. Keep it to about six: past that it stops being a quick read. */
|
|
156
|
+
readonly changes = input.required<readonly MetricChange[]>();
|
|
157
|
+
/** The card's title, which also names it for screen readers. */
|
|
158
|
+
readonly title = input("What's changed");
|
|
159
|
+
/** Quiet text at the end of the title line: "This week". */
|
|
160
|
+
readonly period = input<string>();
|
|
161
|
+
/** Makes the title a heading of this level, so screen-reader users can jump to it. Left out, it is a paragraph. */
|
|
162
|
+
readonly headingLevel = input<ChangeSummaryHeadingLevel | null, ChangeSummaryHeadingLevel | `${ChangeSummaryHeadingLevel}` | null | undefined>(null, {
|
|
163
|
+
transform: (v) => (v ? (Number(v) as ChangeSummaryHeadingLevel) : null),
|
|
164
|
+
});
|
|
165
|
+
/** The rows fade and rise in one after another when the card appears. `false` shows them at once. */
|
|
166
|
+
readonly animate = input(true, { transform: booleanAttribute });
|
|
167
|
+
/** The hidden words read after each change, per tone. */
|
|
168
|
+
readonly labels = input<Partial<ChangeSummaryLabels>>({});
|
|
169
|
+
|
|
170
|
+
protected readonly words = computed(() => ({ ...LABELS, ...this.labels() }));
|
|
171
|
+
protected readonly direction = DIRECTION;
|
|
172
|
+
protected readonly turn: Record<ChangeDirection, string> = { up: '0deg', down: '180deg', flat: 'calc(90deg * var(--_r))' };
|
|
173
|
+
readonly titleId = `ui-change-summary-${nextId++}`;
|
|
174
|
+
|
|
175
|
+
constructor() {
|
|
176
|
+
const host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
177
|
+
const destroyRef = inject(DestroyRef);
|
|
178
|
+
const sync = () => {
|
|
179
|
+
for (const el of host.querySelectorAll<HTMLElement>('.clip')) {
|
|
180
|
+
if (el.scrollWidth > el.clientWidth) el.title = el.textContent?.trim() ?? '';
|
|
181
|
+
else el.removeAttribute('title');
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
afterRenderEffect(() => {
|
|
185
|
+
this.changes();
|
|
186
|
+
this.title();
|
|
187
|
+
this.period();
|
|
188
|
+
sync();
|
|
189
|
+
});
|
|
190
|
+
afterNextRender(() => {
|
|
191
|
+
const view = host.ownerDocument.defaultView;
|
|
192
|
+
if (view?.ResizeObserver) {
|
|
193
|
+
const resize = new view.ResizeObserver(sync);
|
|
194
|
+
resize.observe(host);
|
|
195
|
+
destroyRef.onDestroy(() => resize.disconnect());
|
|
196
|
+
}
|
|
197
|
+
if (isDevMode() && !this.title().trim()) console.warn('ui-change-summary: give it a title; it names the region for screen readers.', host);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|