@worknice/whiteboard 0.13.0 → 0.15.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.
@@ -1,4 +1,4 @@
1
- import type { Dispatch, ReactNode } from "react";
1
+ import { type Dispatch, type ReactNode } from "react";
2
2
  import type { ValidationError } from "../forms/_types";
3
3
  type Props<Option> = {
4
4
  autoFocus?: boolean;
@@ -6,7 +6,6 @@ type Props<Option> = {
6
6
  id: string;
7
7
  includeValueInTracking?: boolean;
8
8
  onChange: Dispatch<Option>;
9
- options: Array<Option>;
10
9
  optionToId: (option: Option) => string;
11
10
  optionToLabel: (option: Option) => ReactNode;
12
11
  value: Option | null;
@@ -20,6 +19,15 @@ type Props<Option> = {
20
19
  label: ReactNode;
21
20
  labelFont?: "heading" | "subheading" | "label" | "regular-bold" | "regular";
22
21
  required?: boolean;
23
- };
24
- declare const SingleSelectComboBoxField: <Option>({ autoFocus, disabled, id, includeValueInTracking, onChange, options, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear, description, errors, label, labelFont, required, }: Props<Option>) => import("react/jsx-runtime").JSX.Element;
22
+ } & ({
23
+ options: Array<Option>;
24
+ optionGroups?: never;
25
+ } | {
26
+ options?: never;
27
+ optionGroups: Array<{
28
+ header: string;
29
+ options: Array<Option>;
30
+ }>;
31
+ });
32
+ declare const SingleSelectComboBoxField: <Option>({ autoFocus, disabled, id, includeValueInTracking, onChange, options, optionGroups, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear, description, errors, label, labelFont, required, }: Props<Option>) => import("react/jsx-runtime").JSX.Element;
25
33
  export default SingleSelectComboBoxField;
@@ -1,13 +1,10 @@
1
1
  import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__ from "react/jsx-runtime";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
3
  import * as __WEBPACK_EXTERNAL_MODULE__forms_RegularField_js_c54537ba__ from "../forms/RegularField.js";
3
4
  import * as __WEBPACK_EXTERNAL_MODULE__inputs_SingleSelectComboboxInput_js_15b92560__ from "../inputs/SingleSelectComboboxInput.js";
4
- const SingleSelectComboBoxField = ({ autoFocus = false, disabled = false, id, includeValueInTracking, onChange, options, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear, description, errors, label, labelFont = "label", required = false })=>/*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__forms_RegularField_js_c54537ba__["default"], {
5
- description: description,
6
- errors: errors,
7
- label: label,
8
- labelFont: labelFont,
9
- required: required,
10
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__inputs_SingleSelectComboboxInput_js_15b92560__["default"], {
5
+ const SingleSelectComboBoxField = ({ autoFocus = false, disabled = false, id, includeValueInTracking, onChange, options, optionGroups, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear, description, errors, label, labelFont = "label", required = false })=>{
6
+ const comboboxInput = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
7
+ if (options) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__inputs_SingleSelectComboboxInput_js_15b92560__["default"], {
11
8
  autoFocus: autoFocus,
12
9
  disabled: disabled,
13
10
  id: id,
@@ -22,7 +19,48 @@ const SingleSelectComboBoxField = ({ autoFocus = false, disabled = false, id, in
22
19
  searchFields: searchFields,
23
20
  onCreate: onCreate,
24
21
  onClear: onClear
25
- })
22
+ });
23
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__inputs_SingleSelectComboboxInput_js_15b92560__["default"], {
24
+ autoFocus: autoFocus,
25
+ disabled: disabled,
26
+ id: id,
27
+ includeValueInTracking: includeValueInTracking,
28
+ onChange: onChange,
29
+ optionGroups: optionGroups,
30
+ optionToId: optionToId,
31
+ optionToLabel: optionToLabel,
32
+ value: value,
33
+ placeholder: placeholder,
34
+ searchPlaceholder: searchPlaceholder,
35
+ searchFields: searchFields,
36
+ onCreate: onCreate,
37
+ onClear: onClear
38
+ });
39
+ }, [
40
+ autoFocus,
41
+ disabled,
42
+ id,
43
+ includeValueInTracking,
44
+ onChange,
45
+ optionGroups,
46
+ optionToId,
47
+ optionToLabel,
48
+ value,
49
+ placeholder,
50
+ searchPlaceholder,
51
+ searchFields,
52
+ onCreate,
53
+ onClear,
54
+ options
55
+ ]);
56
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__forms_RegularField_js_c54537ba__["default"], {
57
+ description: description,
58
+ errors: errors,
59
+ label: label,
60
+ labelFont: labelFont,
61
+ required: required,
62
+ children: comboboxInput
26
63
  });
64
+ };
27
65
  const SingleSelectComboboxField_rslib_entry_ = SingleSelectComboBoxField;
28
66
  export { SingleSelectComboboxField_rslib_entry_ as default };
@@ -5,7 +5,6 @@ type Props<Option> = {
5
5
  id: string;
6
6
  includeValueInTracking?: boolean;
7
7
  onChange: Dispatch<Option>;
8
- options: Array<Option>;
9
8
  optionToId: (option: Option) => string;
10
9
  optionToLabel: (option: Option) => ReactNode;
11
10
  value: Option | null;
@@ -14,6 +13,15 @@ type Props<Option> = {
14
13
  searchFields: Array<keyof Option & string>;
15
14
  onCreate?: (onClose: () => void, searchTerm: string) => ReactNode;
16
15
  onClear?: () => void;
17
- };
18
- declare const SingleSelectComboBoxInput: <Option>({ autoFocus, disabled, id, onChange, options, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear, }: Props<Option>) => import("react/jsx-runtime").JSX.Element;
16
+ } & ({
17
+ options: Array<Option>;
18
+ optionGroups?: never;
19
+ } | {
20
+ options?: never;
21
+ optionGroups: Array<{
22
+ header: string;
23
+ options: Array<Option>;
24
+ }>;
25
+ });
26
+ declare const SingleSelectComboBoxInput: <Option>({ autoFocus, disabled, id, onChange, options, optionGroups, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear, }: Props<Option>) => import("react/jsx-runtime").JSX.Element;
19
27
  export default SingleSelectComboBoxInput;
@@ -5,7 +5,9 @@ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
5
5
  import * as __WEBPACK_EXTERNAL_MODULE__presentation_Icon_js_6961aa57__ from "../presentation/Icon.js";
6
6
  import * as __WEBPACK_EXTERNAL_MODULE__utils_search_js_89d5ae26__ from "../utils/search.js";
7
7
  import * as __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__ from "./SingleSelectComboboxInput.module.js";
8
- const SingleSelectComboBoxInput = ({ autoFocus = false, disabled = false, id, onChange, options, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear })=>{
8
+ const SingleSelectComboBoxInput = ({ autoFocus = false, disabled = false, id, onChange, options, optionGroups, optionToId, optionToLabel, value, placeholder, searchPlaceholder, searchFields, onCreate, onClear })=>{
9
+ const listboxId = (0, __WEBPACK_EXTERNAL_MODULE_react__.useId)();
10
+ const buttonId = id;
9
11
  const optionsRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)([]);
10
12
  const searchRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
11
13
  const listBoxRef = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(null);
@@ -13,10 +15,16 @@ const SingleSelectComboBoxInput = ({ autoFocus = false, disabled = false, id, on
13
15
  const [createNewOption, setCreateNewOption] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
14
16
  const [isOpen, setIsOpen] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
15
17
  const [activeIndex, setActiveIndex] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(0);
16
- const filteredOptions = "" !== searchTerm.trim() ? (0, __WEBPACK_EXTERNAL_MODULE__utils_search_js_89d5ae26__["default"])(options.map((option)=>({
17
- ...option,
18
- id: optionToId(option)
19
- })), searchFields, searchTerm) : options;
18
+ const filteredOptions = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>"" !== searchTerm.trim() ? (0, __WEBPACK_EXTERNAL_MODULE__utils_search_js_89d5ae26__["default"])((options ?? optionGroups.flatMap((group)=>group.options) ?? []).map((option)=>({
19
+ ...option,
20
+ id: optionToId(option)
21
+ })), searchFields, searchTerm) : options ?? optionGroups.flatMap((group)=>group.options) ?? [], [
22
+ options,
23
+ optionGroups,
24
+ searchFields,
25
+ searchTerm,
26
+ optionToId
27
+ ]);
20
28
  const { refs: floatingUiRefs, floatingStyles, context } = (0, __WEBPACK_EXTERNAL_MODULE__floating_ui_react_3ddd630a__.useFloating)({
21
29
  open: isOpen,
22
30
  onOpenChange: (open)=>{
@@ -54,9 +62,79 @@ const SingleSelectComboBoxInput = ({ autoFocus = false, disabled = false, id, on
54
62
  dismiss,
55
63
  listNav
56
64
  ]);
65
+ const renderOption = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)((option, index)=>{
66
+ const optionId = optionToId(option);
67
+ const optionLabel = optionToLabel(option);
68
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("li", {
69
+ role: "option",
70
+ className: (0, __WEBPACK_EXTERNAL_MODULE_clsx__["default"])(__WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItem, {
71
+ [__WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].activeListItem]: activeIndex === index
72
+ }),
73
+ ...getItemProps({
74
+ onClick: ()=>{
75
+ setIsOpen(false);
76
+ onChange(option);
77
+ },
78
+ ref: (node)=>{
79
+ optionsRef.current[index] = node;
80
+ }
81
+ }),
82
+ children: [
83
+ optionLabel,
84
+ value && optionToId(value) === optionToId(option) ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__presentation_Icon_js_6961aa57__["default"], {
85
+ symbol: "CheckMark"
86
+ }) : null
87
+ ]
88
+ }, optionId);
89
+ }, [
90
+ activeIndex,
91
+ onChange,
92
+ optionToId,
93
+ optionToLabel,
94
+ value,
95
+ getItemProps
96
+ ]);
97
+ const renderOptions = (0, __WEBPACK_EXTERNAL_MODULE_react__.useCallback)(()=>{
98
+ if (options) return filteredOptions.map(renderOption);
99
+ return optionGroups.map((group)=>{
100
+ if (0 === group.options.length) return null;
101
+ const groupOptionIds = new Set(group.options.map((o)=>optionToId(o)));
102
+ const filteredGroupOptions = filteredOptions.filter((o)=>groupOptionIds.has(optionToId(o)));
103
+ if (0 === filteredGroupOptions.length) return null;
104
+ const headerId = `${listboxId}-group-${group.header}`;
105
+ return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("li", {
106
+ role: "presentation",
107
+ children: [
108
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
109
+ id: headerId,
110
+ className: __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItemGroupHeader,
111
+ children: group.header
112
+ }),
113
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("ul", {
114
+ role: "group",
115
+ "aria-labelledby": headerId,
116
+ children: filteredGroupOptions.map((option)=>{
117
+ const optionIndex = optionGroups.flatMap((group)=>group.options).indexOf(option);
118
+ return renderOption(option, optionIndex);
119
+ })
120
+ })
121
+ ]
122
+ }, group.header);
123
+ });
124
+ }, [
125
+ filteredOptions,
126
+ listboxId,
127
+ optionGroups,
128
+ optionToId,
129
+ renderOption,
130
+ options
131
+ ]);
57
132
  return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
58
133
  children: [
59
134
  /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("button", {
135
+ "aria-controls": listboxId,
136
+ "aria-haspopup": "listbox",
137
+ "aria-expanded": isOpen,
60
138
  autoFocus: autoFocus,
61
139
  disabled: disabled,
62
140
  className: __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].toggleButton,
@@ -64,7 +142,7 @@ const SingleSelectComboBoxInput = ({ autoFocus = false, disabled = false, id, on
64
142
  type: "button",
65
143
  ref: floatingUiRefs.setReference,
66
144
  ...getReferenceProps({
67
- id: id
145
+ id: buttonId
68
146
  }),
69
147
  children: [
70
148
  value ? optionToLabel(value) : placeholder ?? "Select an option",
@@ -90,82 +168,60 @@ const SingleSelectComboBoxInput = ({ autoFocus = false, disabled = false, id, on
90
168
  })
91
169
  ]
92
170
  }),
93
- !disabled && isOpen ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.Fragment, {
94
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__floating_ui_react_3ddd630a__.FloatingPortal, {
95
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__floating_ui_react_3ddd630a__.FloatingFocusManager, {
96
- context: context,
97
- initialFocus: searchRef,
98
- modal: false,
99
- children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
100
- ref: floatingUiRefs.setFloating,
101
- style: floatingStyles,
102
- className: (0, __WEBPACK_EXTERNAL_MODULE_clsx__["default"])(__WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].menu),
103
- ...getFloatingProps(),
104
- children: [
105
- /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("input", {
106
- type: "text",
107
- className: __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].searchInput,
108
- placeholder: searchPlaceholder ?? "Search for an option",
109
- "aria-autocomplete": "list",
110
- onChange: (e)=>{
111
- setSearchTerm(e.target.value);
112
- setActiveIndex(0);
113
- },
114
- value: searchTerm,
115
- ref: searchRef,
116
- onKeyDown: (e)=>{
117
- if ("Enter" === e.key && null != activeIndex) {
118
- setIsOpen(false);
119
- onChange(filteredOptions[activeIndex]);
120
- }
171
+ !disabled && isOpen ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__floating_ui_react_3ddd630a__.FloatingPortal, {
172
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__floating_ui_react_3ddd630a__.FloatingFocusManager, {
173
+ context: context,
174
+ initialFocus: searchRef,
175
+ modal: false,
176
+ children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
177
+ ref: floatingUiRefs.setFloating,
178
+ style: floatingStyles,
179
+ className: (0, __WEBPACK_EXTERNAL_MODULE_clsx__["default"])(__WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].menu),
180
+ ...getFloatingProps(),
181
+ children: [
182
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("input", {
183
+ type: "text",
184
+ className: __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].searchInput,
185
+ placeholder: searchPlaceholder ?? "Search for an option",
186
+ "aria-autocomplete": "list",
187
+ onChange: (e)=>{
188
+ setSearchTerm(e.target.value);
189
+ setActiveIndex(0);
190
+ },
191
+ value: searchTerm,
192
+ ref: searchRef,
193
+ onKeyDown: (e)=>{
194
+ if ("Enter" === e.key && null != activeIndex) {
195
+ setIsOpen(false);
196
+ onChange(filteredOptions[activeIndex]);
121
197
  }
122
- }),
123
- 0 !== filteredOptions.length || onCreate ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("ul", {
124
- className: __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listBox,
125
- ref: listBoxRef,
126
- children: [
127
- filteredOptions.map((option, index)=>{
128
- const optionId = optionToId(option);
129
- const optionLabel = optionToLabel(option);
130
- return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("li", {
131
- className: (0, __WEBPACK_EXTERNAL_MODULE_clsx__["default"])(__WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItem, {
132
- [__WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].activeListItem]: activeIndex === index
133
- }),
134
- ...getItemProps({
135
- onClick: ()=>{
136
- setIsOpen(false);
137
- onChange(option);
138
- },
139
- ref: (node)=>{
140
- optionsRef.current[index] = node;
141
- }
142
- }),
143
- children: [
144
- optionLabel,
145
- value && optionToId(value) === optionToId(option) ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__presentation_Icon_js_6961aa57__["default"], {
146
- symbol: "CheckMark"
147
- }) : null
148
- ]
149
- }, optionId);
150
- }),
151
- onCreate ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("li", {
152
- className: (0, __WEBPACK_EXTERNAL_MODULE_clsx__["default"])([
153
- __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItem,
154
- __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItemCreate
155
- ]),
156
- onClick: ()=>{
157
- setIsOpen(false);
158
- setCreateNewOption(true);
159
- },
160
- children: [
161
- "+ Create new option ",
162
- searchTerm ? `"${searchTerm}"` : null
163
- ]
164
- }) : null
165
- ]
166
- }) : null
167
- ]
168
- })
198
+ }
199
+ }),
200
+ 0 !== filteredOptions.length || onCreate ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("ul", {
201
+ className: __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listBox,
202
+ ref: listBoxRef,
203
+ id: listboxId,
204
+ role: "listbox",
205
+ "aria-labelledby": buttonId,
206
+ children: [
207
+ renderOptions(),
208
+ onCreate ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("li", {
209
+ className: (0, __WEBPACK_EXTERNAL_MODULE_clsx__["default"])([
210
+ __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItem,
211
+ __WEBPACK_EXTERNAL_MODULE__SingleSelectComboboxInput_module_js_54aa53da__["default"].listItemCreate
212
+ ]),
213
+ onClick: ()=>{
214
+ setIsOpen(false);
215
+ setCreateNewOption(true);
216
+ },
217
+ children: [
218
+ "+ Create new option ",
219
+ searchTerm ? `"${searchTerm}"` : null
220
+ ]
221
+ }) : null
222
+ ]
223
+ }) : null
224
+ ]
169
225
  })
170
226
  })
171
227
  }) : null,
@@ -5,6 +5,7 @@ const SingleSelectComboboxInput_module_rslib_entry_ = {
5
5
  searchInput: "searchInput-s9NjcM",
6
6
  menu: "menu-f81oko",
7
7
  listBox: "listBox-biTMkv",
8
+ listItemGroupHeader: "listItemGroupHeader-SdoaP2",
8
9
  listItem: "listItem-ASZkke",
9
10
  listItemCreate: "listItemCreate-_tGId1",
10
11
  activeListItem: "activeListItem-_B_E3X"
@@ -54,6 +54,11 @@
54
54
  overflow-y: auto;
55
55
  }
56
56
 
57
+ .listItemGroupHeader-SdoaP2 {
58
+ padding: var(--size-n2) var(--size-n2) var(--size-n2) 0;
59
+ font: var(--font-regular-bold);
60
+ }
61
+
57
62
  .listItem-ASZkke {
58
63
  padding: var(--size-n2);
59
64
  border-radius: var(--size-n3);
@@ -199,12 +199,12 @@
199
199
 
200
200
  @media (min-width: 1440px) {
201
201
  .centerLayoutContent-OXDuxB {
202
- padding: var(--size-p5) var(--size-p5);
202
+ padding: var(--size-p4) var(--size-p4);
203
203
  }
204
204
  }
205
205
 
206
206
  .narrowLayoutContent-v6PtTH {
207
- padding: 70px var(--size-00) var(--size-00);
207
+ padding: 60px var(--size-00) var(--size-00);
208
208
  grid-template-columns: minmax(0, 720px);
209
209
  justify-content: center;
210
210
  display: grid;
@@ -212,19 +212,19 @@
212
212
 
213
213
  @media (min-width: 768px) {
214
214
  .narrowLayoutContent-v6PtTH {
215
- padding: 70px var(--size-p3) var(--size-p3);
215
+ padding: 60px var(--size-p3) var(--size-p3);
216
216
  }
217
217
  }
218
218
 
219
219
  @media (min-width: 1440px) {
220
220
  .narrowLayoutContent-v6PtTH {
221
- padding: 70px var(--size-p5) var(--size-p5);
221
+ padding: 60px var(--size-p4) var(--size-p4);
222
222
  }
223
223
  }
224
224
 
225
225
  .content-kaxfp0 {
226
226
  column-gap: var(--size-p2);
227
- padding-top: 70px;
227
+ padding-top: 60px;
228
228
  padding-bottom: var(--size-00);
229
229
  padding-left: var(--size-00);
230
230
  padding-right: var(--size-00);
@@ -234,7 +234,7 @@
234
234
 
235
235
  @media (min-width: 768px) {
236
236
  .content-kaxfp0 {
237
- padding: 70px var(--size-p3) var(--size-p3);
237
+ padding: 60px var(--size-p3) var(--size-p3);
238
238
  }
239
239
  }
240
240
 
@@ -255,9 +255,9 @@
255
255
 
256
256
  @media (min-width: 1440px) {
257
257
  .content-kaxfp0 {
258
- padding-bottom: var(--size-p5);
259
- padding-left: var(--size-p5);
260
- padding-right: var(--size-p5);
258
+ padding-bottom: var(--size-p4);
259
+ padding-left: var(--size-p4);
260
+ padding-right: var(--size-p4);
261
261
  }
262
262
  }
263
263
 
@@ -8,18 +8,20 @@
8
8
  }
9
9
 
10
10
  .main-dwl9Kv {
11
- padding: 70px var(--size-00) var(--size-00);
11
+ padding: 60px var(--size-00) var(--size-00);
12
12
  }
13
13
 
14
14
  @media (min-width: 768px) {
15
15
  .main-dwl9Kv {
16
- padding: 70px var(--size-p3) var(--size-p3);
16
+ padding: 60px var(--size-p3) var(--size-p3);
17
17
  }
18
18
  }
19
19
 
20
- @media (min-width: 1024px) {
20
+ @media (min-width: 1440px) {
21
21
  .main-dwl9Kv {
22
- padding: var(--size-p5);
22
+ padding-bottom: var(--size-p4);
23
+ padding-left: var(--size-p4);
24
+ padding-right: var(--size-p4);
23
25
  }
24
26
  }
25
27
 
@@ -62,10 +62,9 @@ type Props<Type> = {
62
62
  estimatedRowSize?: number;
63
63
  emptyState?: ReactNode;
64
64
  id?: string;
65
- showRowCount?: boolean;
66
65
  pathName?: string;
67
66
  localStorageSchema?: ZodTypeAny;
68
67
  getRowId: (row: Type) => string;
69
68
  };
70
- declare const Table: <Type>({ data, columns, bulkActions, secondaryBulkActions, csvFilename, estimatedRowSize, emptyState, pathName, id, showRowCount, localStorageSchema, getRowId, }: Props<Type>) => import("react/jsx-runtime").JSX.Element;
69
+ declare const Table: <Type>({ data, columns, bulkActions, secondaryBulkActions, csvFilename, estimatedRowSize, emptyState, pathName, id, localStorageSchema, getRowId, }: Props<Type>) => import("react/jsx-runtime").JSX.Element;
71
70
  export default Table;
@@ -21,7 +21,7 @@ import * as __WEBPACK_EXTERNAL_MODULE__PlainText_js_cd0b6798__ from "./PlainText
21
21
  import * as __WEBPACK_EXTERNAL_MODULE__Table_module_js_1c0e33be__ from "./Table.module.js";
22
22
  import * as __WEBPACK_EXTERNAL_MODULE__VStack_js_02eb6792__ from "./VStack.js";
23
23
  const selectColumnId = "_selectColumn";
24
- const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csvFilename, estimatedRowSize = 100, emptyState = "No results", pathName, id, showRowCount = true, localStorageSchema, getRowId })=>{
24
+ const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csvFilename, estimatedRowSize = 100, emptyState = "No results", pathName, id, localStorageSchema, getRowId })=>{
25
25
  const [searchTerm, setSearchTerm] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)("");
26
26
  const lastSelectedRow = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(void 0);
27
27
  const { refs, x: bulkSelectionModalXCoordinate } = (0, __WEBPACK_EXTERNAL_MODULE__floating_ui_react_dom_d5bb3c23__.useFloating)({
@@ -336,9 +336,9 @@ const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csv
336
336
  }) : null
337
337
  ]
338
338
  }) : null,
339
- showRowCount || showSearchReset ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__HStack_js_cc26058d__["default"], {
339
+ showSearchReset ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)(__WEBPACK_EXTERNAL_MODULE__HStack_js_cc26058d__["default"], {
340
340
  children: [
341
- showRowCount ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("p", {
341
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("p", {
342
342
  children: [
343
343
  "Showing ",
344
344
  table.getPreGroupedRowModel().flatRows.length,
@@ -346,8 +346,8 @@ const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csv
346
346
  " ",
347
347
  table.getPreFilteredRowModel().flatRows.length
348
348
  ]
349
- }) : null,
350
- showSearchReset ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__controls_Button_js_f591ba2e__["default"], {
349
+ }),
350
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)(__WEBPACK_EXTERNAL_MODULE__controls_Button_js_f591ba2e__["default"], {
351
351
  onClick: ()=>{
352
352
  table.setColumnFilters(columnFiltersInitialState);
353
353
  table.resetGlobalFilter();
@@ -356,7 +356,7 @@ const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csv
356
356
  type: "secondary",
357
357
  size: "small",
358
358
  children: "Reset filters and search"
359
- }) : null
359
+ })
360
360
  ]
361
361
  }) : null,
362
362
  /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsx)("div", {
@@ -461,7 +461,7 @@ const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csv
461
461
  ]
462
462
  })
463
463
  }),
464
- showRowCount || shouldShowCsvExport ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
464
+ /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("div", {
465
465
  className: __WEBPACK_EXTERNAL_MODULE__Table_module_js_1c0e33be__["default"].downloadLink,
466
466
  children: [
467
467
  /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime_225474f2__.jsxs)("p", {
@@ -479,7 +479,7 @@ const Table = ({ data, columns, bulkActions = [], secondaryBulkActions = [], csv
479
479
  children: "Download all rows as CSV"
480
480
  }) : null
481
481
  ]
482
- }) : null
482
+ })
483
483
  ]
484
484
  })
485
485
  ]
@@ -0,0 +1,8 @@
1
+ declare const isValidDate: <Model extends {
2
+ [Field: string]: any;
3
+ }>(field: keyof Model, message?: string) => (data: Model) => {
4
+ id: string;
5
+ field: keyof Model;
6
+ message: string;
7
+ } | null;
8
+ export default isValidDate;
@@ -0,0 +1,18 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_temporal_polyfill_11c1db1c__ from "temporal-polyfill";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_uuid__ from "uuid";
3
+ const isValidDate = (field, message = "Invalid date.")=>(data)=>{
4
+ const value = data[field];
5
+ if (null == value) return null;
6
+ if ("string" == typeof value && "" !== value.trim()) try {
7
+ __WEBPACK_EXTERNAL_MODULE_temporal_polyfill_11c1db1c__.Temporal.PlainDate.from(value);
8
+ } catch {
9
+ return {
10
+ id: (0, __WEBPACK_EXTERNAL_MODULE_uuid__.v4)(),
11
+ field,
12
+ message
13
+ };
14
+ }
15
+ return null;
16
+ };
17
+ const isValidDate_rslib_entry_ = isValidDate;
18
+ export { isValidDate_rslib_entry_ as default };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,107 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_vitest__ from "vitest";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__ from "./isValidDate.js";
3
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.describe)("isValidDate", ()=>{
4
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns null for null values", ()=>{
5
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
6
+ const result = validator({
7
+ date: null
8
+ });
9
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toBeNull();
10
+ });
11
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns null for undefined values", ()=>{
12
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
13
+ const result = validator({});
14
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toBeNull();
15
+ });
16
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns null for valid date strings", ()=>{
17
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
18
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(validator({
19
+ date: "2023-12-25"
20
+ })).toBeNull();
21
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(validator({
22
+ date: "2023-01-01"
23
+ })).toBeNull();
24
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(validator({
25
+ date: "2024-02-29"
26
+ })).toBeNull();
27
+ });
28
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns error for invalid date strings", ()=>{
29
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
30
+ const result = validator({
31
+ date: "invalid-date"
32
+ });
33
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toEqual({
34
+ id: __WEBPACK_EXTERNAL_MODULE_vitest__.expect.any(String),
35
+ field: "date",
36
+ message: "Invalid date."
37
+ });
38
+ });
39
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns error for invalid date formats", ()=>{
40
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
41
+ const result = validator({
42
+ date: "25/12/2023"
43
+ });
44
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toEqual({
45
+ id: __WEBPACK_EXTERNAL_MODULE_vitest__.expect.any(String),
46
+ field: "date",
47
+ message: "Invalid date."
48
+ });
49
+ });
50
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns error for impossible dates", ()=>{
51
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
52
+ const result = validator({
53
+ date: "2023-02-30"
54
+ });
55
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toEqual({
56
+ id: __WEBPACK_EXTERNAL_MODULE_vitest__.expect.any(String),
57
+ field: "date",
58
+ message: "Invalid date."
59
+ });
60
+ });
61
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns null for empty strings", ()=>{
62
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
63
+ const result = validator({
64
+ date: ""
65
+ });
66
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toBeNull();
67
+ });
68
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("returns null for whitespace-only strings", ()=>{
69
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
70
+ const result = validator({
71
+ date: " "
72
+ });
73
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toBeNull();
74
+ });
75
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("uses custom error message when provided", ()=>{
76
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("birthDate", "Please enter a valid birth date.");
77
+ const result = validator({
78
+ birthDate: "invalid"
79
+ });
80
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toEqual({
81
+ id: __WEBPACK_EXTERNAL_MODULE_vitest__.expect.any(String),
82
+ field: "birthDate",
83
+ message: "Please enter a valid birth date."
84
+ });
85
+ });
86
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("works with different field names", ()=>{
87
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("startDate");
88
+ const result = validator({
89
+ startDate: "not-a-date"
90
+ });
91
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result).toEqual({
92
+ id: __WEBPACK_EXTERNAL_MODULE_vitest__.expect.any(String),
93
+ field: "startDate",
94
+ message: "Invalid date."
95
+ });
96
+ });
97
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.it)("generates unique IDs for each error", ()=>{
98
+ const validator = (0, __WEBPACK_EXTERNAL_MODULE__isValidDate_js_ab620b77__["default"])("date");
99
+ const result1 = validator({
100
+ date: "invalid1"
101
+ });
102
+ const result2 = validator({
103
+ date: "invalid2"
104
+ });
105
+ (0, __WEBPACK_EXTERNAL_MODULE_vitest__.expect)(result1?.id).not.toEqual(result2?.id);
106
+ });
107
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@worknice/whiteboard",
3
3
  "description": "",
4
- "version": "0.13.0",
4
+ "version": "0.15.0",
5
5
  "license": "MIT",
6
6
  "private": false,
7
7
  "files": [
@@ -38,7 +38,7 @@
38
38
  "react-markdown": "^10.1.0",
39
39
  "utf8": "^3.0.0",
40
40
  "zod": "^3.22.3",
41
- "@worknice/utils": "^0.6.35"
41
+ "@worknice/utils": "^0.6.37"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@anolilab/semantic-release-pnpm": "^1.1.10",
@@ -70,7 +70,8 @@
70
70
  "semantic-release-scope-filter": "^1.0.0",
71
71
  "temporal-polyfill": "^0.2.5",
72
72
  "typescript": "~5.5.0",
73
- "uuid": "^11.0.5"
73
+ "uuid": "^11.0.5",
74
+ "vitest": "^2.1.0"
74
75
  },
75
76
  "peerDependencies": {
76
77
  "@react-email/components": "^0.0.7",
@@ -87,7 +88,8 @@
87
88
  "fix": "if [[ -z $TURBO_HASH ]]; then pnpm turbo fix; else exit 0; fi",
88
89
  "fix:lint": "eslint \"src/**/*.{js,ts,tsx}\" --fix",
89
90
  "fix:format": "prettier '**/*.{js,ts,tsx,css}' --write",
90
- "test": "exit 0",
91
+ "test": "vitest run",
92
+ "test:unit": "vitest run",
91
93
  "test:format": "prettier '**/*.{js,ts,tsx,css}' --check",
92
94
  "test:lint": "eslint \"src/**/*.{js,ts,tsx}\"",
93
95
  "test:types": "tsc --noEmit --pretty"