@speles7172/controls 0.4.0 → 0.5.1
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/README.md +38 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/Calendar.d.ts +63 -0
- package/dist/Calendar.d.ts.map +1 -0
- package/dist/Calendar.js +220 -0
- package/dist/Calendar.js.map +1 -0
- package/dist/DateRangeFilter.d.ts +113 -0
- package/dist/DateRangeFilter.d.ts.map +1 -0
- package/dist/DateRangeFilter.js +247 -0
- package/dist/DateRangeFilter.js.map +1 -0
- package/dist/SearchableMultiSelect.d.ts.map +1 -1
- package/dist/SearchableMultiSelect.js +10 -1
- package/dist/SearchableMultiSelect.js.map +1 -1
- package/dist/index.d.ts +20 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -1
- package/dist/styles.css +375 -14
- package/dist/useAnchoredPopover.d.ts +71 -0
- package/dist/useAnchoredPopover.d.ts.map +1 -0
- package/dist/useAnchoredPopover.js +314 -0
- package/dist/useAnchoredPopover.js.map +1 -0
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -61,12 +61,31 @@ export { EmptyState, Loading, Skeleton, Spinner, TableSkeleton, } from './states
|
|
|
61
61
|
*/
|
|
62
62
|
export * from './icons.js';
|
|
63
63
|
export { ValueInput } from './ValueInput.js';
|
|
64
|
+
export { DateRangeFilter, } from './DateRangeFilter.js';
|
|
65
|
+
export { Calendar } from './Calendar.js';
|
|
64
66
|
export { KeyValueList, } from './KeyValueList.js';
|
|
65
67
|
export { useOptionSelect, } from './useOptionSelect.js';
|
|
68
|
+
/**
|
|
69
|
+
* Exported for the same reason {@link useOptionSelect} is: an application with
|
|
70
|
+
* its own design system renders its own popover, and placing one so it is not
|
|
71
|
+
* clipped by whatever scrolls around it is the part that is fiddly rather than
|
|
72
|
+
* decorative.
|
|
73
|
+
*/
|
|
74
|
+
export { useAnchoredPopover } from './useAnchoredPopover.js';
|
|
66
75
|
/**
|
|
67
76
|
* Re-exported from `@speles7172/controls-client/core` so a frontend that only
|
|
68
77
|
* renders controls does not need a second dependency to type its options or to
|
|
69
78
|
* filter a static list.
|
|
70
79
|
*/
|
|
71
80
|
export { groupOptions, highlightParts, matchOptions, matchRanges, scoreOption, } from '@speles7172/controls-client/core';
|
|
81
|
+
/**
|
|
82
|
+
* The date range vocabulary, re-exported for the same reason.
|
|
83
|
+
*
|
|
84
|
+
* A screen holding a `<DateRangeFilter>` has to be able to *say* what its
|
|
85
|
+
* filter covers — in a heading, in a chip, in the query string it puts in the
|
|
86
|
+
* URL — and every one of those is a function here rather than a second copy of
|
|
87
|
+
* the arithmetic. What resolves the value into two instants deliberately stays
|
|
88
|
+
* one implementation shared with the endpoint; see `resolveDateRange`.
|
|
89
|
+
*/
|
|
90
|
+
export { DATE_RANGE_PRESETS, MAX_RELATIVE_AMOUNT, dateRangeFromQuery, daysOfRange, describeDateRange, formatHebrewDate, formatHebrewMonth, hebrewFromCivil, hebrewNumeral, isEmptyDateRange, isRelativeDateRange, isSameDateRange, parseDateRange, presetsFor, resolveDateRange, serializeDateRange, } from '@speles7172/controls-client/core';
|
|
72
91
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EACL,qBAAqB,GAEtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAA8B,MAAM,uBAAuB,CAAC;AAErF,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,cAAc,GAIf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,IAAI,EAA+B,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAA0D,MAAM,YAAY,CAAC;AAEpH,OAAO,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EACR,OAAO,EACP,aAAa,GAMd,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,UAAU,EAA6C,MAAM,iBAAiB,CAAC;AAExF,OAAO,EACL,YAAY,GAIb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,eAAe,GAGhB,MAAM,sBAAsB,CAAC;AAE9B;;;;GAIG;AACH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,kCAAkC,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,OAAO,EACL,qBAAqB,GAEtB,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,gBAAgB,EAA8B,MAAM,uBAAuB,CAAC;AAErF,OAAO,EAAE,KAAK,EAAmB,MAAM,YAAY,CAAC;AAEpD,OAAO,EACL,SAAS,EACT,cAAc,GAIf,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,UAAU,EAAwB,MAAM,iBAAiB,CAAC;AAEnE,OAAO,EAAE,OAAO,EAAqB,MAAM,cAAc,CAAC;AAE1D,OAAO,EAAE,IAAI,EAA+B,MAAM,WAAW,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAkB,MAAM,WAAW,CAAC;AAEjD,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,UAAU,EAA0D,MAAM,YAAY,CAAC;AAEpH,OAAO,EAAE,WAAW,EAAyB,MAAM,kBAAkB,CAAC;AAEtE,OAAO,EACL,UAAU,EACV,OAAO,EACP,QAAQ,EACR,OAAO,EACP,aAAa,GAMd,MAAM,aAAa,CAAC;AAErB;;;GAGG;AACH,cAAc,YAAY,CAAC;AAE3B,OAAO,EAAE,UAAU,EAA6C,MAAM,iBAAiB,CAAC;AAExF,OAAO,EACL,eAAe,GAGhB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAE7D,OAAO,EACL,YAAY,GAIb,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EACL,eAAe,GAGhB,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;GAIG;AACH,OAAO,EACL,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,kCAAkC,CAAC;AAE1C;;;;;;;;GAQG;AACH,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,kCAAkC,CAAC"}
|
package/dist/styles.css
CHANGED
|
@@ -101,10 +101,40 @@
|
|
|
101
101
|
color: var(--ctl-text);
|
|
102
102
|
font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
103
103
|
font-size: var(--ctl-text-base);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* `.ctl` lays nothing out, and that is the whole of the rule.
|
|
108
|
+
*
|
|
109
|
+
* It is documented as the class a host puts on its own element to pick up the
|
|
110
|
+
* tokens — so a host writing `<form class="ctl flex flex-wrap items-end">` is
|
|
111
|
+
* writing utility classes that are also a single class: (0,1,0) against
|
|
112
|
+
* (0,1,0), settled by whichever stylesheet the bundler emitted last. A console
|
|
113
|
+
* imports its CSS from a component, so that is this one, and the form came out
|
|
114
|
+
* a column with its fields pushed to the cross-axis end — `items-end` applying
|
|
115
|
+
* while `flex-wrap` had nothing to wrap.
|
|
116
|
+
*
|
|
117
|
+
* `:where()` alone does not fix that, which is worth writing down because it
|
|
118
|
+
* looks as though it should. It makes the declaration (0,0,0), so a host wins
|
|
119
|
+
* every property it *declares* — and Tailwind's `flex` declares `display` and
|
|
120
|
+
* nothing else. `flex-direction: column` at any specificity still beats the
|
|
121
|
+
* initial `row`, so the form stayed a column until `flex-row` was written out
|
|
122
|
+
* as well. Measured in Chromium against a minified bundle, both ways.
|
|
123
|
+
*
|
|
124
|
+
* So the column moves to the three primitives that are one — `.ctl-select`,
|
|
125
|
+
* `.ctl-field` and `.ctl-kv` — and joins the ones already declaring their own
|
|
126
|
+
* box: `.ctl-page-head` a wrapping row, `.ctl-table-wrap` a block, `.ctl-tabs`
|
|
127
|
+
* a scrolling row, `.ctl-card` a column of its own. Every root is then laid out
|
|
128
|
+
* by its own class at (0,1,0) and `.ctl` is what it says it is: the tokens, the
|
|
129
|
+
* type, and nothing about the shape of somebody else's element.
|
|
130
|
+
*
|
|
131
|
+
* `position: relative` stays, at zero specificity, because it is the one part
|
|
132
|
+
* of the old default a consumer may have anchored something to. Nothing in here
|
|
133
|
+
* needs it: the popover is `position: fixed` (see below) and the one stretched
|
|
134
|
+
* `::after` sits inside `.ctl-card-clickable`, which declares its own.
|
|
135
|
+
*/
|
|
136
|
+
:where(.ctl) {
|
|
104
137
|
position: relative;
|
|
105
|
-
display: flex;
|
|
106
|
-
flex-direction: column;
|
|
107
|
-
gap: var(--ctl-space-1);
|
|
108
138
|
}
|
|
109
139
|
|
|
110
140
|
.ctl:where([data-ctl-theme="dark"]) {
|
|
@@ -176,6 +206,9 @@
|
|
|
176
206
|
* otherwise squash it to the width of the word "All".
|
|
177
207
|
*/
|
|
178
208
|
.ctl-select {
|
|
209
|
+
display: flex;
|
|
210
|
+
flex-direction: column;
|
|
211
|
+
gap: var(--ctl-space-1);
|
|
179
212
|
min-width: 160px;
|
|
180
213
|
}
|
|
181
214
|
|
|
@@ -306,31 +339,46 @@
|
|
|
306
339
|
/*
|
|
307
340
|
* The popover.
|
|
308
341
|
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
* the fix is on that ancestor, not here.
|
|
342
|
+
* Fixed rather than absolute, and placed by `useAnchoredPopover` from the
|
|
343
|
+
* control's own rectangle — so `top`, `bottom`, `left`, `width` and
|
|
344
|
+
* `max-height` all arrive as inline styles and are deliberately absent here.
|
|
313
345
|
*
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
346
|
+
* It was `position: absolute; top: 100%`, which is the obvious way to write it
|
|
347
|
+
* and is wrong wherever anything between the control and the page scrolls or
|
|
348
|
+
* clips. `sql-console`'s `.sqlc-panel` clipped the database picker's list
|
|
349
|
+
* partway down; `<Modal>`'s own body — `overflow-y: auto`, because a dialog
|
|
350
|
+
* taller than the screen has to scroll internally — pushed the folder picker's
|
|
351
|
+
* options under the dialog footer, where they could only be reached by noticing
|
|
352
|
+
* a new scrollbar. The advice this comment used to give, that the host must
|
|
353
|
+
* stop clipping, is not advice a host can take when the clipping ancestor is
|
|
354
|
+
* this package's own dialog.
|
|
355
|
+
*
|
|
356
|
+
* Still not portalled: a console bridges its palette onto `--ctl-*` with a
|
|
357
|
+
* descendant selector, and a portal to `document.body` escapes it — so a dark
|
|
358
|
+
* console would open a light list. Fixed positioning leaves the element in the
|
|
359
|
+
* tree and steps out of the scroll container at the same time.
|
|
360
|
+
*
|
|
361
|
+
* `overflow: hidden` pairs with the inline `max-height`: the list scrolls
|
|
362
|
+
* inside, and this is what keeps a footer from spilling past a rounded corner
|
|
363
|
+
* in a window too short for the whole popover.
|
|
317
364
|
*/
|
|
318
365
|
.ctl-popover {
|
|
319
|
-
position:
|
|
320
|
-
top: 100%;
|
|
366
|
+
position: fixed;
|
|
321
367
|
z-index: 30;
|
|
322
368
|
display: flex;
|
|
323
369
|
flex-direction: column;
|
|
324
|
-
width: 100%;
|
|
325
370
|
min-width: 220px;
|
|
326
|
-
|
|
371
|
+
overflow: hidden;
|
|
327
372
|
background: var(--ctl-bg);
|
|
328
373
|
border: 1px solid var(--ctl-border);
|
|
329
374
|
border-radius: var(--ctl-radius);
|
|
330
375
|
box-shadow: var(--ctl-shadow);
|
|
331
376
|
}
|
|
332
377
|
|
|
378
|
+
/* Never squeezed: the search box is what makes a bounded popover usable at all,
|
|
379
|
+
so the list gives up its height and this does not. */
|
|
333
380
|
.ctl-search {
|
|
381
|
+
flex-shrink: 0;
|
|
334
382
|
padding: 6px;
|
|
335
383
|
border-bottom: 1px solid var(--ctl-border);
|
|
336
384
|
}
|
|
@@ -357,7 +405,11 @@
|
|
|
357
405
|
list-style: none;
|
|
358
406
|
}
|
|
359
407
|
|
|
408
|
+
/* `min-height: 0` so the list can shrink below its content when the popover is
|
|
409
|
+
bounded to the room available — a flex item defaults to `min-height: auto`,
|
|
410
|
+
which is what lets an overflowing child push a capped container open. */
|
|
360
411
|
.ctl-list {
|
|
412
|
+
min-height: 0;
|
|
361
413
|
max-height: 260px;
|
|
362
414
|
overflow-y: auto;
|
|
363
415
|
}
|
|
@@ -452,6 +504,7 @@
|
|
|
452
504
|
|
|
453
505
|
.ctl-popover-footer:not(:empty) {
|
|
454
506
|
display: flex;
|
|
507
|
+
flex-shrink: 0;
|
|
455
508
|
gap: 10px;
|
|
456
509
|
padding: 6px 8px;
|
|
457
510
|
border-top: 1px solid var(--ctl-border);
|
|
@@ -481,6 +534,8 @@
|
|
|
481
534
|
*/
|
|
482
535
|
|
|
483
536
|
.ctl-field {
|
|
537
|
+
display: flex;
|
|
538
|
+
flex-direction: column;
|
|
484
539
|
gap: 6px;
|
|
485
540
|
}
|
|
486
541
|
|
|
@@ -549,6 +604,8 @@
|
|
|
549
604
|
*/
|
|
550
605
|
|
|
551
606
|
.ctl-kv {
|
|
607
|
+
display: flex;
|
|
608
|
+
flex-direction: column;
|
|
552
609
|
gap: 6px;
|
|
553
610
|
}
|
|
554
611
|
|
|
@@ -1144,9 +1201,21 @@
|
|
|
1144
1201
|
color: var(--ctl-accent);
|
|
1145
1202
|
}
|
|
1146
1203
|
|
|
1204
|
+
/*
|
|
1205
|
+
* `text-align: start` is stated rather than left to the browser, because a
|
|
1206
|
+
* `rowHeader` column renders `<th scope="row">` — which is what a screen reader
|
|
1207
|
+
* needs to announce a row by the thing that names it — and a `th` defaults to
|
|
1208
|
+
* `center`. `.ctl-th` says `start` and this did not, so the one column naming
|
|
1209
|
+
* each row was the one column not lining up with its own heading, while every
|
|
1210
|
+
* `<td>` beside it started at the edge. It stays above `.ctl-align-*`: those are
|
|
1211
|
+
* a single class too, so a column asking to be end-aligned wins here on source
|
|
1212
|
+
* order — which is why this is a bare `.ctl-td` and not `th.ctl-td`, since
|
|
1213
|
+
* (0,1,1) would outrank them and pin every row header to the start edge.
|
|
1214
|
+
*/
|
|
1147
1215
|
.ctl-td {
|
|
1148
1216
|
padding: var(--ctl-space-3);
|
|
1149
1217
|
font-size: var(--ctl-text-base);
|
|
1218
|
+
text-align: start;
|
|
1150
1219
|
vertical-align: top;
|
|
1151
1220
|
border-top: 1px solid var(--ctl-border);
|
|
1152
1221
|
}
|
|
@@ -1285,6 +1354,10 @@
|
|
|
1285
1354
|
.ctl-skeleton-table {
|
|
1286
1355
|
display: flex;
|
|
1287
1356
|
flex-direction: column;
|
|
1357
|
+
/* Stated, not inherited from `.ctl`, which no longer lays anything out. It
|
|
1358
|
+
was 4px before that and the rows closed up by 8px without it — the one
|
|
1359
|
+
thing in this stylesheet that was taking its gap from the root. */
|
|
1360
|
+
gap: var(--ctl-space-1);
|
|
1288
1361
|
overflow: hidden;
|
|
1289
1362
|
border: 1px solid var(--ctl-border);
|
|
1290
1363
|
border-radius: var(--ctl-radius);
|
|
@@ -1451,3 +1524,291 @@
|
|
|
1451
1524
|
display: none;
|
|
1452
1525
|
}
|
|
1453
1526
|
}
|
|
1527
|
+
|
|
1528
|
+
/*
|
|
1529
|
+
* The date range filter, and the calendar it opens.
|
|
1530
|
+
*
|
|
1531
|
+
* Two rules do most of the work here and are worth naming. The grid is a real
|
|
1532
|
+
* `<table>`, so its cells are laid out by the table algorithm and every column
|
|
1533
|
+
* is the same width without a `grid-template` to keep in step with the seven
|
|
1534
|
+
* headings. And every direction is logical: the calendar is the one control
|
|
1535
|
+
* here most likely to be read right-to-left, and `text-align: left` on a
|
|
1536
|
+
* weekday heading is invisible in English and wrong in Hebrew.
|
|
1537
|
+
*/
|
|
1538
|
+
|
|
1539
|
+
.ctl-daterange {
|
|
1540
|
+
display: flex;
|
|
1541
|
+
flex-direction: column;
|
|
1542
|
+
gap: var(--ctl-space-1);
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
/* Inside the trigger, so the caret keeps its own corner. */
|
|
1546
|
+
.ctl-daterange-icon {
|
|
1547
|
+
display: inline-flex;
|
|
1548
|
+
flex-shrink: 0;
|
|
1549
|
+
color: var(--ctl-faint);
|
|
1550
|
+
}
|
|
1551
|
+
|
|
1552
|
+
/* The trigger is `space-between` and this one has three children rather than
|
|
1553
|
+
two, so without the slack going to the value it sits in the middle of the
|
|
1554
|
+
control — which reads as a heading rather than as what the field is set to. */
|
|
1555
|
+
.ctl-daterange .ctl-value {
|
|
1556
|
+
flex: 1;
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
/*
|
|
1560
|
+
* Wider than the picker popover, because a calendar has seven columns and a
|
|
1561
|
+
* list of presets beside it. `max-width` in view units rather than a second
|
|
1562
|
+
* fixed number: `useAnchoredPopover` caps the width to the room there is, and
|
|
1563
|
+
* this keeps the two panels side by side until there is not room for them.
|
|
1564
|
+
*/
|
|
1565
|
+
.ctl-daterange-popover {
|
|
1566
|
+
min-width: 280px;
|
|
1567
|
+
max-width: min(560px, 96vw);
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
.ctl-daterange-panels {
|
|
1571
|
+
display: flex;
|
|
1572
|
+
gap: var(--ctl-space-3);
|
|
1573
|
+
min-height: 0;
|
|
1574
|
+
padding: var(--ctl-space-3);
|
|
1575
|
+
overflow-y: auto;
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
.ctl-daterange-presets {
|
|
1579
|
+
flex-shrink: 0;
|
|
1580
|
+
min-width: 140px;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
.ctl-daterange-preset-list {
|
|
1584
|
+
display: flex;
|
|
1585
|
+
flex-direction: column;
|
|
1586
|
+
gap: 2px;
|
|
1587
|
+
padding: 0;
|
|
1588
|
+
margin: 0;
|
|
1589
|
+
list-style: none;
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
.ctl-daterange-preset {
|
|
1593
|
+
display: block;
|
|
1594
|
+
width: 100%;
|
|
1595
|
+
padding: 6px var(--ctl-space-2);
|
|
1596
|
+
font: inherit;
|
|
1597
|
+
color: inherit;
|
|
1598
|
+
text-align: start;
|
|
1599
|
+
cursor: pointer;
|
|
1600
|
+
background: none;
|
|
1601
|
+
border: 0;
|
|
1602
|
+
border-radius: var(--ctl-radius-sm);
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
.ctl-daterange-preset:hover {
|
|
1606
|
+
background: var(--ctl-hover);
|
|
1607
|
+
}
|
|
1608
|
+
|
|
1609
|
+
.ctl-daterange-preset[aria-pressed='true'] {
|
|
1610
|
+
font-weight: 500;
|
|
1611
|
+
color: var(--ctl-accent);
|
|
1612
|
+
background: var(--ctl-accent-soft);
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
.ctl-daterange-detail {
|
|
1616
|
+
display: flex;
|
|
1617
|
+
flex: 1;
|
|
1618
|
+
flex-direction: column;
|
|
1619
|
+
gap: var(--ctl-space-3);
|
|
1620
|
+
min-width: 0;
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
.ctl-daterange-row {
|
|
1624
|
+
display: flex;
|
|
1625
|
+
flex-wrap: wrap;
|
|
1626
|
+
gap: var(--ctl-space-2);
|
|
1627
|
+
align-items: flex-end;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
.ctl-daterange-relative {
|
|
1631
|
+
display: flex;
|
|
1632
|
+
flex-direction: column;
|
|
1633
|
+
gap: var(--ctl-space-1);
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
.ctl-daterange-directions,
|
|
1637
|
+
.ctl-daterange-units {
|
|
1638
|
+
display: flex;
|
|
1639
|
+
flex-wrap: wrap;
|
|
1640
|
+
gap: 4px;
|
|
1641
|
+
}
|
|
1642
|
+
|
|
1643
|
+
/* A chip is a choice among a few: a unit, a direction, a calendar. Pill-shaped
|
|
1644
|
+
so it never reads as the button that applies something. */
|
|
1645
|
+
.ctl-daterange-chip {
|
|
1646
|
+
padding: 4px var(--ctl-space-2);
|
|
1647
|
+
font: inherit;
|
|
1648
|
+
font-size: var(--ctl-text-sm);
|
|
1649
|
+
color: var(--ctl-muted);
|
|
1650
|
+
cursor: pointer;
|
|
1651
|
+
background: var(--ctl-bg);
|
|
1652
|
+
border: 1px solid var(--ctl-border);
|
|
1653
|
+
border-radius: var(--ctl-radius-pill);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
.ctl-daterange-chip:hover {
|
|
1657
|
+
background: var(--ctl-hover);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
.ctl-daterange-chip[aria-pressed='true'] {
|
|
1661
|
+
color: var(--ctl-accent-text);
|
|
1662
|
+
background: var(--ctl-accent);
|
|
1663
|
+
border-color: var(--ctl-accent);
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
.ctl-daterange-field {
|
|
1667
|
+
display: flex;
|
|
1668
|
+
flex: 1;
|
|
1669
|
+
flex-direction: column;
|
|
1670
|
+
gap: 2px;
|
|
1671
|
+
min-width: 120px;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
.ctl-daterange-amount {
|
|
1675
|
+
width: 72px;
|
|
1676
|
+
flex-shrink: 0;
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
.ctl-cal {
|
|
1680
|
+
display: flex;
|
|
1681
|
+
flex-direction: column;
|
|
1682
|
+
gap: var(--ctl-space-1);
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1685
|
+
.ctl-cal-head {
|
|
1686
|
+
display: flex;
|
|
1687
|
+
gap: var(--ctl-space-2);
|
|
1688
|
+
align-items: center;
|
|
1689
|
+
justify-content: space-between;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
.ctl-cal-title {
|
|
1693
|
+
font-size: var(--ctl-text-sm);
|
|
1694
|
+
font-weight: 500;
|
|
1695
|
+
color: var(--ctl-text);
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
.ctl-cal-step {
|
|
1699
|
+
display: inline-flex;
|
|
1700
|
+
padding: 4px;
|
|
1701
|
+
color: var(--ctl-muted);
|
|
1702
|
+
cursor: pointer;
|
|
1703
|
+
background: none;
|
|
1704
|
+
border: 0;
|
|
1705
|
+
border-radius: var(--ctl-radius-sm);
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
.ctl-cal-step:hover {
|
|
1709
|
+
color: var(--ctl-text);
|
|
1710
|
+
background: var(--ctl-hover);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
.ctl-cal-grid {
|
|
1714
|
+
width: 100%;
|
|
1715
|
+
border-collapse: collapse;
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
.ctl-cal-weekday {
|
|
1719
|
+
padding: 2px 0;
|
|
1720
|
+
font-size: var(--ctl-text-xs);
|
|
1721
|
+
font-weight: 500;
|
|
1722
|
+
color: var(--ctl-faint);
|
|
1723
|
+
text-align: center;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
.ctl-cal-cell {
|
|
1727
|
+
padding: 1px;
|
|
1728
|
+
text-align: center;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
/* A day of another month. Kept as a cell rather than dropped, so the week it is
|
|
1732
|
+
in still has seven columns and the grid stays a grid to a screen reader. */
|
|
1733
|
+
.ctl-cal-blank {
|
|
1734
|
+
/* Nothing to draw, and nothing to announce. */
|
|
1735
|
+
visibility: hidden;
|
|
1736
|
+
}
|
|
1737
|
+
|
|
1738
|
+
.ctl-cal-day {
|
|
1739
|
+
width: 100%;
|
|
1740
|
+
min-width: 32px;
|
|
1741
|
+
padding: 6px 0;
|
|
1742
|
+
font: inherit;
|
|
1743
|
+
font-size: var(--ctl-text-sm);
|
|
1744
|
+
color: var(--ctl-text);
|
|
1745
|
+
cursor: pointer;
|
|
1746
|
+
background: none;
|
|
1747
|
+
border: 0;
|
|
1748
|
+
border-radius: var(--ctl-radius-sm);
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
.ctl-cal-day:hover:not(:disabled) {
|
|
1752
|
+
background: var(--ctl-hover);
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
.ctl-cal-day:disabled {
|
|
1756
|
+
color: var(--ctl-faint);
|
|
1757
|
+
cursor: default;
|
|
1758
|
+
opacity: 0.6;
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
/* The wash between the two ends, and the two ends themselves. Drawn as a range
|
|
1762
|
+
while the pointer is over a candidate second end, so a range is something you
|
|
1763
|
+
see before you commit to it. */
|
|
1764
|
+
.ctl-cal-day-in-range {
|
|
1765
|
+
background: var(--ctl-selected);
|
|
1766
|
+
border-radius: 0;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
.ctl-cal-day-selected,
|
|
1770
|
+
.ctl-cal-day-selected.ctl-cal-day-in-range {
|
|
1771
|
+
color: var(--ctl-accent-text);
|
|
1772
|
+
background: var(--ctl-accent);
|
|
1773
|
+
border-radius: var(--ctl-radius-sm);
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
/* Today is named by a ring rather than by a fill: a fill is what "selected"
|
|
1777
|
+
means two rules above, and one screen cannot spend the same signal twice. */
|
|
1778
|
+
.ctl-cal-day-today:not(.ctl-cal-day-selected) {
|
|
1779
|
+
box-shadow: inset 0 0 0 1px var(--ctl-accent);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
.ctl-cal-step:focus-visible,
|
|
1783
|
+
.ctl-cal-day:focus-visible,
|
|
1784
|
+
.ctl-daterange-preset:focus-visible,
|
|
1785
|
+
.ctl-daterange-chip:focus-visible {
|
|
1786
|
+
outline: 2px solid var(--ctl-accent);
|
|
1787
|
+
outline-offset: -1px;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
/*
|
|
1791
|
+
* Under about 480px the two panels stop fitting side by side — the calendar
|
|
1792
|
+
* alone wants seven columns of tappable squares. They stack, and the presets go
|
|
1793
|
+
* on top, because a named range is what most people came for.
|
|
1794
|
+
*/
|
|
1795
|
+
@media (max-width: 480px) {
|
|
1796
|
+
.ctl-daterange-panels {
|
|
1797
|
+
flex-direction: column;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
.ctl-daterange-presets {
|
|
1801
|
+
min-width: 0;
|
|
1802
|
+
}
|
|
1803
|
+
|
|
1804
|
+
.ctl-daterange-preset-list {
|
|
1805
|
+
flex-direction: row;
|
|
1806
|
+
flex-wrap: wrap;
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
.ctl-daterange-preset {
|
|
1810
|
+
width: auto;
|
|
1811
|
+
border: 1px solid var(--ctl-border);
|
|
1812
|
+
border-radius: var(--ctl-radius-pill);
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Pin a popover to its anchor, in viewport coordinates.
|
|
4
|
+
*
|
|
5
|
+
* `.ctl-popover` was `position: absolute; top: 100%` against the control, which
|
|
6
|
+
* is the obvious way to write it and is wrong in the one place these controls
|
|
7
|
+
* are used most: inside a dialog. `<Modal>`'s body is `overflow-y: auto` — it
|
|
8
|
+
* has to be, or a tall dialog scrolls the backdrop and its close button ends up
|
|
9
|
+
* somewhere nobody can reach — so an absolutely positioned popover is part of
|
|
10
|
+
* that box's scrollable content. Opening the folder picker in
|
|
11
|
+
* `config-console`'s editor took the body's `scrollHeight` from 446 to 583
|
|
12
|
+
* against a `clientHeight` of 446: the options were *there*, under the footer,
|
|
13
|
+
* and the operator had to notice a new scrollbar and scroll to them. The same
|
|
14
|
+
* shape clipped `sql-console`'s database picker, and the stylesheet's answer at
|
|
15
|
+
* the time — that the host must stop clipping — is not one a host can take when
|
|
16
|
+
* the clipping ancestor is this package's own dialog.
|
|
17
|
+
*
|
|
18
|
+
* So the popover is `position: fixed` and placed here, from the anchor's own
|
|
19
|
+
* rectangle. Fixed rather than a portal for the reason `<Modal>` gives at
|
|
20
|
+
* length: a console bridges its palette onto `--ctl-*` with a descendant
|
|
21
|
+
* selector, and a portal to `document.body` escapes it, so a dark console would
|
|
22
|
+
* open a light list. Staying in the tree keeps the bridge and steps out of the
|
|
23
|
+
* scroll container at the same time.
|
|
24
|
+
*
|
|
25
|
+
* What it does beyond that:
|
|
26
|
+
*
|
|
27
|
+
* - **Flips up** when the list does not fit below and fits better above. The
|
|
28
|
+
* decision is made against the height the popover actually wants — measured
|
|
29
|
+
* with the cap off — rather than against a threshold, because a threshold
|
|
30
|
+
* gets both ends wrong: a fixed "160px is enough" leaves a full list
|
|
31
|
+
* squeezed into 169px with 475px going spare above it, and raising the
|
|
32
|
+
* number flips a list that was fitting perfectly well.
|
|
33
|
+
* - **Keeps the side it chose** while the list still fits on it. Re-deciding
|
|
34
|
+
* on every content change would make the list jump across the field as
|
|
35
|
+
* somebody types, since a search that matches two options wants a
|
|
36
|
+
* different amount of room from one that matches forty.
|
|
37
|
+
* - **Bounds its height** to the room actually available, so the list scrolls
|
|
38
|
+
* inside the popover rather than the popover overhanging the viewport, and
|
|
39
|
+
* its **width** to a window too narrow for it, since the popover hides its
|
|
40
|
+
* overflow and offers no way to scroll sideways to what is cut off.
|
|
41
|
+
* - **Follows the anchor** while any ancestor scrolls. A fixed element does
|
|
42
|
+
* not move with the box it was measured against, so without this the list
|
|
43
|
+
* detaches from its trigger the moment the dialog body scrolls.
|
|
44
|
+
* - **Places again when the content changes size**, which is what the
|
|
45
|
+
* `ResizeObserver` is for. A control over a transport opens saying
|
|
46
|
+
* "Searching…" and is two lines tall at the moment it is first placed — so
|
|
47
|
+
* a list that will want 300px is measured at 80, drops downwards into
|
|
48
|
+
* whatever was there, and is squeezed into it once the options land. That
|
|
49
|
+
* is the picker this whole hook was written for.
|
|
50
|
+
* - **Hides itself** while the anchor is scrolled out of sight. A fixed
|
|
51
|
+
* popover does not go with its trigger through the top of a dialog body:
|
|
52
|
+
* it stays where it was, over unrelated content, offered as though it
|
|
53
|
+
* belonged to whatever is now under it.
|
|
54
|
+
*
|
|
55
|
+
* The one thing that breaks it is an ancestor with `transform`, `filter` or
|
|
56
|
+
* `will-change`, which makes itself the containing block for fixed
|
|
57
|
+
* descendants — the same caveat `<Modal>` carries, and the fix for it is on the
|
|
58
|
+
* ancestor.
|
|
59
|
+
*
|
|
60
|
+
* Styles are written straight onto the node rather than held in state. Placing
|
|
61
|
+
* needs the size the browser settled on *after* the stylesheet's `min-width`
|
|
62
|
+
* and the list's own `max-height` applied, so the effect has to read the
|
|
63
|
+
* element back after writing to it — a render pass in between would be a second
|
|
64
|
+
* paint at the wrong size, and a `setState` on every scroll event besides.
|
|
65
|
+
*
|
|
66
|
+
* @param open Whether the popover is rendered. Placement stops when it is not.
|
|
67
|
+
* @param anchor The element the popover hangs off, normally the control's root.
|
|
68
|
+
* @returns The ref to put on the popover element.
|
|
69
|
+
*/
|
|
70
|
+
export declare function useAnchoredPopover(open: boolean, anchor: RefObject<HTMLElement | null>): RefObject<HTMLDivElement | null>;
|
|
71
|
+
//# sourceMappingURL=useAnchoredPopover.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAnchoredPopover.d.ts","sourceRoot":"","sources":["../src/useAnchoredPopover.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAuB7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,GACpC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CA6KlC"}
|