@torpor/ui 1.3.6 → 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 +2 -2
- 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-CBGbVpkN.js → loader/index.js} +2 -2
- 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/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-CBGbVpkN.js.map +0 -1
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import { createPopoutContent } from "../utils/popoutContent";
|
|
4
|
-
import setContextPosition from "../utils/setContextPosition";
|
|
5
|
-
import { type ContextualContext, ContextualContextName } from "./ContextualTypes";
|
|
2
|
+
import PopoverContent from "../Popover/PopoverContent.torp";
|
|
6
3
|
|
|
7
4
|
interface ContextualContentProps {
|
|
8
5
|
/** An ID for the root element */
|
|
@@ -14,55 +11,17 @@ interface ContextualContentProps {
|
|
|
14
11
|
}
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
|
-
* The content that is displayed for a Contextual when it is open, displayed
|
|
18
|
-
* position that the user right-clicked.
|
|
14
|
+
* The content that is displayed for a Contextual when it is open, displayed
|
|
15
|
+
* at the position that the user right-clicked.
|
|
19
16
|
*/
|
|
20
17
|
export default function ContextualContent($props: ContextualContentProps | undefined) {
|
|
21
|
-
let defaultId = getId();
|
|
22
|
-
|
|
23
|
-
// Get stuff out of the ContextualContext
|
|
24
|
-
const context = $context[ContextualContextName] as ContextualContext;
|
|
25
|
-
if (!context) {
|
|
26
|
-
throw new Error("ContextualContent must be contained within a Contextual");
|
|
27
|
-
}
|
|
28
|
-
let $state = context.state;
|
|
29
|
-
|
|
30
|
-
// Set the content ID so that the trigger can use it with aria-controls
|
|
31
|
-
$state.contentId = $props?.id ?? defaultId;
|
|
32
|
-
|
|
33
|
-
const popout = createPopoutContent({
|
|
34
|
-
getAnchor: () => context.anchorElement,
|
|
35
|
-
getContent: () => div,
|
|
36
|
-
close: (e) => context.handleClickOutside?.(e),
|
|
37
|
-
position: () => {
|
|
38
|
-
if (context.anchorElement && div && $state.position) {
|
|
39
|
-
setContextPosition(context.anchorElement, div, $state.position);
|
|
40
|
-
}
|
|
41
|
-
},
|
|
42
|
-
ignoreAnchorClicks: true,
|
|
43
|
-
focusFirstElement: () => context.focusFirstElement?.(),
|
|
44
|
-
refocusAnchorOnHide: true,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
let div: HTMLDivElement;
|
|
48
|
-
|
|
49
|
-
$run(() => {
|
|
50
|
-
if (!$state.visible) {
|
|
51
|
-
popout.hide();
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
18
|
@render {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
>
|
|
64
|
-
<slot />
|
|
65
|
-
</div>
|
|
66
|
-
}
|
|
19
|
+
<PopoverContent
|
|
20
|
+
id={$props?.id}
|
|
21
|
+
class={["torp-popover-content-contextual", $props?.class]}
|
|
22
|
+
style={$props?.style}
|
|
23
|
+
>
|
|
24
|
+
<slot />
|
|
25
|
+
</PopoverContent>
|
|
67
26
|
}
|
|
68
27
|
}
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
-
import
|
|
3
|
-
import getId from "../utils/getId";
|
|
4
|
-
import {
|
|
5
|
-
type ContextualContext,
|
|
6
|
-
ContextualContextName,
|
|
7
|
-
} from "./ContextualTypes";
|
|
2
|
+
import PopoverHover from "../Popover/PopoverHover.torp";
|
|
8
3
|
|
|
9
4
|
interface ContextualHoverProps {
|
|
10
5
|
/** An ID for the root element */
|
|
@@ -22,22 +17,16 @@ interface ContextualHoverProps {
|
|
|
22
17
|
/**
|
|
23
18
|
* How taps on touch screens open the contextual window (hover never
|
|
24
19
|
* fires on touch). "auto" (default): tapping the trigger's inert surface
|
|
25
|
-
* opens it, but tapping a control inside the trigger
|
|
26
|
-
*
|
|
27
|
-
*
|
|
20
|
+
* opens it, but tapping a control inside the trigger runs that control's
|
|
21
|
+
* action without opening. "open": any tap opens it. "ignore": taps never
|
|
22
|
+
* open it.
|
|
28
23
|
*/
|
|
29
24
|
touchBehavior?: "auto" | "open" | "ignore";
|
|
30
25
|
}
|
|
31
26
|
|
|
32
27
|
/**
|
|
33
28
|
* An element that shows a Contextual while hovered at the pointer's
|
|
34
|
-
* location
|
|
35
|
-
* (so passing over the element doesn't flash a window), and an exit grace
|
|
36
|
-
* period after leaving (so moving into the contextual content doesn't close
|
|
37
|
-
* it).
|
|
38
|
-
*
|
|
39
|
-
* Focusing the element opens it immediately; blurring closes it. Use this
|
|
40
|
-
* in place of ContextualTrigger:
|
|
29
|
+
* location. This is PopoverHover in contextual mode.
|
|
41
30
|
*
|
|
42
31
|
* ```
|
|
43
32
|
* <Contextual>
|
|
@@ -47,78 +36,17 @@ interface ContextualHoverProps {
|
|
|
47
36
|
* ```
|
|
48
37
|
*/
|
|
49
38
|
export default function ContextualHover($props?: ContextualHoverProps) {
|
|
50
|
-
let defaultId = getId();
|
|
51
|
-
|
|
52
|
-
// Get stuff out of the ContextualContext
|
|
53
|
-
const context = $context[ContextualContextName] as ContextualContext;
|
|
54
|
-
if (!context) {
|
|
55
|
-
throw new Error("ContextualHover must be contained within a Contextual");
|
|
56
|
-
}
|
|
57
|
-
const $state = context.state;
|
|
58
|
-
|
|
59
|
-
// Set the trigger ID so that it can be used with aria-labelledby
|
|
60
|
-
$state.triggerId = $props?.id ?? defaultId;
|
|
61
|
-
|
|
62
|
-
let node: HTMLElement;
|
|
63
|
-
|
|
64
|
-
function activate(e: MouseEvent | TouchEvent) {
|
|
65
|
-
if ($state.position) {
|
|
66
|
-
// Get the position relative to the element, so we can reposition on scroll
|
|
67
|
-
const rect = node.getBoundingClientRect();
|
|
68
|
-
const point = e instanceof TouchEvent ? e.touches[0] : e;
|
|
69
|
-
$state.position = {
|
|
70
|
-
x: (point?.clientX ?? 0) - rect.left,
|
|
71
|
-
y: (point?.clientY ?? 0) - rect.top,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function setVisible(visible: boolean) {
|
|
77
|
-
$state.visible = visible;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const hover = createHoverReveal({
|
|
81
|
-
show: () => setVisible(true),
|
|
82
|
-
hide: () => setVisible(false),
|
|
83
|
-
isVisible: () => $state.visible,
|
|
84
|
-
disabled: () => $props?.disabled === true,
|
|
85
|
-
getContent: () => ($state.contentId ? document.getElementById($state.contentId) : undefined),
|
|
86
|
-
hoverDelay: $props?.hoverDelay,
|
|
87
|
-
exitGrace: $props?.exitGrace,
|
|
88
|
-
touchBehavior: $props?.touchBehavior,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
$run(() => {
|
|
92
|
-
return () => hover.dispose();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
function handleEnter() {
|
|
96
|
-
// Suppressed touch taps (a tap on an embedded control) don't anchor
|
|
97
|
-
// the content either — the tap belongs to the control's action
|
|
98
|
-
if (!hover.handleEnter()) return;
|
|
99
|
-
activate({ clientX: node.offsetWidth / 2, clientY: node.offsetHeight / 2 } as MouseEvent);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
39
|
@render {
|
|
103
|
-
<
|
|
104
|
-
id={$props?.id
|
|
40
|
+
<PopoverHover
|
|
41
|
+
id={$props?.id}
|
|
105
42
|
class={["torp-contextual-hover", $props?.class]}
|
|
106
|
-
{$props?.style}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
onmouseenter={handleEnter}
|
|
112
|
-
onmouseleave={(e: MouseEvent) => hover.handleLeave(e)}
|
|
113
|
-
onpointerdown={(e: PointerEvent) => hover.handlePointerDown(e)}
|
|
114
|
-
onfocus={() => hover.handleFocus()}
|
|
115
|
-
onblur={(e: FocusEvent) => hover.handleBlur(e)}
|
|
116
|
-
onmount={(el) => {
|
|
117
|
-
node = el;
|
|
118
|
-
context.anchorElement = el;
|
|
119
|
-
}}
|
|
43
|
+
style={$props?.style}
|
|
44
|
+
hoverDelay={$props?.hoverDelay}
|
|
45
|
+
exitGrace={$props?.exitGrace}
|
|
46
|
+
disabled={$props?.disabled}
|
|
47
|
+
touchBehavior={$props?.touchBehavior}
|
|
120
48
|
>
|
|
121
49
|
<slot />
|
|
122
|
-
</
|
|
50
|
+
</PopoverHover>
|
|
123
51
|
}
|
|
124
52
|
}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import type { ClassValue, StyleValue } from "@torpor/view";
|
|
2
|
+
import { type PopoverContext, PopoverContextName } from "../Popover/PopoverTypes";
|
|
2
3
|
import PopoutClickTrigger from "../utils/PopoutClickTrigger.torp";
|
|
3
|
-
import {
|
|
4
|
-
type ContextualContext,
|
|
5
|
-
ContextualContextName,
|
|
6
|
-
type Point,
|
|
7
|
-
} from "./ContextualTypes";
|
|
8
4
|
|
|
9
5
|
interface ContextualTriggerProps {
|
|
10
6
|
/** An ID for the root element */
|
|
@@ -24,23 +20,20 @@ interface ContextualTriggerProps {
|
|
|
24
20
|
* doesn't.
|
|
25
21
|
*/
|
|
26
22
|
export default function ContextualTrigger($props?: ContextualTriggerProps) {
|
|
27
|
-
//
|
|
28
|
-
const context = $context[
|
|
23
|
+
// Contextual uses Popover's context
|
|
24
|
+
const context = $context[PopoverContextName] as PopoverContext;
|
|
29
25
|
if (!context) {
|
|
30
26
|
throw new Error("ContextualTrigger must be contained within a Contextual");
|
|
31
27
|
}
|
|
32
28
|
const $state = context.state;
|
|
33
29
|
|
|
34
30
|
function activate(node: HTMLElement, e: MouseEvent) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
42
|
-
$state.position = point;
|
|
43
|
-
}
|
|
31
|
+
// Get the position relative to the element, so we can reposition on scroll
|
|
32
|
+
const rect = node.getBoundingClientRect();
|
|
33
|
+
$state.position = {
|
|
34
|
+
x: e.clientX - rect.left,
|
|
35
|
+
y: e.clientY - rect.top,
|
|
36
|
+
};
|
|
44
37
|
}
|
|
45
38
|
|
|
46
39
|
@render {
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { PopoverContext, PopoverState } from "../Popover/PopoverTypes";
|
|
2
2
|
|
|
3
|
+
/** @deprecated Contextual uses Popover's context */
|
|
3
4
|
export const ContextualContextName: unique symbol = Symbol.for("torp.Contextual");
|
|
4
5
|
|
|
5
|
-
/** The shared context for
|
|
6
|
-
export
|
|
7
|
-
state: ContextualState;
|
|
8
|
-
}
|
|
6
|
+
/** The shared context for Contextual components */
|
|
7
|
+
export type ContextualContext = PopoverContext;
|
|
9
8
|
|
|
10
|
-
export
|
|
11
|
-
position: Point;
|
|
12
|
-
}
|
|
9
|
+
export type ContextualState = PopoverState;
|
|
13
10
|
|
|
14
|
-
export
|
|
15
|
-
x: number;
|
|
16
|
-
y: number;
|
|
17
|
-
}
|
|
11
|
+
export type { Point } from "../Popover/PopoverTypes";
|
|
@@ -8,13 +8,13 @@ interface ContextualProps {
|
|
|
8
8
|
class?: ClassValue;
|
|
9
9
|
/** Styles for the root element */
|
|
10
10
|
style?: StyleValue;
|
|
11
|
-
/** Whether the contextual is modal
|
|
11
|
+
/** Whether the contextual is modal */
|
|
12
12
|
modal?: boolean;
|
|
13
|
-
/** Whether the contextual is visible
|
|
13
|
+
/** Whether the contextual is visible */
|
|
14
14
|
visible: Bindable<boolean | undefined>;
|
|
15
|
-
/** The element to anchor this contextual to, as an alternative to supplying a ContextualTrigger
|
|
15
|
+
/** The element to anchor this contextual to, as an alternative to supplying a ContextualTrigger */
|
|
16
16
|
anchor?: HTMLElement;
|
|
17
|
-
/** The position to display this contextual at
|
|
17
|
+
/** The position to display this contextual at */
|
|
18
18
|
position?: Point;
|
|
19
19
|
/** Raised when the contextual has opened */
|
|
20
20
|
onopen?: () => void;
|
|
@@ -25,6 +25,9 @@ interface ContextualProps {
|
|
|
25
25
|
/**
|
|
26
26
|
* A contextual window that is shown to the user at the cursor's location.
|
|
27
27
|
*
|
|
28
|
+
* Contextual is Popover in contextual mode: the same root, trigger and
|
|
29
|
+
* content machinery, positioned at a point instead of at a side.
|
|
30
|
+
*
|
|
28
31
|
* The structure of a Contextual is:
|
|
29
32
|
*
|
|
30
33
|
* ```
|
|
@@ -54,8 +57,8 @@ interface ContextualContentProps {
|
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
/**
|
|
57
|
-
* The content that is displayed for a Contextual when it is open, displayed
|
|
58
|
-
* position that the user right-clicked.
|
|
60
|
+
* The content that is displayed for a Contextual when it is open, displayed
|
|
61
|
+
* at the position that the user right-clicked.
|
|
59
62
|
*/
|
|
60
63
|
declare function ContextualContent(
|
|
61
64
|
$parent: ParentNode,
|
|
@@ -69,13 +72,7 @@ declare function ContextualContent(
|
|
|
69
72
|
|
|
70
73
|
/**
|
|
71
74
|
* An element that shows a Contextual while hovered at the pointer's
|
|
72
|
-
* location
|
|
73
|
-
* (so passing over the element doesn't flash a window), and an exit grace
|
|
74
|
-
* period after leaving (so moving into the contextual content doesn't close
|
|
75
|
-
* it).
|
|
76
|
-
*
|
|
77
|
-
* Focusing the element opens it immediately; blurring closes it. Use this
|
|
78
|
-
* in place of ContextualTrigger:
|
|
75
|
+
* location. This is PopoverHover in contextual mode.
|
|
79
76
|
*
|
|
80
77
|
* ```
|
|
81
78
|
* <Contextual>
|
|
@@ -58,7 +58,7 @@ interface DataGridProps {
|
|
|
58
58
|
/** Called when a load starts, including reloads triggered by sorting or paging */
|
|
59
59
|
onloadstart?: () => void;
|
|
60
60
|
/** Called when the user sorts by a column */
|
|
61
|
-
|
|
61
|
+
onchange?: (sortBy: string | undefined, sortDirection: "asc" | "desc") => void;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
/**
|
|
@@ -315,7 +315,7 @@ export default function DataGrid($props: DataGridProps) {
|
|
|
315
315
|
$state.sortBy = column.key;
|
|
316
316
|
$state.sortDirection = "asc";
|
|
317
317
|
}
|
|
318
|
-
$props.
|
|
318
|
+
$props.onchange?.($state.sortBy, $state.sortDirection);
|
|
319
319
|
}
|
|
320
320
|
|
|
321
321
|
// Scrolls the virtual window so a logical row is rendered, before it is
|
package/dist/DataGrid/index.d.ts
CHANGED
|
@@ -48,7 +48,7 @@ interface DataGridProps {
|
|
|
48
48
|
/** Called when a load starts, including reloads triggered by sorting or paging */
|
|
49
49
|
onloadstart?: () => void;
|
|
50
50
|
/** Called when the user sorts by a column */
|
|
51
|
-
|
|
51
|
+
onchange?: (sortBy: string | undefined, sortDirection: "asc" | "desc") => void;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
/**
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type FormContext,
|
|
6
6
|
FormContextName,
|
|
7
7
|
} from "../Form/FormTypes";
|
|
8
|
+
import FormValues from "../Form/FormValues.torp";
|
|
8
9
|
import { formatDate } from "../utils/dateUtils";
|
|
9
10
|
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
10
11
|
import getId from "../utils/getId";
|
|
@@ -59,7 +60,7 @@ export default function DatePicker($props: DatePickerProps | undefined) {
|
|
|
59
60
|
|
|
60
61
|
// Wire up the enclosing Form and Field, if any
|
|
61
62
|
const form = createFormField(
|
|
62
|
-
$props?.name,
|
|
63
|
+
() => $props?.name,
|
|
63
64
|
$context[FormContextName] as FormContext | undefined,
|
|
64
65
|
$context[FieldContextName] as FieldContext | undefined,
|
|
65
66
|
);
|
|
@@ -195,8 +196,9 @@ export default function DatePicker($props: DatePickerProps | undefined) {
|
|
|
195
196
|
</slot>
|
|
196
197
|
</div>
|
|
197
198
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
199
|
+
<FormValues
|
|
200
|
+
name={form.name}
|
|
201
|
+
value={$state.value ? formatDate($unwrap($state.value), "yyyy-MM-dd") : undefined}
|
|
202
|
+
/>
|
|
201
203
|
}
|
|
202
204
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type FormContext,
|
|
6
6
|
FormContextName,
|
|
7
7
|
} from "../Form/FormTypes";
|
|
8
|
+
import FormValues from "../Form/FormValues.torp";
|
|
8
9
|
import { areDatesEqual, formatDate } from "../utils/dateUtils";
|
|
9
10
|
import { addDocumentEvent, removeDocumentEvent } from "../utils/documentEvents";
|
|
10
11
|
import getId from "../utils/getId";
|
|
@@ -68,11 +69,22 @@ export default function DateRangePicker($props: DateRangePickerProps | undefined
|
|
|
68
69
|
|
|
69
70
|
// Wire up the enclosing Form and Field, if any
|
|
70
71
|
const form = createFormField(
|
|
71
|
-
$props?.name,
|
|
72
|
+
() => $props?.name,
|
|
72
73
|
$context[FormContextName] as FormContext | undefined,
|
|
73
74
|
$context[FieldContextName] as FieldContext | undefined,
|
|
74
75
|
);
|
|
75
76
|
|
|
77
|
+
// Both ends of the range submit under the one field name, like other
|
|
78
|
+
// multi-value inputs
|
|
79
|
+
function submittedValues(): string[] | undefined {
|
|
80
|
+
const value = $state.value;
|
|
81
|
+
if (!value) return undefined;
|
|
82
|
+
const values: string[] = [];
|
|
83
|
+
if (value.start) values.push(formatDate($unwrap(value.start), "yyyy-MM-dd"));
|
|
84
|
+
if (value.end) values.push(formatDate($unwrap(value.end), "yyyy-MM-dd"));
|
|
85
|
+
return values.length > 0 ? values : undefined;
|
|
86
|
+
}
|
|
87
|
+
|
|
76
88
|
function getDateFormat(): string {
|
|
77
89
|
return $props?.dateFormat ?? "yyyy-MM-dd";
|
|
78
90
|
}
|
|
@@ -275,17 +287,6 @@ export default function DateRangePicker($props: DateRangePickerProps | undefined
|
|
|
275
287
|
</slot>
|
|
276
288
|
</div>
|
|
277
289
|
|
|
278
|
-
|
|
279
|
-
<input
|
|
280
|
-
type="hidden"
|
|
281
|
-
name={`${form.name}-start`}
|
|
282
|
-
value={$state.value?.start ? formatDate($unwrap($state.value.start), "yyyy-MM-dd") : ""}
|
|
283
|
-
/>
|
|
284
|
-
<input
|
|
285
|
-
type="hidden"
|
|
286
|
-
name={`${form.name}-end`}
|
|
287
|
-
value={$state.value?.end ? formatDate($unwrap($state.value.end), "yyyy-MM-dd") : ""}
|
|
288
|
-
/>
|
|
289
|
-
}
|
|
290
|
+
<FormValues name={form.name} value={submittedValues()} />
|
|
290
291
|
}
|
|
291
292
|
}
|