@torpor/ui 0.2.1 → 0.3.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/CHANGELOG.md +32 -0
- package/dist/Accordion/Accordion.torp +29 -22
- package/dist/Accordion/AccordionContent.torp +7 -8
- package/dist/Accordion/AccordionHeader.torp +4 -6
- package/dist/Accordion/AccordionItem.torp +15 -12
- package/dist/Accordion/AccordionTrigger.torp +6 -7
- package/dist/Accordion/AccordionTypes.ts +4 -3
- package/dist/Accordion/index.d.ts +5 -5
- package/dist/Breadcrumb/Breadcrumb.torp +9 -10
- package/dist/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/dist/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/dist/Breadcrumb/index.d.ts +8 -7
- package/dist/Calendar/Calendar.torp +12 -13
- package/dist/Calendar/CalendarDay.torp +3 -3
- package/dist/Contextual/Contextual.torp +125 -0
- package/dist/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/dist/Contextual/ContextualTrigger.torp +66 -0
- package/dist/Contextual/ContextualTypes.ts +30 -0
- package/dist/Contextual/index.d.ts +90 -0
- package/dist/Contextual/index.js +14 -0
- package/dist/Contextual/index.js.map +1 -0
- package/dist/Dialog/Dialog.torp +38 -72
- package/dist/Dialog/DialogBody.torp +6 -8
- package/dist/Dialog/DialogButton.torp +14 -12
- package/dist/Dialog/DialogFooter.torp +3 -5
- package/dist/Dialog/DialogHeader.torp +6 -8
- package/dist/Dialog/DialogTypes.ts +3 -2
- package/dist/Dialog/index.d.ts +16 -11
- package/dist/Disclosure/Disclosure.torp +22 -23
- package/dist/Disclosure/DisclosureContent.torp +7 -8
- package/dist/Disclosure/DisclosureHeader.torp +5 -7
- package/dist/Disclosure/DisclosureTrigger.torp +7 -8
- package/dist/Disclosure/DisclosureTypes.ts +0 -1
- package/dist/Disclosure/index.d.ts +12 -12
- package/dist/Drawer/Drawer.torp +101 -70
- package/dist/Drawer/DrawerContent.torp +80 -0
- package/dist/Drawer/DrawerOverlay.torp +38 -0
- package/dist/Drawer/DrawerTrigger.torp +35 -0
- package/dist/Drawer/DrawerTypes.ts +24 -0
- package/dist/Drawer/index.d.ts +90 -3
- package/dist/Drawer/index.js +13 -1
- package/dist/Form/CheckBox.torp +91 -0
- package/dist/Form/Field.torp +2 -4
- package/dist/Form/File.torp +106 -0
- package/dist/Form/Form.torp +17 -10
- package/dist/Form/FormTypes.ts +5 -0
- package/dist/Form/Input.torp +28 -17
- package/dist/Form/Label.torp +1 -1
- package/dist/Form/Message.torp +1 -1
- package/dist/Form/Option.torp +24 -0
- package/dist/Form/Select.torp +97 -0
- package/dist/Form/TextArea.torp +101 -0
- package/dist/Form/index.d.ts +192 -5
- package/dist/Form/index.js +21 -1
- package/dist/Menu/Menu.torp +16 -15
- package/dist/Menu/MenuButton.torp +19 -13
- package/dist/Menu/MenuCheck.torp +18 -14
- package/dist/Menu/MenuGroup.torp +4 -6
- package/dist/Menu/MenuIndicator.torp +5 -7
- package/dist/Menu/MenuPopout.torp +12 -15
- package/dist/Menu/MenuPopoutContent.torp +6 -8
- package/dist/Menu/MenuPopoutTrigger.torp +12 -14
- package/dist/Menu/MenuRadio.torp +14 -14
- package/dist/Menu/MenuRadioGroup.torp +22 -14
- package/dist/Menu/MenuSeparator.torp +3 -5
- package/dist/Menu/MenuTypes.ts +7 -5
- package/dist/Menu/index.d.ts +28 -22
- package/dist/MenuBar/MenuBar.torp +13 -14
- package/dist/MenuBar/MenuBarItem.torp +13 -16
- package/dist/MenuBar/MenuBarItemContent.torp +7 -9
- package/dist/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/dist/MenuBar/index.d.ts +16 -16
- package/dist/Modal/Modal.torp +118 -0
- package/dist/Modal/ModalContent.torp +77 -0
- package/dist/Modal/ModalOverlay.torp +38 -0
- package/dist/Modal/ModalTrigger.torp +50 -0
- package/dist/Modal/ModalTypes.ts +22 -0
- package/dist/Modal/index.d.ts +108 -0
- package/dist/Modal/index.js +33 -0
- package/dist/Modal/index.js.map +1 -0
- package/dist/Modal/showModal.ts +19 -0
- package/dist/Modal/showPrompt.ts +23 -0
- package/dist/NavMenu/NavMenu.torp +7 -8
- package/dist/NavMenu/NavMenuButton.torp +6 -8
- package/dist/NavMenu/NavMenuElement.torp +8 -8
- package/dist/NavMenu/NavMenuGroup.torp +4 -6
- package/dist/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/dist/NavMenu/NavMenuLink.torp +8 -11
- package/dist/NavMenu/NavMenuPopout.torp +25 -17
- package/dist/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/dist/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/dist/NavMenu/NavMenuSeparator.torp +3 -5
- package/dist/NavMenu/index.d.ts +17 -11
- package/dist/Notification/Notification.torp +22 -13
- package/dist/Notification/NotificationClose.torp +3 -5
- package/dist/Notification/NotificationContainer.torp +3 -5
- package/dist/Notification/NotificationContent.torp +3 -5
- package/dist/Notification/index.d.ts +4 -4
- package/dist/Popover/Popover.torp +31 -25
- package/dist/Popover/PopoverContent.torp +35 -10
- package/dist/Popover/PopoverTrigger.torp +24 -4
- package/dist/Popover/PopoverTypes.ts +1 -1
- package/dist/Popover/index.d.ts +16 -124
- package/dist/Popover/index.js +1 -163
- package/dist/Popover/index.js.map +1 -1
- package/dist/TabGroup/TabContent.torp +12 -9
- package/dist/TabGroup/TabGroup.torp +41 -35
- package/dist/TabGroup/TabGroupTypes.ts +10 -5
- package/dist/TabGroup/TabHeader.torp +15 -8
- package/dist/TabGroup/TabList.torp +4 -6
- package/dist/TabGroup/TabTrigger.torp +8 -9
- package/dist/TabGroup/index.d.ts +14 -6
- package/dist/icons/ArrowDown.torp +3 -1
- package/dist/icons/ArrowLeft.torp +3 -1
- package/dist/icons/ArrowRight.torp +3 -1
- package/dist/icons/ArrowUp.torp +3 -1
- package/dist/icons/Bars.torp +3 -1
- package/dist/icons/Check.torp +3 -1
- package/dist/icons/ChevronDown.torp +3 -1
- package/dist/icons/ChevronLeft.torp +3 -1
- package/dist/icons/ChevronRight.torp +3 -1
- package/dist/icons/ChevronUp.torp +3 -1
- package/dist/icons/Cross.torp +3 -1
- package/dist/icons/IconTypes.ts +6 -0
- package/dist/icons/Loading.torp +3 -1
- package/dist/icons/Minus.torp +3 -1
- package/dist/icons/Plus.torp +3 -1
- package/dist/icons/index.d.ts +271 -14
- package/dist/index.d.ts +17 -4
- package/dist/metafile-esm.json +1 -1
- package/dist/motion/fade.ts +15 -6
- package/dist/motion/grow.ts +23 -0
- package/dist/motion/index.d.ts +19 -2
- package/dist/motion/index.js +93 -3
- package/dist/motion/index.js.map +1 -1
- package/dist/motion/measure.ts +28 -0
- package/dist/motion/slide.ts +45 -0
- package/dist/mount/clickPopover.ts +51 -0
- package/dist/mount/contextPopover.ts +51 -0
- package/dist/mount/hoverPopover.ts +58 -0
- package/package.json +21 -14
- package/scripts/postbuild.ts +11 -1
- package/src/Accordion/Accordion.torp +29 -22
- package/src/Accordion/AccordionContent.torp +7 -8
- package/src/Accordion/AccordionHeader.torp +4 -6
- package/src/Accordion/AccordionItem.torp +15 -12
- package/src/Accordion/AccordionTrigger.torp +6 -7
- package/src/Accordion/AccordionTypes.ts +4 -3
- package/src/Breadcrumb/Breadcrumb.torp +9 -10
- package/src/Breadcrumb/BreadcrumbItem.torp +5 -7
- package/src/Breadcrumb/BreadcrumbSeparator.torp +3 -5
- package/src/Calendar/Calendar.torp +12 -13
- package/src/Calendar/CalendarDay.torp +3 -3
- package/src/Contextual/Contextual.torp +125 -0
- package/src/{Popover/PopoverContentContextual.torp → Contextual/ContextualContent.torp} +15 -15
- package/src/Contextual/ContextualTrigger.torp +66 -0
- package/src/Contextual/ContextualTypes.ts +30 -0
- package/src/Contextual/index.ts +5 -0
- package/src/Dialog/Dialog.torp +38 -72
- package/src/Dialog/DialogBody.torp +6 -8
- package/src/Dialog/DialogButton.torp +14 -12
- package/src/Dialog/DialogFooter.torp +3 -5
- package/src/Dialog/DialogHeader.torp +6 -8
- package/src/Dialog/DialogTypes.ts +3 -2
- package/src/Disclosure/Disclosure.torp +22 -23
- package/src/Disclosure/DisclosureContent.torp +7 -8
- package/src/Disclosure/DisclosureHeader.torp +5 -7
- package/src/Disclosure/DisclosureTrigger.torp +7 -8
- package/src/Disclosure/DisclosureTypes.ts +0 -1
- package/src/Drawer/Drawer.torp +101 -70
- package/src/Drawer/DrawerContent.torp +80 -0
- package/src/Drawer/DrawerOverlay.torp +38 -0
- package/src/Drawer/DrawerTrigger.torp +35 -0
- package/src/Drawer/DrawerTypes.ts +24 -0
- package/src/Drawer/index.ts +4 -1
- package/src/Form/CheckBox.torp +91 -0
- package/src/Form/Field.torp +2 -4
- package/src/Form/File.torp +106 -0
- package/src/Form/Form.torp +17 -10
- package/src/Form/FormTypes.ts +5 -0
- package/src/Form/Input.torp +28 -17
- package/src/Form/Label.torp +1 -1
- package/src/Form/Message.torp +1 -1
- package/src/Form/Option.torp +24 -0
- package/src/Form/Select.torp +97 -0
- package/src/Form/TextArea.torp +101 -0
- package/src/Form/index.ts +6 -1
- package/src/Menu/Menu.torp +16 -15
- package/src/Menu/MenuButton.torp +19 -13
- package/src/Menu/MenuCheck.torp +18 -14
- package/src/Menu/MenuGroup.torp +4 -6
- package/src/Menu/MenuIndicator.torp +5 -7
- package/src/Menu/MenuPopout.torp +12 -15
- package/src/Menu/MenuPopoutContent.torp +6 -8
- package/src/Menu/MenuPopoutTrigger.torp +12 -14
- package/src/Menu/MenuRadio.torp +14 -14
- package/src/Menu/MenuRadioGroup.torp +22 -14
- package/src/Menu/MenuSeparator.torp +3 -5
- package/src/Menu/MenuTypes.ts +7 -5
- package/src/MenuBar/MenuBar.torp +13 -14
- package/src/MenuBar/MenuBarItem.torp +13 -16
- package/src/MenuBar/MenuBarItemContent.torp +7 -9
- package/src/MenuBar/MenuBarItemTrigger.torp +6 -9
- package/src/Modal/Modal.torp +118 -0
- package/src/Modal/ModalContent.torp +77 -0
- package/src/Modal/ModalOverlay.torp +38 -0
- package/src/Modal/ModalTrigger.torp +50 -0
- package/src/Modal/ModalTypes.ts +22 -0
- package/src/Modal/index.ts +10 -0
- package/src/Modal/showModal.ts +19 -0
- package/src/Modal/showPrompt.ts +23 -0
- package/src/NavMenu/NavMenu.torp +7 -8
- package/src/NavMenu/NavMenuButton.torp +6 -8
- package/src/NavMenu/NavMenuElement.torp +8 -8
- package/src/NavMenu/NavMenuGroup.torp +4 -6
- package/src/NavMenu/NavMenuGroupHeader.torp +5 -6
- package/src/NavMenu/NavMenuLink.torp +8 -11
- package/src/NavMenu/NavMenuPopout.torp +25 -17
- package/src/NavMenu/NavMenuPopoutButton.torp +12 -13
- package/src/NavMenu/NavMenuPopoutContent.torp +12 -12
- package/src/NavMenu/NavMenuSeparator.torp +3 -5
- package/src/Notification/Notification.torp +22 -13
- package/src/Notification/NotificationClose.torp +3 -5
- package/src/Notification/NotificationContainer.torp +3 -5
- package/src/Notification/NotificationContent.torp +3 -5
- package/src/Popover/Popover.torp +31 -25
- package/src/Popover/PopoverContent.torp +35 -10
- package/src/Popover/PopoverTrigger.torp +24 -4
- package/src/Popover/PopoverTypes.ts +1 -1
- package/src/Popover/index.ts +1 -24
- package/src/Slider/Slider.torp +3 -3
- package/src/TabGroup/TabContent.torp +12 -9
- package/src/TabGroup/TabGroup.torp +41 -35
- package/src/TabGroup/TabGroupTypes.ts +10 -5
- package/src/TabGroup/TabHeader.torp +15 -8
- package/src/TabGroup/TabList.torp +4 -6
- package/src/TabGroup/TabTrigger.torp +8 -9
- package/src/icons/ArrowDown.torp +3 -1
- package/src/icons/ArrowLeft.torp +3 -1
- package/src/icons/ArrowRight.torp +3 -1
- package/src/icons/ArrowUp.torp +3 -1
- package/src/icons/Bars.torp +3 -1
- package/src/icons/Check.torp +3 -1
- package/src/icons/ChevronDown.torp +3 -1
- package/src/icons/ChevronLeft.torp +3 -1
- package/src/icons/ChevronRight.torp +3 -1
- package/src/icons/ChevronUp.torp +3 -1
- package/src/icons/Cross.torp +3 -1
- package/src/icons/IconTypes.ts +6 -0
- package/src/icons/Loading.torp +3 -1
- package/src/icons/Minus.torp +3 -1
- package/src/icons/Plus.torp +3 -1
- package/src/motion/fade.ts +15 -6
- package/src/motion/grow.ts +23 -0
- package/src/motion/index.ts +4 -1
- package/src/motion/measure.ts +28 -0
- package/src/motion/slide.ts +45 -0
- package/src/mount/clickPopover.ts +51 -0
- package/src/mount/contextPopover.ts +51 -0
- package/src/mount/hoverPopover.ts +58 -0
- package/test/Accordion/components/AccordionAccessibility.torp +1 -3
- package/test/Accordion/components/AccordionKeyboard.torp +1 -3
- package/test/Accordion/components/AccordionList.torp +1 -3
- package/test/Accordion/components/AccordionMultiple.torp +2 -4
- package/test/Accordion/components/AccordionSingle.torp +2 -4
- package/test/Dialog/accessibility-modal.test.ts +2 -2
- package/test/Dialog/components/DialogAccessibility.torp +8 -14
- package/test/Dialog/components/DialogFunction.torp +20 -4
- package/test/Dialog/components/DialogModal.torp +30 -0
- package/test/Dialog/components/DialogVariable.torp +7 -7
- package/test/Disclosure/components/DisclosureTest.torp +1 -3
- package/test/Menu/components/MenuAccessibility.torp +5 -5
- package/test/Menu/components/MenuBasic.torp +5 -5
- package/test/Notification/components/NotificationFunction.torp +0 -3
- package/test/Notification/components/NotificationVariable.torp +1 -1
- package/test/Popover/components/PopoverFunction.torp +37 -0
- package/test/Popover/components/PopoverTrigger.torp +36 -0
- package/test/Popover/components/{PromptVariable.torp → PopoverVariable.torp} +5 -3
- package/test/Popover/function.test.ts +2 -7
- package/test/Popover/trigger.test.ts +27 -0
- package/test/Popover/variable.test.ts +2 -2
- package/test/TabGroup/components/TabGroupAccessibility.torp +1 -3
- package/test/TabGroup/components/TabGroupKeyboard.torp +1 -3
- package/test/TabGroup/components/TabGroupList.torp +1 -3
- package/test/TabGroup/components/TabGroupTrigger.torp +1 -3
- package/tsup.config.ts +2 -0
- package/dist/Popover/PopoverContentAnchored.torp +0 -113
- package/dist/Popover/PopoverOverlay.torp +0 -39
- package/dist/Popover/PopoverTriggerContextual.torp +0 -46
- package/dist/Popover/PopoverTriggerHover.torp +0 -47
- package/dist/Popover/mountClickPopover.ts +0 -50
- package/dist/Popover/mountContextPopover.ts +0 -50
- package/dist/Popover/mountHoverPopover.ts +0 -57
- package/dist/Popover/showPopoverPrompt.ts +0 -23
- package/src/Popover/PopoverContentAnchored.torp +0 -113
- package/src/Popover/PopoverOverlay.torp +0 -39
- package/src/Popover/PopoverTriggerContextual.torp +0 -46
- package/src/Popover/PopoverTriggerHover.torp +0 -47
- package/src/Popover/mountClickPopover.ts +0 -50
- package/src/Popover/mountContextPopover.ts +0 -50
- package/src/Popover/mountHoverPopover.ts +0 -57
- package/src/Popover/showPopoverPrompt.ts +0 -23
- package/test/Dialog/components/CustomDialog.torp +0 -20
- package/test/Popover/components/PromptFunction.torp +0 -19
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
|
|
3
|
+
|
|
4
|
+
interface SelectProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The name of the input's form data field */
|
|
10
|
+
name?: string,
|
|
11
|
+
/** The data value that this field is bound to */
|
|
12
|
+
value?: any,
|
|
13
|
+
/** Text to display when the input value is empty */
|
|
14
|
+
placeholder?: string,
|
|
15
|
+
/** Whether the input should be readonly */
|
|
16
|
+
readonly?: boolean,
|
|
17
|
+
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
18
|
+
ariaLabel?: string,
|
|
19
|
+
/** Raised on change */
|
|
20
|
+
onchange?: (e: Event) => void,
|
|
21
|
+
/** Raised on input */
|
|
22
|
+
oninput?: (e: Event) => void,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* A select in a form.
|
|
27
|
+
*/
|
|
28
|
+
export default function Select($props: SelectProps | undefined) {
|
|
29
|
+
let defaultId = getId();
|
|
30
|
+
|
|
31
|
+
let name = $props?.name
|
|
32
|
+
|
|
33
|
+
let blurred = false;
|
|
34
|
+
|
|
35
|
+
// Get stuff out of the FormContext and FieldContext
|
|
36
|
+
const formContext = $context[FormContextName] as FormContext;
|
|
37
|
+
const fieldContext = $context[FieldContextName] as FieldContext;
|
|
38
|
+
if (fieldContext) {
|
|
39
|
+
name ??= fieldContext.name;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Use the FieldContext's state, or create a new one
|
|
43
|
+
let $state = fieldContext?.state ?? $watch({
|
|
44
|
+
inputId: $props?.id ?? defaultId,
|
|
45
|
+
value: $props?.value,
|
|
46
|
+
errors: {} as Record<string, string>,
|
|
47
|
+
valid: false,
|
|
48
|
+
message: "",
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Binding
|
|
52
|
+
$run(() => {
|
|
53
|
+
if ($props !== undefined) {
|
|
54
|
+
$props.value = $state.value;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Set the input ID now that we know it and it will get linked with the associated label
|
|
59
|
+
$state.inputId = $props?.id ?? defaultId;
|
|
60
|
+
|
|
61
|
+
function handleInput(e: Event & { currentTarget: EventTarget & HTMLInputElement }) {
|
|
62
|
+
if (formContext) {
|
|
63
|
+
formContext.validate();
|
|
64
|
+
}
|
|
65
|
+
if (fieldContext && blurred) {
|
|
66
|
+
fieldContext.validate();
|
|
67
|
+
}
|
|
68
|
+
if ($props?.oninput) {
|
|
69
|
+
$props.oninput(e);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function handleBlur() {
|
|
74
|
+
if (fieldContext) {
|
|
75
|
+
fieldContext.validate();
|
|
76
|
+
}
|
|
77
|
+
blurred = true;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@render {
|
|
81
|
+
<select
|
|
82
|
+
id={$props?.id ?? defaultId}
|
|
83
|
+
class={`torp-select ${$props?.class ?? ""}`.trim()}
|
|
84
|
+
{name}
|
|
85
|
+
&value={$state.value}
|
|
86
|
+
{$props?.placeholder}
|
|
87
|
+
{$props?.readonly}
|
|
88
|
+
aria-label={$props?.ariaLabel}
|
|
89
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
90
|
+
onchange={$props?.onchange}
|
|
91
|
+
oninput={handleInput}
|
|
92
|
+
onblur={handleBlur}
|
|
93
|
+
>
|
|
94
|
+
<slot />
|
|
95
|
+
</select>
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import getId from "../utils/getId";
|
|
2
|
+
import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
|
|
3
|
+
|
|
4
|
+
interface TextAreaProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The name of the input's form data field */
|
|
10
|
+
name?: string,
|
|
11
|
+
/** The data value that this field is bound to */
|
|
12
|
+
value?: any,
|
|
13
|
+
/** The number of rows to show in the input */
|
|
14
|
+
rows?: number,
|
|
15
|
+
/** Text to display when the input's value is empty */
|
|
16
|
+
placeholder?: string,
|
|
17
|
+
/** Whether the input should be readonly */
|
|
18
|
+
readonly?: boolean,
|
|
19
|
+
/** The maximum number of characters allowed for the input value */
|
|
20
|
+
maxlength?: number,
|
|
21
|
+
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
22
|
+
ariaLabel?: string,
|
|
23
|
+
/** Raised on change */
|
|
24
|
+
onchange?: (e: Event) => void,
|
|
25
|
+
/** Raised on input */
|
|
26
|
+
oninput?: (e: Event) => void,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A standard input in a form.
|
|
31
|
+
*/
|
|
32
|
+
export default function TextArea($props: TextAreaProps | undefined) {
|
|
33
|
+
let defaultId = getId();
|
|
34
|
+
|
|
35
|
+
let name = $props?.name
|
|
36
|
+
|
|
37
|
+
let blurred = false;
|
|
38
|
+
|
|
39
|
+
// Get stuff out of the FormContext and FieldContext
|
|
40
|
+
const formContext = $context[FormContextName] as FormContext;
|
|
41
|
+
const fieldContext = $context[FieldContextName] as FieldContext;
|
|
42
|
+
if (fieldContext) {
|
|
43
|
+
name ??= fieldContext.name;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Use the FieldContext's state, or create a new one
|
|
47
|
+
let $state = fieldContext?.state ?? $watch({
|
|
48
|
+
inputId: $props?.id ?? defaultId,
|
|
49
|
+
value: $props?.value,
|
|
50
|
+
errors: {} as Record<string, string>,
|
|
51
|
+
valid: false,
|
|
52
|
+
message: "",
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Binding
|
|
56
|
+
$run(() => {
|
|
57
|
+
if ($props !== undefined) {
|
|
58
|
+
$props.value = $state.value;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// Set the input ID now that we know it and it will get linked with the associated label
|
|
63
|
+
$state.inputId = $props?.id ?? defaultId;
|
|
64
|
+
|
|
65
|
+
function handleInput(e: Event) {
|
|
66
|
+
if (formContext) {
|
|
67
|
+
formContext.validate();
|
|
68
|
+
}
|
|
69
|
+
if (fieldContext && blurred) {
|
|
70
|
+
fieldContext.validate();
|
|
71
|
+
}
|
|
72
|
+
if ($props?.oninput) {
|
|
73
|
+
$props.oninput(e);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function handleBlur() {
|
|
78
|
+
if (fieldContext) {
|
|
79
|
+
fieldContext.validate();
|
|
80
|
+
}
|
|
81
|
+
blurred = true;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@render {
|
|
85
|
+
<input
|
|
86
|
+
id={$props?.id ?? defaultId}
|
|
87
|
+
class={`torp-text-area ${$props?.class ?? ""}`.trim()}
|
|
88
|
+
{name}
|
|
89
|
+
&value={$state.value}
|
|
90
|
+
{$props?.rows}
|
|
91
|
+
{$props?.placeholder}
|
|
92
|
+
{$props?.readonly}
|
|
93
|
+
{$props?.maxlength}
|
|
94
|
+
aria-label={$props?.ariaLabel}
|
|
95
|
+
data-valid={$state.valid ? "valid" : "invalid"}
|
|
96
|
+
onchange={$props?.onchange}
|
|
97
|
+
oninput={handleInput}
|
|
98
|
+
onblur={handleBlur}
|
|
99
|
+
/>
|
|
100
|
+
}
|
|
101
|
+
}
|
package/dist/Form/index.d.ts
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
import { type SlotRender } from "@torpor/view";
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
interface CheckBoxProps {
|
|
5
|
+
/** An ID for the root element */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** Class name(s) for the root element */
|
|
8
|
+
class?: string,
|
|
9
|
+
/** The name of the checkbox's form data field */
|
|
10
|
+
name?: string,
|
|
11
|
+
/** Whether the checkbox is checked */
|
|
12
|
+
checked?: boolean,
|
|
13
|
+
/** An ARIA label for describing the checkbox to screen readers when there is no associated label element */
|
|
14
|
+
ariaLabel?: string,
|
|
15
|
+
/** Raised on change */
|
|
16
|
+
onchange?: (e: Event) => void,
|
|
17
|
+
/** Raised on input */
|
|
18
|
+
oninput?: (e: Event) => void,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A checkbox input in a form.
|
|
23
|
+
*/
|
|
24
|
+
declare function CheckBox(
|
|
25
|
+
$parent: ParentNode,
|
|
26
|
+
$anchor: Node | null,
|
|
27
|
+
$props: CheckBoxProps | undefined,
|
|
28
|
+
$context?: Record<PropertyKey, any>,
|
|
29
|
+
$slots?: Record<string, SlotRender>,
|
|
30
|
+
): void;
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
4
34
|
interface FieldProps {
|
|
5
35
|
/** An ID for the root element */
|
|
6
36
|
id?: string;
|
|
@@ -28,6 +58,44 @@ declare function Field(
|
|
|
28
58
|
|
|
29
59
|
|
|
30
60
|
|
|
61
|
+
interface FileProps {
|
|
62
|
+
/** An ID for the root element */
|
|
63
|
+
id?: string;
|
|
64
|
+
/** Class name(s) for the root element */
|
|
65
|
+
class?: string,
|
|
66
|
+
/** The name of the input's form data field */
|
|
67
|
+
name?: string,
|
|
68
|
+
/** The type of files that this input accepts e.g. `image/*` */
|
|
69
|
+
accepts?: string,
|
|
70
|
+
/** The data value that this field is bound to */
|
|
71
|
+
value?: any,
|
|
72
|
+
/** Text to display when the input value is empty */
|
|
73
|
+
placeholder?: string,
|
|
74
|
+
/** Whether the input should be readonly */
|
|
75
|
+
readonly?: boolean,
|
|
76
|
+
/** The maximum number of characters allowed for the input value */
|
|
77
|
+
maxlength?: number,
|
|
78
|
+
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
79
|
+
ariaLabel?: string,
|
|
80
|
+
/** Raised on change */
|
|
81
|
+
onchange?: (e: Event) => void,
|
|
82
|
+
/** Raised on input */
|
|
83
|
+
oninput?: (e: Event) => void,
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A file input in a form.
|
|
88
|
+
*/
|
|
89
|
+
declare function Input(
|
|
90
|
+
$parent: ParentNode,
|
|
91
|
+
$anchor: Node | null,
|
|
92
|
+
$props: FileProps | undefined,
|
|
93
|
+
$context?: Record<PropertyKey, any>,
|
|
94
|
+
$slots?: Record<string, SlotRender>,
|
|
95
|
+
): void;
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
31
99
|
interface FormProps {
|
|
32
100
|
/** An ID for the root element */
|
|
33
101
|
id?: string;
|
|
@@ -37,6 +105,13 @@ interface FormProps {
|
|
|
37
105
|
data?: any,
|
|
38
106
|
/** Where to post the form's data **/
|
|
39
107
|
action?: string,
|
|
108
|
+
/** The action to use when submitting the form, which defaults to POST */
|
|
109
|
+
method?: string,
|
|
110
|
+
/**
|
|
111
|
+
* The form's encoding type e.g. `multipart/form-data` where there are file
|
|
112
|
+
* inputs. This will be automatically set unless overridden
|
|
113
|
+
*/
|
|
114
|
+
enctype?: string,
|
|
40
115
|
/** The schema validator to use for this form */
|
|
41
116
|
schema?: StandardSchemaV1,
|
|
42
117
|
onsubmit?: (e: SubmitEvent) => boolean | void | Promise<boolean | void>,
|
|
@@ -48,7 +123,7 @@ interface FormProps {
|
|
|
48
123
|
declare function Form(
|
|
49
124
|
$parent: ParentNode,
|
|
50
125
|
$anchor: Node | null,
|
|
51
|
-
$props: FormProps,
|
|
126
|
+
$props: FormProps | undefined,
|
|
52
127
|
$context?: Record<PropertyKey, any>,
|
|
53
128
|
$slots?: Record<string, SlotRender>,
|
|
54
129
|
): void;
|
|
@@ -74,6 +149,10 @@ interface InputProps {
|
|
|
74
149
|
maxlength?: number,
|
|
75
150
|
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
76
151
|
ariaLabel?: string,
|
|
152
|
+
/** Raised on change */
|
|
153
|
+
onchange?: (e: Event) => void,
|
|
154
|
+
/** Raised on input */
|
|
155
|
+
oninput?: (e: Event) => void,
|
|
77
156
|
}
|
|
78
157
|
|
|
79
158
|
/**
|
|
@@ -82,26 +161,40 @@ interface InputProps {
|
|
|
82
161
|
declare function Input(
|
|
83
162
|
$parent: ParentNode,
|
|
84
163
|
$anchor: Node | null,
|
|
85
|
-
$props: InputProps,
|
|
164
|
+
$props: InputProps | undefined,
|
|
86
165
|
$context?: Record<PropertyKey, any>,
|
|
87
166
|
$slots?: Record<string, SlotRender>,
|
|
88
167
|
): void;
|
|
89
168
|
|
|
90
169
|
|
|
91
170
|
|
|
171
|
+
interface LabelProps {
|
|
172
|
+
/** An ID for the root element */
|
|
173
|
+
id?: string;
|
|
174
|
+
/** Class name(s) for the root element */
|
|
175
|
+
class?: string,
|
|
176
|
+
}
|
|
177
|
+
|
|
92
178
|
/**
|
|
93
179
|
* A label to describe the contents of an input in a form.
|
|
94
180
|
*/
|
|
95
181
|
declare function Label(
|
|
96
182
|
$parent: ParentNode,
|
|
97
183
|
$anchor: Node | null,
|
|
98
|
-
$props
|
|
184
|
+
$props: LabelProps | undefined,
|
|
99
185
|
$context?: Record<PropertyKey, any>,
|
|
100
186
|
$slots?: Record<string, SlotRender>,
|
|
101
187
|
): void;
|
|
102
188
|
|
|
103
189
|
|
|
104
190
|
|
|
191
|
+
interface MessageProps {
|
|
192
|
+
/** An ID for the root element */
|
|
193
|
+
id?: string;
|
|
194
|
+
/** Class name(s) for the root element */
|
|
195
|
+
class?: string,
|
|
196
|
+
}
|
|
197
|
+
|
|
105
198
|
/**
|
|
106
199
|
* A validation message to show when the contents of an input component have
|
|
107
200
|
* problems that need to be fixed.
|
|
@@ -109,9 +202,103 @@ declare function Label(
|
|
|
109
202
|
declare function Message(
|
|
110
203
|
$parent: ParentNode,
|
|
111
204
|
$anchor: Node | null,
|
|
112
|
-
$props
|
|
205
|
+
$props: MessageProps | undefined,
|
|
206
|
+
$context?: Record<PropertyKey, any>,
|
|
207
|
+
$slots?: Record<string, SlotRender>,
|
|
208
|
+
): void;
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
interface OptionProps {
|
|
213
|
+
/** An ID for the root element */
|
|
214
|
+
id?: string;
|
|
215
|
+
/** Class name(s) for the root element */
|
|
216
|
+
class?: string,
|
|
217
|
+
/** The data value that this option has */
|
|
218
|
+
value?: any,
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* An option in a select.
|
|
223
|
+
*/
|
|
224
|
+
declare function Option(
|
|
225
|
+
$parent: ParentNode,
|
|
226
|
+
$anchor: Node | null,
|
|
227
|
+
$props: OptionProps | undefined,
|
|
228
|
+
$context?: Record<PropertyKey, any>,
|
|
229
|
+
$slots?: Record<string, SlotRender>,
|
|
230
|
+
): void;
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
interface SelectProps {
|
|
235
|
+
/** An ID for the root element */
|
|
236
|
+
id?: string;
|
|
237
|
+
/** Class name(s) for the root element */
|
|
238
|
+
class?: string,
|
|
239
|
+
/** The name of the input's form data field */
|
|
240
|
+
name?: string,
|
|
241
|
+
/** The data value that this field is bound to */
|
|
242
|
+
value?: any,
|
|
243
|
+
/** Text to display when the input value is empty */
|
|
244
|
+
placeholder?: string,
|
|
245
|
+
/** Whether the input should be readonly */
|
|
246
|
+
readonly?: boolean,
|
|
247
|
+
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
248
|
+
ariaLabel?: string,
|
|
249
|
+
/** Raised on change */
|
|
250
|
+
onchange?: (e: Event) => void,
|
|
251
|
+
/** Raised on input */
|
|
252
|
+
oninput?: (e: Event) => void,
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A select in a form.
|
|
257
|
+
*/
|
|
258
|
+
declare function Select(
|
|
259
|
+
$parent: ParentNode,
|
|
260
|
+
$anchor: Node | null,
|
|
261
|
+
$props: SelectProps | undefined,
|
|
262
|
+
$context?: Record<PropertyKey, any>,
|
|
263
|
+
$slots?: Record<string, SlotRender>,
|
|
264
|
+
): void;
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
interface TextAreaProps {
|
|
269
|
+
/** An ID for the root element */
|
|
270
|
+
id?: string;
|
|
271
|
+
/** Class name(s) for the root element */
|
|
272
|
+
class?: string,
|
|
273
|
+
/** The name of the input's form data field */
|
|
274
|
+
name?: string,
|
|
275
|
+
/** The data value that this field is bound to */
|
|
276
|
+
value?: any,
|
|
277
|
+
/** The number of rows to show in the input */
|
|
278
|
+
rows?: number,
|
|
279
|
+
/** Text to display when the input's value is empty */
|
|
280
|
+
placeholder?: string,
|
|
281
|
+
/** Whether the input should be readonly */
|
|
282
|
+
readonly?: boolean,
|
|
283
|
+
/** The maximum number of characters allowed for the input value */
|
|
284
|
+
maxlength?: number,
|
|
285
|
+
/** An ARIA label for describing the input to screen readers when there is no associated label element */
|
|
286
|
+
ariaLabel?: string,
|
|
287
|
+
/** Raised on change */
|
|
288
|
+
onchange?: (e: Event) => void,
|
|
289
|
+
/** Raised on input */
|
|
290
|
+
oninput?: (e: Event) => void,
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* A standard input in a form.
|
|
295
|
+
*/
|
|
296
|
+
declare function TextArea(
|
|
297
|
+
$parent: ParentNode,
|
|
298
|
+
$anchor: Node | null,
|
|
299
|
+
$props: TextAreaProps | undefined,
|
|
113
300
|
$context?: Record<PropertyKey, any>,
|
|
114
301
|
$slots?: Record<string, SlotRender>,
|
|
115
302
|
): void;
|
|
116
303
|
|
|
117
|
-
export { Field, Form, Input, Label, Message };
|
|
304
|
+
export { CheckBox, Field, Input, Form, Input, Label, Message, Option, Select, TextArea };
|
package/dist/Form/index.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
|
+
// src/Form/CheckBox.torp
|
|
2
|
+
import CheckBox_default from "./CheckBox.torp";
|
|
3
|
+
|
|
1
4
|
// src/Form/Field.torp
|
|
2
5
|
import Field_default from "./Field.torp";
|
|
3
6
|
|
|
7
|
+
// src/Form/File.torp
|
|
8
|
+
import File_default from "./File.torp";
|
|
9
|
+
|
|
4
10
|
// src/Form/Form.torp
|
|
5
11
|
import Form_default from "./Form.torp";
|
|
6
12
|
|
|
@@ -12,11 +18,25 @@ import Label_default from "./Label.torp";
|
|
|
12
18
|
|
|
13
19
|
// src/Form/Message.torp
|
|
14
20
|
import Message_default from "./Message.torp";
|
|
21
|
+
|
|
22
|
+
// src/Form/Option.torp
|
|
23
|
+
import Option_default from "./Option.torp";
|
|
24
|
+
|
|
25
|
+
// src/Form/Select.torp
|
|
26
|
+
import Select_default from "./Select.torp";
|
|
27
|
+
|
|
28
|
+
// src/Form/TextArea.torp
|
|
29
|
+
import TextArea_default from "./TextArea.torp";
|
|
15
30
|
export {
|
|
31
|
+
CheckBox_default as CheckBox,
|
|
16
32
|
Field_default as Field,
|
|
33
|
+
File_default as File,
|
|
17
34
|
Form_default as Form,
|
|
18
35
|
Input_default as Input,
|
|
19
36
|
Label_default as Label,
|
|
20
|
-
Message_default as Message
|
|
37
|
+
Message_default as Message,
|
|
38
|
+
Option_default as Option,
|
|
39
|
+
Select_default as Select,
|
|
40
|
+
TextArea_default as TextArea
|
|
21
41
|
};
|
|
22
42
|
//# sourceMappingURL=index.js.map
|
package/dist/Menu/Menu.torp
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ContextualContextName } from "../Contextual/ContextualTypes";
|
|
2
|
+
import { ModalContextName } from "../Modal/ModalTypes";
|
|
1
3
|
import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
|
|
2
4
|
import {
|
|
3
5
|
MenuContextName,
|
|
@@ -26,27 +28,26 @@ interface MenuProps {
|
|
|
26
28
|
*
|
|
27
29
|
* ```
|
|
28
30
|
* <Menu>
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* <MenuButton />
|
|
32
|
+
* <MenuSeparator /> (optional)
|
|
33
|
+
* <MenuGroup> (optional)
|
|
34
|
+
* <MenuButton />
|
|
35
|
+
* </MenuGroup>
|
|
34
36
|
* </Menu>
|
|
35
37
|
* ```
|
|
36
38
|
*/
|
|
37
|
-
export default function Menu($props: MenuProps) {
|
|
38
|
-
$props ??= $watch({});
|
|
39
|
-
|
|
39
|
+
export default function Menu($props: MenuProps | undefined) {
|
|
40
40
|
// A collection containing the state and some functions for each item
|
|
41
41
|
let itemStates: ItemState[] = [];
|
|
42
42
|
let focusIndex = -1;
|
|
43
43
|
|
|
44
44
|
// Get stuff out of the PopoverContext
|
|
45
|
-
|
|
45
|
+
// HACK: share state in PopupState and extend in context/modal/popover
|
|
46
|
+
const popoverContext = $context[ContextualContextName] ?? $context[ModalContextName] ?? $context[PopoverContextName] as PopoverContext;
|
|
46
47
|
if (!popoverContext) {
|
|
47
|
-
throw new Error("Menu must be contained within a
|
|
48
|
+
throw new Error("Menu must be contained within a Context, Modal or Popover");
|
|
48
49
|
}
|
|
49
|
-
const { setVisible, handleButton,
|
|
50
|
+
const { setVisible, handleButton, visible } = popoverContext;
|
|
50
51
|
|
|
51
52
|
// Check whether this is a menu in a popout
|
|
52
53
|
const popoutContext = $context[MenuPopoutContextName] as MenuPopoutContext;
|
|
@@ -77,7 +78,7 @@ export default function Menu($props: MenuProps) {
|
|
|
77
78
|
}
|
|
78
79
|
|
|
79
80
|
function registerItem(setFocused: () => void) {
|
|
80
|
-
// Add the item
|
|
81
|
+
// Add the item's state to the array and return its index
|
|
81
82
|
const newItemState: ItemState = {
|
|
82
83
|
setFocused
|
|
83
84
|
};
|
|
@@ -156,11 +157,11 @@ export default function Menu($props: MenuProps) {
|
|
|
156
157
|
|
|
157
158
|
@render {
|
|
158
159
|
<div
|
|
159
|
-
{$props
|
|
160
|
-
class={`torp-menu ${$props
|
|
160
|
+
{$props?.id}
|
|
161
|
+
class={`torp-menu ${$props?.class ?? ""}`.trim()}
|
|
161
162
|
tabindex="-1"
|
|
162
163
|
role="menu"
|
|
163
|
-
aria-label={$props
|
|
164
|
+
aria-label={$props?.ariaLabel}
|
|
164
165
|
aria-orientation="vertical"
|
|
165
166
|
>
|
|
166
167
|
<slot />
|
|
@@ -9,15 +9,17 @@ interface MenuButtonProps {
|
|
|
9
9
|
value?: any,
|
|
10
10
|
/** Whether this button is disabled */
|
|
11
11
|
disabled?: boolean,
|
|
12
|
+
/** Raised when the button is clicked */
|
|
13
|
+
onclick?: (e: MouseEvent) => void,
|
|
14
|
+
/** Raised when a key is pressed down */
|
|
15
|
+
onkeydown?: (e: KeyboardEvent) => void,
|
|
12
16
|
}
|
|
13
17
|
|
|
14
18
|
/**
|
|
15
19
|
* A button that is placed in a Menu or MenuGroup and signals a response by a user.
|
|
16
20
|
*
|
|
17
21
|
*/
|
|
18
|
-
export default function MenuButton($props: MenuButtonProps) {
|
|
19
|
-
$props ??= $watch({});
|
|
20
|
-
|
|
22
|
+
export default function MenuButton($props: MenuButtonProps | undefined) {
|
|
21
23
|
let button: HTMLButtonElement;
|
|
22
24
|
|
|
23
25
|
// Get stuff out of the MenuContext
|
|
@@ -30,14 +32,18 @@ export default function MenuButton($props: MenuButtonProps) {
|
|
|
30
32
|
// Register this item with the parent Menu and store the index
|
|
31
33
|
const { index } = registerItem(setFocused);
|
|
32
34
|
|
|
33
|
-
function handleKeyDown(e) {
|
|
35
|
+
function handleKeyDown(e: KeyboardEvent) {
|
|
34
36
|
handleItemKey(e);
|
|
35
|
-
if ($props
|
|
37
|
+
if ($props?.onkeydown) {
|
|
38
|
+
$props.onkeydown(e);
|
|
39
|
+
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
|
-
function handleClick(e) {
|
|
39
|
-
handleButton($props
|
|
40
|
-
if ($props
|
|
42
|
+
function handleClick(e: MouseEvent) {
|
|
43
|
+
handleButton($props?.value);
|
|
44
|
+
if ($props?.onclick) {
|
|
45
|
+
$props.onclick(e);
|
|
46
|
+
}
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
function setFocused() {
|
|
@@ -46,13 +52,13 @@ export default function MenuButton($props: MenuButtonProps) {
|
|
|
46
52
|
|
|
47
53
|
@render {
|
|
48
54
|
<button
|
|
49
|
-
{$props
|
|
50
|
-
class={`torp-menu-button ${$props
|
|
55
|
+
{$props?.id}
|
|
56
|
+
class={`torp-menu-button ${$props?.class ?? ""}`.trim()}
|
|
51
57
|
type="button"
|
|
52
|
-
{$props
|
|
58
|
+
{$props?.disabled}
|
|
53
59
|
role="menuitem"
|
|
54
|
-
aria-disabled={$props
|
|
55
|
-
data-disabled={$props
|
|
60
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
61
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
56
62
|
onkeydown={handleKeyDown}
|
|
57
63
|
onclick={handleClick}
|
|
58
64
|
onfocus={() => handleItemFocus(index)}
|
package/dist/Menu/MenuCheck.torp
CHANGED
|
@@ -14,6 +14,8 @@ interface MenuCheckProps {
|
|
|
14
14
|
checked?: boolean,
|
|
15
15
|
/** Whether this item is disabled */
|
|
16
16
|
disabled?: boolean,
|
|
17
|
+
/** Raised when the checkbox is clicked */
|
|
18
|
+
onclick?: (e: MouseEvent) => void,
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -21,15 +23,15 @@ interface MenuCheckProps {
|
|
|
21
23
|
* option on or off.
|
|
22
24
|
*
|
|
23
25
|
*/
|
|
24
|
-
export default function MenuCheck($props: MenuCheckProps) {
|
|
25
|
-
$props ??= $watch({});
|
|
26
|
-
|
|
26
|
+
export default function MenuCheck($props: MenuCheckProps | undefined) {
|
|
27
27
|
let $state = $watch({
|
|
28
|
-
checked: $props
|
|
28
|
+
checked: $props?.checked ?? false
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
$run(() => {
|
|
32
|
-
$props
|
|
32
|
+
if ($props !== undefined) {
|
|
33
|
+
$props.checked = $state.checked;
|
|
34
|
+
}
|
|
33
35
|
});
|
|
34
36
|
|
|
35
37
|
let button: HTMLButtonElement;
|
|
@@ -54,22 +56,24 @@ export default function MenuCheck($props: MenuCheckProps) {
|
|
|
54
56
|
button.focus();
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
function handleClick() {
|
|
59
|
+
function handleClick(e: MouseEvent) {
|
|
58
60
|
$state.checked = !$state.checked;
|
|
59
|
-
if ($props
|
|
61
|
+
if ($props?.onclick) {
|
|
62
|
+
$props.onclick(e);
|
|
63
|
+
}
|
|
60
64
|
}
|
|
61
65
|
|
|
62
66
|
@render {
|
|
63
67
|
<button
|
|
64
|
-
{$props
|
|
65
|
-
class={`torp-menu-check ${$props
|
|
68
|
+
{$props?.id}
|
|
69
|
+
class={`torp-menu-check ${$props?.class ?? ""}`.trim()}
|
|
66
70
|
type="button"
|
|
67
|
-
{$props
|
|
71
|
+
{$props?.disabled}
|
|
68
72
|
role="menuitemcheckbox"
|
|
69
|
-
aria-checked={$props
|
|
70
|
-
aria-disabled={$props
|
|
71
|
-
data-state={$props
|
|
72
|
-
data-disabled={$props
|
|
73
|
+
aria-checked={$props?.checked ? "true" : "false"}
|
|
74
|
+
aria-disabled={$props?.disabled ? "true" : undefined}
|
|
75
|
+
data-state={$props?.checked ? "checked" : "unchecked"}
|
|
76
|
+
data-disabled={$props?.disabled ? "true" : undefined}
|
|
73
77
|
onkeydown={handleItemKey}
|
|
74
78
|
onclick={handleClick}
|
|
75
79
|
onfocus={() => handleItemFocus(index)}
|