@torpor/ui 0.3.5 → 0.3.7

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.
Files changed (241) hide show
  1. package/dist/Chart/BarChart.torp +159 -0
  2. package/dist/Chart/DataSeries.ts +5 -0
  3. package/dist/Chart/GridLines.torp +62 -0
  4. package/dist/Chart/LineChart.torp +196 -0
  5. package/dist/Chart/PieChart.torp +145 -0
  6. package/dist/Chart/ScatterChart.torp +215 -0
  7. package/dist/Chart/SparkLine.torp +71 -0
  8. package/dist/Chart/XAxis.torp +60 -0
  9. package/dist/Chart/YAxis.torp +41 -0
  10. package/dist/Chart/index.d.ts +220 -0
  11. package/dist/Chart/index.js +34 -0
  12. package/dist/Chart/index.js.map +1 -0
  13. package/dist/Form/TextArea.torp +3 -0
  14. package/dist/Form/index.d.ts +2 -0
  15. package/dist/metafile-esm.json +1 -1
  16. package/dist/utils/chartColors.ts +17 -0
  17. package/dist/utils/chartUtils.ts +71 -0
  18. package/package.json +10 -3
  19. package/CHANGELOG.md +0 -344
  20. package/scripts/postbuild.ts +0 -127
  21. package/src/Accordion/Accordion.torp +0 -230
  22. package/src/Accordion/AccordionContent.torp +0 -46
  23. package/src/Accordion/AccordionHeader.torp +0 -45
  24. package/src/Accordion/AccordionItem.torp +0 -101
  25. package/src/Accordion/AccordionTrigger.torp +0 -70
  26. package/src/Accordion/AccordionTypes.ts +0 -36
  27. package/src/Accordion/index.ts +0 -7
  28. package/src/Breadcrumb/Breadcrumb.torp +0 -45
  29. package/src/Breadcrumb/BreadcrumbItem.torp +0 -30
  30. package/src/Breadcrumb/BreadcrumbSeparator.torp +0 -27
  31. package/src/Breadcrumb/index.ts +0 -5
  32. package/src/Calendar/Calendar.torp +0 -277
  33. package/src/Calendar/CalendarDay.torp +0 -78
  34. package/src/Calendar/CalendarTypes.ts +0 -22
  35. package/src/Calendar/index.ts +0 -4
  36. package/src/Contextual/Contextual.torp +0 -129
  37. package/src/Contextual/ContextualContent.torp +0 -112
  38. package/src/Contextual/ContextualTrigger.torp +0 -70
  39. package/src/Contextual/ContextualTypes.ts +0 -30
  40. package/src/Contextual/index.ts +0 -5
  41. package/src/Dialog/Dialog.torp +0 -136
  42. package/src/Dialog/DialogBody.torp +0 -44
  43. package/src/Dialog/DialogButton.torp +0 -66
  44. package/src/Dialog/DialogFooter.torp +0 -25
  45. package/src/Dialog/DialogHeader.torp +0 -45
  46. package/src/Dialog/DialogTypes.ts +0 -17
  47. package/src/Dialog/index.ts +0 -7
  48. package/src/Disclosure/Disclosure.torp +0 -82
  49. package/src/Disclosure/DisclosureContent.torp +0 -46
  50. package/src/Disclosure/DisclosureHeader.torp +0 -45
  51. package/src/Disclosure/DisclosureTrigger.torp +0 -47
  52. package/src/Disclosure/DisclosureTypes.ts +0 -13
  53. package/src/Disclosure/index.ts +0 -6
  54. package/src/Drawer/Drawer.torp +0 -127
  55. package/src/Drawer/DrawerContent.torp +0 -83
  56. package/src/Drawer/DrawerOverlay.torp +0 -42
  57. package/src/Drawer/DrawerTrigger.torp +0 -39
  58. package/src/Drawer/DrawerTypes.ts +0 -24
  59. package/src/Drawer/index.ts +0 -6
  60. package/src/Form/CheckBox.torp +0 -94
  61. package/src/Form/Field.torp +0 -95
  62. package/src/Form/File.torp +0 -102
  63. package/src/Form/Form.torp +0 -147
  64. package/src/Form/FormTypes.ts +0 -35
  65. package/src/Form/Hidden.torp +0 -25
  66. package/src/Form/Input.torp +0 -112
  67. package/src/Form/Label.torp +0 -35
  68. package/src/Form/Message.torp +0 -39
  69. package/src/Form/Option.torp +0 -28
  70. package/src/Form/Select.torp +0 -101
  71. package/src/Form/StandardSchemaV1.ts +0 -70
  72. package/src/Form/TextArea.torp +0 -105
  73. package/src/Form/index.ts +0 -13
  74. package/src/Menu/Menu.torp +0 -174
  75. package/src/Menu/MenuButton.torp +0 -74
  76. package/src/Menu/MenuCheck.torp +0 -89
  77. package/src/Menu/MenuGroup.torp +0 -31
  78. package/src/Menu/MenuIndicator.torp +0 -40
  79. package/src/Menu/MenuPopout.torp +0 -83
  80. package/src/Menu/MenuPopoutContent.torp +0 -84
  81. package/src/Menu/MenuPopoutTrigger.torp +0 -128
  82. package/src/Menu/MenuRadio.torp +0 -103
  83. package/src/Menu/MenuRadioGroup.torp +0 -109
  84. package/src/Menu/MenuSeparator.torp +0 -26
  85. package/src/Menu/MenuTypes.ts +0 -60
  86. package/src/Menu/index.ts +0 -25
  87. package/src/MenuBar/MenuBar.torp +0 -162
  88. package/src/MenuBar/MenuBarItem.torp +0 -116
  89. package/src/MenuBar/MenuBarItemContent.torp +0 -119
  90. package/src/MenuBar/MenuBarItemTrigger.torp +0 -99
  91. package/src/MenuBar/MenuBarTypes.ts +0 -36
  92. package/src/MenuBar/index.ts +0 -6
  93. package/src/Modal/Modal.torp +0 -122
  94. package/src/Modal/ModalContent.torp +0 -81
  95. package/src/Modal/ModalOverlay.torp +0 -42
  96. package/src/Modal/ModalTrigger.torp +0 -54
  97. package/src/Modal/ModalTypes.ts +0 -22
  98. package/src/Modal/index.ts +0 -10
  99. package/src/Modal/showModal.ts +0 -19
  100. package/src/Modal/showPrompt.ts +0 -23
  101. package/src/NavMenu/NavMenu.torp +0 -190
  102. package/src/NavMenu/NavMenuButton.torp +0 -55
  103. package/src/NavMenu/NavMenuElement.torp +0 -55
  104. package/src/NavMenu/NavMenuGroup.torp +0 -41
  105. package/src/NavMenu/NavMenuGroupHeader.torp +0 -41
  106. package/src/NavMenu/NavMenuLink.torp +0 -60
  107. package/src/NavMenu/NavMenuPopout.torp +0 -89
  108. package/src/NavMenu/NavMenuPopoutButton.torp +0 -129
  109. package/src/NavMenu/NavMenuPopoutContent.torp +0 -92
  110. package/src/NavMenu/NavMenuSeparator.torp +0 -24
  111. package/src/NavMenu/NavMenuTypes.ts +0 -32
  112. package/src/NavMenu/index.ts +0 -23
  113. package/src/Notification/Notification.torp +0 -71
  114. package/src/Notification/NotificationClose.torp +0 -39
  115. package/src/Notification/NotificationContainer.torp +0 -26
  116. package/src/Notification/NotificationContent.torp +0 -25
  117. package/src/Notification/NotificationTypes.ts +0 -5
  118. package/src/Notification/index.ts +0 -13
  119. package/src/Notification/showNotification.ts +0 -30
  120. package/src/Popover/Popover.torp +0 -129
  121. package/src/Popover/PopoverContent.torp +0 -117
  122. package/src/Popover/PopoverTrigger.torp +0 -62
  123. package/src/Popover/PopoverTypes.ts +0 -30
  124. package/src/Popover/index.ts +0 -6
  125. package/src/Popover/showPopover.ts +0 -24
  126. package/src/Slider/Slider.torp +0 -84
  127. package/src/Slider/index.ts +0 -3
  128. package/src/TabGroup/TabContent.torp +0 -49
  129. package/src/TabGroup/TabGroup.torp +0 -250
  130. package/src/TabGroup/TabGroupTypes.ts +0 -44
  131. package/src/TabGroup/TabHeader.torp +0 -81
  132. package/src/TabGroup/TabList.torp +0 -61
  133. package/src/TabGroup/TabTrigger.torp +0 -76
  134. package/src/TabGroup/index.ts +0 -7
  135. package/src/ambient.d.ts +0 -7
  136. package/src/icons/ArrowDown.torp +0 -18
  137. package/src/icons/ArrowLeft.torp +0 -18
  138. package/src/icons/ArrowRight.torp +0 -18
  139. package/src/icons/ArrowUp.torp +0 -18
  140. package/src/icons/Bars.torp +0 -20
  141. package/src/icons/Check.torp +0 -18
  142. package/src/icons/ChevronDown.torp +0 -18
  143. package/src/icons/ChevronLeft.torp +0 -18
  144. package/src/icons/ChevronRight.torp +0 -18
  145. package/src/icons/ChevronUp.torp +0 -18
  146. package/src/icons/Cross.torp +0 -19
  147. package/src/icons/IconTypes.ts +0 -10
  148. package/src/icons/Loading.torp +0 -19
  149. package/src/icons/Minus.torp +0 -18
  150. package/src/icons/Plus.torp +0 -19
  151. package/src/icons/index.ts +0 -31
  152. package/src/motion/fade.ts +0 -16
  153. package/src/motion/grow.ts +0 -23
  154. package/src/motion/index.ts +0 -6
  155. package/src/motion/measure.ts +0 -28
  156. package/src/motion/slide.ts +0 -45
  157. package/src/mount/clickPopover.ts +0 -51
  158. package/src/mount/contextPopover.ts +0 -51
  159. package/src/mount/disableScroll.ts +0 -28
  160. package/src/mount/hoverPopover.ts +0 -58
  161. package/src/mount/hoverTrigger.ts +0 -59
  162. package/src/mount/trapFocus.ts +0 -58
  163. package/src/utils/dateUtils.ts +0 -244
  164. package/src/utils/documentEvents.ts +0 -17
  165. package/src/utils/getId.ts +0 -6
  166. package/src/utils/getScrollParent.ts +0 -22
  167. package/src/utils/setContextPosition.ts +0 -31
  168. package/src/utils/setPopoverPosition.ts +0 -142
  169. package/test/Accordion/accessibility.test.ts +0 -59
  170. package/test/Accordion/components/AccordionAccessibility.torp +0 -44
  171. package/test/Accordion/components/AccordionKeyboard.torp +0 -32
  172. package/test/Accordion/components/AccordionList.torp +0 -23
  173. package/test/Accordion/components/AccordionMultiple.torp +0 -32
  174. package/test/Accordion/components/AccordionSingle.torp +0 -32
  175. package/test/Accordion/for-items.test.ts +0 -52
  176. package/test/Accordion/keyboard.test.ts +0 -64
  177. package/test/Accordion/multiple-item-toggle.test.ts +0 -32
  178. package/test/Accordion/multiple-item-value.test.ts +0 -17
  179. package/test/Accordion/single-item-toggle.test.ts +0 -31
  180. package/test/Accordion/single-item-value.test.ts +0 -17
  181. package/test/Breadcrumb/accessibility.test.ts +0 -29
  182. package/test/Breadcrumb/basic.test.ts +0 -17
  183. package/test/Breadcrumb/components/BreadcrumbTest.torp +0 -15
  184. package/test/Calendar/components/CalendarTest.torp +0 -9
  185. package/test/Calendar/default.test.ts +0 -18
  186. package/test/Dialog/accessibility-alert.test.ts +0 -40
  187. package/test/Dialog/accessibility-modal.test.ts +0 -52
  188. package/test/Dialog/components/DialogAccessibility.torp +0 -25
  189. package/test/Dialog/components/DialogFunction.torp +0 -36
  190. package/test/Dialog/components/DialogModal.torp +0 -30
  191. package/test/Dialog/components/DialogVariable.torp +0 -33
  192. package/test/Dialog/function.test.ts +0 -26
  193. package/test/Dialog/variable.test.ts +0 -27
  194. package/test/Disclosure/accessibility.test.ts +0 -31
  195. package/test/Disclosure/components/DisclosureTest.torp +0 -17
  196. package/test/Disclosure/default.test.ts +0 -15
  197. package/test/Disclosure/toggle.test.ts +0 -20
  198. package/test/Form/components/FieldTest.torp +0 -25
  199. package/test/Form/components/FormTest.torp +0 -31
  200. package/test/Form/components/InputTest.torp +0 -9
  201. package/test/Form/field.test.ts +0 -34
  202. package/test/Form/form.test.ts +0 -34
  203. package/test/Form/input.test.ts +0 -19
  204. package/test/Menu/accessibility.test.ts +0 -83
  205. package/test/Menu/basic.test.ts +0 -58
  206. package/test/Menu/components/MenuAccessibility.torp +0 -59
  207. package/test/Menu/components/MenuBasic.torp +0 -58
  208. package/test/MenuBar/accessibility.test.ts +0 -87
  209. package/test/MenuBar/basic.test.ts +0 -22
  210. package/test/MenuBar/components/MenuBarAccessibility.torp +0 -34
  211. package/test/MenuBar/components/MenuBarBasic.torp +0 -25
  212. package/test/NavMenu/accessibility.test.ts +0 -97
  213. package/test/NavMenu/basic.test.ts +0 -22
  214. package/test/NavMenu/components/NavMenuAccessibility.torp +0 -35
  215. package/test/NavMenu/components/NavMenuBasic.torp +0 -28
  216. package/test/Notification/accessibility.test.ts +0 -21
  217. package/test/Notification/components/CustomNotification.torp +0 -14
  218. package/test/Notification/components/NotificationAccessibility.torp +0 -14
  219. package/test/Notification/components/NotificationFunction.torp +0 -17
  220. package/test/Notification/components/NotificationVariable.torp +0 -22
  221. package/test/Notification/function.test.ts +0 -25
  222. package/test/Notification/variable.test.ts +0 -25
  223. package/test/Popover/components/CustomDialog.torp +0 -25
  224. package/test/Popover/components/PopoverFunction.torp +0 -37
  225. package/test/Popover/components/PopoverTrigger.torp +0 -36
  226. package/test/Popover/components/PopoverVariable.torp +0 -40
  227. package/test/Popover/function.test.ts +0 -21
  228. package/test/Popover/trigger.test.ts +0 -27
  229. package/test/Popover/variable.test.ts +0 -27
  230. package/test/TabGroup/accessibility.test.ts +0 -67
  231. package/test/TabGroup/components/TabGroupAccessibility.torp +0 -28
  232. package/test/TabGroup/components/TabGroupKeyboard.torp +0 -28
  233. package/test/TabGroup/components/TabGroupList.torp +0 -26
  234. package/test/TabGroup/components/TabGroupTrigger.torp +0 -28
  235. package/test/TabGroup/for-items.test.ts +0 -52
  236. package/test/TabGroup/item-trigger.test.ts +0 -33
  237. package/test/TabGroup/item-value.test.ts +0 -17
  238. package/test/TabGroup/keyboard.test.ts +0 -72
  239. package/tsconfig.json +0 -4
  240. package/tsup.config.ts +0 -37
  241. package/vitest.config.ts +0 -12
@@ -1,35 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { FieldContextName, type FieldContext } from "./FormTypes";
3
-
4
- interface LabelProps {
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
- }
12
-
13
- /**
14
- * A label to describe the contents of an input in a form.
15
- */
16
- export default function Label($props: LabelProps | undefined) {
17
- // Get stuff out of the FieldContext
18
- const context = $context[FieldContextName] as FieldContext;
19
- if (!context) {
20
- throw new Error("Label must be contained within a Field");
21
- }
22
- let { state: $state } = context;
23
-
24
- @render {
25
- <label
26
- {$props?.id}
27
- class={["torp-label", $props?.class]}
28
- {$props?.style}
29
- for={$state.inputId}
30
- data-valid={$state.valid ? "valid" : "invalid"}
31
- >
32
- <slot />
33
- </label>
34
- }
35
- }
@@ -1,39 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { FieldContextName, type FieldContext } from "./FormTypes";
3
-
4
- interface MessageProps {
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
- }
12
-
13
- /**
14
- * A validation message to show when the contents of an input component have
15
- * problems that need to be fixed.
16
- */
17
- export default function Message($props: MessageProps | undefined) {
18
- // Get stuff out of the FieldContext
19
- const context = $context[FieldContextName] as FieldContext;
20
- if (!context) {
21
- throw new Error("Message must be contained within a Field");
22
- }
23
- const { state: $state } = context;
24
-
25
- @render {
26
- @if ($state.message) {
27
- <div
28
- {$props?.id}
29
- class={["torp-message", $props?.class]}
30
- {$props?.style}
31
- data-valid={$state.valid ? "valid" : "invalid"}
32
- >
33
- <slot name="message">
34
- {$state.message}
35
- </slot>
36
- </div>
37
- }
38
- }
39
- }
@@ -1,28 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import getId from "../utils/getId";
3
- import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
4
-
5
- interface OptionProps {
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 data value that this option has */
13
- value?: any,
14
- };
15
-
16
- /**
17
- * An option in a select.
18
- */
19
- export default function Option($props: OptionProps | undefined) {
20
- @render {
21
- <option
22
- {$props?.id}
23
- class={["torp-option", $props?.class]}
24
- {$props?.style}
25
- &value={$props.value}
26
- />
27
- }
28
- }
@@ -1,101 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import getId from "../utils/getId";
3
- import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
4
-
5
- interface SelectProps {
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 name of the input's form data field */
13
- name?: string,
14
- /** The data value that this field is bound to */
15
- value?: any,
16
- /** Text to display when the input value is empty */
17
- placeholder?: string,
18
- /** Whether the input should be readonly */
19
- readonly?: boolean,
20
- /** An ARIA label for describing the input to screen readers when there is no associated label element */
21
- ariaLabel?: string,
22
- /** Raised on change */
23
- onchange?: (e: Event) => void,
24
- /** Raised on input */
25
- oninput?: (e: Event) => void,
26
- };
27
-
28
- /**
29
- * A select in a form.
30
- */
31
- export default function Select($props: SelectProps | undefined) {
32
- let defaultId = getId();
33
-
34
- let name = $props?.name
35
-
36
- let blurred = false;
37
-
38
- // Get stuff out of the FormContext and FieldContext
39
- const formContext = $context[FormContextName] as FormContext;
40
- const fieldContext = $context[FieldContextName] as FieldContext;
41
- if (fieldContext) {
42
- name ??= fieldContext.name;
43
- }
44
-
45
- // Use the FieldContext's state, or create a new one
46
- let $state = fieldContext?.state ?? $watch({
47
- inputId: $props?.id ?? defaultId,
48
- value: $props?.value,
49
- errors: {} as Record<string, string>,
50
- valid: false,
51
- message: "",
52
- });
53
-
54
- // Binding
55
- $run(() => {
56
- if ($props !== undefined) {
57
- $props.value = $state.value;
58
- }
59
- });
60
-
61
- // Set the input ID now that we know it and it will get linked with the associated label
62
- $state.inputId = $props?.id ?? defaultId;
63
-
64
- function handleInput(e: Event & { currentTarget: EventTarget & HTMLInputElement }) {
65
- if (formContext) {
66
- formContext.validate();
67
- }
68
- if (fieldContext && blurred) {
69
- fieldContext.validate();
70
- }
71
- if ($props?.oninput) {
72
- $props.oninput(e);
73
- }
74
- }
75
-
76
- function handleBlur() {
77
- if (fieldContext) {
78
- fieldContext.validate();
79
- }
80
- blurred = true;
81
- }
82
-
83
- @render {
84
- <select
85
- id={$props?.id ?? defaultId}
86
- class={["torp-select", $props?.class]}
87
- {$props?.style}
88
- {name}
89
- &value={$state.value}
90
- {$props?.placeholder}
91
- {$props?.readonly}
92
- aria-label={$props?.ariaLabel}
93
- data-valid={$state.valid ? "valid" : "invalid"}
94
- onchange={$props?.onchange}
95
- oninput={handleInput}
96
- onblur={handleBlur}
97
- >
98
- <slot />
99
- </select>
100
- }
101
- }
@@ -1,70 +0,0 @@
1
- // From https://github.com/standard-schema/standard-schema
2
-
3
- /** The Standard Schema interface. */
4
- export interface StandardSchemaV1<Input = unknown, Output = Input> {
5
- /** The Standard Schema properties. */
6
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
7
- }
8
-
9
- export declare namespace StandardSchemaV1 {
10
- /** The Standard Schema properties interface. */
11
- export interface Props<Input = unknown, Output = Input> {
12
- /** The version number of the standard. */
13
- readonly version: 1;
14
- /** The vendor name of the schema library. */
15
- readonly vendor: string;
16
- /** Validates unknown input values. */
17
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
18
- /** Inferred types associated with the schema. */
19
- readonly types?: Types<Input, Output> | undefined;
20
- }
21
-
22
- /** The result interface of the validate function. */
23
- export type Result<Output> = SuccessResult<Output> | FailureResult;
24
-
25
- /** The result interface if validation succeeds. */
26
- export interface SuccessResult<Output> {
27
- /** The typed output value. */
28
- readonly value: Output;
29
- /** The non-existent issues. */
30
- readonly issues?: undefined;
31
- }
32
-
33
- /** The result interface if validation fails. */
34
- export interface FailureResult {
35
- /** The issues of failed validation. */
36
- readonly issues: ReadonlyArray<Issue>;
37
- }
38
-
39
- /** The issue interface of the failure output. */
40
- export interface Issue {
41
- /** The error message of the issue. */
42
- readonly message: string;
43
- /** The path of the issue, if any. */
44
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
45
- }
46
-
47
- /** The path segment interface of the issue. */
48
- export interface PathSegment {
49
- /** The key representing a path segment. */
50
- readonly key: PropertyKey;
51
- }
52
-
53
- /** The Standard Schema types interface. */
54
- export interface Types<Input = unknown, Output = Input> {
55
- /** The input type of the schema. */
56
- readonly input: Input;
57
- /** The output type of the schema. */
58
- readonly output: Output;
59
- }
60
-
61
- /** Infers the input type of a Standard Schema. */
62
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<
63
- Schema["~standard"]["types"]
64
- >["input"];
65
-
66
- /** Infers the output type of a Standard Schema. */
67
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<
68
- Schema["~standard"]["types"]
69
- >["output"];
70
- }
@@ -1,105 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import getId from "../utils/getId";
3
- import { FormContextName, FieldContextName, type FormContext, type FieldContext } from "./FormTypes";
4
-
5
- interface TextAreaProps {
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 name of the input's form data field */
13
- name?: string,
14
- /** The data value that this field is bound to */
15
- value?: any,
16
- /** The number of rows to show in the input */
17
- rows?: number,
18
- /** Text to display when the input's value is empty */
19
- placeholder?: string,
20
- /** Whether the input should be readonly */
21
- readonly?: boolean,
22
- /** The maximum number of characters allowed for the input value */
23
- maxlength?: number,
24
- /** An ARIA label for describing the input to screen readers when there is no associated label element */
25
- ariaLabel?: string,
26
- /** Raised on change */
27
- onchange?: (e: Event) => void,
28
- /** Raised on input */
29
- oninput?: (e: Event) => void,
30
- };
31
-
32
- /**
33
- * A standard input in a form.
34
- */
35
- export default function TextArea($props: TextAreaProps | undefined) {
36
- let defaultId = getId();
37
-
38
- let name = $props?.name
39
-
40
- let blurred = false;
41
-
42
- // Get stuff out of the FormContext and FieldContext
43
- const formContext = $context[FormContextName] as FormContext;
44
- const fieldContext = $context[FieldContextName] as FieldContext;
45
- if (fieldContext) {
46
- name ??= fieldContext.name;
47
- }
48
-
49
- // Use the FieldContext's state, or create a new one
50
- let $state = fieldContext?.state ?? $watch({
51
- inputId: $props?.id ?? defaultId,
52
- value: $props?.value,
53
- errors: {} as Record<string, string>,
54
- valid: false,
55
- message: "",
56
- });
57
-
58
- // Binding
59
- $run(() => {
60
- if ($props !== undefined) {
61
- $props.value = $state.value;
62
- }
63
- });
64
-
65
- // Set the input ID now that we know it and it will get linked with the associated label
66
- $state.inputId = $props?.id ?? defaultId;
67
-
68
- function handleInput(e: Event) {
69
- if (formContext) {
70
- formContext.validate();
71
- }
72
- if (fieldContext && blurred) {
73
- fieldContext.validate();
74
- }
75
- if ($props?.oninput) {
76
- $props.oninput(e);
77
- }
78
- }
79
-
80
- function handleBlur() {
81
- if (fieldContext) {
82
- fieldContext.validate();
83
- }
84
- blurred = true;
85
- }
86
-
87
- @render {
88
- <textarea
89
- id={$props?.id ?? defaultId}
90
- class={["torp-text-area", $props?.class]}
91
- {$props?.style}
92
- {name}
93
- &value={$state.value}
94
- {$props?.rows}
95
- {$props?.placeholder}
96
- {$props?.readonly}
97
- {$props?.maxlength}
98
- aria-label={$props?.ariaLabel}
99
- data-valid={$state.valid ? "valid" : "invalid"}
100
- onchange={$props?.onchange}
101
- oninput={handleInput}
102
- onblur={handleBlur}
103
- />
104
- }
105
- }
package/src/Form/index.ts DELETED
@@ -1,13 +0,0 @@
1
- import CheckBox from "./CheckBox.torp";
2
- import Field from "./Field.torp";
3
- import File from "./File.torp";
4
- import Form from "./Form.torp";
5
- import Hidden from "./Hidden.torp";
6
- import Input from "./Input.torp";
7
- import Label from "./Label.torp";
8
- import Message from "./Message.torp";
9
- import Option from "./Option.torp";
10
- import Select from "./Select.torp";
11
- import TextArea from "./TextArea.torp";
12
-
13
- export { CheckBox, Field, File, Form, Hidden, Input, Label, Message, Option, Select, TextArea };
@@ -1,174 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { ContextualContextName } from "../Contextual/ContextualTypes";
3
- import { ModalContextName } from "../Modal/ModalTypes";
4
- import { PopoverContextName, type PopoverContext } from "../Popover/PopoverTypes";
5
- import {
6
- MenuContextName,
7
- type MenuContext,
8
- type ItemState,
9
- MenuPopoutContextName,
10
- type MenuPopoutContext
11
- } from "./MenuTypes";
12
-
13
- interface MenuProps {
14
- /** An ID for the root element */
15
- id?: string;
16
- /** Classes for the root element */
17
- class?: ClassValue,
18
- /** Styles for the root element */
19
- style?: StyleValue,
20
- /** An ARIA label for describing the menu to screen readers */
21
- ariaLabel?: string,
22
- }
23
-
24
- /**
25
- * A list of choices for the user, such as a set of actions or functions. A
26
- * menu is usually hidden until made visible by the user.
27
- *
28
- * See [the WAI ARIA guidelines for Menus](https://www.w3.org/WAI/ARIA/apg/patterns/menu/).
29
- *
30
- * The structure of a Menu is:
31
- *
32
- * ```
33
- * <Menu>
34
- * <MenuButton />
35
- * <MenuSeparator /> (optional)
36
- * <MenuGroup> (optional)
37
- * <MenuButton />
38
- * </MenuGroup>
39
- * </Menu>
40
- * ```
41
- */
42
- export default function Menu($props: MenuProps | undefined) {
43
- // A collection containing the state and some functions for each item
44
- let itemStates: ItemState[] = [];
45
- let focusIndex = -1;
46
-
47
- // Get stuff out of the PopoverContext
48
- // HACK: share state in PopupState and extend in context/modal/popover
49
- const popoverContext = $context[ContextualContextName] ?? $context[ModalContextName] ?? $context[PopoverContextName] as PopoverContext;
50
- if (!popoverContext) {
51
- throw new Error("Menu must be contained within a Context, Modal or Popover");
52
- }
53
- const { setVisible, handleButton, visible } = popoverContext;
54
-
55
- // Check whether this is a menu in a popout
56
- const popoutContext = $context[MenuPopoutContextName] as MenuPopoutContext;
57
- const inPopout = !!popoutContext;
58
- const setPopoutVisible = popoutContext?.setVisible;
59
-
60
- // Set the focusFirstElement method in the PopoverContext(s) so that it can be called after everything has been shown
61
- popoverContext.focusFirstElement = focusFirstElement;
62
- if (popoutContext) {
63
- popoutContext.focusFirstElement = focusFirstElement;
64
- }
65
-
66
- // Set the context to pass down to items
67
- let context: MenuContext = {
68
- setVisible,
69
- handleButton,
70
- handleItemFocus,
71
- handleItemKey,
72
- visible,
73
- registerItem
74
- };
75
- $context[MenuContextName] = context;
76
-
77
- function focusFirstElement() {
78
- if (itemStates.length) {
79
- itemStates[0].setFocused();
80
- }
81
- }
82
-
83
- function registerItem(setFocused: () => void) {
84
- // Add the item's state to the array and return its index
85
- const newItemState: ItemState = {
86
- setFocused
87
- };
88
- itemStates.push(newItemState);
89
- itemStates = itemStates;
90
- return { index: itemStates.length - 1 };
91
- }
92
-
93
- function handleItemFocus(index: number) {
94
- focusIndex = index;
95
- }
96
-
97
- function handleItemKey(e: KeyboardEvent) {
98
- switch (e.key) {
99
- case "Esc":
100
- case "Escape": {
101
- e.preventDefault();
102
- setVisible(false);
103
- break;
104
- }
105
- case "Down":
106
- case "ArrowDown": {
107
- e.preventDefault();
108
- focusItem("next");
109
- break;
110
- }
111
- case "Up":
112
- case "ArrowUp": {
113
- e.preventDefault();
114
- focusItem("previous");
115
- break;
116
- }
117
- case "Left":
118
- case "ArrowLeft": {
119
- // TODO: This should be based on what side the menu shows on
120
- if (inPopout) {
121
- e.preventDefault();
122
- setPopoutVisible(false);
123
- }
124
- break;
125
- }
126
- case "Home": {
127
- e.preventDefault();
128
- focusItem("start");
129
- break;
130
- }
131
- case "End": {
132
- e.preventDefault();
133
- focusItem("end");
134
- break;
135
- }
136
- }
137
- }
138
-
139
- function focusItem(target: "start" | "previous" | "next" | "end") {
140
- switch (target) {
141
- case "start": {
142
- focusIndex = 0;
143
- break;
144
- }
145
- case "previous": {
146
- focusIndex = Math.max(0, focusIndex - 1);
147
- break;
148
- }
149
- case "next": {
150
- focusIndex = Math.min(itemStates.length - 1, focusIndex + 1);
151
- break;
152
- }
153
- case "end": {
154
- focusIndex = itemStates.length - 1;
155
- break;
156
- }
157
- }
158
- itemStates[focusIndex]?.setFocused();
159
- }
160
-
161
- @render {
162
- <div
163
- {$props?.id}
164
- class={["torp-menu", $props?.class]}
165
- {$props?.style}
166
- tabindex="-1"
167
- role="menu"
168
- aria-label={$props?.ariaLabel}
169
- aria-orientation="vertical"
170
- >
171
- <slot />
172
- </div>
173
- }
174
- }
@@ -1,74 +0,0 @@
1
- import type { ClassValue, StyleValue } from "@torpor/view";
2
- import { MenuContextName, type MenuContext } from "./MenuTypes";
3
-
4
- interface MenuButtonProps {
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 value that should be returned when this button is pressed and the Dialog was invoked by calling showContextual, showPrompt or showPopover */
12
- value?: any,
13
- /** Whether this button is disabled */
14
- disabled?: boolean,
15
- /** Raised when the button is clicked */
16
- onclick?: (e: MouseEvent) => void,
17
- /** Raised when a key is pressed down */
18
- onkeydown?: (e: KeyboardEvent) => void,
19
- }
20
-
21
- /**
22
- * A button that is placed in a Menu or MenuGroup and signals a response by a user.
23
- *
24
- */
25
- export default function MenuButton($props: MenuButtonProps | undefined) {
26
- let button: HTMLButtonElement;
27
-
28
- // Get stuff out of the MenuContext
29
- const menuContext = $context[MenuContextName] as MenuContext;
30
- if (!menuContext) {
31
- throw new Error("MenuButton must be contained within a Menu");
32
- }
33
- const { registerItem, handleButton, handleItemKey, handleItemFocus } = menuContext;
34
-
35
- // Register this item with the parent Menu and store the index
36
- const { index } = registerItem(setFocused);
37
-
38
- function handleKeyDown(e: KeyboardEvent) {
39
- handleItemKey(e);
40
- if ($props?.onkeydown) {
41
- $props.onkeydown(e);
42
- }
43
- }
44
-
45
- function handleClick(e: MouseEvent) {
46
- handleButton($props?.value);
47
- if ($props?.onclick) {
48
- $props.onclick(e);
49
- }
50
- }
51
-
52
- function setFocused() {
53
- button.focus();
54
- }
55
-
56
- @render {
57
- <button
58
- {$props?.id}
59
- class={["torp-menu-button", $props?.class]}
60
- {$props?.style}
61
- type="button"
62
- {$props?.disabled}
63
- role="menuitem"
64
- aria-disabled={$props?.disabled ? "true" : undefined}
65
- data-disabled={$props?.disabled ? "true" : undefined}
66
- onkeydown={handleKeyDown}
67
- onclick={handleClick}
68
- onfocus={() => handleItemFocus(index)}
69
- &ref={button}
70
- >
71
- <slot />
72
- </button>
73
- }
74
- }