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,322 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Reaction Bar, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens and the ui-rise keyframes), which `npx ochreui init` adds once.
|
|
5
|
+
*
|
|
6
|
+
* <ui-reaction-bar>
|
|
7
|
+
* <button uiReaction="like" [(pressed)]="liked" [(count)]="likes"></button>
|
|
8
|
+
* <button uiReaction="comment" [(count)]="comments"></button>
|
|
9
|
+
* <button uiReaction="share" [count]="0"></button>
|
|
10
|
+
* </ui-reaction-bar>
|
|
11
|
+
* Each action is your own <button>: a toggle with aria-pressed and a count that rolls when it changes.
|
|
12
|
+
* Built-in icons for like, comment, repost and share; any other kind takes your <svg> and a label.
|
|
13
|
+
*
|
|
14
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
15
|
+
* --ui-reaction-bar-on pressed color, every action (default: blue); Clean look
|
|
16
|
+
* --ui-reaction-bar-like pressed like (default: pink) with data-ui-look="tray"
|
|
17
|
+
* --ui-reaction-bar-comment pressed comment (default: sky blue) with data-ui-look="tray"
|
|
18
|
+
* --ui-reaction-bar-repost pressed repost (default: purple) with data-ui-look="tray"
|
|
19
|
+
* --ui-reaction-bar-share pressed share and custom kinds (default: ink) with data-ui-look="tray"
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
Component,
|
|
23
|
+
DestroyRef,
|
|
24
|
+
ElementRef,
|
|
25
|
+
LOCALE_ID,
|
|
26
|
+
afterNextRender,
|
|
27
|
+
booleanAttribute,
|
|
28
|
+
computed,
|
|
29
|
+
inject,
|
|
30
|
+
input,
|
|
31
|
+
isDevMode,
|
|
32
|
+
model,
|
|
33
|
+
output,
|
|
34
|
+
viewChild,
|
|
35
|
+
} from '@angular/core';
|
|
36
|
+
|
|
37
|
+
export type ReactionKind = 'like' | 'comment' | 'repost' | 'share' | (string & {});
|
|
38
|
+
|
|
39
|
+
export interface ReactionLabels {
|
|
40
|
+
/** Name of the group. */
|
|
41
|
+
group: string;
|
|
42
|
+
/** Action names by kind: "Like". */
|
|
43
|
+
names: Record<string, string>;
|
|
44
|
+
/** Count nouns by kind and plural category: `{ one: 'like', other: 'likes' }`. */
|
|
45
|
+
units: Record<string, Partial<Record<Intl.LDMLPluralRule, string>>>;
|
|
46
|
+
/** The spoken name when there is a count. `{name}`, `{count}` and `{unit}` are filled in. */
|
|
47
|
+
withCount: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ReactionToggle {
|
|
51
|
+
pressed: boolean;
|
|
52
|
+
count: number | null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const LABELS: ReactionLabels = {
|
|
56
|
+
group: 'Reactions',
|
|
57
|
+
names: { like: 'Like', comment: 'Comment', repost: 'Repost', share: 'Share' },
|
|
58
|
+
units: {
|
|
59
|
+
like: { one: 'like', other: 'likes' },
|
|
60
|
+
comment: { one: 'comment', other: 'comments' },
|
|
61
|
+
repost: { one: 'repost', other: 'reposts' },
|
|
62
|
+
share: { one: 'share', other: 'shares' },
|
|
63
|
+
},
|
|
64
|
+
withCount: '{name}, {count} {unit}',
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
@Component({
|
|
68
|
+
selector: 'ui-reaction-bar',
|
|
69
|
+
host: {
|
|
70
|
+
role: 'group',
|
|
71
|
+
'[attr.aria-label]': 'ariaLabel() ?? texts().group',
|
|
72
|
+
},
|
|
73
|
+
template: '<ng-content />',
|
|
74
|
+
styles: `
|
|
75
|
+
:host {
|
|
76
|
+
--_t: var(--ui-look-tray, 0);
|
|
77
|
+
display: flex;
|
|
78
|
+
flex-wrap: wrap;
|
|
79
|
+
align-items: center;
|
|
80
|
+
justify-content: center;
|
|
81
|
+
inline-size: fit-content;
|
|
82
|
+
max-inline-size: 100%;
|
|
83
|
+
box-sizing: border-box;
|
|
84
|
+
gap: calc(var(--ui-space-1) - 2px * var(--_t));
|
|
85
|
+
padding: calc(var(--ui-space-1) * var(--_t)) calc(var(--ui-space-2-5) * var(--_t));
|
|
86
|
+
border-radius: var(--ui-radius-full);
|
|
87
|
+
background: color-mix(in srgb, var(--ui-bg-surface) calc(var(--_t) * 100%), transparent);
|
|
88
|
+
}
|
|
89
|
+
@container style(--ui-look-tray: 1) { :host { box-shadow: var(--ui-shadow-md); } }
|
|
90
|
+
@media (pointer: coarse) {
|
|
91
|
+
:host { gap: calc(var(--ui-space-1-5) - 4px * var(--_t)); }
|
|
92
|
+
}
|
|
93
|
+
@media (forced-colors: active) {
|
|
94
|
+
@container style(--ui-look-tray: 1) { :host { outline: 1px solid CanvasText; } }
|
|
95
|
+
}
|
|
96
|
+
`,
|
|
97
|
+
})
|
|
98
|
+
export class UiReactionBar {
|
|
99
|
+
/** Overrides the group name, "Reactions" by default. */
|
|
100
|
+
readonly ariaLabel = input<string>(undefined, { alias: 'aria-label' });
|
|
101
|
+
/** Translations of the group name, the action names and the count nouns. Merged over the English defaults. */
|
|
102
|
+
readonly labels = input<Partial<ReactionLabels>>({});
|
|
103
|
+
/** Turns a count into its text, for every action in the bar, e.g. `n => compact.format(n)`. Default: the locale's grouping, "1,284". */
|
|
104
|
+
readonly format = input<(n: number) => string>();
|
|
105
|
+
|
|
106
|
+
readonly texts = computed<ReactionLabels>(() => {
|
|
107
|
+
const l = this.labels();
|
|
108
|
+
return { ...LABELS, ...l, names: { ...LABELS.names, ...l.names }, units: { ...LABELS.units, ...l.units } };
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@Component({
|
|
113
|
+
selector: 'button[uiReaction]',
|
|
114
|
+
host: {
|
|
115
|
+
type: 'button',
|
|
116
|
+
style: 'display: inline-flex; align-items: center; justify-content: center; flex: none; box-sizing: border-box; -webkit-tap-highlight-color: transparent',
|
|
117
|
+
'[attr.data-kind]': 'kind()',
|
|
118
|
+
'[attr.aria-pressed]': 'pressed()',
|
|
119
|
+
'[attr.aria-label]': 'spoken()',
|
|
120
|
+
'(click)': 'toggle()',
|
|
121
|
+
},
|
|
122
|
+
template: `
|
|
123
|
+
<span class="ic" style="display: grid; aspect-ratio: 1" #ic>
|
|
124
|
+
@switch (kind()) {
|
|
125
|
+
@case ('like') {
|
|
126
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path class="f" d="M12 21.36c-.59 0-9.95-5.38-9.95-12.4A5.38 5.38 0 0 1 12 5.92a5.38 5.38 0 0 1 9.95 3.04c0 7.02-9.36 12.4-9.95 12.4Z" /></svg>
|
|
127
|
+
}
|
|
128
|
+
@case ('comment') {
|
|
129
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path class="f" d="M3.34 16.45a9.95 9.95 0 1 1 3.74 3.63l-5.03 1.87Z" /></svg>
|
|
130
|
+
}
|
|
131
|
+
@case ('repost') {
|
|
132
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="m16.5 3.5 3 3-3 3" /><path d="M4.5 11.5v-1a4 4 0 0 1 4-4h11" /><path d="m7.5 20.5-3-3 3-3" /><path d="M19.5 12.5v1a4 4 0 0 1-4 4h-11" /></svg>
|
|
133
|
+
}
|
|
134
|
+
@case ('share') {
|
|
135
|
+
<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M20.5 3.5 10.2 13.8" /><path d="M20.5 3.5 14 20.5l-3.8-6.7-6.7-3.8Z" /></svg>
|
|
136
|
+
}
|
|
137
|
+
@default {
|
|
138
|
+
<ng-content />
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
</span>
|
|
142
|
+
<span class="n" aria-hidden="true" style="flex: none; overflow: hidden; white-space: nowrap; font-variant-numeric: tabular-nums" #clip>
|
|
143
|
+
<span class="row" style="display: inline-flex" #row><span dir="ltr">@for (c of chars(); track c.key) {<span class="d" style="display: inline-block">{{ c.ch }}</span>}</span></span>
|
|
144
|
+
</span>
|
|
145
|
+
`,
|
|
146
|
+
styles: `
|
|
147
|
+
:host {
|
|
148
|
+
--_t: var(--ui-look-tray, 0);
|
|
149
|
+
--_h: calc(var(--ui-control-h-sm)*(1 - var(--_t)) + (var(--ui-space-10) + var(--ui-space-0-5))*var(--_t));
|
|
150
|
+
--_px: calc(var(--ui-space-2) + 2px*var(--_t));
|
|
151
|
+
--_e: cubic-bezier(.8, 0, .2, 1);
|
|
152
|
+
--_d: calc((160ms + 40ms*var(--_t))*var(--ui-motion-scale));
|
|
153
|
+
--_ink: color-mix(in srgb, var(--ui-text) 82%, var(--ui-bg-surface));
|
|
154
|
+
--_sky: color-mix(in srgb, var(--ui-cyan-dark) 70%, var(--ui-blue-dark));
|
|
155
|
+
--_k: var(--ui-reaction-bar-share, var(--ui-text));
|
|
156
|
+
--_on: color-mix(in srgb, var(--_k) calc(var(--_t)*100%), var(--ui-reaction-bar-on, light-dark(var(--ui-hue-blue), var(--_sky))));
|
|
157
|
+
--_c: color-mix(in srgb, var(--_ink) calc(var(--_t)*100%), var(--ui-text-muted));
|
|
158
|
+
--_i: color-mix(in srgb, var(--_ink) calc(var(--_t)*100%), color-mix(in srgb, var(--ui-text-muted) 75%, var(--ui-bg-surface)));
|
|
159
|
+
--_w: color-mix(in srgb, var(--ui-text) calc(3.5% + 1%*var(--_t)), transparent);
|
|
160
|
+
--_tint: color-mix(in srgb, light-dark(color-mix(in srgb, var(--_on) 50%, transparent), var(--_on)) calc(12% - 12%*var(--_t)), transparent);
|
|
161
|
+
--_ring: color-mix(in srgb, var(--ui-text) 7%, transparent);
|
|
162
|
+
--_bg: transparent;
|
|
163
|
+
block-size: var(--_h);
|
|
164
|
+
min-inline-size: calc(var(--_h)*var(--_t));
|
|
165
|
+
margin: 0;
|
|
166
|
+
padding: 0 var(--_px);
|
|
167
|
+
border: 0;
|
|
168
|
+
border-radius: calc(var(--ui-radius-sm) + var(--ui-radius-full)*var(--_t));
|
|
169
|
+
background: var(--_bg);
|
|
170
|
+
box-shadow: inset 0 0 0 .5px color-mix(in srgb, var(--_ring) calc(100% - var(--_t)*100%), transparent);
|
|
171
|
+
font: var(--ui-weight-medium) calc(var(--ui-text-base) + 1px*var(--_t))/var(--ui-leading-base) var(--ui-font-sans);
|
|
172
|
+
cursor: pointer;
|
|
173
|
+
transition: calc(160ms*var(--ui-motion-scale)) var(--ui-ease-out);
|
|
174
|
+
transition-property: background-color, box-shadow;
|
|
175
|
+
}
|
|
176
|
+
:host([data-kind='like']) { --_k: var(--ui-reaction-bar-like, light-dark(oklch(from var(--ui-hue-pink) calc(l + .035) calc(c*1.09) calc(h + 6)), var(--ui-hue-pink))); }
|
|
177
|
+
:host([data-kind='comment']) { --_k: var(--ui-reaction-bar-comment, var(--_sky)); }
|
|
178
|
+
:host([data-kind='repost']) { --_k: var(--ui-reaction-bar-repost, light-dark(oklch(from var(--ui-hue-purple) calc(l + .06) calc(c*1.26) h), var(--ui-hue-purple))); }
|
|
179
|
+
:host([aria-pressed='true']) {
|
|
180
|
+
--_c: var(--_on);
|
|
181
|
+
--_i: var(--_on);
|
|
182
|
+
--_ring: color-mix(in srgb, var(--_on) 45%, transparent);
|
|
183
|
+
--_bg: var(--_tint);
|
|
184
|
+
--_id: 0s;
|
|
185
|
+
}
|
|
186
|
+
@media (hover: hover) {
|
|
187
|
+
:host(:not(:disabled):hover) { --_bg: var(--_w); }
|
|
188
|
+
:host(:not(:disabled, [aria-pressed='true']):hover) {
|
|
189
|
+
--_c: color-mix(in srgb, var(--_ink) calc(var(--_t)*100%), var(--ui-text));
|
|
190
|
+
--_i: var(--_c);
|
|
191
|
+
}
|
|
192
|
+
:host([aria-pressed='true']:not(:disabled):hover) { --_bg: color-mix(in srgb, var(--_w) calc(var(--_t)*100%), var(--_tint)); }
|
|
193
|
+
}
|
|
194
|
+
:host(:focus-visible) { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
|
|
195
|
+
:host(:disabled) { opacity: var(--ui-disabled-opacity); cursor: default; }
|
|
196
|
+
.ic {
|
|
197
|
+
inline-size: calc(var(--ui-icon-md) + 6px*var(--_t));
|
|
198
|
+
color: var(--_i);
|
|
199
|
+
transition: color var(--_id, var(--_d)) var(--ui-ease-out);
|
|
200
|
+
}
|
|
201
|
+
.ic ::ng-deep svg {
|
|
202
|
+
inline-size: 100%;
|
|
203
|
+
block-size: 100%;
|
|
204
|
+
fill: none;
|
|
205
|
+
stroke: currentColor;
|
|
206
|
+
stroke-width: calc(1.65 - .05*var(--_t));
|
|
207
|
+
stroke-linecap: round;
|
|
208
|
+
stroke-linejoin: round;
|
|
209
|
+
}
|
|
210
|
+
:host([aria-pressed='true']) .f { fill: currentColor; }
|
|
211
|
+
.n {
|
|
212
|
+
block-size: var(--ui-leading-base);
|
|
213
|
+
color: var(--_c);
|
|
214
|
+
transition: width calc(400ms*var(--ui-motion-scale)) var(--_e), color var(--_d) var(--ui-ease-out);
|
|
215
|
+
}
|
|
216
|
+
.row { padding-inline: var(--ui-space-1-5) calc(2px - 2px*var(--_t)); }
|
|
217
|
+
.d {
|
|
218
|
+
--ui-rise-distance: calc(var(--ui-leading-base)*.7);
|
|
219
|
+
animation: ui-rise calc(400ms*var(--ui-motion-scale)) var(--_e) both;
|
|
220
|
+
}
|
|
221
|
+
@media (pointer: coarse) {
|
|
222
|
+
:host { --_px: var(--ui-space-2-5); }
|
|
223
|
+
}
|
|
224
|
+
@media (forced-colors: active) {
|
|
225
|
+
:host { outline: 1px solid CanvasText; outline-offset: -1px; }
|
|
226
|
+
:host([aria-pressed='true']:not(:disabled)) { forced-color-adjust: none; background: Highlight; --_c: HighlightText; --_i: HighlightText; }
|
|
227
|
+
:host(:disabled) { outline-color: GrayText; color: GrayText; }
|
|
228
|
+
}
|
|
229
|
+
`,
|
|
230
|
+
})
|
|
231
|
+
export class UiReaction {
|
|
232
|
+
/** `like`, `comment`, `repost` or `share` draw their own icon; any other kind shows the `<svg>` you put inside. */
|
|
233
|
+
readonly kind = input.required<ReactionKind>({ alias: 'uiReaction' });
|
|
234
|
+
/** On or off, as `aria-pressed`. Bind it two-way: `[(pressed)]`. */
|
|
235
|
+
readonly pressed = model(false);
|
|
236
|
+
/** The public count. `0` hides the number until someone reacts; `null` keeps it hidden and unchanged. */
|
|
237
|
+
readonly count = model<number | null>(null);
|
|
238
|
+
/** The action's name. Built-in kinds have one; a custom kind needs it. */
|
|
239
|
+
readonly label = input<string>();
|
|
240
|
+
/** Turns the count into its text. Default: the bar's `format`, else the locale's grouping. */
|
|
241
|
+
readonly format = input<(n: number) => string>();
|
|
242
|
+
/** When on, a click flips `pressed` and adds or removes one itself. Off: it only emits `toggled`, and you set both. */
|
|
243
|
+
readonly optimistic = input(true, { transform: booleanAttribute });
|
|
244
|
+
/** After a click, with the new state and count. */
|
|
245
|
+
readonly toggled = output<ReactionToggle>();
|
|
246
|
+
|
|
247
|
+
private readonly bar = inject(UiReactionBar, { optional: true });
|
|
248
|
+
private readonly el = inject<ElementRef<HTMLButtonElement>>(ElementRef).nativeElement;
|
|
249
|
+
private readonly locale = inject(LOCALE_ID);
|
|
250
|
+
private readonly ic = viewChild.required<ElementRef<HTMLElement>>('ic');
|
|
251
|
+
private readonly clip = viewChild.required<ElementRef<HTMLElement>>('clip');
|
|
252
|
+
private readonly row = viewChild.required<ElementRef<HTMLElement>>('row');
|
|
253
|
+
|
|
254
|
+
private readonly texts = computed(() => this.bar?.texts() ?? LABELS);
|
|
255
|
+
private readonly fmt = computed(() => {
|
|
256
|
+
const own = this.format() ?? this.bar?.format();
|
|
257
|
+
if (own) return own;
|
|
258
|
+
const nf = new Intl.NumberFormat(this.locale);
|
|
259
|
+
return (n: number) => nf.format(n);
|
|
260
|
+
});
|
|
261
|
+
private readonly plural = computed(() => new Intl.PluralRules(this.locale));
|
|
262
|
+
private readonly name = computed(() => this.label() ?? this.texts().names[this.kind()] ?? '');
|
|
263
|
+
private readonly text = computed(() => {
|
|
264
|
+
const n = this.count();
|
|
265
|
+
return n ? this.fmt()(n) : '';
|
|
266
|
+
});
|
|
267
|
+
protected readonly chars = computed(() => {
|
|
268
|
+
const s = [...this.text()];
|
|
269
|
+
return s.map((ch, i) => ({ ch, key: `${s.length}.${i}.${ch}` }));
|
|
270
|
+
});
|
|
271
|
+
protected readonly spoken = computed(() => {
|
|
272
|
+
const n = this.count();
|
|
273
|
+
const name = this.name();
|
|
274
|
+
if (!n) return name || null;
|
|
275
|
+
const l = this.texts();
|
|
276
|
+
const unit = l.units[this.kind()];
|
|
277
|
+
const word = unit?.[this.plural().select(n)] ?? unit?.other ?? '';
|
|
278
|
+
return l.withCount.replace('{name}', name).replace('{count}', this.text()).replace('{unit}', word).trim();
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
constructor() {
|
|
282
|
+
const destroy = inject(DestroyRef);
|
|
283
|
+
afterNextRender(() => {
|
|
284
|
+
if (isDevMode() && !this.name() && !this.el.hasAttribute('aria-label')) {
|
|
285
|
+
console.warn(`ui-reaction: give the "${this.kind()}" action a label.`, this.el);
|
|
286
|
+
}
|
|
287
|
+
const clip = this.clip().nativeElement;
|
|
288
|
+
const fit = () => {
|
|
289
|
+
const row = this.row().nativeElement;
|
|
290
|
+
clip.style.width = this.text() ? `${parseFloat(row.ownerDocument.defaultView?.getComputedStyle(row).width ?? '') || row.offsetWidth}px` : '0px';
|
|
291
|
+
};
|
|
292
|
+
fit();
|
|
293
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
294
|
+
const ro = new ResizeObserver(fit);
|
|
295
|
+
ro.observe(this.row().nativeElement);
|
|
296
|
+
destroy.onDestroy(() => ro.disconnect());
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
protected toggle() {
|
|
301
|
+
const on = !this.pressed();
|
|
302
|
+
const was = this.count();
|
|
303
|
+
const count = Math.max(0, (was ?? 0) + (on ? 1 : -1));
|
|
304
|
+
if (this.optimistic()) {
|
|
305
|
+
this.pressed.set(on);
|
|
306
|
+
if (was !== null) this.count.set(count);
|
|
307
|
+
}
|
|
308
|
+
this.pop();
|
|
309
|
+
this.toggled.emit({ pressed: on, count: was === null ? null : count });
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
private pop() {
|
|
313
|
+
const scale = parseFloat(this.el.ownerDocument.defaultView?.getComputedStyle(this.el).getPropertyValue('--ui-motion-scale') ?? '');
|
|
314
|
+
const k = Number.isNaN(scale) ? 1 : scale;
|
|
315
|
+
if (!k) return;
|
|
316
|
+
const e = 'ease-in-out';
|
|
317
|
+
this.ic().nativeElement.animate?.(
|
|
318
|
+
[{ scale: 1, easing: e }, { scale: 0.75, offset: 0.35, easing: e }, { scale: 1.12, offset: 0.65, easing: e }, { scale: 1 }],
|
|
319
|
+
{ duration: 320 * k },
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
}
|