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,541 @@
|
|
|
1
|
+
// Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
|
|
2
|
+
/**
|
|
3
|
+
* Filter Menu, from Ochre (https://ochreui.dev).
|
|
4
|
+
* Needs ochre.css (the --ui-* tokens, .ui-btn-icon, .ui-sr and the shared keyframes), which `npx ochreui init` adds once.
|
|
5
|
+
*
|
|
6
|
+
* <ui-filter-menu [groups]="groups" [formField]="form.filters" />
|
|
7
|
+
* Grouped checkbox filters in one card, with a removable chip per pick and Clear all.
|
|
8
|
+
* The value is `{ [groupId]: optionId[] }`, via [(value)], signal forms, reactive forms or ngModel.
|
|
9
|
+
*
|
|
10
|
+
* Public styling hooks (set them on the element or any ancestor):
|
|
11
|
+
* --ui-filter-menu-width widest the card grows (default 400px; Classic adds its 20px tray)
|
|
12
|
+
* --ui-filter-menu-radius card corners (default 10px; Classic 20px)
|
|
13
|
+
* --ui-filter-menu-fill checked box fill (default: blue; Classic: ink)
|
|
14
|
+
* --ui-checkbox-edge unchecked box edge, shared with Checkbox (default: faint; var(--ui-border-input) gives 3:1)
|
|
15
|
+
*/
|
|
16
|
+
import {
|
|
17
|
+
Component,
|
|
18
|
+
DOCUMENT,
|
|
19
|
+
DestroyRef,
|
|
20
|
+
ElementRef,
|
|
21
|
+
Injector,
|
|
22
|
+
afterNextRender,
|
|
23
|
+
afterRenderEffect,
|
|
24
|
+
booleanAttribute,
|
|
25
|
+
computed,
|
|
26
|
+
forwardRef,
|
|
27
|
+
inject,
|
|
28
|
+
input,
|
|
29
|
+
isDevMode,
|
|
30
|
+
model,
|
|
31
|
+
output,
|
|
32
|
+
signal,
|
|
33
|
+
viewChild,
|
|
34
|
+
} from '@angular/core';
|
|
35
|
+
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
36
|
+
import { FormValueControl } from '@angular/forms/signals';
|
|
37
|
+
|
|
38
|
+
export interface FilterOption {
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly label: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FilterGroup {
|
|
44
|
+
readonly id: string;
|
|
45
|
+
readonly label: string;
|
|
46
|
+
readonly options: readonly FilterOption[];
|
|
47
|
+
/** Put in front of this group's chips, such as "Priority: ". */
|
|
48
|
+
readonly chipPrefix?: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Picked option ids per group id, in option order. Groups with nothing picked are left out. */
|
|
52
|
+
export type FilterValue = Readonly<Record<string, readonly string[]>>;
|
|
53
|
+
|
|
54
|
+
export interface FilterMenuLabels {
|
|
55
|
+
heading: string;
|
|
56
|
+
clearAll: string;
|
|
57
|
+
remove: (chip: string) => string;
|
|
58
|
+
more: (count: number, chips: readonly string[]) => string;
|
|
59
|
+
less: string;
|
|
60
|
+
picked: (count: number) => string;
|
|
61
|
+
options: (count: number) => string;
|
|
62
|
+
navigate: string;
|
|
63
|
+
select: string;
|
|
64
|
+
cleared: string;
|
|
65
|
+
added: (chip: string) => string;
|
|
66
|
+
removed: (chip: string) => string;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const LABELS: FilterMenuLabels = {
|
|
70
|
+
heading: 'Filters',
|
|
71
|
+
clearAll: 'Clear all',
|
|
72
|
+
remove: (c) => `Remove ${c}`,
|
|
73
|
+
more: (n, chips) => `+${n} more: ${chips.join(', ')}`,
|
|
74
|
+
less: 'Show less',
|
|
75
|
+
picked: (n) => (n === 1 ? '1 filter' : `${n} filters`),
|
|
76
|
+
options: (n) => (n === 1 ? '1 option' : `${n} options`),
|
|
77
|
+
navigate: 'to navigate',
|
|
78
|
+
select: 'to select',
|
|
79
|
+
cleared: 'All filters cleared',
|
|
80
|
+
added: (c) => `${c} added`,
|
|
81
|
+
removed: (c) => `${c} removed`,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
interface Chip {
|
|
85
|
+
readonly key: string;
|
|
86
|
+
readonly group: FilterGroup;
|
|
87
|
+
readonly option: FilterOption;
|
|
88
|
+
readonly text: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
interface Row {
|
|
92
|
+
readonly key: string;
|
|
93
|
+
readonly group: FilterGroup;
|
|
94
|
+
readonly option?: FilterOption;
|
|
95
|
+
readonly label: string;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const gKey = (g: FilterGroup) => `g\n${g.id}`;
|
|
99
|
+
const oKey = (g: FilterGroup, o: FilterOption) => `o\n${g.id}\n${o.id}`;
|
|
100
|
+
const EMPTY: FilterValue = {};
|
|
101
|
+
|
|
102
|
+
let nextId = 0;
|
|
103
|
+
|
|
104
|
+
const tray = (clean: string, delta: string) => `calc(${clean} + ${delta} * var(--_t))`;
|
|
105
|
+
const ms = (d: string) => `calc(${d} * var(--_m))`;
|
|
106
|
+
const CLIP = 'min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap';
|
|
107
|
+
const DROP = '0 1px 1px color-mix(in srgb, var(--ui-gray-1000) 6%, transparent)';
|
|
108
|
+
const ROW = `display: flex; align-items: center; inline-size: 100%; box-sizing: border-box; border-radius: ${tray('var(--ui-radius-sm)', '4px')}; text-align: start; transition: background-color calc(var(--_hd) * var(--_m)) var(--ui-ease-out)`;
|
|
109
|
+
const SOFT = 'color-mix(in srgb, var(--ui-text-muted) calc(40% * var(--_t)), var(--ui-text))';
|
|
110
|
+
const CHIP = `flex: none; display: inline-flex; align-items: center; gap: var(--ui-space-0-5); box-sizing: border-box; block-size: var(--_ch); padding-inline: ${tray('var(--ui-space-2)', '3px')} ${tray('3px', '1px')}; border-radius: ${tray('var(--ui-radius-sm)', '4px')}; background: var(--_cb); color: ${SOFT}; font: ${tray('var(--ui-text-sm)', '1px')} / ${tray('var(--ui-leading-xs)', '2.6px')} var(--ui-font-sans); font-weight: ${tray('var(--ui-weight-medium)', '-100')}`;
|
|
111
|
+
const SMALL = `font-size: ${tray('var(--ui-text-sm)', '0.5px')}; line-height: ${tray('var(--ui-leading-xs)', '2.6px')}`;
|
|
112
|
+
const COUNT = `flex: none; ${SMALL}; font-weight: var(--ui-weight-regular); font-variant-numeric: tabular-nums`;
|
|
113
|
+
const ICON = 'fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round';
|
|
114
|
+
const KEY = tray('var(--ui-space-4)', '6px');
|
|
115
|
+
|
|
116
|
+
/** Static geometry kept inline so the stylesheet stays under budget; --_t switches to Classic values. */
|
|
117
|
+
const S = {
|
|
118
|
+
card: `padding: ${tray('0px', 'var(--ui-space-4)')} ${tray('0px', 'var(--ui-space-4)')} ${tray('0px', '10px')}; border-radius: var(--ui-filter-menu-radius, ${tray('10px', '10px')}); background: color-mix(in srgb, var(--ui-bg-surface) calc(100% * var(--_t)), transparent); box-shadow: 0 0 0 calc(1px * var(--_t)) var(--ui-hairline), 0 1px 2px color-mix(in srgb, var(--ui-gray-1000) calc(6% * var(--_t)), transparent)`,
|
|
119
|
+
head: `display: flex; align-items: center; justify-content: space-between; gap: var(--ui-space-3); padding-block: ${tray('var(--ui-space-3)', '-12px')} ${tray('8px', '-8px')}; padding-inline: ${tray('var(--ui-space-4)', '-14px')} ${tray('10px', '-8px')}`,
|
|
120
|
+
title: `${CLIP}; font-size: calc(var(--ui-text-md) + 1px); line-height: ${tray('var(--ui-leading-lg)', '-5.4px')}; font-weight: ${tray('var(--ui-weight-medium)', '100')}; letter-spacing: calc(-0.15px * var(--_t))`,
|
|
121
|
+
clear: `flex: none; block-size: ${tray('var(--ui-control-h-sm)', '-1.4px')}; padding-inline: ${tray('var(--ui-space-2)', '-2px')}; border-radius: ${tray('var(--ui-radius-sm)', '2px')}; font-weight: ${tray('var(--ui-weight-medium)', '-100')}; transition: ${ms('160ms')} var(--ui-ease-out); transition-property: color, background-color, opacity`,
|
|
122
|
+
chips: `display: grid; grid-template-rows: var(--_g); transition: grid-template-rows ${ms('320ms')} var(--ui-ease-out)`,
|
|
123
|
+
clip: 'min-inline-size: 0; min-block-size: 0; overflow: clip',
|
|
124
|
+
line: `position: relative; display: flex; flex-wrap: var(--_fw); gap: ${tray('var(--ui-space-1)', '2px')}; padding: ${tray('0px', 'var(--ui-space-3)')} ${tray('var(--ui-space-4)', '-16px')} ${tray('var(--ui-space-3)', '-12px')}`,
|
|
125
|
+
chip: CHIP,
|
|
126
|
+
more: `${CHIP}; padding-inline: var(--ui-space-2)`,
|
|
127
|
+
text: `${CLIP}; max-inline-size: 180px`,
|
|
128
|
+
x: `--_s: var(--_xs); border-radius: ${tray('4px', '2px')}`,
|
|
129
|
+
xIcon: `width: ${tray('var(--ui-icon-xs)', '2px')}; height: ${tray('var(--ui-icon-xs)', '2px')}; stroke-width: ${tray('1.25px', '0.25px')}`,
|
|
130
|
+
list: `margin-inline: calc(-6px * var(--_t)); padding: ${tray('var(--ui-space-1)', '2px')} ${tray('var(--ui-space-1)', '-4px')} ${tray('var(--ui-space-1)', '-4px')}; border-block-start: calc(1px - 1px * var(--_t)) solid var(--ui-hairline)`,
|
|
131
|
+
header: `${ROW}; block-size: ${tray('var(--ui-control-h-md)', '4px')}; padding-inline: ${tray('var(--ui-space-2)', '-2px')} var(--ui-space-2); gap: ${tray('var(--ui-space-2)', '-1px')}; font-size: ${tray('var(--ui-text-base)', '1px')}; font-weight: var(--ui-weight-medium)`,
|
|
132
|
+
chevron: `flex: none; width: var(--ui-icon-md); height: var(--ui-icon-md); ${ICON}; stroke-width: ${tray('1.2px', '0.6px')}; rotate: calc(var(--_rot, -90deg) * var(--_dir)); transition: rotate ${ms('260ms')} var(--ui-ease-out)`,
|
|
133
|
+
name: CLIP,
|
|
134
|
+
count: `${COUNT}; color: var(--ui-text-placeholder)`,
|
|
135
|
+
picked: `${COUNT}; margin-inline-start: auto; color: var(--ui-text-muted)`,
|
|
136
|
+
body: `display: grid; grid-template-rows: var(--_g); padding-block: var(--_pb); transition: ${ms('320ms')} var(--ui-ease-out); transition-property: grid-template-rows, padding`,
|
|
137
|
+
options: `min-block-size: 0; overflow: clip; opacity: var(--_o); transition: opacity ${ms('220ms')} var(--ui-ease-out)`,
|
|
138
|
+
option: `${ROW}; block-size: ${tray('var(--ui-control-h-md)', '2px')}; padding-inline: ${tray('var(--ui-space-8)', '-26px')} ${tray('var(--ui-space-2)', '-2px')}; gap: ${tray('var(--ui-space-2)', '4px')}; color: ${SOFT}`,
|
|
139
|
+
box: `flex: none; display: grid; place-items: center; box-sizing: border-box; width: var(--_bs); height: var(--_bs); border: ${tray('0.5px', '0.5px')} solid var(--_e); border-radius: ${tray('4px', '2px')}; background: var(--_bx); box-shadow: ${DROP}; color: var(--_ck, var(--ui-text-on-neutral)); transition: ${ms(tray('160ms', '20ms'))} var(--ui-ease-out); transition-property: background-color, border-color`,
|
|
140
|
+
check: `width: ${tray('var(--ui-icon-xs)', '2px')}; height: ${tray('var(--ui-icon-xs)', '2px')}; ${ICON}; stroke-width: 2; stroke-dasharray: 1; stroke-dashoffset: var(--_k)`,
|
|
141
|
+
hints: `display: var(--_hn, flex); align-items: center; justify-content: space-between; gap: var(--ui-space-3); box-sizing: border-box; block-size: ${tray('var(--ui-space-8)', '4px')}; padding: ${tray('0px', '10px')} ${tray('var(--ui-space-3)', '-4px')} ${tray('0px', '4px')}; border-block-start: calc(1px - 1px * var(--_t)) solid var(--ui-hairline); color: var(--ui-text-muted); ${SMALL}`,
|
|
142
|
+
hint: `display: flex; align-items: center; gap: ${tray('2px', '4px')}`,
|
|
143
|
+
hintText: `display: inline-block; order: 3; margin-inline-start: ${tray('4px', '-2px')}`,
|
|
144
|
+
key: `display: inline-grid; place-items: center; box-sizing: border-box; width: ${KEY}; height: ${KEY}; border-radius: ${tray('4px', '2px')}; background: var(--ui-bg-surface); box-shadow: 0 0 0 ${tray('0.5px', '0.5px')} var(--ui-hairline), ${DROP}`,
|
|
145
|
+
keyIcon: `width: ${tray('9px', '4px')}; height: ${tray('9px', '4px')}; ${ICON}; stroke-width: 1.4`,
|
|
146
|
+
} as const;
|
|
147
|
+
|
|
148
|
+
@Component({
|
|
149
|
+
selector: 'ui-filter-menu',
|
|
150
|
+
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiFilterMenu), multi: true }],
|
|
151
|
+
host: {
|
|
152
|
+
role: 'group',
|
|
153
|
+
'[attr.aria-labelledby]': 'named ? null : uid + "t"',
|
|
154
|
+
'[attr.aria-disabled]': 'off() || null',
|
|
155
|
+
'[attr.data-tray]': 'tray() || null',
|
|
156
|
+
'(focusout)': 'left($event)',
|
|
157
|
+
},
|
|
158
|
+
template: `
|
|
159
|
+
<div class="card" [style]="S.card">
|
|
160
|
+
<div [style]="S.head">
|
|
161
|
+
<span dir="auto" [id]="uid + 't'" [title]="title()" [style]="S.title">{{ title() }}</span>
|
|
162
|
+
<button type="button" class="clear" [style]="S.clear" [disabled]="off() || !chips().length" (click)="clearAll()">{{ t().clearAll }}</button>
|
|
163
|
+
</div>
|
|
164
|
+
<div [class.on]="chips().length" [style]="S.chips">
|
|
165
|
+
<div [style]="S.clip">
|
|
166
|
+
<div #line [class.wrap]="tray() || expanded()" [style]="S.line">
|
|
167
|
+
@for (c of chips(); track c.key; let i = $index) {
|
|
168
|
+
<span class="chip" [class.off]="!tray() && !expanded() && i >= fit()" [class.pop]="fresh() === c.key" [style]="S.chip">
|
|
169
|
+
<span dir="auto" [title]="c.text" [style]="S.text">{{ c.text }}</span>
|
|
170
|
+
<button type="button" class="ui-btn-icon x" [style]="S.x" [attr.aria-label]="t().remove(c.text)" [disabled]="off()" (click)="remove(c)">
|
|
171
|
+
<svg class="ui-icon" viewBox="0 0 12 12" aria-hidden="true" [style]="S.xIcon"><path d="M3.6 3.6l4.8 4.8M8.4 3.6 3.6 8.4" /></svg>
|
|
172
|
+
</button>
|
|
173
|
+
</span>
|
|
174
|
+
}
|
|
175
|
+
@if (!tray() && chips().length) {
|
|
176
|
+
<button type="button" class="chip more" [style]="S.more" [class.off]="!expanded() && !overflow().length" [attr.aria-expanded]="expanded()" [disabled]="off()"
|
|
177
|
+
[attr.aria-label]="expanded() ? null : t().more(overflow().length, overflow())" (click)="expanded.set(!expanded())">
|
|
178
|
+
{{ expanded() ? t().less : '+' + (overflow().length || chips().length) }}
|
|
179
|
+
</button>
|
|
180
|
+
}
|
|
181
|
+
</div>
|
|
182
|
+
</div>
|
|
183
|
+
</div>
|
|
184
|
+
<div [style]="S.list" (keydown)="key($event)" (focusin)="landed($event)">
|
|
185
|
+
@for (g of view(); track g.group.id; let gi = $index) {
|
|
186
|
+
<section [attr.data-open]="g.open || null">
|
|
187
|
+
<button type="button" class="row" [style]="S.header" [attr.data-key]="g.key" [tabindex]="stop() === g.key ? 0 : -1" [disabled]="off()"
|
|
188
|
+
[attr.aria-expanded]="g.open" [attr.aria-controls]="uid + 'b' + gi" [attr.aria-describedby]="uid + 'd' + gi" (click)="setOpen(g.group, !g.open)">
|
|
189
|
+
<svg viewBox="0 0 16 16" aria-hidden="true" [style]="S.chevron"><path d="M4.5 6.25 8 9.75l3.5-3.5" /></svg>
|
|
190
|
+
<span dir="auto" [id]="uid + 'n' + gi" [title]="g.group.label" [style]="S.name">{{ g.group.label }}</span>
|
|
191
|
+
<span aria-hidden="true" [style]="S.count">{{ g.group.options.length }}</span>
|
|
192
|
+
@for (k of [g.count]; track 'k' + k) {
|
|
193
|
+
@if (k) {<span dir="auto" aria-hidden="true" [class.pop]="live" [style]="S.picked">{{ t().picked(k) }}</span>}
|
|
194
|
+
}
|
|
195
|
+
</button>
|
|
196
|
+
<span class="ui-sr" [id]="uid + 'd' + gi">{{ t().options(g.group.options.length) }}{{ g.count ? ', ' + t().picked(g.count) : '' }}</span>
|
|
197
|
+
<div role="group" [id]="uid + 'b' + gi" [attr.aria-labelledby]="uid + 'n' + gi" [inert]="!g.open" [style]="S.body">
|
|
198
|
+
<div [style]="S.options">
|
|
199
|
+
@for (o of g.options; track o.key) {
|
|
200
|
+
<button type="button" role="checkbox" class="row" [style]="S.option" [attr.data-key]="o.key" [tabindex]="stop() === o.key ? 0 : -1" [disabled]="off()"
|
|
201
|
+
[attr.aria-checked]="o.on" (click)="toggle(g.group, o.option)">
|
|
202
|
+
<span class="box" aria-hidden="true" [style]="S.box"><svg viewBox="0 0 16 16" [style]="S.check"><path pathLength="1" d="M4.2 8.3l2.5 2.5 5.1-5.6" /></svg></span>
|
|
203
|
+
<span dir="auto" [title]="o.option.label" [style]="S.name">{{ o.option.label }}</span>
|
|
204
|
+
</button>
|
|
205
|
+
}
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
</section>
|
|
209
|
+
}
|
|
210
|
+
</div>
|
|
211
|
+
</div>
|
|
212
|
+
@if (hints() && groups().length) {
|
|
213
|
+
<div aria-hidden="true" [style]="S.hints">
|
|
214
|
+
<span [style]="S.hint">
|
|
215
|
+
<kbd [style]="S.key + '; order: calc(2 * var(--_t))'"><svg viewBox="0 0 12 12" [style]="S.keyIcon"><path d="M6 9.5v-7M3 5.5l3-3 3 3" /></svg></kbd>
|
|
216
|
+
<kbd [style]="S.key + '; order: 1'"><svg viewBox="0 0 12 12" [style]="S.keyIcon"><path d="M6 2.5v7M3 6.5l3 3 3-3" /></svg></kbd>
|
|
217
|
+
<span class="ht" [style]="S.hintText">{{ t().navigate }}</span>
|
|
218
|
+
</span>
|
|
219
|
+
<span [style]="S.hint">
|
|
220
|
+
<kbd [style]="S.key"><svg viewBox="0 0 12 12" [style]="S.keyIcon"><path d="M9.5 2.5v4h-7M4.5 4.5l-2 2 2 2" /></svg></kbd>
|
|
221
|
+
<span class="ht" [style]="S.hintText">{{ t().select }}</span>
|
|
222
|
+
</span>
|
|
223
|
+
</div>
|
|
224
|
+
}
|
|
225
|
+
<span class="ui-sr" role="status">{{ message() }}</span>
|
|
226
|
+
`,
|
|
227
|
+
styles: `
|
|
228
|
+
:host {
|
|
229
|
+
--_t: var(--ui-look-tray, 0);
|
|
230
|
+
--_m: var(--ui-motion-scale, 1);
|
|
231
|
+
--_hd: calc(140ms + 20ms * var(--_t));
|
|
232
|
+
--_on: var(--ui-filter-menu-fill, color-mix(in srgb, var(--ui-bg-neutral-solid) calc(100% * var(--_t)), var(--ui-hue-blue)));
|
|
233
|
+
--_e: var(--ui-checkbox-edge, color-mix(in srgb, var(--ui-text) calc(26% - 12% * var(--_t)), transparent));
|
|
234
|
+
--_bx: color-mix(in srgb, var(--ui-text) calc(6% * var(--_t)), var(--ui-bg-surface));
|
|
235
|
+
--_bs: calc(14px + 6px * var(--_t));
|
|
236
|
+
--_ch: calc(var(--ui-space-6) + 6px * var(--_t));
|
|
237
|
+
--_xs: calc(18px + 4px * var(--_t));
|
|
238
|
+
--_cb: color-mix(in srgb, var(--ui-text) 8%, var(--ui-bg-surface));
|
|
239
|
+
--_dir: 1;
|
|
240
|
+
--_k: 1;
|
|
241
|
+
--_g: 0fr;
|
|
242
|
+
--_o: 0;
|
|
243
|
+
--_pb: 0px;
|
|
244
|
+
--_fw: nowrap;
|
|
245
|
+
display: block;
|
|
246
|
+
box-sizing: border-box;
|
|
247
|
+
inline-size: 100%;
|
|
248
|
+
max-inline-size: calc(var(--ui-filter-menu-width, 400px) + 20px * var(--_t));
|
|
249
|
+
padding: calc(var(--ui-space-1-5) * var(--_t));
|
|
250
|
+
border-radius: calc(var(--ui-filter-menu-radius, calc(10px + 10px * var(--_t))) + 4px * var(--_t));
|
|
251
|
+
background: color-mix(in srgb, var(--ui-tray-bg) calc(100% * var(--_t)), var(--ui-bg-surface));
|
|
252
|
+
box-shadow: 0 0 0 calc(0.5px - 0.5px * var(--_t)) var(--ui-hairline), 0 1px 2px color-mix(in srgb, var(--ui-gray-1000) calc(6% - 6% * var(--_t)), transparent);
|
|
253
|
+
color: var(--ui-text);
|
|
254
|
+
font: var(--ui-text-base) / calc(var(--ui-leading-base) - 1.4px * var(--_t)) var(--ui-font-sans);
|
|
255
|
+
}
|
|
256
|
+
:host(:dir(rtl)) { --_dir: -1; }
|
|
257
|
+
:host([aria-disabled]) { opacity: var(--ui-disabled-opacity); }
|
|
258
|
+
button { margin: 0; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; }
|
|
259
|
+
button:disabled { cursor: default; }
|
|
260
|
+
button:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset-inset); }
|
|
261
|
+
.clear { color: var(--ui-text-muted); }
|
|
262
|
+
.clear:disabled { opacity: var(--ui-disabled-opacity); }
|
|
263
|
+
@media (hover: hover) { .row:hover:not(:disabled), .clear:hover:not(:disabled), .more:hover, .x:hover:not(:disabled) { --_hd: calc(90ms + 70ms * var(--_t)); --_cb: color-mix(in srgb, var(--ui-text) 13%, var(--ui-bg-surface)); background: color-mix(in srgb, var(--ui-text) 6%, transparent); color: var(--ui-text); } }
|
|
264
|
+
.on, [data-open] { --_g: 1fr; --_rot: 0deg; --_o: 1; --_pb: calc(2px * var(--_t)) calc(var(--ui-space-1) + 2px * var(--_t)); }
|
|
265
|
+
section + section { margin-block-start: calc(2px * var(--_t)); }
|
|
266
|
+
.wrap { --_fw: wrap; }
|
|
267
|
+
.off { position: absolute; visibility: hidden; }
|
|
268
|
+
.x { color: color-mix(in srgb, var(--ui-text-muted) 80%, transparent); }
|
|
269
|
+
.pop { animation: ui-pop calc(260ms * var(--_m)) var(--ui-ease-spring), ui-fade-in calc(200ms * var(--_m)) var(--ui-ease-out); }
|
|
270
|
+
[aria-checked='true'] { --_e: var(--_on); --_bx: var(--_on); --_k: 0; }
|
|
271
|
+
[aria-checked='true'] path { transition: stroke-dashoffset calc(240ms * var(--_m)) var(--ui-ease-out) calc(40ms * var(--_m)); }
|
|
272
|
+
:host([data-tray]) .ht::first-letter { text-transform: uppercase; }
|
|
273
|
+
@media (pointer: coarse) {
|
|
274
|
+
:host { --_bs: calc(18px + 2px * var(--_t)); --_ch: var(--ui-space-8); --_xs: 26px; --_hn: none; }
|
|
275
|
+
}
|
|
276
|
+
@media (forced-colors: active) {
|
|
277
|
+
:host { --_e: CanvasText; --_bx: Canvas; --_on: Highlight; --_ck: HighlightText; }
|
|
278
|
+
:host, .card, .chip { outline: 1px solid; outline-offset: -1px; }
|
|
279
|
+
.card { outline-width: calc(1px * var(--_t)); }
|
|
280
|
+
.box { forced-color-adjust: none; }
|
|
281
|
+
}
|
|
282
|
+
`,
|
|
283
|
+
})
|
|
284
|
+
export class UiFilterMenu implements ControlValueAccessor, FormValueControl<FilterValue> {
|
|
285
|
+
/** The groups, top to bottom, each with its options. */
|
|
286
|
+
readonly groups = input.required<readonly FilterGroup[]>();
|
|
287
|
+
/** Picked option ids per group id. Bind `[(value)]`, `[formField]`, `formControlName` or `ngModel`. */
|
|
288
|
+
readonly value = model<FilterValue>(EMPTY);
|
|
289
|
+
/** Ids of the open groups. Leave it unset to start with the first group open. */
|
|
290
|
+
readonly open = model<readonly string[] | undefined>(undefined);
|
|
291
|
+
/** The title on top. Default: "Filters". */
|
|
292
|
+
readonly heading = input<string>();
|
|
293
|
+
/** Shows the keyboard hint row at the bottom. Hidden on touch screens either way. */
|
|
294
|
+
readonly hints = input(true, { transform: booleanAttribute });
|
|
295
|
+
/** Disables every control. Forms set it too. */
|
|
296
|
+
readonly disabled = input(false, { transform: booleanAttribute });
|
|
297
|
+
/** Words for the title, the buttons, the counts and the announcements, to translate them. */
|
|
298
|
+
readonly labels = input<Partial<FilterMenuLabels>>({});
|
|
299
|
+
/** Emits when focus leaves the menu. */
|
|
300
|
+
readonly touch = output<void>();
|
|
301
|
+
|
|
302
|
+
protected readonly S = S;
|
|
303
|
+
protected readonly uid = `ui-fm-${nextId++}-`;
|
|
304
|
+
private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
|
|
305
|
+
private readonly doc = inject(DOCUMENT);
|
|
306
|
+
private readonly injector = inject(Injector);
|
|
307
|
+
private readonly line = viewChild<ElementRef<HTMLElement>>('line');
|
|
308
|
+
protected readonly named = this.host.hasAttribute('aria-label') || this.host.hasAttribute('aria-labelledby');
|
|
309
|
+
private readonly formDisabled = signal(false);
|
|
310
|
+
private readonly active = signal<string | undefined>(undefined);
|
|
311
|
+
protected readonly tray = signal(false);
|
|
312
|
+
protected readonly fit = signal(Infinity);
|
|
313
|
+
protected readonly expanded = signal(false);
|
|
314
|
+
protected readonly fresh = signal<string | undefined>(undefined);
|
|
315
|
+
protected readonly message = signal('');
|
|
316
|
+
protected live = false;
|
|
317
|
+
private typed = '';
|
|
318
|
+
private typedAt = 0;
|
|
319
|
+
private onChange: (v: FilterValue) => void = () => {};
|
|
320
|
+
private onTouched: () => void = () => {};
|
|
321
|
+
|
|
322
|
+
protected readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
|
|
323
|
+
protected readonly title = computed(() => this.heading() ?? this.t().heading);
|
|
324
|
+
readonly off = computed(() => this.disabled() || this.formDisabled());
|
|
325
|
+
private readonly openIds = computed(() => new Set(this.open() ?? this.groups().slice(0, 1).map((g) => g.id)));
|
|
326
|
+
|
|
327
|
+
protected readonly view = computed(() => {
|
|
328
|
+
const value = this.value() ?? EMPTY;
|
|
329
|
+
const open = this.openIds();
|
|
330
|
+
return this.groups().map((group) => {
|
|
331
|
+
const picked = new Set(value[group.id] ?? []);
|
|
332
|
+
const options = group.options.map((option) => ({ option, key: oKey(group, option), on: picked.has(option.id) }));
|
|
333
|
+
return { group, key: gKey(group), open: open.has(group.id), options, count: options.filter((o) => o.on).length };
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
/** Picked options in group order, then option order. */
|
|
338
|
+
protected readonly chips = computed<Chip[]>(() =>
|
|
339
|
+
this.view().flatMap((g) =>
|
|
340
|
+
g.options.filter((o) => o.on).map((o) => ({ key: o.key, group: g.group, option: o.option, text: (g.group.chipPrefix ?? '') + o.option.label })),
|
|
341
|
+
),
|
|
342
|
+
);
|
|
343
|
+
protected readonly overflow = computed(() => (this.tray() ? [] : this.chips().slice(this.fit()).map((c) => c.text)));
|
|
344
|
+
|
|
345
|
+
/** Every reachable row, in arrow-key order: each header, then the options of open groups. */
|
|
346
|
+
private readonly rows = computed<Row[]>(() =>
|
|
347
|
+
this.view().flatMap((g) => [
|
|
348
|
+
{ key: g.key, group: g.group, label: g.group.label },
|
|
349
|
+
...(g.open ? g.options.map((o) => ({ key: o.key, group: g.group, option: o.option, label: o.option.label })) : []),
|
|
350
|
+
]),
|
|
351
|
+
);
|
|
352
|
+
/** The row that Tab lands on: the last one focused, or the first. */
|
|
353
|
+
protected readonly stop = computed(() => {
|
|
354
|
+
const rows = this.rows();
|
|
355
|
+
const a = this.active();
|
|
356
|
+
return rows.some((r) => r.key === a) ? a : rows[0]?.key;
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
constructor() {
|
|
360
|
+
afterRenderEffect(() => {
|
|
361
|
+
this.chips();
|
|
362
|
+
this.expanded();
|
|
363
|
+
this.measure();
|
|
364
|
+
});
|
|
365
|
+
afterNextRender(() => {
|
|
366
|
+
this.live = true;
|
|
367
|
+
const view = this.doc.defaultView;
|
|
368
|
+
const ro = view?.ResizeObserver && new view.ResizeObserver(() => this.measure());
|
|
369
|
+
ro?.observe(this.host);
|
|
370
|
+
const line = this.line()?.nativeElement;
|
|
371
|
+
if (line) ro?.observe(line);
|
|
372
|
+
this.doc.fonts?.ready.then(() => this.measure());
|
|
373
|
+
this.injector.get(DestroyRef).onDestroy(() => ro?.disconnect());
|
|
374
|
+
if (isDevMode() && !this.named && !this.title().trim()) {
|
|
375
|
+
console.warn('ui-filter-menu: give it a heading, or an aria-label that names the filters.', this.host);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/** Reads the look, and in Clean works out how many chips fit on one line before "+N". */
|
|
381
|
+
private measure() {
|
|
382
|
+
const line = this.line()?.nativeElement;
|
|
383
|
+
const view = this.doc.defaultView;
|
|
384
|
+
if (!line || !view) return;
|
|
385
|
+
const tray = view.getComputedStyle(this.host).getPropertyValue('--ui-look-tray').trim() === '1';
|
|
386
|
+
this.tray.set(tray);
|
|
387
|
+
if (tray) return;
|
|
388
|
+
const cs = view.getComputedStyle(line);
|
|
389
|
+
const px = (v: string) => parseFloat(v) || 0;
|
|
390
|
+
const room = line.clientWidth - px(cs.paddingLeft) - px(cs.paddingRight) + 0.5;
|
|
391
|
+
const gap = px(cs.columnGap);
|
|
392
|
+
if (room <= 1) return this.fit.set(Infinity);
|
|
393
|
+
const z = line.offsetWidth / line.getBoundingClientRect().width || 1;
|
|
394
|
+
const widths = [...line.querySelectorAll<HTMLElement>('.chip:not(.more)')].map((el) => el.getBoundingClientRect().width * z);
|
|
395
|
+
if (widths.reduce((sum, w) => sum + w + gap, -gap) <= room) return this.fit.set(Infinity);
|
|
396
|
+
let used = (line.querySelector('.more')?.getBoundingClientRect().width ?? 0) * z;
|
|
397
|
+
let k = 0;
|
|
398
|
+
while (k < widths.length && used + widths[k] + gap <= room) used += widths[k++] + gap;
|
|
399
|
+
this.fit.set(k);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
private commit(next: FilterValue, said: string) {
|
|
403
|
+
this.value.set(next);
|
|
404
|
+
this.onChange(next);
|
|
405
|
+
this.message.set(this.message() === said ? `${said} ` : said);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
protected toggle(group: FilterGroup, option: FilterOption) {
|
|
409
|
+
if (this.off()) return;
|
|
410
|
+
const value = this.value() ?? EMPTY;
|
|
411
|
+
const cur = value[group.id] ?? [];
|
|
412
|
+
const on = !cur.includes(option.id);
|
|
413
|
+
const set = new Set(on ? [...cur, option.id] : cur.filter((id) => id !== option.id));
|
|
414
|
+
const known = new Set(group.options.map((o) => o.id));
|
|
415
|
+
const list = [...group.options.map((o) => o.id).filter((id) => set.has(id)), ...[...set].filter((id) => !known.has(id))];
|
|
416
|
+
const next: Record<string, readonly string[]> = { ...value };
|
|
417
|
+
if (list.length) next[group.id] = list;
|
|
418
|
+
else delete next[group.id];
|
|
419
|
+
const text = (group.chipPrefix ?? '') + option.label;
|
|
420
|
+
this.fresh.set(on ? oKey(group, option) : undefined);
|
|
421
|
+
this.commit(next, on ? this.t().added(text) : this.t().removed(text));
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
protected remove(chip: Chip) {
|
|
425
|
+
const at = this.chips().indexOf(chip);
|
|
426
|
+
this.toggle(chip.group, chip.option);
|
|
427
|
+
afterNextRender(
|
|
428
|
+
() => {
|
|
429
|
+
const left = [...this.host.querySelectorAll<HTMLElement>('.chip:not(.off) > .x')];
|
|
430
|
+
const next = left[Math.min(at, left.length - 1)];
|
|
431
|
+
if (next) next.focus();
|
|
432
|
+
else this.focusRow(this.stop());
|
|
433
|
+
},
|
|
434
|
+
{ injector: this.injector },
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
protected clearAll() {
|
|
439
|
+
if (this.off()) return;
|
|
440
|
+
this.focusRow(this.stop());
|
|
441
|
+
const value = this.value() ?? EMPTY;
|
|
442
|
+
const next: Record<string, readonly string[]> = { ...value };
|
|
443
|
+
for (const g of this.groups()) {
|
|
444
|
+
const known = new Set(g.options.map((o) => o.id));
|
|
445
|
+
const rest = (value[g.id] ?? []).filter((id) => !known.has(id));
|
|
446
|
+
if (rest.length) next[g.id] = rest;
|
|
447
|
+
else delete next[g.id];
|
|
448
|
+
}
|
|
449
|
+
this.expanded.set(false);
|
|
450
|
+
this.fresh.set(undefined);
|
|
451
|
+
this.commit(next, this.t().cleared);
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
protected setOpen(group: FilterGroup, on: boolean) {
|
|
455
|
+
const cur = [...this.openIds()];
|
|
456
|
+
this.open.set(on ? [...cur.filter((id) => id !== group.id), group.id] : cur.filter((id) => id !== group.id));
|
|
457
|
+
const a = this.rows().find((r) => r.key === this.active());
|
|
458
|
+
if (!on && a?.option && a.group === group) this.active.set(gKey(group));
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
private focusRow(key: string | undefined) {
|
|
462
|
+
if (key === undefined) return;
|
|
463
|
+
this.active.set(key);
|
|
464
|
+
[...this.host.querySelectorAll<HTMLElement>('[data-key]')].find((el) => el.dataset['key'] === key)?.focus();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
protected landed(e: FocusEvent) {
|
|
468
|
+
const key = (e.target as HTMLElement).dataset?.['key'];
|
|
469
|
+
if (key) this.active.set(key);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
protected key(e: KeyboardEvent) {
|
|
473
|
+
const key = (e.target as HTMLElement).dataset?.['key'];
|
|
474
|
+
const rows = this.rows();
|
|
475
|
+
const i = rows.findIndex((r) => r.key === key);
|
|
476
|
+
if (i < 0 || e.altKey || e.ctrlKey || e.metaKey) return;
|
|
477
|
+
const row = rows[i];
|
|
478
|
+
const last = rows.length - 1;
|
|
479
|
+
const go = (to: number) => {
|
|
480
|
+
e.preventDefault();
|
|
481
|
+
this.focusRow(rows[to].key);
|
|
482
|
+
};
|
|
483
|
+
switch (e.key) {
|
|
484
|
+
case 'ArrowDown':
|
|
485
|
+
return go(Math.min(i + 1, last));
|
|
486
|
+
case 'ArrowUp':
|
|
487
|
+
return go(Math.max(i - 1, 0));
|
|
488
|
+
case 'Home':
|
|
489
|
+
return go(0);
|
|
490
|
+
case 'End':
|
|
491
|
+
return go(last);
|
|
492
|
+
case 'ArrowRight':
|
|
493
|
+
case 'ArrowLeft': {
|
|
494
|
+
e.preventDefault();
|
|
495
|
+
const rtl = (this.host.closest('[dir]')?.getAttribute('dir') ?? this.doc.defaultView?.getComputedStyle(this.host).direction) === 'rtl';
|
|
496
|
+
const isOpen = this.openIds().has(row.group.id);
|
|
497
|
+
if ((e.key === 'ArrowRight') !== rtl) {
|
|
498
|
+
if (row.option) return;
|
|
499
|
+
if (!isOpen) return this.setOpen(row.group, true);
|
|
500
|
+
if (rows[i + 1]?.option) this.focusRow(rows[i + 1].key);
|
|
501
|
+
} else if (row.option) {
|
|
502
|
+
this.focusRow(gKey(row.group));
|
|
503
|
+
this.setOpen(row.group, false);
|
|
504
|
+
} else if (isOpen) this.setOpen(row.group, false);
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (e.key.length !== 1 || e.key === ' ') return;
|
|
509
|
+
const now = Date.now();
|
|
510
|
+
this.typed = (now - this.typedAt > 600 ? '' : this.typed) + e.key.toLowerCase();
|
|
511
|
+
this.typedAt = now;
|
|
512
|
+
const from = this.typed.length > 1 ? i : i + 1;
|
|
513
|
+
const hit = [...rows.slice(from), ...rows.slice(0, from)].find((r) => r.label.toLowerCase().startsWith(this.typed));
|
|
514
|
+
if (hit) {
|
|
515
|
+
e.preventDefault();
|
|
516
|
+
this.focusRow(hit.key);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
protected left(e: FocusEvent) {
|
|
521
|
+
if (this.host.contains(e.relatedTarget as Node)) return;
|
|
522
|
+
this.onTouched();
|
|
523
|
+
this.touch.emit();
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
writeValue(v: FilterValue | null) {
|
|
527
|
+
this.value.set(v ?? EMPTY);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
registerOnChange(fn: (v: FilterValue) => void) {
|
|
531
|
+
this.onChange = fn;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
registerOnTouched(fn: () => void) {
|
|
535
|
+
this.onTouched = fn;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
setDisabledState(disabled: boolean) {
|
|
539
|
+
this.formDisabled.set(disabled);
|
|
540
|
+
}
|
|
541
|
+
}
|