@torpor/ui 1.3.5 → 1.4.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/Accordion/AccordionItem.torp +1 -1
- package/dist/Alert/Alert.torp +41 -0
- package/dist/Alert/index.d.ts +37 -0
- package/dist/Alert/index.js +1 -0
- package/dist/Charts/ChartScatter.torp +167 -0
- package/dist/Charts/ScatterChart.torp +49 -178
- package/dist/Charts/index.d.ts +38 -78
- package/dist/Charts/index.js +2 -4
- package/dist/ColorPicker/ColorPalette.torp +107 -29
- package/dist/ColorPicker/ColorPicker.torp +121 -10
- package/dist/ColorPicker/ColorPickerAlpha.torp +58 -0
- package/dist/ColorPicker/ColorPickerArea.torp +175 -0
- package/dist/ColorPicker/ColorPickerEyedropper.torp +77 -0
- package/dist/ColorPicker/ColorPickerHue.torp +59 -0
- package/dist/ColorPicker/ColorPickerInput.torp +7 -18
- package/dist/ColorPicker/ColorPickerTypes.ts +11 -1
- package/dist/ColorPicker/index.d.ts +139 -14
- package/dist/ColorPicker/index.js +5 -1
- package/dist/ComboBox/ComboBox.torp +40 -5
- package/dist/ComboBox/index.d.ts +5 -2
- package/dist/ComboBox/index.js +1 -2
- package/dist/Contextual/Contextual.torp +25 -77
- package/dist/Contextual/ContextualContent.torp +10 -51
- package/dist/Contextual/ContextualHover.torp +13 -85
- package/dist/Contextual/ContextualTrigger.torp +9 -16
- package/dist/Contextual/ContextualTypes.ts +6 -12
- package/dist/Contextual/index.d.ts +10 -13
- package/dist/DataGrid/DataGrid.torp +21 -3
- package/dist/DataGrid/index.d.ts +1 -1
- package/dist/DatePicker/DatePicker.torp +6 -4
- package/dist/DateRangePicker/DateRangePicker.torp +14 -13
- package/dist/DateTimePicker/DateTimePicker.torp +264 -0
- package/dist/DateTimePicker/index.d.ts +46 -0
- package/dist/DateTimePicker/index.js +1 -0
- package/dist/Dialog/Dialog.torp +0 -1
- package/dist/Dialog/index.d.ts +0 -1
- package/dist/Drawer/Drawer.torp +5 -23
- package/dist/Drawer/DrawerContent.torp +1 -0
- package/dist/Drawer/DrawerOverlay.torp +9 -16
- package/dist/Drawer/DrawerTrigger.torp +9 -24
- package/dist/Drawer/DrawerTypes.ts +3 -1
- package/dist/Form/CheckBox.torp +10 -18
- package/dist/Form/File.torp +10 -18
- package/dist/Form/FileDrop.torp +16 -22
- package/dist/Form/Input.torp +14 -20
- package/dist/Form/Radio.torp +71 -0
- package/dist/Form/RadioGroup.torp +221 -0
- package/dist/Form/RadioGroupTypes.ts +40 -0
- package/dist/Form/Select.torp +10 -18
- package/dist/Form/{Toggle.torp → Switch.torp} +17 -21
- package/dist/Form/TextArea.torp +10 -18
- package/dist/Form/ToggleButton.torp +94 -0
- package/dist/Form/ToggleGroup.torp +150 -0
- package/dist/Form/ToggleGroupTypes.ts +23 -0
- package/dist/Form/index.d.ts +173 -15
- package/dist/Form/index.js +6 -2
- package/dist/ListBox/ListBox.torp +27 -5
- package/dist/ListBox/ListBoxItem.torp +1 -1
- package/dist/ListBox/index.d.ts +6 -2
- package/dist/MaskedInput/MaskedInput.torp +1 -1
- package/dist/Menu/MenuPopoutTrigger.torp +1 -1
- package/dist/MenuBar/MenuBar.torp +5 -3
- package/dist/MenuBar/MenuBarItemTrigger.torp +2 -2
- package/dist/Meter/Meter.torp +126 -0
- package/dist/Meter/MeterIndicator.torp +41 -0
- package/dist/Meter/MeterTypes.ts +8 -0
- package/dist/Meter/index.d.ts +79 -0
- package/dist/Meter/index.js +3 -0
- package/dist/Modal/Modal.torp +4 -22
- package/dist/Modal/ModalOverlay.torp +9 -16
- package/dist/NavMenu/NavMenu.torp +5 -3
- package/dist/NumberInput/NumberInput.torp +1 -1
- package/dist/PinInput/PinInput.torp +220 -0
- package/dist/PinInput/index.d.ts +48 -0
- package/dist/PinInput/index.js +1 -0
- package/dist/Popover/Popover.torp +18 -24
- package/dist/Popover/PopoverContent.torp +8 -0
- package/dist/Popover/PopoverHover.torp +30 -3
- package/dist/Popover/PopoverTypes.ts +2 -0
- package/dist/Popover/index.d.ts +8 -1
- package/dist/Rating/Rating.torp +1 -1
- package/dist/SegmentedControl/SegmentedControl.torp +3 -3
- package/dist/SegmentedControl/SegmentedItem.torp +1 -1
- package/dist/SelectBox/SelectBox.torp +40 -5
- package/dist/SelectBox/index.d.ts +5 -2
- package/dist/SelectBox/index.js +1 -2
- package/dist/Slider/Slider.torp +1 -1
- package/dist/SortableList/SortableList.torp +132 -0
- package/dist/SortableList/SortableListItem.torp +117 -0
- package/dist/SortableList/SortableListTypes.ts +16 -0
- package/dist/SortableList/index.d.ts +81 -0
- package/dist/SortableList/index.js +3 -0
- package/dist/TabGroup/TabContent.torp +1 -1
- package/dist/TabGroup/TabGroup.torp +2 -2
- package/dist/TabGroup/TabHeader.torp +1 -1
- package/dist/TagInput/TagInput.torp +1 -1
- package/dist/TimePicker/TimePicker.torp +1 -1
- package/dist/ToolBar/ToolBar.torp +8 -4
- package/dist/ToolBar/ToolBarPopoutTrigger.torp +1 -1
- package/dist/Tooltip/Tooltip.torp +104 -0
- package/dist/Tooltip/TooltipContent.torp +81 -0
- package/dist/Tooltip/TooltipTrigger.torp +79 -0
- package/dist/Tooltip/TooltipTypes.ts +28 -0
- package/dist/Tooltip/index.d.ts +104 -0
- package/dist/Tooltip/index.js +4 -0
- package/dist/Tree/Tree.torp +1 -1
- package/dist/Tree/TreeItem.torp +1 -1
- package/dist/VirtualList/VirtualList.torp +149 -0
- package/dist/VirtualList/index.d.ts +46 -0
- package/dist/VirtualList/index.js +1 -0
- package/dist/dnd/index.d.ts +2 -0
- package/dist/dnd/index.js +212 -0
- package/dist/dnd/index.js.map +1 -0
- package/dist/loader/index.d.ts +2 -0
- package/dist/{loader-DEeG5vFY.js → loader/index.js} +10 -3
- package/dist/loader/index.js.map +1 -0
- package/dist/utils/PopoutClickTrigger.torp +1 -0
- package/dist/utils/PopoutOverlay.torp +39 -0
- package/dist/utils/PopoutTypes.ts +4 -0
- package/dist/utils/SubmenuPopoutTrigger.torp +5 -5
- package/dist/utils/colorUtils.ts +260 -75
- package/dist/utils/formField.ts +4 -3
- package/dist/utils/handlePopoutButton.ts +43 -0
- package/dist/utils/loader.ts +20 -3
- package/package.json +41 -5
- package/dist/Charts/GridLines.torp +0 -65
- package/dist/Charts/XAxis.torp +0 -69
- package/dist/Charts/YAxis.torp +0 -49
- package/dist/loader-DEeG5vFY.js.map +0 -1
|
@@ -34,7 +34,9 @@ interface MenuBarProps {
|
|
|
34
34
|
* ```
|
|
35
35
|
*/
|
|
36
36
|
export default function MenuBar($props: MenuBarProps | undefined) {
|
|
37
|
-
|
|
37
|
+
function getOrientation(): "horizontal" | "vertical" {
|
|
38
|
+
return $props?.orientation ?? "horizontal";
|
|
39
|
+
}
|
|
38
40
|
|
|
39
41
|
let $state = $watch({
|
|
40
42
|
active: false,
|
|
@@ -86,7 +88,7 @@ export default function MenuBar($props: MenuBarProps | undefined) {
|
|
|
86
88
|
|
|
87
89
|
function handleButtonKey(e: KeyboardEvent) {
|
|
88
90
|
group.handleGroupKey(group.getFocusIndex(), e, {
|
|
89
|
-
vertical:
|
|
91
|
+
vertical: getOrientation() === "vertical",
|
|
90
92
|
});
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -102,7 +104,7 @@ export default function MenuBar($props: MenuBarProps | undefined) {
|
|
|
102
104
|
tabindex="-1"
|
|
103
105
|
role="menubar"
|
|
104
106
|
aria-label={$props?.ariaLabel}
|
|
105
|
-
aria-orientation={
|
|
107
|
+
aria-orientation={getOrientation()}
|
|
106
108
|
>
|
|
107
109
|
<slot />
|
|
108
110
|
</div>
|
|
@@ -54,8 +54,8 @@ export default function MenuBarItemTrigger($props: MenuBarItemTriggerProps | und
|
|
|
54
54
|
handleItemKey={handleButtonKey}
|
|
55
55
|
handleItemFocus={handleButtonFocus}
|
|
56
56
|
setVisible={itemContext.setVisible}
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
onregister={(index: number) => (itemContext.index = index)}
|
|
58
|
+
onactivate={() => (menubarContext.state.active = true)}
|
|
59
59
|
onclick={handleClick}
|
|
60
60
|
>
|
|
61
61
|
<slot />
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import { type MeterContext, MeterContextName } from "./MeterTypes";
|
|
3
|
+
import MeterIndicator from "./MeterIndicator.torp";
|
|
4
|
+
|
|
5
|
+
interface MeterProps {
|
|
6
|
+
/** An ID for the root element */
|
|
7
|
+
id?: string;
|
|
8
|
+
/** Classes for the root element */
|
|
9
|
+
class?: ClassValue;
|
|
10
|
+
/** Styles for the root element */
|
|
11
|
+
style?: StyleValue;
|
|
12
|
+
/** The minimum value (default 0) */
|
|
13
|
+
min?: number;
|
|
14
|
+
/** The maximum value (default 100) */
|
|
15
|
+
max?: number;
|
|
16
|
+
/** The current value */
|
|
17
|
+
value: number;
|
|
18
|
+
/** The upper bound of the "low" region */
|
|
19
|
+
low?: number;
|
|
20
|
+
/** The lower bound of the "high" region */
|
|
21
|
+
high?: number;
|
|
22
|
+
/** The most desirable value, for rating the current value */
|
|
23
|
+
optimum?: number;
|
|
24
|
+
/** A human-readable version of the current value, e.g. "12 GB of 20 GB" */
|
|
25
|
+
valuetext?: string;
|
|
26
|
+
/** An accessible name for the meter */
|
|
27
|
+
ariaLabel?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function clamp(value: number, min: number, max: number): number {
|
|
31
|
+
return Math.min(max, Math.max(min, value));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* A gauge that shows a measurement within a known range, such as disk usage
|
|
36
|
+
* or a score.
|
|
37
|
+
*
|
|
38
|
+
* See [the WAI ARIA guidelines for Meters](https://www.w3.org/WAI/ARIA/apg/patterns/meter/).
|
|
39
|
+
*
|
|
40
|
+
* Unlike Progress, a Meter always has a value and can rate it against
|
|
41
|
+
* `low`, `high` and `optimum` thresholds.
|
|
42
|
+
*
|
|
43
|
+
* The structure of a Meter is:
|
|
44
|
+
*
|
|
45
|
+
* ```
|
|
46
|
+
* <Meter value={72} low={25} high={75} optimum={25}>
|
|
47
|
+
* <MeterIndicator />
|
|
48
|
+
* </Meter>
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* With no children, the indicator is rendered automatically.
|
|
52
|
+
*/
|
|
53
|
+
export default function Meter($props: MeterProps | undefined) {
|
|
54
|
+
function getMin(): number {
|
|
55
|
+
return $props?.min ?? 0;
|
|
56
|
+
}
|
|
57
|
+
function getMax(): number {
|
|
58
|
+
return $props?.max ?? 100;
|
|
59
|
+
}
|
|
60
|
+
function getValue(): number {
|
|
61
|
+
return clamp($props?.value ?? getMin(), getMin(), getMax());
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// The percentage of the range that the value represents (0..100)
|
|
65
|
+
function getPct(): number {
|
|
66
|
+
const min = getMin();
|
|
67
|
+
const max = getMax();
|
|
68
|
+
if (max <= min) return 0;
|
|
69
|
+
return ((getValue() - min) / (max - min)) * 100;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Rate the value against the thresholds, following the ARIA meter
|
|
73
|
+
// guidance: the region containing the optimum is the good one
|
|
74
|
+
function getState(): "optimum" | "suboptimum" | "poor" {
|
|
75
|
+
const low = $props?.low;
|
|
76
|
+
const high = $props?.high;
|
|
77
|
+
const optimum = $props?.optimum;
|
|
78
|
+
const value = getValue();
|
|
79
|
+
if (low === undefined || high === undefined || optimum === undefined) {
|
|
80
|
+
return "optimum";
|
|
81
|
+
}
|
|
82
|
+
if (optimum <= low) {
|
|
83
|
+
if (value <= low) return "optimum";
|
|
84
|
+
return value <= high ? "suboptimum" : "poor";
|
|
85
|
+
}
|
|
86
|
+
if (optimum >= high) {
|
|
87
|
+
if (value >= high) return "optimum";
|
|
88
|
+
return value >= low ? "suboptimum" : "poor";
|
|
89
|
+
}
|
|
90
|
+
return value >= low && value <= high ? "optimum" : "suboptimum";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
let context: MeterContext = {
|
|
94
|
+
getPct,
|
|
95
|
+
getState,
|
|
96
|
+
};
|
|
97
|
+
$context[MeterContextName] = context;
|
|
98
|
+
|
|
99
|
+
@render {
|
|
100
|
+
<div
|
|
101
|
+
{$props?.id}
|
|
102
|
+
class={["torp-meter", $props?.class]}
|
|
103
|
+
{$props?.style}
|
|
104
|
+
role="meter"
|
|
105
|
+
aria-label={$props?.ariaLabel}
|
|
106
|
+
aria-valuemin={getMin()}
|
|
107
|
+
aria-valuemax={getMax()}
|
|
108
|
+
aria-valuenow={getValue()}
|
|
109
|
+
aria-valuetext={$props?.valuetext}
|
|
110
|
+
data-state={getState()}
|
|
111
|
+
>
|
|
112
|
+
<slot>
|
|
113
|
+
<MeterIndicator />
|
|
114
|
+
</slot>
|
|
115
|
+
</div>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@style {
|
|
119
|
+
/* Headless: layout only, so the indicator fills the track. All
|
|
120
|
+
appearance is up to the consuming theme */
|
|
121
|
+
.torp-meter {
|
|
122
|
+
position: relative;
|
|
123
|
+
overflow: hidden;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import { type MeterContext, MeterContextName } from "./MeterTypes";
|
|
3
|
+
|
|
4
|
+
interface MeterIndicatorProps {
|
|
5
|
+
/** An ID for the indicator element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Classes for the indicator element */
|
|
8
|
+
class?: ClassValue;
|
|
9
|
+
/** Styles for the indicator element */
|
|
10
|
+
style?: StyleValue;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The bar of a Meter that fills the track in proportion to the current
|
|
15
|
+
* value.
|
|
16
|
+
*/
|
|
17
|
+
export default function MeterIndicator($props: MeterIndicatorProps | undefined) {
|
|
18
|
+
// Get stuff out of the Meter context
|
|
19
|
+
const context = $context[MeterContextName] as MeterContext;
|
|
20
|
+
if (!context) {
|
|
21
|
+
throw new Error("MeterIndicator must be contained within a Meter");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@render {
|
|
25
|
+
<div
|
|
26
|
+
{$props?.id}
|
|
27
|
+
class={["torp-meter-bar", $props?.class]}
|
|
28
|
+
style={[`width: ${context.getPct()}%;`, $props?.style]}
|
|
29
|
+
data-state={context.getState()}
|
|
30
|
+
/>
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@style {
|
|
34
|
+
/* Headless: layout only, so the bar fills the track proportionally.
|
|
35
|
+
All appearance is up to the consuming theme */
|
|
36
|
+
.torp-meter-bar {
|
|
37
|
+
position: absolute;
|
|
38
|
+
inset: 0 auto 0 0;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const MeterContextName: unique symbol = Symbol("Meter");
|
|
2
|
+
|
|
3
|
+
export interface MeterContext {
|
|
4
|
+
/** The percentage of the range that the value represents (0..100) */
|
|
5
|
+
getPct: () => number;
|
|
6
|
+
/** How the value rates compared to the low/high/optimum thresholds */
|
|
7
|
+
getState: () => "optimum" | "suboptimum" | "poor";
|
|
8
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { type SlotRender } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface MeterProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Classes for the root element */
|
|
8
|
+
class?: ClassValue;
|
|
9
|
+
/** Styles for the root element */
|
|
10
|
+
style?: StyleValue;
|
|
11
|
+
/** The minimum value (default 0) */
|
|
12
|
+
min?: number;
|
|
13
|
+
/** The maximum value (default 100) */
|
|
14
|
+
max?: number;
|
|
15
|
+
/** The current value */
|
|
16
|
+
value: number;
|
|
17
|
+
/** The upper bound of the "low" region */
|
|
18
|
+
low?: number;
|
|
19
|
+
/** The lower bound of the "high" region */
|
|
20
|
+
high?: number;
|
|
21
|
+
/** The most desirable value, for rating the current value */
|
|
22
|
+
optimum?: number;
|
|
23
|
+
/** A human-readable version of the current value, e.g. "12 GB of 20 GB" */
|
|
24
|
+
valuetext?: string;
|
|
25
|
+
/** An accessible name for the meter */
|
|
26
|
+
ariaLabel?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A gauge that shows a measurement within a known range, such as disk usage
|
|
31
|
+
* or a score.
|
|
32
|
+
*
|
|
33
|
+
* See [the WAI ARIA guidelines for Meters](https://www.w3.org/WAI/ARIA/apg/patterns/meter/).
|
|
34
|
+
*
|
|
35
|
+
* Unlike Progress, a Meter always has a value and can rate it against
|
|
36
|
+
* `low`, `high` and `optimum` thresholds.
|
|
37
|
+
*
|
|
38
|
+
* The structure of a Meter is:
|
|
39
|
+
*
|
|
40
|
+
* ```
|
|
41
|
+
* <Meter value={72} low={25} high={75} optimum={25}>
|
|
42
|
+
* <MeterIndicator />
|
|
43
|
+
* </Meter>
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* With no children, the indicator is rendered automatically.
|
|
47
|
+
*/
|
|
48
|
+
declare function Meter(
|
|
49
|
+
$parent: ParentNode,
|
|
50
|
+
$anchor: Node | null,
|
|
51
|
+
$props: MeterProps | undefined,
|
|
52
|
+
$context?: Record<PropertyKey, any>,
|
|
53
|
+
$slots?: Record<string, SlotRender>,
|
|
54
|
+
): void;
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
interface MeterIndicatorProps {
|
|
59
|
+
/** An ID for the indicator element */
|
|
60
|
+
id?: string;
|
|
61
|
+
/** Classes for the indicator element */
|
|
62
|
+
class?: ClassValue;
|
|
63
|
+
/** Styles for the indicator element */
|
|
64
|
+
style?: StyleValue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The bar of a Meter that fills the track in proportion to the current
|
|
69
|
+
* value.
|
|
70
|
+
*/
|
|
71
|
+
declare function MeterIndicator(
|
|
72
|
+
$parent: ParentNode,
|
|
73
|
+
$anchor: Node | null,
|
|
74
|
+
$props: MeterIndicatorProps | undefined,
|
|
75
|
+
$context?: Record<PropertyKey, any>,
|
|
76
|
+
$slots?: Record<string, SlotRender>,
|
|
77
|
+
): void;
|
|
78
|
+
|
|
79
|
+
export { Meter, MeterIndicator };
|
package/dist/Modal/Modal.torp
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
2
|
import $handle from "../utils/$handle";
|
|
3
|
+
import { createPopoutButtonHandler } from "../utils/handlePopoutButton";
|
|
3
4
|
import { type PopoutContext, PopoutContextName } from "../utils/PopoutTypes";
|
|
4
5
|
import { type ModalContext, ModalContextName, type ModalState } from "./ModalTypes";
|
|
5
6
|
|
|
@@ -43,7 +44,8 @@ export default function Modal($props: ModalProps | undefined) {
|
|
|
43
44
|
|
|
44
45
|
$bind($state, $props, "visible");
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
|
|
48
|
+
const { handleButton, getResult } = createPopoutButtonHandler($state);
|
|
47
49
|
|
|
48
50
|
// Set the context to pass down to items
|
|
49
51
|
let context: ModalContext = {
|
|
@@ -64,30 +66,10 @@ export default function Modal($props: ModalProps | undefined) {
|
|
|
64
66
|
if (visible) {
|
|
65
67
|
$props?.onopen?.();
|
|
66
68
|
} else {
|
|
67
|
-
$props?.onclose?.(
|
|
69
|
+
$props?.onclose?.(getResult());
|
|
68
70
|
}
|
|
69
71
|
});
|
|
70
72
|
|
|
71
|
-
function handleButton(type: "confirm" | "cancel" | undefined, value?: any) {
|
|
72
|
-
// Get the button's result
|
|
73
|
-
switch (type) {
|
|
74
|
-
case "confirm": {
|
|
75
|
-
result = value ?? true;
|
|
76
|
-
break;
|
|
77
|
-
}
|
|
78
|
-
case "cancel": {
|
|
79
|
-
result = value ?? false;
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
default: {
|
|
83
|
-
result = value;
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// Hide the modal
|
|
89
|
-
$state.visible = false;
|
|
90
|
-
}
|
|
91
73
|
|
|
92
74
|
function handleClickOutside(e: MouseEvent | KeyboardEvent) {
|
|
93
75
|
e.preventDefault();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
2
|
+
import PopoutOverlay from "../utils/PopoutOverlay.torp";
|
|
3
3
|
import { type ModalContext, ModalContextName } from "./ModalTypes";
|
|
4
4
|
|
|
5
5
|
interface ModalOverlayProps {
|
|
@@ -21,22 +21,15 @@ export default function ModalOverlay($props: ModalOverlayProps | undefined) {
|
|
|
21
21
|
if (!context) {
|
|
22
22
|
throw new Error("ModalOverlay must be contained within a Modal");
|
|
23
23
|
}
|
|
24
|
-
let $state = context.state;
|
|
25
|
-
|
|
26
|
-
// Any popup with an overlay is modal
|
|
27
|
-
$state.modal = true;
|
|
28
24
|
|
|
29
25
|
@render {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
<slot />
|
|
39
|
-
</div>
|
|
40
|
-
}
|
|
26
|
+
<PopoutOverlay
|
|
27
|
+
id={$props?.id}
|
|
28
|
+
class={["torp-modal-overlay", $props?.class]}
|
|
29
|
+
style={$props?.style}
|
|
30
|
+
{context}
|
|
31
|
+
>
|
|
32
|
+
<slot />
|
|
33
|
+
</PopoutOverlay>
|
|
41
34
|
}
|
|
42
35
|
}
|
|
@@ -33,7 +33,9 @@ interface NavMenuProps {
|
|
|
33
33
|
* ```
|
|
34
34
|
*/
|
|
35
35
|
export default function NavMenu($props: NavMenuProps | undefined) {
|
|
36
|
-
|
|
36
|
+
function getOrientation(): "horizontal" | "vertical" {
|
|
37
|
+
return $props?.orientation ?? "horizontal";
|
|
38
|
+
}
|
|
37
39
|
|
|
38
40
|
// The focus group owns the item ledger and roving-tabindex bookkeeping
|
|
39
41
|
const group = createFocusGroup<ItemState>();
|
|
@@ -83,7 +85,7 @@ export default function NavMenu($props: NavMenuProps | undefined) {
|
|
|
83
85
|
}
|
|
84
86
|
default: {
|
|
85
87
|
group.handleGroupKey(group.getFocusIndex(), e, {
|
|
86
|
-
vertical:
|
|
88
|
+
vertical: getOrientation() === "vertical",
|
|
87
89
|
});
|
|
88
90
|
break;
|
|
89
91
|
}
|
|
@@ -99,7 +101,7 @@ export default function NavMenu($props: NavMenuProps | undefined) {
|
|
|
99
101
|
tabindex="0"
|
|
100
102
|
role="menubar"
|
|
101
103
|
aria-label={$props?.ariaLabel}
|
|
102
|
-
aria-orientation={
|
|
104
|
+
aria-orientation={getOrientation()}
|
|
103
105
|
onfocus={handleFocus}
|
|
104
106
|
>
|
|
105
107
|
<slot />
|
|
@@ -46,7 +46,7 @@ export default function NumberInput($props: NumberInputProps | undefined) {
|
|
|
46
46
|
|
|
47
47
|
// Wire up the enclosing Form and Field, if any
|
|
48
48
|
const form = createFormField(
|
|
49
|
-
$props?.name,
|
|
49
|
+
() => $props?.name,
|
|
50
50
|
$context[FormContextName] as FormContext | undefined,
|
|
51
51
|
$context[FieldContextName] as FieldContext | undefined,
|
|
52
52
|
);
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { Bindable, ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import getId from "../utils/getId";
|
|
3
|
+
import {
|
|
4
|
+
type FieldContext,
|
|
5
|
+
FieldContextName,
|
|
6
|
+
type FormContext,
|
|
7
|
+
FormContextName,
|
|
8
|
+
} from "../Form/FormTypes";
|
|
9
|
+
import FormValues from "../Form/FormValues.torp";
|
|
10
|
+
import createFormField from "../utils/formField";
|
|
11
|
+
|
|
12
|
+
interface PinInputProps {
|
|
13
|
+
/** An ID for the root element */
|
|
14
|
+
id?: string;
|
|
15
|
+
/** Classes for the root element */
|
|
16
|
+
class?: ClassValue;
|
|
17
|
+
/** Styles for the root element */
|
|
18
|
+
style?: StyleValue;
|
|
19
|
+
/** The name of the input's form data field */
|
|
20
|
+
name?: string;
|
|
21
|
+
/** The entered characters, without separators */
|
|
22
|
+
value?: Bindable<string | undefined>;
|
|
23
|
+
/** The number of characters (default 6) */
|
|
24
|
+
length?: number;
|
|
25
|
+
/** Whether digits only or any characters are accepted (default "numeric") */
|
|
26
|
+
type?: "numeric" | "text";
|
|
27
|
+
/** If set to true, the characters are obscured like a password */
|
|
28
|
+
mask?: boolean;
|
|
29
|
+
/** If set to true, the user cannot interact with this input */
|
|
30
|
+
disabled?: boolean;
|
|
31
|
+
/** An accessible name for the whole input */
|
|
32
|
+
ariaLabel?: string;
|
|
33
|
+
/** Raised when the value has changed */
|
|
34
|
+
onchange?: (value: string) => void;
|
|
35
|
+
/** Raised when every character has been entered */
|
|
36
|
+
oncomplete?: (value: string) => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* An input for one-time passcodes or PINs, made of one field per character.
|
|
41
|
+
* Typing advances to the next field, Backspace goes back, pasting fills the
|
|
42
|
+
* remaining fields, and the arrow keys move between them.
|
|
43
|
+
*
|
|
44
|
+
* ```
|
|
45
|
+
* <PinInput name="code" length={6} oncomplete={(code) => verify(code)} />
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export default function PinInput($props: PinInputProps | undefined) {
|
|
49
|
+
let defaultId = getId();
|
|
50
|
+
const inputs: HTMLInputElement[] = [];
|
|
51
|
+
|
|
52
|
+
// Wire up the enclosing Form and Field, if any
|
|
53
|
+
const formContext = $context[FormContextName] as FormContext | undefined;
|
|
54
|
+
const fieldContext = $context[FieldContextName] as FieldContext | undefined;
|
|
55
|
+
const form = createFormField(() => $props?.name, formContext, fieldContext);
|
|
56
|
+
|
|
57
|
+
let $state = $watch({
|
|
58
|
+
value: ($props?.value ?? "") as string,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
$bind($state, $props, "value");
|
|
62
|
+
|
|
63
|
+
function getLength(): number {
|
|
64
|
+
return Math.max(1, $props?.length ?? 6);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function getDisabled(): boolean {
|
|
68
|
+
return $props?.disabled === true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function sanitize(text: string): string {
|
|
72
|
+
if ($props?.type === "text") return text;
|
|
73
|
+
return text.replace(/[^0-9]/g, "");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Keeps the Field's Label pointing at the first character field */
|
|
77
|
+
function updateInputId() {
|
|
78
|
+
if (fieldContext) {
|
|
79
|
+
const el = inputs[0];
|
|
80
|
+
fieldContext.state.inputId = el?.id || `${$props?.id ?? defaultId}-0`;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
$run(() => {
|
|
85
|
+
$state.value;
|
|
86
|
+
updateInputId();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
function commit(next: string) {
|
|
90
|
+
next = next.slice(0, getLength());
|
|
91
|
+
if (next === $state.value) return;
|
|
92
|
+
$state.value = next;
|
|
93
|
+
form.handleInput();
|
|
94
|
+
$props?.onchange?.(next);
|
|
95
|
+
if (next.length === getLength()) {
|
|
96
|
+
$props?.oncomplete?.(next);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function focusAt(index: number) {
|
|
101
|
+
const clamped = Math.min(getLength() - 1, Math.max(0, index));
|
|
102
|
+
inputs[clamped]?.focus();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function handleInput(index: number, e: Event) {
|
|
106
|
+
const el = e.currentTarget as HTMLInputElement;
|
|
107
|
+
const current = $state.value ?? "";
|
|
108
|
+
const text = sanitize(el.value);
|
|
109
|
+
if (text === "") {
|
|
110
|
+
// The character was deleted
|
|
111
|
+
commit(current.slice(0, index) + current.slice(index + 1));
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
// Typing replaces the character at this position; a longer value
|
|
115
|
+
// (from an IME or an autofill) fills the following positions
|
|
116
|
+
const before = current.slice(0, index);
|
|
117
|
+
const after = current.slice(index + Math.max(1, text.length));
|
|
118
|
+
commit(before + text + after);
|
|
119
|
+
focusAt(index + text.length);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function handlePaste(index: number, e: ClipboardEvent) {
|
|
123
|
+
if (getDisabled()) return;
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
const pasted = sanitize(e.clipboardData?.getData("text") ?? "");
|
|
126
|
+
if (!pasted) return;
|
|
127
|
+
const current = $state.value ?? "";
|
|
128
|
+
const before = current.slice(0, index);
|
|
129
|
+
const after = current.slice(index + pasted.length);
|
|
130
|
+
commit(before + pasted + after);
|
|
131
|
+
focusAt(index + pasted.length);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function handleKey(index: number, e: KeyboardEvent) {
|
|
135
|
+
if (getDisabled()) return;
|
|
136
|
+
const current = $state.value ?? "";
|
|
137
|
+
switch (e.key) {
|
|
138
|
+
case "Backspace": {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
if (current[index] !== undefined) {
|
|
141
|
+
commit(current.slice(0, index) + current.slice(index + 1));
|
|
142
|
+
} else {
|
|
143
|
+
commit(current.slice(0, index - 1) + current.slice(index));
|
|
144
|
+
focusAt(index - 1);
|
|
145
|
+
}
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
case "Delete": {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
commit(current.slice(0, index) + current.slice(index + 1));
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
case "ArrowLeft": {
|
|
154
|
+
e.preventDefault();
|
|
155
|
+
focusAt(index - 1);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case "ArrowRight": {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
focusAt(index + 1);
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
case "Home": {
|
|
164
|
+
e.preventDefault();
|
|
165
|
+
focusAt(0);
|
|
166
|
+
break;
|
|
167
|
+
}
|
|
168
|
+
case "End": {
|
|
169
|
+
e.preventDefault();
|
|
170
|
+
focusAt(getLength() - 1);
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function handleFocus(e: FocusEvent) {
|
|
177
|
+
(e.currentTarget as HTMLInputElement).select();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
@render {
|
|
181
|
+
<div
|
|
182
|
+
{$props?.id}
|
|
183
|
+
class={["torp-pin-input", $props?.class]}
|
|
184
|
+
{$props?.style}
|
|
185
|
+
role="group"
|
|
186
|
+
aria-label={$props?.ariaLabel}
|
|
187
|
+
aria-disabled={getDisabled() ? "true" : undefined}
|
|
188
|
+
data-valid={form.valid ? "valid" : "invalid"}
|
|
189
|
+
aria-describedby={form.messageId}
|
|
190
|
+
aria-invalid={form.inField && !form.valid ? "true" : undefined}
|
|
191
|
+
>
|
|
192
|
+
@for (let i of Array.from({ length: getLength() }, (_, i) => i)) {
|
|
193
|
+
<input
|
|
194
|
+
id={`${$props?.id ?? defaultId}-${i}`}
|
|
195
|
+
class="torp-pin-input-field"
|
|
196
|
+
type={$props?.mask ? "password" : "text"}
|
|
197
|
+
inputmode={$props?.type === "text" ? undefined : "numeric"}
|
|
198
|
+
autocomplete={i === 0 ? "one-time-code" : "off"}
|
|
199
|
+
maxlength="1"
|
|
200
|
+
aria-label={`Character ${i + 1}`}
|
|
201
|
+
disabled={getDisabled()}
|
|
202
|
+
value={($state.value ?? "")[i] ?? ""}
|
|
203
|
+
oninput={(e: Event) => handleInput(i, e)}
|
|
204
|
+
onkeydown={(e: KeyboardEvent) => handleKey(i, e)}
|
|
205
|
+
onpaste={(e: ClipboardEvent) => handlePaste(i, e)}
|
|
206
|
+
onfocus={handleFocus}
|
|
207
|
+
onmount={(el: HTMLInputElement) => {
|
|
208
|
+
inputs[i] = el;
|
|
209
|
+
if (i === 0) updateInputId();
|
|
210
|
+
return () => {
|
|
211
|
+
if (inputs[i] === el) inputs[i] = undefined as any;
|
|
212
|
+
};
|
|
213
|
+
}}
|
|
214
|
+
/>
|
|
215
|
+
}
|
|
216
|
+
</div>
|
|
217
|
+
|
|
218
|
+
<FormValues name={form.name} value={$state.value} />
|
|
219
|
+
}
|
|
220
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type SlotRender } from "@torpor/view";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
interface PinInputProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Classes for the root element */
|
|
8
|
+
class?: ClassValue;
|
|
9
|
+
/** Styles for the root element */
|
|
10
|
+
style?: StyleValue;
|
|
11
|
+
/** The name of the input's form data field */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** The entered characters, without separators */
|
|
14
|
+
value?: Bindable<string | undefined>;
|
|
15
|
+
/** The number of characters (default 6) */
|
|
16
|
+
length?: number;
|
|
17
|
+
/** Whether digits only or any characters are accepted (default "numeric") */
|
|
18
|
+
type?: "numeric" | "text";
|
|
19
|
+
/** If set to true, the characters are obscured like a password */
|
|
20
|
+
mask?: boolean;
|
|
21
|
+
/** If set to true, the user cannot interact with this input */
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
/** An accessible name for the whole input */
|
|
24
|
+
ariaLabel?: string;
|
|
25
|
+
/** Raised when the value has changed */
|
|
26
|
+
onchange?: (value: string) => void;
|
|
27
|
+
/** Raised when every character has been entered */
|
|
28
|
+
oncomplete?: (value: string) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* An input for one-time passcodes or PINs, made of one field per character.
|
|
33
|
+
* Typing advances to the next field, Backspace goes back, pasting fills the
|
|
34
|
+
* remaining fields, and the arrow keys move between them.
|
|
35
|
+
*
|
|
36
|
+
* ```
|
|
37
|
+
* <PinInput name="code" length={6} oncomplete={(code) => verify(code)} />
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare function PinInput(
|
|
41
|
+
$parent: ParentNode,
|
|
42
|
+
$anchor: Node | null,
|
|
43
|
+
$props: PinInputProps | undefined,
|
|
44
|
+
$context?: Record<PropertyKey, any>,
|
|
45
|
+
$slots?: Record<string, SlotRender>,
|
|
46
|
+
): void;
|
|
47
|
+
|
|
48
|
+
export { PinInput };
|