@snupo/jmc 1.5.0 → 1.6.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.
Files changed (90) hide show
  1. package/components.md +251 -0
  2. package/dist/comps/checkbox.css +45 -0
  3. package/dist/comps/checkbox.d.ts +16 -0
  4. package/dist/comps/checkbox.d.ts.map +1 -0
  5. package/dist/comps/checkbox.js +20 -0
  6. package/dist/comps/checkbox.js.map +1 -0
  7. package/dist/comps/combobox.css +63 -0
  8. package/dist/comps/combobox.d.ts +30 -0
  9. package/dist/comps/combobox.d.ts.map +1 -0
  10. package/dist/comps/combobox.js +87 -0
  11. package/dist/comps/combobox.js.map +1 -0
  12. package/dist/comps/datalistinput.css +22 -0
  13. package/dist/comps/datalistinput.d.ts +20 -0
  14. package/dist/comps/datalistinput.d.ts.map +1 -0
  15. package/dist/comps/datalistinput.js +23 -0
  16. package/dist/comps/datalistinput.js.map +1 -0
  17. package/dist/comps/icon.css +6 -0
  18. package/dist/comps/icon.d.ts +11 -0
  19. package/dist/comps/icon.d.ts.map +1 -0
  20. package/dist/comps/icon.js +6 -0
  21. package/dist/comps/icon.js.map +1 -0
  22. package/dist/comps/index.d.ts +12 -0
  23. package/dist/comps/index.d.ts.map +1 -0
  24. package/dist/comps/index.js +12 -0
  25. package/dist/comps/index.js.map +1 -0
  26. package/dist/comps/numberstepper.css +44 -0
  27. package/dist/comps/numberstepper.d.ts +26 -0
  28. package/dist/comps/numberstepper.d.ts.map +1 -0
  29. package/dist/comps/numberstepper.js +72 -0
  30. package/dist/comps/numberstepper.js.map +1 -0
  31. package/dist/comps/radiogroup.css +20 -0
  32. package/dist/comps/radiogroup.d.ts +19 -0
  33. package/dist/comps/radiogroup.d.ts.map +1 -0
  34. package/dist/comps/radiogroup.js +21 -0
  35. package/dist/comps/radiogroup.js.map +1 -0
  36. package/dist/comps/rangeslider.css +46 -0
  37. package/dist/comps/rangeslider.d.ts +18 -0
  38. package/dist/comps/rangeslider.d.ts.map +1 -0
  39. package/dist/comps/rangeslider.js +15 -0
  40. package/dist/comps/rangeslider.js.map +1 -0
  41. package/dist/comps/select.css +16 -0
  42. package/dist/comps/select.d.ts +19 -0
  43. package/dist/comps/select.d.ts.map +1 -0
  44. package/dist/comps/select.js +21 -0
  45. package/dist/comps/select.js.map +1 -0
  46. package/dist/comps/tabs.css +22 -0
  47. package/dist/comps/tabs.d.ts +15 -0
  48. package/dist/comps/tabs.d.ts.map +1 -0
  49. package/dist/comps/tabs.js +11 -0
  50. package/dist/comps/tabs.js.map +1 -0
  51. package/dist/comps/textarea.css +19 -0
  52. package/dist/comps/textarea.d.ts +17 -0
  53. package/dist/comps/textarea.d.ts.map +1 -0
  54. package/dist/comps/textarea.js +32 -0
  55. package/dist/comps/textarea.js.map +1 -0
  56. package/dist/comps/togglegroup.css +29 -0
  57. package/dist/comps/togglegroup.d.ts +16 -0
  58. package/dist/comps/togglegroup.d.ts.map +1 -0
  59. package/dist/comps/togglegroup.js +11 -0
  60. package/dist/comps/togglegroup.js.map +1 -0
  61. package/dist/jsx.d.ts +1 -0
  62. package/dist/jsx.d.ts.map +1 -1
  63. package/dist/jsx.js.map +1 -1
  64. package/package.json +89 -76
  65. package/readme.md +4 -0
  66. package/src/comps/checkbox.css +45 -0
  67. package/src/comps/checkbox.tsx +31 -0
  68. package/src/comps/combobox.css +63 -0
  69. package/src/comps/combobox.tsx +100 -0
  70. package/src/comps/css.d.ts +1 -0
  71. package/src/comps/datalistinput.css +22 -0
  72. package/src/comps/datalistinput.tsx +35 -0
  73. package/src/comps/icon.css +6 -0
  74. package/src/comps/icon.tsx +13 -0
  75. package/src/comps/index.ts +11 -0
  76. package/src/comps/numberstepper.css +44 -0
  77. package/src/comps/numberstepper.tsx +73 -0
  78. package/src/comps/radiogroup.css +20 -0
  79. package/src/comps/radiogroup.tsx +40 -0
  80. package/src/comps/rangeslider.css +46 -0
  81. package/src/comps/rangeslider.tsx +27 -0
  82. package/src/comps/select.css +16 -0
  83. package/src/comps/select.tsx +36 -0
  84. package/src/comps/tabs.css +22 -0
  85. package/src/comps/tabs.tsx +22 -0
  86. package/src/comps/textarea.css +19 -0
  87. package/src/comps/textarea.tsx +41 -0
  88. package/src/comps/togglegroup.css +29 -0
  89. package/src/comps/togglegroup.tsx +23 -0
  90. package/src/jsx.ts +1 -0
package/components.md ADDED
@@ -0,0 +1,251 @@
1
+ # jmc components
2
+
3
+ A small set of ready-made input components for jmc apps. They are light DOM only (no Shadow DOM), wrap the native elements, and follow the architecture of the [design guide](design-guide.md): the value lives in the model, the component shows it, and a controller method changes it.
4
+
5
+ ```tsx
6
+ import { NumberStepper } from '@snupo/jmc/comps'
7
+
8
+ <NumberStepper value={m.count} setvalue={c.setcount} min={0} max={10} />
9
+ ```
10
+
11
+ ```ts
12
+ // controller
13
+ setcount(x: number) { m.count = x; updateview() }
14
+ ```
15
+
16
+ Each component imports its own stylesheet, so your bundler must handle CSS imports (Vite and webpack do). Import from `@snupo/jmc/comps`, or a single component from `@snupo/jmc/comps/numberstepper`.
17
+
18
+ ## Rules for all components
19
+
20
+ - **`value` and `setvalue`.** The component shows `value` and calls `setvalue(newvalue)` when the user changes it. It hands out values (a string, a number, an item), never the DOM event. `setvalue` is a controller method, which changes the model and updates the view.
21
+ - **The model decides.** A component never keeps its own copy of the value. If the controller refuses a change, the component shows the old value again. `Checkbox` and `RadioGroup` re-apply the model value after a click, `NumberStepper` after a change.
22
+ - **Own state only for the UI.** `ComboBox` keeps whether its list is open, `NumberStepper` the text you are typing. Nothing else needs it.
23
+ - **`class` and `disabled`.** All input components take `class`. All of them can be disabled: `disabled` is a prop, or passed through to the native element.
24
+ - **Other attributes.** `TextArea`, `Select`, `ComboBox`, `DataListInput` and `Checkbox` pass every other standard attribute (`id`, `title`, `name`, `placeholder`, ...) on to the native element. `Checkbox` sends `class` and `style` to its label. The other components take only the props listed below.
25
+ - **Items.** `Select`, `ToggleGroup`, `RadioGroup` and `Tabs` work on any items, not only strings. They hand out the item itself. `label(item)` sets what is shown, the default is `String(item)`.
26
+ - **Timing.** `Select` and `TextArea` finish their work (the selected option, the height) in a microtask after the render. Code that reads the DOM synchronously after `updateview()` may see the state before that.
27
+
28
+ ### Styling
29
+
30
+ Class names start with `jmc-` and all rules are in the CSS layer `jmc`, so any CSS of your app wins without specificity fights. Colors and sizes are CSS variables with defaults. Set them on `:root`, or on one element to change only the components below it:
31
+
32
+ | variable | meaning |
33
+ |---|---|
34
+ | `--jmc-color` | text color |
35
+ | `--jmc-bg` | background of inputs |
36
+ | `--jmc-border` | border color |
37
+ | `--jmc-radius` | corner radius |
38
+ | `--jmc-padding` | padding of inputs and buttons |
39
+ | `--jmc-accent` | focus and selection color |
40
+ | `--jmc-bg-focus` | hover and focus background |
41
+ | `--jmc-bg-button` | button background of `NumberStepper` |
42
+ | `--jmc-stepper-width` | width of `NumberStepper` |
43
+ | `--jmc-slider-width`, `--jmc-track-height`, `--jmc-track`, `--jmc-thumb`, `--jmc-thumb-size` | `RangeSlider` |
44
+ | `--jmc-checkbox-radius` | corner radius of `Checkbox` |
45
+
46
+ ---
47
+
48
+ ## TextArea
49
+
50
+ A textarea that grows and shrinks with its text. Use it where a text can have several lines and you don't want a scrollbar.
51
+
52
+ | prop | type | |
53
+ |---|---|---|
54
+ | `value` | `string` | |
55
+ | `setvalue?` | `(value: string) => void` | called on every input |
56
+ | other | textarea attributes | `placeholder`, `disabled`, `rows` (default 1), ... |
57
+
58
+ ```tsx
59
+ <TextArea value={m.note} setvalue={c.setnote} placeholder='a note' />
60
+ ```
61
+
62
+ - The height follows the text when the user types, when the model changes the value, and when the width changes (the text wraps anew).
63
+ - A hidden textarea is adjusted once it is shown.
64
+ - `autofocus` focuses it when it is mounted.
65
+ - Browsers that support `field-sizing: content` can do this in CSS alone.
66
+
67
+ ## NumberStepper
68
+
69
+ A number input with minus and plus buttons.
70
+
71
+ | prop | type | |
72
+ |---|---|---|
73
+ | `value` | `number` | |
74
+ | `setvalue` | `(value: number) => void` | |
75
+ | `min?`, `max?` | `number` | bounds of the buttons |
76
+ | `step?` | `number` | default 1 |
77
+ | `decimals?` | `number` | default: the decimals of `step` |
78
+ | `class?`, `disabled?` | | |
79
+
80
+ ```tsx
81
+ <NumberStepper value={m.price} setvalue={c.setprice} min={0} max={100} step={0.5} />
82
+ ```
83
+
84
+ - The buttons stop at `min` and `max`, but only while the value is inside them. Typed text may leave the range, from where the buttons step freely.
85
+ - The text is committed on Enter or blur. A comma is accepted as the decimal separator, invalid text reverts to the current value, valid text is rounded to `decimals`.
86
+ - Keys: Enter commits, Escape reverts, ArrowUp or `+` and ArrowDown or `-` commit the pending text and step. Other characters than digits, `.` and `,` are not accepted.
87
+
88
+ ## RangeSlider
89
+
90
+ A styled native range input.
91
+
92
+ | prop | type | |
93
+ |---|---|---|
94
+ | `value` | `number` | |
95
+ | `setvalue` | `(value: number) => void` | called while dragging |
96
+ | `min?`, `max?`, `step?` | `number` | |
97
+ | `class?`, `disabled?` | | |
98
+
99
+ ```tsx
100
+ <RangeSlider value={m.volume} setvalue={c.setvolume} min={0} max={100} />
101
+ ```
102
+
103
+ It combines with `NumberStepper`: both take the same `value` and `setvalue`, so they can edit one model field side by side.
104
+
105
+ ## Select
106
+
107
+ A native select over any items. It hands out the item, not text.
108
+
109
+ | prop | type | |
110
+ |---|---|---|
111
+ | `items` | `T[]` | |
112
+ | `value` | `T \| undefined` | |
113
+ | `setvalue` | `(item: T) => void` | |
114
+ | `label?` | `(item: T) => string` | default `String(item)` |
115
+ | other | select attributes | `disabled`, `name`, ... |
116
+
117
+ ```tsx
118
+ <Select items={m.trains} value={m.train} setvalue={c.settrain} label={t => t.name} />
119
+ ```
120
+
121
+ A `value` that is not in `items`, or `undefined`, shows nothing selected. Items are found by position, so two items with the same label are fine.
122
+
123
+ ## ComboBox
124
+
125
+ A text input with a dropdown of suggestions. Any text is allowed, the suggestions only help.
126
+
127
+ | prop | type | |
128
+ |---|---|---|
129
+ | `items` | `string[]` | the suggestions |
130
+ | `value` | `string` | |
131
+ | `setvalue` | `(value: string) => void` | called on every input, and when an item is picked |
132
+ | other | input attributes | `placeholder`, `disabled`, ... |
133
+
134
+ ```tsx
135
+ <ComboBox items={m.cities} value={m.city} setvalue={c.setcity} placeholder='city' />
136
+ ```
137
+
138
+ - Clicking the input, the arrow button or ArrowDown opens the list with **all** items, also when the text matches one.
139
+ - Typing narrows the list to the items that contain the text, ignoring case. When nothing matches, no list is shown.
140
+ - Keys: ArrowDown and ArrowUp highlight (and wrap around), Enter picks the highlighted item, Escape closes, Enter with nothing highlighted just closes.
141
+ - Leaving the input closes the list.
142
+
143
+ Use [DataListInput](#datalistinput) instead for the browser's own suggestions: simpler, and better on mobile.
144
+
145
+ ## DataListInput
146
+
147
+ A text input with the browser's own suggestions: a native `<input>` with a `<datalist>`. Same props as `ComboBox`.
148
+
149
+ ```tsx
150
+ <DataListInput items={m.cities} value={m.city} setvalue={c.setcity} />
151
+ ```
152
+
153
+ - The browser narrows the suggestions to those matching the text. With a filled-in value it shows only that one. This cannot be changed. If it gets in the way, use `ComboBox`.
154
+ - It looks and works the way the user's browser or phone does it, with no code of ours for the list.
155
+ - The input finds its list by id, so every instance creates a unique one.
156
+
157
+ ## Checkbox
158
+
159
+ A checkbox with a third state, for a group of which only some are checked. The label is the content of the component.
160
+
161
+ | prop | type | |
162
+ |---|---|---|
163
+ | `checked` | `boolean \| 'mixed'` | |
164
+ | `setchecked` | `(checked: boolean) => void` | |
165
+ | `round?` | `boolean` | round instead of square |
166
+ | children | | the label |
167
+ | other | input attributes | `disabled`, `name`, ... |
168
+
169
+ ```tsx
170
+ const state = checked == 0 ? false : checked == all ? true : 'mixed' // a plain function of the model
171
+
172
+ <Checkbox checked={state} setchecked={c.setall} round>all</Checkbox>
173
+ ```
174
+
175
+ - A click on `'mixed'` hands out `true`, a click on `true` hands out `false`.
176
+ - `'mixed'` is the native `indeterminate` state.
177
+ - `class` and `style` go to the label. A color for one checkbox is `style='--jmc-accent: red'`.
178
+
179
+ ## ToggleGroup
180
+
181
+ A row of buttons of which exactly one is selected: a segmented control.
182
+
183
+ | prop | type | |
184
+ |---|---|---|
185
+ | `items` | `T[]` | |
186
+ | `value` | `T \| undefined` | |
187
+ | `setvalue` | `(item: T) => void` | |
188
+ | `label?` | `(item: T) => any` | text or a view such as an `Icon`, default `String(item)` |
189
+ | `class?`, `disabled?` | | |
190
+
191
+ ```tsx
192
+ <ToggleGroup items={['list', 'grid']} value={m.layout} setvalue={c.setlayout} />
193
+ <ToggleGroup items={m.modes} value={m.mode} setvalue={c.setmode} label={i => <Icon icon={icons[i]} />} />
194
+ ```
195
+
196
+ The items are real buttons, so Tab and Enter work. The buttons have `role="radio"`, the group `role="radiogroup"`.
197
+
198
+ ## RadioGroup
199
+
200
+ Native radio inputs, one per item, in a row.
201
+
202
+ | prop | type | |
203
+ |---|---|---|
204
+ | `items` | `T[]` | |
205
+ | `value` | `T \| undefined` | |
206
+ | `setvalue` | `(item: T) => void` | |
207
+ | `label?` | `(item: T) => any` | default `String(item)` |
208
+ | `color?` | `(item: T) => string \| undefined` | tints the radio of the item |
209
+ | `class?`, `disabled?` | | |
210
+
211
+ ```tsx
212
+ <RadioGroup items={m.groups} value={m.group} setvalue={c.setgroup} color={g => colors[g]} />
213
+ ```
214
+
215
+ Radios belong to one group by name, so every instance creates a unique one. The arrow keys move within the group, as with any native radios. Use `ToggleGroup` instead for a segmented look.
216
+
217
+ ## Tabs
218
+
219
+ The tab bar only. The content below it belongs to your app, which shows what the selected tab says.
220
+
221
+ | prop | type | |
222
+ |---|---|---|
223
+ | `items` | `T[]` | |
224
+ | `value` | `T \| undefined` | |
225
+ | `setvalue` | `(item: T) => void` | |
226
+ | `label?` | `(item: T) => any` | default `String(item)` |
227
+ | `class?` | | |
228
+
229
+ ```tsx
230
+ <Tabs items={m.pages} value={m.page} setvalue={c.gotopage} />
231
+ {m.page == 'events' ? <Events /> : <Week />}
232
+ ```
233
+
234
+ The tabs are buttons with `role="tab"`, the bar has `role="tablist"`.
235
+
236
+ ## Icon
237
+
238
+ An `<svg>` icon from an icon node in the format of [lucide](https://lucide.dev), drawn in the text color. jmc has no dependency on lucide: import the nodes from lucide, or write them as a list of `[tag, attributes]`.
239
+
240
+ | prop | type | |
241
+ |---|---|---|
242
+ | `icon` | `IconNode` | `[tag, attributes][]` |
243
+ | `size?` | `number` | px, default 18 |
244
+ | `stroke?` | `number` | default 2 |
245
+ | `class?` | | |
246
+
247
+ ```tsx
248
+ import { Eye } from 'lucide'
249
+
250
+ <Icon icon={Eye} size={24} />
251
+ ```
@@ -0,0 +1,45 @@
1
+ @layer jmc {
2
+ .jmc-checkbox {
3
+ --c: var(--jmc-accent, #3b82f6);
4
+ display: inline-flex;
5
+ align-items: center;
6
+ gap: 0.4em;
7
+ cursor: pointer;
8
+
9
+ input {
10
+ appearance: none;
11
+ display: grid;
12
+ place-content: center;
13
+ flex: none; /* a squeezed box would turn a round one into an ellipse */
14
+ width: 1.1em;
15
+ height: 1.1em;
16
+ margin: 0;
17
+ color: var(--jmc-bg, #fff);
18
+ background: var(--jmc-bg, #fff);
19
+ border: 1.5px solid var(--c);
20
+ border-radius: var(--jmc-checkbox-radius, 3px);
21
+ cursor: inherit;
22
+
23
+ &::after {
24
+ content: '';
25
+ width: 0.65em;
26
+ height: 0.65em;
27
+ background: currentColor;
28
+ transform: scale(0);
29
+ }
30
+ &:checked, &:indeterminate { background: var(--c); }
31
+ &:checked::after {
32
+ transform: scale(1);
33
+ clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
34
+ }
35
+ &:indeterminate::after {
36
+ transform: scale(1);
37
+ clip-path: polygon(0 40%, 100% 40%, 100% 60%, 0 60%);
38
+ }
39
+ &:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; }
40
+ &:disabled { opacity: 0.4; }
41
+ }
42
+
43
+ &.jmc-round input { border-radius: 50%; }
44
+ }
45
+ }
@@ -0,0 +1,16 @@
1
+ import type { InputHTMLAttributes } from '../jsx.js';
2
+ import { Component } from '../lib.js';
3
+ import './checkbox.css';
4
+ type Props = Omit<InputHTMLAttributes, 'checked' | 'indeterminate' | 'onchange' | 'oninput' | 'type' | 'value'> & {
5
+ checked: boolean | 'mixed';
6
+ setchecked: (checked: boolean) => void;
7
+ round?: boolean;
8
+ children?: any;
9
+ };
10
+ /** a checkbox with a third state. a click on 'mixed' hands out true. class and style go to the label */
11
+ export declare class Checkbox extends Component<Props> {
12
+ view(): any;
13
+ onchange(ev: Event): void;
14
+ }
15
+ export {};
16
+ //# sourceMappingURL=checkbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox.d.ts","sourceRoot":"","sources":["../../src/comps/checkbox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,gBAAgB,CAAA;AAEvB,KAAK,KAAK,GAAG,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,eAAe,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC,GAAG;IAC9G,OAAO,EAAE,OAAO,GAAG,OAAO,CAAA;IAC1B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IACtC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,QAAQ,CAAC,EAAE,GAAG,CAAA;CACjB,CAAA;AAED,wGAAwG;AACxG,qBAAa,QAAS,SAAQ,SAAS,CAAC,KAAK,CAAC;IAE1C,IAAI;IAQJ,QAAQ,CAAC,EAAE,EAAE,KAAK;CAOrB"}
@@ -0,0 +1,20 @@
1
+ import { jsx } from '../h.js';
2
+ import { Component, cc } from '../lib.js';
3
+ import './checkbox.css';
4
+ /** a checkbox with a third state. a click on 'mixed' hands out true. class and style go to the label */
5
+ export class Checkbox extends Component {
6
+ view() {
7
+ const { checked, setchecked, round, class: cls, style, children, ...rest } = this.props;
8
+ return jsx("label", { class: cc('jmc-checkbox', { 'jmc-round': round }, cls), style: style },
9
+ jsx("input", { type: 'checkbox', ...rest, checked: checked === true, indeterminate: checked === 'mixed', onchange: this.onchange }),
10
+ children);
11
+ }
12
+ onchange(ev) {
13
+ const i = ev.target;
14
+ this.props.setchecked(i.checked);
15
+ // the click changed the element. jmc writes only props that changed, so show what the model decided
16
+ i.checked = this.props.checked === true;
17
+ i.indeterminate = this.props.checked === 'mixed';
18
+ }
19
+ }
20
+ //# sourceMappingURL=checkbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkbox.js","sourceRoot":"","sources":["../../src/comps/checkbox.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,gBAAgB,CAAA;AASvB,wGAAwG;AACxG,MAAM,OAAO,QAAS,SAAQ,SAAgB;IAE1C,IAAI;QACA,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QACvF,OAAO,eAAO,KAAK,EAAE,EAAE,CAAC,cAAc,EAAE,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK;YAC9E,eAAO,IAAI,EAAC,UAAU,KAAK,IAAI,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,EAAE,aAAa,EAAE,OAAO,KAAK,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,GAAI;YAC1H,QAAQ,CACL,CAAA;IACZ,CAAC;IAED,QAAQ,CAAC,EAAS;QACd,MAAM,CAAC,GAAG,EAAE,CAAC,MAA0B,CAAA;QACvC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAA;QAChC,oGAAoG;QACpG,CAAC,CAAC,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,IAAI,CAAA;QACvC,CAAC,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,KAAK,OAAO,CAAA;IACpD,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport type { InputHTMLAttributes } from '../jsx.js'\nimport { Component, cc } from '../lib.js'\nimport './checkbox.css'\n\ntype Props = Omit<InputHTMLAttributes, 'checked' | 'indeterminate' | 'onchange' | 'oninput' | 'type' | 'value'> & {\n checked: boolean | 'mixed' // 'mixed' is the third state, for a group of which only some are checked\n setchecked: (checked: boolean) => void\n round?: boolean\n children?: any // the label: text or a view\n}\n\n/** a checkbox with a third state. a click on 'mixed' hands out true. class and style go to the label */\nexport class Checkbox extends Component<Props> {\n\n view() {\n const { checked, setchecked, round, class: cls, style, children, ...rest } = this.props\n return <label class={cc('jmc-checkbox', { 'jmc-round': round }, cls)} style={style}>\n <input type='checkbox' {...rest} checked={checked === true} indeterminate={checked === 'mixed'} onchange={this.onchange} />\n {children}\n </label>\n }\n\n onchange(ev: Event) {\n const i = ev.target as HTMLInputElement\n this.props.setchecked(i.checked)\n // the click changed the element. jmc writes only props that changed, so show what the model decided\n i.checked = this.props.checked === true\n i.indeterminate = this.props.checked === 'mixed'\n }\n}\n"]}
@@ -0,0 +1,63 @@
1
+ @layer jmc {
2
+ .jmc-combobox {
3
+ position: relative;
4
+ display: inline-flex;
5
+ align-items: stretch;
6
+ color: var(--jmc-color, inherit);
7
+ background: var(--jmc-bg, #fff);
8
+ border: 1px solid var(--jmc-border, #cbd5e1);
9
+ border-radius: var(--jmc-radius, 6px);
10
+
11
+ &:focus-within { border-color: var(--jmc-accent, #3b82f6); }
12
+ &:has(input:disabled) { opacity: 0.5; }
13
+
14
+ input {
15
+ flex: 1;
16
+ min-width: 0;
17
+ font: inherit;
18
+ padding: var(--jmc-padding, 0.3em 0.5em);
19
+ color: inherit;
20
+ background: transparent;
21
+ border: none;
22
+ outline: none;
23
+ }
24
+
25
+ button {
26
+ padding: 0 0.5em;
27
+ font: inherit;
28
+ color: inherit;
29
+ background: transparent;
30
+ border: none;
31
+ cursor: pointer;
32
+
33
+ &:hover:not(:disabled) { opacity: 0.6; }
34
+ &:disabled { cursor: default; }
35
+ }
36
+
37
+ ul {
38
+ position: absolute;
39
+ z-index: 10;
40
+ top: 100%;
41
+ left: -1px; /* over the border */
42
+ min-width: calc(100% + 2px);
43
+ max-height: 14rem;
44
+ margin: 2px 0 0;
45
+ padding: 0.2rem 0;
46
+ overflow-y: auto;
47
+ list-style: none;
48
+ background: var(--jmc-bg, #fff);
49
+ border: 1px solid var(--jmc-border, #cbd5e1);
50
+ border-radius: var(--jmc-radius, 6px);
51
+ box-shadow: 0 4px 12px rgb(0 0 0 / 0.12);
52
+ }
53
+
54
+ li {
55
+ padding: 0.25em 0.6em;
56
+ cursor: pointer;
57
+ white-space: nowrap;
58
+
59
+ &:hover, &.active { background: var(--jmc-bg-focus, #f0f7ff); }
60
+ &.selected { font-weight: 600; }
61
+ }
62
+ }
63
+ }
@@ -0,0 +1,30 @@
1
+ import type { InputHTMLAttributes } from '../jsx.js';
2
+ import { Component } from '../lib.js';
3
+ import './combobox.css';
4
+ type Props = Omit<InputHTMLAttributes, 'value' | 'oninput' | 'type'> & {
5
+ items: string[];
6
+ value: string;
7
+ setvalue: (value: string) => void;
8
+ };
9
+ /**
10
+ * a text input with a dropdown of suggestions. any text is allowed.
11
+ * opening it (click, arrow button, ArrowDown) shows all items, typing narrows them to those containing the text.
12
+ * open, filter and the highlighted item are the component's own state: nothing else needs them
13
+ */
14
+ export declare class ComboBox extends Component<Props> {
15
+ open: boolean;
16
+ filtering: boolean;
17
+ active: number;
18
+ get shown(): string[];
19
+ view(): any;
20
+ keepfocus(ev: Event): void;
21
+ openall(): void;
22
+ toggle(ev: Event): void;
23
+ close(): void;
24
+ pick(s: string): void;
25
+ oninput(ev: Event): void;
26
+ onkeydown(ev: KeyboardEvent): void;
27
+ get input(): HTMLInputElement;
28
+ }
29
+ export {};
30
+ //# sourceMappingURL=combobox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox.d.ts","sourceRoot":"","sources":["../../src/comps/combobox.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,gBAAgB,CAAA;AAEvB,KAAK,KAAK,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC,GAAG;IACnE,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACpC,CAAA;AAED;;;;GAIG;AACH,qBAAa,QAAS,SAAQ,SAAS,CAAC,KAAK,CAAC;IAE1C,IAAI,UAAQ;IACZ,SAAS,UAAQ;IACjB,MAAM,SAAK;IAEX,IAAI,KAAK,aAGR;IAED,IAAI;IAcJ,SAAS,CAAC,EAAE,EAAE,KAAK;IAEnB,OAAO;IAOP,MAAM,CAAC,EAAE,EAAE,KAAK;IAOhB,KAAK;IAKL,IAAI,CAAC,CAAC,EAAE,MAAM;IAKd,OAAO,CAAC,EAAE,EAAE,KAAK;IAQjB,SAAS,CAAC,EAAE,EAAE,aAAa;IAuB3B,IAAI,KAAK,qBAAkD;CAC9D"}
@@ -0,0 +1,87 @@
1
+ import { jsx } from '../h.js';
2
+ import { Component, cc } from '../lib.js';
3
+ import './combobox.css';
4
+ /**
5
+ * a text input with a dropdown of suggestions. any text is allowed.
6
+ * opening it (click, arrow button, ArrowDown) shows all items, typing narrows them to those containing the text.
7
+ * open, filter and the highlighted item are the component's own state: nothing else needs them
8
+ */
9
+ export class ComboBox extends Component {
10
+ open = false;
11
+ filtering = false; // set by typing, cleared by opening: whether the list is narrowed to the text
12
+ active = -1; // index in shown of the highlighted item
13
+ get shown() {
14
+ const { items, value } = this.props;
15
+ return this.filtering ? items.filter(i => i.toLowerCase().includes(value.toLowerCase())) : items;
16
+ }
17
+ view() {
18
+ const { items, value, setvalue, class: cls, ...rest } = this.props;
19
+ const shown = this.shown;
20
+ return jsx("div", { class: cc('jmc-combobox', cls) },
21
+ jsx("input", { type: 'text', ...rest, value: value, role: 'combobox', "aria-expanded": this.open, "aria-autocomplete": 'list', autocomplete: 'off', oninput: this.oninput, onkeydown: this.onkeydown, onmousedown: this.openall, onblur: this.close }),
22
+ jsx("button", { type: 'button', tabindex: -1, disabled: rest.disabled, onmousedown: this.toggle }, "\u25BE"),
23
+ this.open && shown.length > 0 && jsx("ul", { role: 'listbox', onmousedown: this.keepfocus }, shown.map((s, i) => jsx("li", { role: 'option', "aria-selected": s == value, class: cc({ active: i == this.active, selected: s == value }), onmousedown: () => this.pick(s) }, s))));
24
+ }
25
+ // the dropdown must not take the focus from the input, or the blur would close it before a click lands
26
+ keepfocus(ev) { ev.preventDefault(); }
27
+ openall() {
28
+ this.open = true;
29
+ this.filtering = false;
30
+ this.active = -1;
31
+ this.updateview();
32
+ }
33
+ toggle(ev) {
34
+ ev.preventDefault(); // keeps the focus where it is
35
+ if (this.open)
36
+ return this.close();
37
+ this.input.focus();
38
+ this.openall();
39
+ }
40
+ close() {
41
+ this.open = false;
42
+ this.updateview();
43
+ }
44
+ pick(s) {
45
+ this.props.setvalue(s);
46
+ this.close();
47
+ }
48
+ oninput(ev) {
49
+ this.open = true;
50
+ this.filtering = true;
51
+ this.active = -1;
52
+ this.props.setvalue(ev.target.value);
53
+ this.updateview();
54
+ }
55
+ onkeydown(ev) {
56
+ const n = this.shown.length;
57
+ switch (ev.key) {
58
+ case 'ArrowDown':
59
+ case 'ArrowUp': {
60
+ ev.preventDefault();
61
+ if (!this.open)
62
+ return this.openall();
63
+ const step = ev.key == 'ArrowDown' ? 1 : -1;
64
+ this.active = n == 0 ? -1 : (this.active + step + n) % n;
65
+ this.updateview();
66
+ this.element.querySelector('.active')?.scrollIntoView?.({ block: 'nearest' });
67
+ break;
68
+ }
69
+ case 'Enter':
70
+ if (this.open && this.active >= 0) {
71
+ ev.preventDefault();
72
+ this.pick(this.shown[this.active]);
73
+ }
74
+ else if (this.open)
75
+ this.close();
76
+ break;
77
+ case 'Escape':
78
+ if (this.open) {
79
+ ev.preventDefault();
80
+ this.close();
81
+ }
82
+ break;
83
+ }
84
+ }
85
+ get input() { return this.element.querySelector('input'); }
86
+ }
87
+ //# sourceMappingURL=combobox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"combobox.js","sourceRoot":"","sources":["../../src/comps/combobox.tsx"],"names":[],"mappings":"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","sourcesContent":["import { jsx } from '../h.js'\nimport type { InputHTMLAttributes } from '../jsx.js'\nimport { Component, cc } from '../lib.js'\nimport './combobox.css'\n\ntype Props = Omit<InputHTMLAttributes, 'value' | 'oninput' | 'type'> & {\n items: string[]\n value: string\n setvalue: (value: string) => void\n}\n\n/**\n * a text input with a dropdown of suggestions. any text is allowed.\n * opening it (click, arrow button, ArrowDown) shows all items, typing narrows them to those containing the text.\n * open, filter and the highlighted item are the component's own state: nothing else needs them\n */\nexport class ComboBox extends Component<Props> {\n\n open = false\n filtering = false // set by typing, cleared by opening: whether the list is narrowed to the text\n active = -1 // index in shown of the highlighted item\n\n get shown() {\n const { items, value } = this.props\n return this.filtering ? items.filter(i => i.toLowerCase().includes(value.toLowerCase())) : items\n }\n\n view() {\n const { items, value, setvalue, class: cls, ...rest } = this.props\n const shown = this.shown\n return <div class={cc('jmc-combobox', cls)}>\n <input type='text' {...rest} value={value} role='combobox' aria-expanded={this.open} aria-autocomplete='list' autocomplete='off'\n oninput={this.oninput} onkeydown={this.onkeydown} onmousedown={this.openall} onblur={this.close} />\n <button type='button' tabindex={-1} disabled={rest.disabled} onmousedown={this.toggle}>&#9662;</button>\n {this.open && shown.length > 0 && <ul role='listbox' onmousedown={this.keepfocus}>\n {shown.map((s, i) => <li role='option' aria-selected={s == value} class={cc({ active: i == this.active, selected: s == value })} onmousedown={() => this.pick(s)}>{s}</li>)}\n </ul>}\n </div>\n }\n\n // the dropdown must not take the focus from the input, or the blur would close it before a click lands\n keepfocus(ev: Event) { ev.preventDefault() }\n\n openall() {\n this.open = true\n this.filtering = false\n this.active = -1\n this.updateview()\n }\n\n toggle(ev: Event) {\n ev.preventDefault() // keeps the focus where it is\n if (this.open) return this.close()\n this.input.focus()\n this.openall()\n }\n\n close() {\n this.open = false\n this.updateview()\n }\n\n pick(s: string) {\n this.props.setvalue(s)\n this.close()\n }\n\n oninput(ev: Event) {\n this.open = true\n this.filtering = true\n this.active = -1\n this.props.setvalue((ev.target as HTMLInputElement).value)\n this.updateview()\n }\n\n onkeydown(ev: KeyboardEvent) {\n const n = this.shown.length\n switch (ev.key) {\n case 'ArrowDown':\n case 'ArrowUp': {\n ev.preventDefault()\n if (!this.open) return this.openall()\n const step = ev.key == 'ArrowDown' ? 1 : -1\n this.active = n == 0 ? -1 : (this.active + step + n) % n\n this.updateview()\n this.element.querySelector('.active')?.scrollIntoView?.({ block: 'nearest' })\n break\n }\n case 'Enter':\n if (this.open && this.active >= 0) { ev.preventDefault(); this.pick(this.shown[this.active]) }\n else if (this.open) this.close()\n break\n case 'Escape':\n if (this.open) { ev.preventDefault(); this.close() }\n break\n }\n }\n\n get input() { return this.element.querySelector('input')! }\n}\n"]}
@@ -0,0 +1,22 @@
1
+ @layer jmc {
2
+ .jmc-datalist-input {
3
+ display: inline-block;
4
+
5
+ input {
6
+ box-sizing: border-box;
7
+ width: 100%;
8
+ font: inherit;
9
+ padding: var(--jmc-padding, 0.3em 0.5em);
10
+ color: var(--jmc-color, inherit);
11
+ background: var(--jmc-bg, #fff);
12
+ border: 1px solid var(--jmc-border, #cbd5e1);
13
+ border-radius: var(--jmc-radius, 6px);
14
+
15
+ &:focus {
16
+ outline: none;
17
+ border-color: var(--jmc-accent, #3b82f6);
18
+ }
19
+ &:disabled { opacity: 0.5; }
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ import type { InputHTMLAttributes } from '../jsx.js';
2
+ import { Component } from '../lib.js';
3
+ import './datalistinput.css';
4
+ type Props = Omit<InputHTMLAttributes, 'value' | 'oninput' | 'list' | 'type'> & {
5
+ items: string[];
6
+ value: string;
7
+ setvalue: (value: string) => void;
8
+ };
9
+ /**
10
+ * a text input with the browser's own suggestions: a native input with a datalist. any text is allowed.
11
+ * the simple alternative to ComboBox, and the better one on mobile. the browser narrows the suggestions
12
+ * to those matching the text, so with a filled-in value it shows only that one
13
+ */
14
+ export declare class DataListInput extends Component<Props> {
15
+ listid: string;
16
+ view(): any;
17
+ oninput(ev: Event): void;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=datalistinput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datalistinput.d.ts","sourceRoot":"","sources":["../../src/comps/datalistinput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACpD,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,qBAAqB,CAAA;AAE5B,KAAK,KAAK,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,CAAC,GAAG;IAC5E,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACpC,CAAA;AAID;;;;GAIG;AACH,qBAAa,aAAc,SAAQ,SAAS,CAAC,KAAK,CAAC;IAG/C,MAAM,SAA0B;IAEhC,IAAI;IAQJ,OAAO,CAAC,EAAE,EAAE,KAAK;CAGpB"}
@@ -0,0 +1,23 @@
1
+ import { jsx } from '../h.js';
2
+ import { Component, cc } from '../lib.js';
3
+ import './datalistinput.css';
4
+ let counter = 0;
5
+ /**
6
+ * a text input with the browser's own suggestions: a native input with a datalist. any text is allowed.
7
+ * the simple alternative to ComboBox, and the better one on mobile. the browser narrows the suggestions
8
+ * to those matching the text, so with a filled-in value it shows only that one
9
+ */
10
+ export class DataListInput extends Component {
11
+ // the input finds its list by id only, so every instance needs its own
12
+ listid = `jmc-list-${counter++}`;
13
+ view() {
14
+ const { items, value, setvalue, class: cls, ...rest } = this.props;
15
+ return jsx("div", { class: cc('jmc-datalist-input', cls) },
16
+ jsx("input", { type: 'text', ...rest, list: this.listid, value: value, oninput: this.oninput }),
17
+ jsx("datalist", { id: this.listid }, items.map(i => jsx("option", { value: i }))));
18
+ }
19
+ oninput(ev) {
20
+ this.props.setvalue(ev.target.value);
21
+ }
22
+ }
23
+ //# sourceMappingURL=datalistinput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"datalistinput.js","sourceRoot":"","sources":["../../src/comps/datalistinput.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,qBAAqB,CAAA;AAQ5B,IAAI,OAAO,GAAG,CAAC,CAAA;AAEf;;;;GAIG;AACH,MAAM,OAAO,aAAc,SAAQ,SAAgB;IAE/C,uEAAuE;IACvE,MAAM,GAAG,YAAY,OAAO,EAAE,EAAE,CAAA;IAEhC,IAAI;QACA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAClE,OAAO,aAAK,KAAK,EAAE,EAAE,CAAC,oBAAoB,EAAE,GAAG,CAAC;YAC5C,eAAO,IAAI,EAAC,MAAM,KAAK,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,GAAI;YACvF,kBAAU,EAAE,EAAE,IAAI,CAAC,MAAM,IAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAQ,KAAK,EAAE,CAAC,GAAI,CAAC,CAAY,CAC1E,CAAA;IACV,CAAC;IAED,OAAO,CAAC,EAAS;QACb,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAE,EAAE,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAA;IAC9D,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport type { InputHTMLAttributes } from '../jsx.js'\nimport { Component, cc } from '../lib.js'\nimport './datalistinput.css'\n\ntype Props = Omit<InputHTMLAttributes, 'value' | 'oninput' | 'list' | 'type'> & {\n items: string[]\n value: string\n setvalue: (value: string) => void\n}\n\nlet counter = 0\n\n/**\n * a text input with the browser's own suggestions: a native input with a datalist. any text is allowed.\n * the simple alternative to ComboBox, and the better one on mobile. the browser narrows the suggestions\n * to those matching the text, so with a filled-in value it shows only that one\n */\nexport class DataListInput extends Component<Props> {\n\n // the input finds its list by id only, so every instance needs its own\n listid = `jmc-list-${counter++}`\n\n view() {\n const { items, value, setvalue, class: cls, ...rest } = this.props\n return <div class={cc('jmc-datalist-input', cls)}>\n <input type='text' {...rest} list={this.listid} value={value} oninput={this.oninput} />\n <datalist id={this.listid}>{items.map(i => <option value={i} />)}</datalist>\n </div>\n }\n\n oninput(ev: Event) {\n this.props.setvalue((ev.target as HTMLInputElement).value)\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ @layer jmc {
2
+ .jmc-icon {
3
+ flex: none;
4
+ vertical-align: middle;
5
+ }
6
+ }
@@ -0,0 +1,11 @@
1
+ import './icon.css';
2
+ /** the icon format of lucide (IconNode): a list of [tag, attributes] */
3
+ export type IconNode = [tag: string, attrs: Record<string, string | number>][];
4
+ /** an svg icon from a lucide icon node. it is drawn in the text color and sized by size, in px */
5
+ export declare const Icon: ({ icon, size, stroke, class: cls }: {
6
+ icon: IconNode;
7
+ size?: number;
8
+ stroke?: number;
9
+ class?: string;
10
+ }) => any;
11
+ //# sourceMappingURL=icon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"icon.d.ts","sourceRoot":"","sources":["../../src/comps/icon.tsx"],"names":[],"mappings":"AAEA,OAAO,YAAY,CAAA;AAEnB,wEAAwE;AACxE,MAAM,MAAM,QAAQ,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAA;AAE9E,kGAAkG;AAClG,eAAO,MAAM,IAAI,GAAI,oCAA6C;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,QAI1H,CAAA"}