-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy pathCommandPalette.css
More file actions
309 lines (275 loc) · 9.52 KB
/
Copy pathCommandPalette.css
File metadata and controls
309 lines (275 loc) · 9.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/**
* CommandPalette.css
*
* Styles for the Cmd/Ctrl+K command palette overlay.
*
* ## Design-token usage
* All colour values reference CSS custom properties from `src/index.css`:
* --bg, --surface, --border, --text, --muted, --accent
*
* Fallback hex values (e.g. `var(--accent, #58a6ff)`) are provided as a
* safety net for rendering environments where the custom properties are not
* yet defined. They mirror the default-theme values exactly — never diverge
* from `src/utils/tokens.ts`.
*
* ## WCAG 2.1 AA contrast ratios (verified against --bg #0d1117)
* Item labels --text #e6edf3 → ~13:1 ✓ AA
* Descriptions --muted #8b949e → 4.8:1 ✓ AA
* Accent highlight --accent #58a6ff → 5.2:1 ✓ AA (large text)
*
* ## Responsive breakpoints
* ≤ 480 px — reduced top padding, footer hidden (touch users rely on tap)
*
* ## Motion
* @media (prefers-reduced-motion: reduce) — entrance animation disabled
* [data-motion="reduced"] — runtime override (ReducedMotionContext)
*/
/* ── Overlay ─────────────────────────────────────────────────────────────── */
/**
* Full-viewport stacking context. `z-index: 80` places the palette above
* all page content (headers use ~10, modals use ~50, toasts use ~70).
*/
.cp-overlay {
position: fixed;
inset: 0;
z-index: 80;
display: flex;
align-items: flex-start;
justify-content: center;
/* Vertical offset keeps the palette in the upper-centre — a conventional
command-palette position that avoids covering the primary content area. */
padding-top: clamp(4rem, 12vh, 8rem);
padding-inline: 1rem;
}
/**
* Semi-opaque backdrop — dims background content without completely obscuring
* it, giving users context about where they are in the app.
* `backdrop-filter: blur` softens the visual seam on supporting browsers.
*/
.cp-backdrop {
position: absolute;
inset: 0;
background: rgba(7, 10, 14, 0.75);
backdrop-filter: blur(3px);
}
/* ── Dialog ──────────────────────────────────────────────────────────────── */
/**
* The palette card itself. `min(600px, 100%)` provides a comfortable width
* on desktop while remaining fully responsive on mobile.
*
* The subtle border uses `var(--accent)` at low opacity to stay visually
* coherent with the active-state highlight colour.
*/
.cp-dialog {
position: relative;
width: min(600px, 100%);
border: 1px solid rgba(88, 166, 255, 0.25); /* --accent at 25% opacity */
border-radius: 1rem;
background: linear-gradient(180deg, rgba(22, 28, 40, 0.99), rgba(13, 17, 23, 0.99));
box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
overflow: hidden;
animation: cpEnter 150ms ease-out;
}
/* ── Search row ──────────────────────────────────────────────────────────── */
/** Horizontal bar containing the decorative icon, input, and close button. */
.cp-search-row {
display: flex;
align-items: center;
gap: 0.5rem;
padding: 0.75rem 1rem;
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}
/** ⌘ glyph — purely decorative, aria-hidden in the component. */
.cp-search-icon {
font-size: 1rem;
color: var(--muted, #8b949e);
flex-shrink: 0;
}
/**
* Transparent background inherits from `.cp-dialog`.
* `caret-color` matches --accent for a cohesive accent treatment.
* No outline here — focus styles are managed globally by `src/styles/focus.css`
* and the caret is the only visible edit indicator needed inside the palette.
*/
.cp-input {
flex: 1;
background: transparent;
border: none;
outline: none;
color: var(--text, #e6edf3);
font-size: 1rem;
line-height: 1.5;
caret-color: var(--accent, #58a6ff);
}
.cp-input::placeholder {
color: var(--muted, #8b949e);
}
/** Close button — minimal styling; focus ring provided by :focus-visible. */
.cp-close {
display: flex;
align-items: center;
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 0.4rem;
padding: 0.15rem 0.45rem;
cursor: pointer;
color: var(--muted, #8b949e);
}
.cp-close:focus-visible {
/* 2 px outline at 2 px offset — matches the global focus style in focus.css */
outline: 2px solid var(--accent, #58a6ff);
outline-offset: 2px;
}
.cp-close kbd {
font-size: 0.75rem;
font-family: inherit;
color: inherit;
}
/* ── Results list ────────────────────────────────────────────────────────── */
/**
* Scrollable list of matching commands.
* `max-height: min(360px, 60vh)` prevents the palette from overflowing on
* short viewports. `overscroll-behavior: contain` stops scroll-chaining to
* the page body.
*/
.cp-list {
list-style: none;
margin: 0;
padding: 0.375rem 0;
max-height: min(360px, 60vh);
overflow-y: auto;
overscroll-behavior: contain;
}
/** Empty-state message — centred, muted, slightly smaller text. */
.cp-empty {
padding: 1.25rem 1rem;
text-align: center;
color: var(--muted, #8b949e);
font-size: 0.9rem;
}
/**
* Individual command item button.
*
* Full-width, zero-tabindex (keyboard nav uses arrow keys + aria-activedescendant).
* `transition: background 80ms` keeps hover/active feedback snappy without
* feeling instant.
*/
.cp-item {
display: flex;
align-items: center;
gap: 0.75rem;
width: 100%;
padding: 0.625rem 1rem;
background: transparent;
border: none;
cursor: pointer;
color: var(--text, #e6edf3);
text-align: left;
border-radius: 0;
transition: background 80ms;
/* Minimum touch target: 0.625rem top + bottom padding + ~1.25rem line-height
≈ 44 px — meets the WCAG 2.5.5 AA 44×44 px target. */
min-height: 44px;
}
.cp-item:focus-visible {
/* Inset outline avoids layout shift within the list container. */
outline: 2px solid var(--accent, #58a6ff);
outline-offset: -2px;
}
/** Active keyboard selection + hover share the same highlight colour. */
.cp-item--active,
.cp-item:hover {
background: rgba(88, 166, 255, 0.12); /* --accent at 12% opacity */
}
/** Icon column — fixed width keeps label text left-aligned across all items. */
.cp-item-icon {
font-size: 1.1rem;
flex-shrink: 0;
width: 1.5rem;
text-align: center;
}
/** Text column — fills available space; label and description stacked. */
.cp-item-text {
flex: 1;
min-width: 0; /* Allows text-overflow to work on flex children. */
display: flex;
flex-direction: column;
gap: 0.1rem;
}
/**
* Primary label — ~15 px medium weight.
* #e6edf3 on dark surface → ~13:1 contrast ✓ AA
*/
.cp-item-label {
font-size: 0.9375rem;
font-weight: 500;
}
/**
* Secondary description — smaller, muted.
* #8b949e on dark surface → ~4.8:1 contrast ✓ AA
* Truncated to prevent multi-line overflow in the fixed-height list.
*/
.cp-item-desc {
font-size: 0.8125rem;
color: var(--muted, #8b949e);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
/** ↵ keyboard hint shown only on navigation items (not callbacks). */
.cp-item-hint {
flex-shrink: 0;
}
.cp-item-hint kbd {
font-size: 0.75rem;
font-family: inherit;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 0.3rem;
padding: 0.1rem 0.35rem;
background: rgba(255, 255, 255, 0.05);
color: var(--muted, #8b949e);
}
/* ── Footer ──────────────────────────────────────────────────────────────── */
/**
* Keyboard legend row — purely visual; marked aria-hidden in the component.
* Hidden on small screens because touch users don't need keyboard hints.
*/
.cp-footer {
display: flex;
gap: 1rem;
padding: 0.5rem 1rem;
border-top: 1px solid rgba(255, 255, 255, 0.07);
color: var(--muted, #8b949e);
font-size: 0.75rem;
}
.cp-footer kbd {
font-family: inherit;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 0.3rem;
padding: 0.05rem 0.3rem;
background: rgba(255, 255, 255, 0.05);
color: var(--muted, #8b949e);
font-size: 0.7rem;
}
/* ── Entrance animation ───────────────────────────────────────────────────── */
/**
* Short slide-and-fade from slightly above the final position.
* 150 ms is fast enough to feel snappy but slow enough to avoid jarring users.
* Disabled entirely under prefers-reduced-motion and [data-motion="reduced"].
*/
@keyframes cpEnter {
from { opacity: 0; transform: translateY(-6px) scale(0.98); }
to { opacity: 1; transform: translateY(0) scale(1); }
}
@media (prefers-reduced-motion: reduce) {
.cp-dialog { animation: none; }
}
/** Runtime reduced-motion override from ReducedMotionContext. */
[data-motion="reduced"] .cp-dialog { animation: none; }
/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
/** Reduced top padding keeps the palette reachable with one thumb. */
.cp-overlay { padding-top: 2rem; padding-inline: 0.5rem; }
/** Footer keyboard hints are irrelevant on touch devices. */
.cp-footer { display: none; }
}