@torpor/ui 1.0.1 → 1.1.0
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/dist/ColorPicker/ColorPicker.torp +36 -75
- package/dist/ColorPicker/ColorPickerInput.torp +122 -0
- package/dist/ColorPicker/ColorPickerTypes.ts +12 -0
- package/dist/ColorPicker/index.d.ts +40 -1
- package/dist/ColorPicker/index.js +2 -1
- package/dist/CommandPalette/CommandPalette.torp +49 -47
- package/dist/CommandPalette/CommandPaletteInput.torp +51 -0
- package/dist/CommandPalette/CommandPaletteItem.torp +62 -0
- package/dist/CommandPalette/CommandPaletteList.torp +55 -0
- package/dist/CommandPalette/CommandPaletteTypes.ts +32 -0
- package/dist/CommandPalette/index.d.ts +88 -2
- package/dist/CommandPalette/index.js +4 -1
- package/dist/DataGrid/DataGrid.torp +22 -22
- package/dist/DataGrid/DataGridCell.torp +50 -0
- package/dist/DataGrid/DataGridColumnHeader.torp +54 -0
- package/dist/DataGrid/DataGridTypes.ts +17 -0
- package/dist/DataGrid/index.d.ts +57 -2
- package/dist/DataGrid/index.js +3 -2
- package/dist/DatePicker/DatePicker.torp +45 -65
- package/dist/DatePicker/DatePickerContent.torp +82 -0
- package/dist/DatePicker/DatePickerTrigger.torp +56 -0
- package/dist/DatePicker/DatePickerTypes.ts +36 -0
- package/dist/DatePicker/index.d.ts +61 -2
- package/dist/DatePicker/index.js +3 -1
- package/dist/DateRangePicker/DateRangePicker.torp +52 -76
- package/dist/DateRangePicker/DateRangePickerContent.torp +90 -0
- package/dist/DateRangePicker/DateRangePickerTrigger.torp +59 -0
- package/dist/DateRangePicker/DateRangePickerTypes.ts +41 -0
- package/dist/DateRangePicker/index.d.ts +61 -2
- package/dist/DateRangePicker/index.js +3 -1
- package/dist/Progress/Progress.torp +24 -14
- package/dist/Progress/ProgressIndicator.torp +52 -0
- package/dist/Progress/ProgressTypes.ts +8 -0
- package/dist/Progress/index.d.ts +34 -1
- package/dist/Progress/index.js +2 -1
- package/dist/Rating/Rating.torp +41 -37
- package/dist/Rating/RatingStar.torp +71 -0
- package/dist/Rating/RatingTypes.ts +22 -0
- package/dist/Rating/index.d.ts +39 -1
- package/dist/Rating/index.js +2 -1
- package/dist/Slider/Slider.torp +48 -63
- package/dist/Slider/SliderHandle.torp +107 -0
- package/dist/Slider/SliderRange.torp +36 -0
- package/dist/Slider/SliderTypes.ts +34 -0
- package/dist/Slider/index.d.ts +65 -1
- package/dist/Slider/index.js +3 -1
- package/dist/TagInput/TagInput.torp +63 -84
- package/dist/TagInput/TagInputField.torp +68 -0
- package/dist/TagInput/TagInputSuggestions.torp +79 -0
- package/dist/TagInput/TagInputTag.torp +55 -0
- package/dist/TagInput/TagInputTypes.ts +42 -0
- package/dist/TagInput/index.d.ts +93 -1
- package/dist/TagInput/index.js +4 -1
- package/dist/TimePicker/TimePicker.torp +88 -85
- package/dist/TimePicker/TimePickerPart.torp +61 -0
- package/dist/TimePicker/TimePickerPeriod.torp +48 -0
- package/dist/TimePicker/TimePickerTypes.ts +37 -0
- package/dist/TimePicker/index.d.ts +61 -1
- package/dist/TimePicker/index.js +3 -1
- package/package.json +7 -7
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export const DatePickerContextName: unique symbol = Symbol.for("torp.DatePicker");
|
|
2
|
+
|
|
3
|
+
export interface DatePickerContext {
|
|
4
|
+
/** Whether the user cannot interact with the date picker */
|
|
5
|
+
getDisabled: () => boolean;
|
|
6
|
+
/** The ID of the trigger, for the content's aria-labelledby */
|
|
7
|
+
getTriggerId: () => string;
|
|
8
|
+
/** The ID of the content, for the trigger's aria-controls */
|
|
9
|
+
getContentId: () => string;
|
|
10
|
+
/** Whether the popout is visible */
|
|
11
|
+
isVisible: () => boolean;
|
|
12
|
+
/** Toggles the popout */
|
|
13
|
+
toggle: () => void;
|
|
14
|
+
/** The text displayed in the trigger */
|
|
15
|
+
getDisplayText: () => string;
|
|
16
|
+
/** An accessible name for the trigger */
|
|
17
|
+
getAriaLabel: () => string | undefined;
|
|
18
|
+
/** Whether the picker is contained within a Form Field */
|
|
19
|
+
inField: () => boolean;
|
|
20
|
+
/** Whether the picker's value is currently valid */
|
|
21
|
+
valid: () => boolean;
|
|
22
|
+
/** The ID of the Field's Message component, for aria-describedby */
|
|
23
|
+
messageId: () => string | undefined;
|
|
24
|
+
/** Called when the trigger loses focus */
|
|
25
|
+
handleBlur: () => void;
|
|
26
|
+
/** The selected date */
|
|
27
|
+
getValue: () => Date | undefined;
|
|
28
|
+
/** Selects a date, closing the popout */
|
|
29
|
+
selectDate: (date: Date) => void;
|
|
30
|
+
/** Closes the popout, returning focus to the trigger */
|
|
31
|
+
close: () => void;
|
|
32
|
+
/** Called from the content when it is added */
|
|
33
|
+
registerContent: (el: HTMLDivElement) => void;
|
|
34
|
+
/** Called from the content when it is removed */
|
|
35
|
+
unregisterContent: (el: HTMLDivElement) => void;
|
|
36
|
+
}
|
|
@@ -28,7 +28,16 @@ interface DatePickerProps {
|
|
|
28
28
|
* An input for selecting a date from a calendar popout.
|
|
29
29
|
*
|
|
30
30
|
* The structure of a DatePicker is a trigger button that displays the
|
|
31
|
-
* selected date, with a selectable Calendar in a popout
|
|
31
|
+
* selected date, with a selectable Calendar in a popout:
|
|
32
|
+
*
|
|
33
|
+
* ```
|
|
34
|
+
* <DatePicker>
|
|
35
|
+
* <DatePickerTrigger />
|
|
36
|
+
* <DatePickerContent />
|
|
37
|
+
* </DatePicker>
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* With no children, the trigger and content are rendered automatically.
|
|
32
41
|
*/
|
|
33
42
|
declare function DatePicker(
|
|
34
43
|
$parent: ParentNode,
|
|
@@ -40,6 +49,29 @@ declare function DatePicker(
|
|
|
40
49
|
|
|
41
50
|
|
|
42
51
|
|
|
52
|
+
interface DatePickerContentProps {
|
|
53
|
+
/** An ID for the content element */
|
|
54
|
+
id?: string;
|
|
55
|
+
/** Classes for the content element */
|
|
56
|
+
class?: ClassValue;
|
|
57
|
+
/** Styles for the content element */
|
|
58
|
+
style?: StyleValue;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The popout of a DatePicker, containing the calendar the user selects a
|
|
63
|
+
* date from.
|
|
64
|
+
*/
|
|
65
|
+
declare function DatePickerContent(
|
|
66
|
+
$parent: ParentNode,
|
|
67
|
+
$anchor: Node | null,
|
|
68
|
+
$props: DatePickerContentProps | undefined,
|
|
69
|
+
$context?: Record<PropertyKey, any>,
|
|
70
|
+
$slots?: Record<string, SlotRender>,
|
|
71
|
+
): void;
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
43
75
|
/**
|
|
44
76
|
* Displays the month and year of the currently visible date in a Calendar.
|
|
45
77
|
* Must be contained within a Calendar.
|
|
@@ -52,4 +84,31 @@ declare function DatePickerHeader(
|
|
|
52
84
|
$slots?: Record<string, SlotRender>,
|
|
53
85
|
): void;
|
|
54
86
|
|
|
55
|
-
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
interface DatePickerTriggerProps {
|
|
90
|
+
/** An ID for the trigger element */
|
|
91
|
+
id?: string;
|
|
92
|
+
/** Classes for the trigger element */
|
|
93
|
+
class?: ClassValue;
|
|
94
|
+
/** Styles for the trigger element */
|
|
95
|
+
style?: StyleValue;
|
|
96
|
+
/** An accessible name for the trigger; falls back to the picker's ariaLabel */
|
|
97
|
+
ariaLabel?: string;
|
|
98
|
+
/** If set to true, the user cannot interact with this trigger */
|
|
99
|
+
disabled?: boolean;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The button of a DatePicker that displays the selected date and opens the
|
|
104
|
+
* calendar popout.
|
|
105
|
+
*/
|
|
106
|
+
declare function DatePickerTrigger(
|
|
107
|
+
$parent: ParentNode,
|
|
108
|
+
$anchor: Node | null,
|
|
109
|
+
$props: DatePickerTriggerProps | undefined,
|
|
110
|
+
$context?: Record<PropertyKey, any>,
|
|
111
|
+
$slots?: Record<string, SlotRender>,
|
|
112
|
+
): void;
|
|
113
|
+
|
|
114
|
+
export { DatePicker, DatePickerContent, DatePickerHeader, DatePickerTrigger };
|
package/dist/DatePicker/index.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
import { type Bindable, type ClassValue, type StyleValue } from "@torpor/view";
|
|
2
|
-
import {
|
|
3
|
-
Calendar,
|
|
4
|
-
CalendarDayHeader,
|
|
5
|
-
CalendarGrid,
|
|
6
|
-
CalendarGridHeader,
|
|
7
|
-
CalendarHeader,
|
|
8
|
-
CalendarHeaderTrigger,
|
|
9
|
-
} from "../Calendar/index";
|
|
10
|
-
import DatePickerHeader from "../DatePicker/DatePickerHeader.torp";
|
|
11
2
|
import {
|
|
12
3
|
type FieldContext,
|
|
13
4
|
FieldContextName,
|
|
@@ -18,8 +9,15 @@ import { areDatesEqual, formatDate } from "../utils/dateUtils";
|
|
|
18
9
|
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
19
10
|
import getId from "../utils/getId";
|
|
20
11
|
import createFormField from "../utils/formField";
|
|
21
|
-
import {
|
|
22
|
-
|
|
12
|
+
import {
|
|
13
|
+
type DateRange,
|
|
14
|
+
type DateRangePickerContext,
|
|
15
|
+
DateRangePickerContextName,
|
|
16
|
+
type DateRangePickerShellContext,
|
|
17
|
+
DateRangePickerShellContextName,
|
|
18
|
+
} from "./DateRangePickerTypes";
|
|
19
|
+
import DateRangePickerContent from "./DateRangePickerContent.torp";
|
|
20
|
+
import DateRangePickerTrigger from "./DateRangePickerTrigger.torp";
|
|
23
21
|
|
|
24
22
|
interface DateRangePickerProps {
|
|
25
23
|
/** An ID for the root element */
|
|
@@ -51,12 +49,21 @@ interface DateRangePickerProps {
|
|
|
51
49
|
* over.
|
|
52
50
|
*
|
|
53
51
|
* The structure of a DateRangePicker is a trigger button that displays the
|
|
54
|
-
* selected range, with a selectable Calendar in a popout
|
|
52
|
+
* selected range, with a selectable Calendar in a popout:
|
|
53
|
+
*
|
|
54
|
+
* ```
|
|
55
|
+
* <DateRangePicker>
|
|
56
|
+
* <DateRangePickerTrigger />
|
|
57
|
+
* <DateRangePickerContent />
|
|
58
|
+
* </DateRangePicker>
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* With no children, the trigger and content are rendered automatically.
|
|
55
62
|
*/
|
|
56
63
|
export default function DateRangePicker($props: DateRangePickerProps | undefined) {
|
|
57
64
|
let defaultId = getId();
|
|
58
65
|
|
|
59
|
-
let content: HTMLDivElement;
|
|
66
|
+
let content: HTMLDivElement | undefined;
|
|
60
67
|
let closeOnClick = false;
|
|
61
68
|
|
|
62
69
|
// Wire up the enclosing Form and Field, if any
|
|
@@ -139,6 +146,34 @@ export default function DateRangePicker($props: DateRangePickerProps | undefined
|
|
|
139
146
|
setVisible(!$state.visible);
|
|
140
147
|
}
|
|
141
148
|
|
|
149
|
+
// Set the context to pass down to the trigger and content
|
|
150
|
+
let shell: DateRangePickerShellContext = {
|
|
151
|
+
getDisabled,
|
|
152
|
+
getTriggerId: () => $state.triggerId,
|
|
153
|
+
getContentId: () => $state.contentId,
|
|
154
|
+
isVisible: () => $state.visible,
|
|
155
|
+
toggle,
|
|
156
|
+
getDisplayText: displayText,
|
|
157
|
+
getAriaLabel: () => $props?.ariaLabel,
|
|
158
|
+
inField: () => form.inField,
|
|
159
|
+
valid: () => form.valid,
|
|
160
|
+
messageId: () => form.messageId,
|
|
161
|
+
handleBlur: () => form.handleBlur(),
|
|
162
|
+
getStartValue: () => $state.start,
|
|
163
|
+
isDaySelected,
|
|
164
|
+
selectDay: handleDay,
|
|
165
|
+
close: handleClose,
|
|
166
|
+
registerContent: (el) => {
|
|
167
|
+
content = el;
|
|
168
|
+
},
|
|
169
|
+
unregisterContent: (el) => {
|
|
170
|
+
if (content === el) {
|
|
171
|
+
content = undefined;
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
};
|
|
175
|
+
$context[DateRangePickerShellContextName] = shell;
|
|
176
|
+
|
|
142
177
|
function setVisible(visible: boolean) {
|
|
143
178
|
$state.visible = visible;
|
|
144
179
|
if (visible) {
|
|
@@ -224,12 +259,6 @@ export default function DateRangePicker($props: DateRangePickerProps | undefined
|
|
|
224
259
|
}
|
|
225
260
|
}
|
|
226
261
|
|
|
227
|
-
function handleClick(e: MouseEvent) {
|
|
228
|
-
// Don't close when the trigger itself is clicked
|
|
229
|
-
e.stopPropagation();
|
|
230
|
-
toggle();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
262
|
@render {
|
|
234
263
|
<div
|
|
235
264
|
{$props?.id}
|
|
@@ -240,56 +269,10 @@ export default function DateRangePicker($props: DateRangePickerProps | undefined
|
|
|
240
269
|
]}
|
|
241
270
|
{$props?.style}
|
|
242
271
|
>
|
|
243
|
-
<
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
aria-haspopup="dialog"
|
|
248
|
-
aria-expanded={$state.visible ? "true" : "false"}
|
|
249
|
-
aria-controls={$state.visible ? $state.contentId : undefined}
|
|
250
|
-
aria-label={$props?.ariaLabel}
|
|
251
|
-
data-valid={form.valid ? "valid" : "invalid"}
|
|
252
|
-
aria-describedby={form.messageId}
|
|
253
|
-
aria-invalid={form.inField && !form.valid ? "true" : undefined}
|
|
254
|
-
onblur={() => form.handleBlur()}
|
|
255
|
-
disabled={getDisabled()}
|
|
256
|
-
onclick={handleClick}
|
|
257
|
-
>
|
|
258
|
-
{displayText()}
|
|
259
|
-
</button>
|
|
260
|
-
|
|
261
|
-
<div
|
|
262
|
-
id={$state.contentId}
|
|
263
|
-
class={["torp-date-range-picker-content", $state.visible ? undefined : "hidden"]}
|
|
264
|
-
aria-hidden={$state.visible ? undefined : "true"}
|
|
265
|
-
&ref={content}
|
|
266
|
-
>
|
|
267
|
-
<Calendar
|
|
268
|
-
selectable
|
|
269
|
-
value={$state.start}
|
|
270
|
-
isSelected={isDaySelected}
|
|
271
|
-
onchange={handleDay}
|
|
272
|
-
onclose={handleClose}
|
|
273
|
-
>
|
|
274
|
-
<CalendarHeader>
|
|
275
|
-
<CalendarHeaderTrigger type="previous" />
|
|
276
|
-
<DatePickerHeader class="torp-date-range-picker-header" />
|
|
277
|
-
<CalendarHeaderTrigger type="next" />
|
|
278
|
-
</CalendarHeader>
|
|
279
|
-
<CalendarGridHeader>
|
|
280
|
-
@for (let day of $slot.days) {
|
|
281
|
-
<CalendarDayHeader {day.dayName} {day.shortDayName} />
|
|
282
|
-
}
|
|
283
|
-
</CalendarGridHeader>
|
|
284
|
-
<CalendarGrid>
|
|
285
|
-
<DateRangePickerDay
|
|
286
|
-
date={$slot.day.date}
|
|
287
|
-
muted={$slot.day.muted}
|
|
288
|
-
active={$slot.day.active}
|
|
289
|
-
/>
|
|
290
|
-
</CalendarGrid>
|
|
291
|
-
</Calendar>
|
|
292
|
-
</div>
|
|
272
|
+
<slot>
|
|
273
|
+
<DateRangePickerTrigger />
|
|
274
|
+
<DateRangePickerContent />
|
|
275
|
+
</slot>
|
|
293
276
|
</div>
|
|
294
277
|
|
|
295
278
|
@if (form.name) {
|
|
@@ -305,11 +288,4 @@ export default function DateRangePicker($props: DateRangePickerProps | undefined
|
|
|
305
288
|
/>
|
|
306
289
|
}
|
|
307
290
|
}
|
|
308
|
-
|
|
309
|
-
@style {
|
|
310
|
-
/* Visibility only -- see SelectBoxContent */
|
|
311
|
-
.torp-date-range-picker-content.hidden {
|
|
312
|
-
display: none;
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
291
|
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import {
|
|
3
|
+
Calendar,
|
|
4
|
+
CalendarDayHeader,
|
|
5
|
+
CalendarGrid,
|
|
6
|
+
CalendarGridHeader,
|
|
7
|
+
CalendarHeader,
|
|
8
|
+
CalendarHeaderTrigger,
|
|
9
|
+
} from "../Calendar/index";
|
|
10
|
+
import DatePickerHeader from "../DatePicker/DatePickerHeader.torp";
|
|
11
|
+
import DateRangePickerDay from "./DateRangePickerDay.torp";
|
|
12
|
+
import {
|
|
13
|
+
type DateRangePickerShellContext,
|
|
14
|
+
DateRangePickerShellContextName,
|
|
15
|
+
} from "./DateRangePickerTypes";
|
|
16
|
+
|
|
17
|
+
interface DateRangePickerContentProps {
|
|
18
|
+
/** An ID for the content element */
|
|
19
|
+
id?: string;
|
|
20
|
+
/** Classes for the content element */
|
|
21
|
+
class?: ClassValue;
|
|
22
|
+
/** Styles for the content element */
|
|
23
|
+
style?: StyleValue;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The popout of a DateRangePicker, containing the calendar the user selects
|
|
28
|
+
* a range of dates from.
|
|
29
|
+
*/
|
|
30
|
+
export default function DateRangePickerContent($props: DateRangePickerContentProps | undefined) {
|
|
31
|
+
// Get stuff out of the DateRangePicker context
|
|
32
|
+
const context = $context[DateRangePickerShellContextName] as DateRangePickerShellContext;
|
|
33
|
+
if (!context) {
|
|
34
|
+
throw new Error("DateRangePickerContent must be contained within a DateRangePicker");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@render {
|
|
38
|
+
<div
|
|
39
|
+
id={$props?.id ?? context.getContentId()}
|
|
40
|
+
class={[
|
|
41
|
+
"torp-date-range-picker-content",
|
|
42
|
+
context.isVisible() ? undefined : "hidden",
|
|
43
|
+
$props?.class,
|
|
44
|
+
]}
|
|
45
|
+
{$props?.style}
|
|
46
|
+
aria-hidden={context.isVisible() ? undefined : "true"}
|
|
47
|
+
onmount={(el) => {
|
|
48
|
+
context.registerContent(el);
|
|
49
|
+
return () => {
|
|
50
|
+
context.unregisterContent(el);
|
|
51
|
+
};
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
<slot>
|
|
55
|
+
<Calendar
|
|
56
|
+
selectable
|
|
57
|
+
value={context.getStartValue()}
|
|
58
|
+
isSelected={context.isDaySelected}
|
|
59
|
+
onchange={context.selectDay}
|
|
60
|
+
onclose={context.close}
|
|
61
|
+
>
|
|
62
|
+
<CalendarHeader>
|
|
63
|
+
<CalendarHeaderTrigger type="previous" />
|
|
64
|
+
<DatePickerHeader class="torp-date-range-picker-header" />
|
|
65
|
+
<CalendarHeaderTrigger type="next" />
|
|
66
|
+
</CalendarHeader>
|
|
67
|
+
<CalendarGridHeader>
|
|
68
|
+
@for (let day of $slot.days) {
|
|
69
|
+
<CalendarDayHeader {day.dayName} {day.shortDayName} />
|
|
70
|
+
}
|
|
71
|
+
</CalendarGridHeader>
|
|
72
|
+
<CalendarGrid>
|
|
73
|
+
<DateRangePickerDay
|
|
74
|
+
date={$slot.day.date}
|
|
75
|
+
muted={$slot.day.muted}
|
|
76
|
+
active={$slot.day.active}
|
|
77
|
+
/>
|
|
78
|
+
</CalendarGrid>
|
|
79
|
+
</Calendar>
|
|
80
|
+
</slot>
|
|
81
|
+
</div>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@style {
|
|
85
|
+
/* Visibility only -- see SelectBoxContent */
|
|
86
|
+
.torp-date-range-picker-content.hidden {
|
|
87
|
+
display: none;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import {
|
|
3
|
+
type DateRangePickerShellContext,
|
|
4
|
+
DateRangePickerShellContextName,
|
|
5
|
+
} from "./DateRangePickerTypes";
|
|
6
|
+
|
|
7
|
+
interface DateRangePickerTriggerProps {
|
|
8
|
+
/** An ID for the trigger element */
|
|
9
|
+
id?: string;
|
|
10
|
+
/** Classes for the trigger element */
|
|
11
|
+
class?: ClassValue;
|
|
12
|
+
/** Styles for the trigger element */
|
|
13
|
+
style?: StyleValue;
|
|
14
|
+
/** An accessible name for the trigger; falls back to the picker's ariaLabel */
|
|
15
|
+
ariaLabel?: string;
|
|
16
|
+
/** If set to true, the user cannot interact with this trigger */
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The button of a DateRangePicker that displays the selected range and
|
|
22
|
+
* opens the calendar popout.
|
|
23
|
+
*/
|
|
24
|
+
export default function DateRangePickerTrigger($props: DateRangePickerTriggerProps | undefined) {
|
|
25
|
+
// Get stuff out of the DateRangePicker context
|
|
26
|
+
const context = $context[DateRangePickerShellContextName] as DateRangePickerShellContext;
|
|
27
|
+
if (!context) {
|
|
28
|
+
throw new Error("DateRangePickerTrigger must be contained within a DateRangePicker");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getDisabled(): boolean {
|
|
32
|
+
return $props?.disabled === true || context.getDisabled();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@render {
|
|
36
|
+
<button
|
|
37
|
+
type="button"
|
|
38
|
+
id={$props?.id ?? context.getTriggerId()}
|
|
39
|
+
class={["torp-date-range-picker-trigger", $props?.class]}
|
|
40
|
+
{$props?.style}
|
|
41
|
+
aria-haspopup="dialog"
|
|
42
|
+
aria-expanded={context.isVisible() ? "true" : "false"}
|
|
43
|
+
aria-controls={context.isVisible() ? context.getContentId() : undefined}
|
|
44
|
+
aria-label={$props?.ariaLabel ?? context.getAriaLabel()}
|
|
45
|
+
data-valid={context.valid() ? "valid" : "invalid"}
|
|
46
|
+
aria-describedby={context.messageId()}
|
|
47
|
+
aria-invalid={context.inField() && !context.valid() ? "true" : undefined}
|
|
48
|
+
onblur={() => context.handleBlur()}
|
|
49
|
+
disabled={getDisabled()}
|
|
50
|
+
onclick={(e: MouseEvent) => {
|
|
51
|
+
// Don't close when the trigger itself is clicked
|
|
52
|
+
e.stopPropagation();
|
|
53
|
+
context.toggle();
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
<slot>{context.getDisplayText()}</slot>
|
|
57
|
+
</button>
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -19,3 +19,44 @@ export interface DateRangePickerContext {
|
|
|
19
19
|
/** Sets the hovered date that extends the range preview */
|
|
20
20
|
setPreview: (date: Date | undefined) => void;
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
export const DateRangePickerShellContextName: unique symbol = Symbol.for(
|
|
24
|
+
"torp.DateRangePickerShell",
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export interface DateRangePickerShellContext {
|
|
28
|
+
/** Whether the user cannot interact with the date range picker */
|
|
29
|
+
getDisabled: () => boolean;
|
|
30
|
+
/** The ID of the trigger, for the content's aria-labelledby */
|
|
31
|
+
getTriggerId: () => string;
|
|
32
|
+
/** The ID of the content, for the trigger's aria-controls */
|
|
33
|
+
getContentId: () => string;
|
|
34
|
+
/** Whether the popout is visible */
|
|
35
|
+
isVisible: () => boolean;
|
|
36
|
+
/** Toggles the popout */
|
|
37
|
+
toggle: () => void;
|
|
38
|
+
/** The text displayed in the trigger */
|
|
39
|
+
getDisplayText: () => string;
|
|
40
|
+
/** An accessible name for the trigger */
|
|
41
|
+
getAriaLabel: () => string | undefined;
|
|
42
|
+
/** Whether the picker is contained within a Form Field */
|
|
43
|
+
inField: () => boolean;
|
|
44
|
+
/** Whether the picker's value is currently valid */
|
|
45
|
+
valid: () => boolean;
|
|
46
|
+
/** The ID of the Field's Message component, for aria-describedby */
|
|
47
|
+
messageId: () => string | undefined;
|
|
48
|
+
/** Called when the trigger loses focus */
|
|
49
|
+
handleBlur: () => void;
|
|
50
|
+
/** The start of the range being selected */
|
|
51
|
+
getStartValue: () => Date | undefined;
|
|
52
|
+
/** Whether a day is one of the range's endpoints, for aria-selected */
|
|
53
|
+
isDaySelected: (date: Date) => boolean;
|
|
54
|
+
/** Handles a day being picked, completing the range on the second pick */
|
|
55
|
+
selectDay: (date: Date) => void;
|
|
56
|
+
/** Closes the popout, returning focus to the trigger */
|
|
57
|
+
close: () => void;
|
|
58
|
+
/** Called from the content when it is added */
|
|
59
|
+
registerContent: (el: HTMLDivElement) => void;
|
|
60
|
+
/** Called from the content when it is removed */
|
|
61
|
+
unregisterContent: (el: HTMLDivElement) => void;
|
|
62
|
+
}
|
|
@@ -31,7 +31,16 @@ interface DateRangePickerProps {
|
|
|
31
31
|
* over.
|
|
32
32
|
*
|
|
33
33
|
* The structure of a DateRangePicker is a trigger button that displays the
|
|
34
|
-
* selected range, with a selectable Calendar in a popout
|
|
34
|
+
* selected range, with a selectable Calendar in a popout:
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
* <DateRangePicker>
|
|
38
|
+
* <DateRangePickerTrigger />
|
|
39
|
+
* <DateRangePickerContent />
|
|
40
|
+
* </DateRangePicker>
|
|
41
|
+
* ```
|
|
42
|
+
*
|
|
43
|
+
* With no children, the trigger and content are rendered automatically.
|
|
35
44
|
*/
|
|
36
45
|
declare function DateRangePicker(
|
|
37
46
|
$parent: ParentNode,
|
|
@@ -43,6 +52,29 @@ declare function DateRangePicker(
|
|
|
43
52
|
|
|
44
53
|
|
|
45
54
|
|
|
55
|
+
interface DateRangePickerContentProps {
|
|
56
|
+
/** An ID for the content element */
|
|
57
|
+
id?: string;
|
|
58
|
+
/** Classes for the content element */
|
|
59
|
+
class?: ClassValue;
|
|
60
|
+
/** Styles for the content element */
|
|
61
|
+
style?: StyleValue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The popout of a DateRangePicker, containing the calendar the user selects
|
|
66
|
+
* a range of dates from.
|
|
67
|
+
*/
|
|
68
|
+
declare function DateRangePickerContent(
|
|
69
|
+
$parent: ParentNode,
|
|
70
|
+
$anchor: Node | null,
|
|
71
|
+
$props: DateRangePickerContentProps | undefined,
|
|
72
|
+
$context?: Record<PropertyKey, any>,
|
|
73
|
+
$slots?: Record<string, SlotRender>,
|
|
74
|
+
): void;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
|
|
46
78
|
interface DateRangePickerDayProps {
|
|
47
79
|
/** An ID for the root element */
|
|
48
80
|
id?: string;
|
|
@@ -73,4 +105,31 @@ declare function DateRangePickerDay(
|
|
|
73
105
|
$slots?: Record<string, SlotRender>,
|
|
74
106
|
): void;
|
|
75
107
|
|
|
76
|
-
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
interface DateRangePickerTriggerProps {
|
|
111
|
+
/** An ID for the trigger element */
|
|
112
|
+
id?: string;
|
|
113
|
+
/** Classes for the trigger element */
|
|
114
|
+
class?: ClassValue;
|
|
115
|
+
/** Styles for the trigger element */
|
|
116
|
+
style?: StyleValue;
|
|
117
|
+
/** An accessible name for the trigger; falls back to the picker's ariaLabel */
|
|
118
|
+
ariaLabel?: string;
|
|
119
|
+
/** If set to true, the user cannot interact with this trigger */
|
|
120
|
+
disabled?: boolean;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The button of a DateRangePicker that displays the selected range and
|
|
125
|
+
* opens the calendar popout.
|
|
126
|
+
*/
|
|
127
|
+
declare function DateRangePickerTrigger(
|
|
128
|
+
$parent: ParentNode,
|
|
129
|
+
$anchor: Node | null,
|
|
130
|
+
$props: DateRangePickerTriggerProps | undefined,
|
|
131
|
+
$context?: Record<PropertyKey, any>,
|
|
132
|
+
$slots?: Record<string, SlotRender>,
|
|
133
|
+
): void;
|
|
134
|
+
|
|
135
|
+
export { DateRangePicker, DateRangePickerContent, DateRangePickerDay, DateRangePickerTrigger };
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import DateRangePicker from "./DateRangePicker.torp";
|
|
2
|
+
import DateRangePickerContent from "./DateRangePickerContent.torp";
|
|
2
3
|
import DateRangePickerDay from "./DateRangePickerDay.torp";
|
|
3
|
-
|
|
4
|
+
import DateRangePickerTrigger from "./DateRangePickerTrigger.torp";
|
|
5
|
+
export { DateRangePicker, DateRangePickerContent, DateRangePickerDay, DateRangePickerTrigger };
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import { type ProgressContext, ProgressContextName } from "./ProgressTypes";
|
|
3
|
+
import ProgressIndicator from "./ProgressIndicator.torp";
|
|
2
4
|
|
|
3
5
|
interface ProgressProps {
|
|
4
6
|
/** An ID for the root element */
|
|
@@ -24,6 +26,16 @@ interface ProgressProps {
|
|
|
24
26
|
* specific value or as indeterminate when the extent is unknown.
|
|
25
27
|
*
|
|
26
28
|
* See [the WAI ARIA guidelines for Progress Bars](https://www.w3.org/WAI/ARIA/apg/patterns/progressbar/).
|
|
29
|
+
*
|
|
30
|
+
* The structure of a Progress is:
|
|
31
|
+
*
|
|
32
|
+
* ```
|
|
33
|
+
* <Progress>
|
|
34
|
+
* <ProgressIndicator />
|
|
35
|
+
* </Progress>
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* With no children, the indicator is rendered automatically.
|
|
27
39
|
*/
|
|
28
40
|
export default function Progress($props: ProgressProps | undefined) {
|
|
29
41
|
function getMin(): number {
|
|
@@ -49,6 +61,13 @@ export default function Progress($props: ProgressProps | undefined) {
|
|
|
49
61
|
return ((getValue() - min) / (max - min)) * 100;
|
|
50
62
|
}
|
|
51
63
|
|
|
64
|
+
// Set the context to pass down to the indicator
|
|
65
|
+
let context: ProgressContext = {
|
|
66
|
+
isIndeterminate,
|
|
67
|
+
getPct,
|
|
68
|
+
};
|
|
69
|
+
$context[ProgressContextName] = context;
|
|
70
|
+
|
|
52
71
|
@render {
|
|
53
72
|
<div
|
|
54
73
|
{$props?.id}
|
|
@@ -62,27 +81,18 @@ export default function Progress($props: ProgressProps | undefined) {
|
|
|
62
81
|
aria-valuetext={$props?.valuetext}
|
|
63
82
|
data-state={isIndeterminate() ? "indeterminate" : "determinate"}
|
|
64
83
|
>
|
|
65
|
-
<
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
style={isIndeterminate() ? undefined : `width: ${getPct()}%;`}
|
|
69
|
-
/>
|
|
84
|
+
<slot>
|
|
85
|
+
<ProgressIndicator />
|
|
86
|
+
</slot>
|
|
70
87
|
</div>
|
|
71
88
|
}
|
|
72
89
|
|
|
73
90
|
@style {
|
|
74
|
-
/* Headless: layout only, so the
|
|
75
|
-
|
|
91
|
+
/* Headless: layout only, so the indicator fills the track. All
|
|
92
|
+
appearance is up to the consuming theme */
|
|
76
93
|
.torp-progress {
|
|
77
94
|
position: relative;
|
|
78
95
|
overflow: hidden;
|
|
79
96
|
}
|
|
80
|
-
.torp-progress-bar {
|
|
81
|
-
position: absolute;
|
|
82
|
-
inset: 0 auto 0 0;
|
|
83
|
-
}
|
|
84
|
-
.torp-progress-bar[data-state="indeterminate"] {
|
|
85
|
-
width: 100%;
|
|
86
|
-
}
|
|
87
97
|
}
|
|
88
98
|
}
|