@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.
- package/components.md +251 -0
- package/dist/comps/checkbox.css +45 -0
- package/dist/comps/checkbox.d.ts +16 -0
- package/dist/comps/checkbox.d.ts.map +1 -0
- package/dist/comps/checkbox.js +20 -0
- package/dist/comps/checkbox.js.map +1 -0
- package/dist/comps/combobox.css +63 -0
- package/dist/comps/combobox.d.ts +30 -0
- package/dist/comps/combobox.d.ts.map +1 -0
- package/dist/comps/combobox.js +87 -0
- package/dist/comps/combobox.js.map +1 -0
- package/dist/comps/datalistinput.css +22 -0
- package/dist/comps/datalistinput.d.ts +20 -0
- package/dist/comps/datalistinput.d.ts.map +1 -0
- package/dist/comps/datalistinput.js +23 -0
- package/dist/comps/datalistinput.js.map +1 -0
- package/dist/comps/icon.css +6 -0
- package/dist/comps/icon.d.ts +11 -0
- package/dist/comps/icon.d.ts.map +1 -0
- package/dist/comps/icon.js +6 -0
- package/dist/comps/icon.js.map +1 -0
- package/dist/comps/index.d.ts +12 -0
- package/dist/comps/index.d.ts.map +1 -0
- package/dist/comps/index.js +12 -0
- package/dist/comps/index.js.map +1 -0
- package/dist/comps/numberstepper.css +44 -0
- package/dist/comps/numberstepper.d.ts +26 -0
- package/dist/comps/numberstepper.d.ts.map +1 -0
- package/dist/comps/numberstepper.js +72 -0
- package/dist/comps/numberstepper.js.map +1 -0
- package/dist/comps/radiogroup.css +20 -0
- package/dist/comps/radiogroup.d.ts +19 -0
- package/dist/comps/radiogroup.d.ts.map +1 -0
- package/dist/comps/radiogroup.js +21 -0
- package/dist/comps/radiogroup.js.map +1 -0
- package/dist/comps/rangeslider.css +46 -0
- package/dist/comps/rangeslider.d.ts +18 -0
- package/dist/comps/rangeslider.d.ts.map +1 -0
- package/dist/comps/rangeslider.js +15 -0
- package/dist/comps/rangeslider.js.map +1 -0
- package/dist/comps/select.css +16 -0
- package/dist/comps/select.d.ts +19 -0
- package/dist/comps/select.d.ts.map +1 -0
- package/dist/comps/select.js +21 -0
- package/dist/comps/select.js.map +1 -0
- package/dist/comps/tabs.css +22 -0
- package/dist/comps/tabs.d.ts +15 -0
- package/dist/comps/tabs.d.ts.map +1 -0
- package/dist/comps/tabs.js +11 -0
- package/dist/comps/tabs.js.map +1 -0
- package/dist/comps/textarea.css +19 -0
- package/dist/comps/textarea.d.ts +17 -0
- package/dist/comps/textarea.d.ts.map +1 -0
- package/dist/comps/textarea.js +32 -0
- package/dist/comps/textarea.js.map +1 -0
- package/dist/comps/togglegroup.css +29 -0
- package/dist/comps/togglegroup.d.ts +16 -0
- package/dist/comps/togglegroup.d.ts.map +1 -0
- package/dist/comps/togglegroup.js +11 -0
- package/dist/comps/togglegroup.js.map +1 -0
- package/dist/jsx.d.ts +1 -0
- package/dist/jsx.d.ts.map +1 -1
- package/dist/jsx.js.map +1 -1
- package/package.json +89 -76
- package/readme.md +4 -0
- package/src/comps/checkbox.css +45 -0
- package/src/comps/checkbox.tsx +31 -0
- package/src/comps/combobox.css +63 -0
- package/src/comps/combobox.tsx +100 -0
- package/src/comps/css.d.ts +1 -0
- package/src/comps/datalistinput.css +22 -0
- package/src/comps/datalistinput.tsx +35 -0
- package/src/comps/icon.css +6 -0
- package/src/comps/icon.tsx +13 -0
- package/src/comps/index.ts +11 -0
- package/src/comps/numberstepper.css +44 -0
- package/src/comps/numberstepper.tsx +73 -0
- package/src/comps/radiogroup.css +20 -0
- package/src/comps/radiogroup.tsx +40 -0
- package/src/comps/rangeslider.css +46 -0
- package/src/comps/rangeslider.tsx +27 -0
- package/src/comps/select.css +16 -0
- package/src/comps/select.tsx +36 -0
- package/src/comps/tabs.css +22 -0
- package/src/comps/tabs.tsx +22 -0
- package/src/comps/textarea.css +19 -0
- package/src/comps/textarea.tsx +41 -0
- package/src/comps/togglegroup.css +29 -0
- package/src/comps/togglegroup.tsx +23 -0
- package/src/jsx.ts +1 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx } from '../h.js'
|
|
2
|
+
import { Component, cc } from '../lib.js'
|
|
3
|
+
import './radiogroup.css'
|
|
4
|
+
|
|
5
|
+
type Props<T> = {
|
|
6
|
+
items: T[]
|
|
7
|
+
value: T | undefined
|
|
8
|
+
setvalue: (item: T) => void
|
|
9
|
+
label?: (item: T) => any // default: String(item)
|
|
10
|
+
color?: (item: T) => string | undefined // tints the item's radio
|
|
11
|
+
class?: string
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let counter = 0
|
|
16
|
+
|
|
17
|
+
/** native radio inputs, one per item, in a row. a radio needs a group name to be exclusive, unique per instance */
|
|
18
|
+
export class RadioGroup<T = any> extends Component<Props<T>> {
|
|
19
|
+
|
|
20
|
+
name = `jmc-radio-${counter++}`
|
|
21
|
+
|
|
22
|
+
view() {
|
|
23
|
+
const { items, value, setvalue, label = String, color, class: cls, disabled } = this.props
|
|
24
|
+
return <div role='radiogroup' class={cc('jmc-radio-group', cls)}>
|
|
25
|
+
{items.map(i =>
|
|
26
|
+
<label>
|
|
27
|
+
<input type='radio' name={this.name} checked={i === value} disabled={disabled}
|
|
28
|
+
style={color?.(i) ? `accent-color:${color(i)}` : undefined} onchange={() => this.onchange(i)} />
|
|
29
|
+
{label(i)}
|
|
30
|
+
</label>)}
|
|
31
|
+
</div>
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
onchange(item: T) {
|
|
35
|
+
this.props.setvalue(item)
|
|
36
|
+
// the click checked the radio. jmc writes only props that changed, so show what the model decided
|
|
37
|
+
const { items, value } = this.props
|
|
38
|
+
this.element.querySelectorAll('input').forEach((r, n) => r.checked = items[n] === value)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-range-slider {
|
|
3
|
+
--track: var(--jmc-track-height, 7px);
|
|
4
|
+
--thumb: var(--jmc-thumb-size, 20px);
|
|
5
|
+
appearance: none;
|
|
6
|
+
width: var(--jmc-slider-width, 10rem);
|
|
7
|
+
background: transparent;
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
|
|
10
|
+
&:focus { outline: none; }
|
|
11
|
+
&:disabled { opacity: 0.5; cursor: default; }
|
|
12
|
+
|
|
13
|
+
&::-webkit-slider-runnable-track {
|
|
14
|
+
height: var(--track);
|
|
15
|
+
background: var(--jmc-track, #555);
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
}
|
|
18
|
+
&::-moz-range-track {
|
|
19
|
+
height: var(--track);
|
|
20
|
+
background: var(--jmc-track, #555);
|
|
21
|
+
border-radius: 4px;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&::-webkit-slider-thumb {
|
|
25
|
+
appearance: none;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
width: var(--thumb);
|
|
28
|
+
height: var(--thumb);
|
|
29
|
+
margin-top: calc((var(--track) - var(--thumb)) / 2); /* centers the thumb on the track */
|
|
30
|
+
background: var(--jmc-bg, #fff);
|
|
31
|
+
border: 3px solid var(--jmc-thumb, #1c1c1c);
|
|
32
|
+
border-radius: 50%;
|
|
33
|
+
}
|
|
34
|
+
&::-moz-range-thumb {
|
|
35
|
+
box-sizing: border-box;
|
|
36
|
+
width: var(--thumb);
|
|
37
|
+
height: var(--thumb);
|
|
38
|
+
background: var(--jmc-bg, #fff);
|
|
39
|
+
border: 3px solid var(--jmc-thumb, #1c1c1c);
|
|
40
|
+
border-radius: 50%;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
&:focus-visible::-webkit-slider-thumb { border-color: var(--jmc-accent, #3b82f6); }
|
|
44
|
+
&:focus-visible::-moz-range-thumb { border-color: var(--jmc-accent, #3b82f6); }
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx } from '../h.js'
|
|
2
|
+
import { Component, cc } from '../lib.js'
|
|
3
|
+
import './rangeslider.css'
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
value: number
|
|
7
|
+
setvalue: (value: number) => void
|
|
8
|
+
min?: number
|
|
9
|
+
max?: number
|
|
10
|
+
step?: number
|
|
11
|
+
class?: string
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** a styled native range input. setvalue is called while dragging */
|
|
16
|
+
export class RangeSlider extends Component<Props> {
|
|
17
|
+
|
|
18
|
+
view() {
|
|
19
|
+
const { value, min, max, step, class: cls, disabled } = this.props
|
|
20
|
+
// value comes last: the browser clamps it to the range, so min, max and step must be set before
|
|
21
|
+
return <input type='range' class={cc('jmc-range-slider', cls)} disabled={disabled} min={min} max={max} step={step} value={value} oninput={this.oninput} />
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
oninput(ev: Event) {
|
|
25
|
+
this.props.setvalue(parseFloat((ev.target as HTMLInputElement).value))
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-select {
|
|
3
|
+
font: inherit;
|
|
4
|
+
padding: var(--jmc-padding, 0.3em 0.5em);
|
|
5
|
+
color: var(--jmc-color, inherit);
|
|
6
|
+
background: var(--jmc-bg, #fff);
|
|
7
|
+
border: 1px solid var(--jmc-border, #cbd5e1);
|
|
8
|
+
border-radius: var(--jmc-radius, 6px);
|
|
9
|
+
|
|
10
|
+
&:focus {
|
|
11
|
+
outline: none;
|
|
12
|
+
border-color: var(--jmc-accent, #3b82f6);
|
|
13
|
+
}
|
|
14
|
+
&:disabled { opacity: 0.5; }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { jsx } from '../h.js'
|
|
2
|
+
import type { SelectHTMLAttributes } from '../jsx.js'
|
|
3
|
+
import { Component, cc } from '../lib.js'
|
|
4
|
+
import './select.css'
|
|
5
|
+
|
|
6
|
+
type Props<T> = Omit<SelectHTMLAttributes, 'value' | 'onchange' | 'oninput'> & {
|
|
7
|
+
items: T[]
|
|
8
|
+
value: T | undefined
|
|
9
|
+
setvalue: (item: T) => void
|
|
10
|
+
label?: (item: T) => string // default: String(item)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** a native select over any items. it hands out the item, not text */
|
|
14
|
+
export class Select<T = any> extends Component<Props<T>> {
|
|
15
|
+
|
|
16
|
+
view() {
|
|
17
|
+
const { items, value, setvalue, label = String, class: cls, ...rest } = this.props
|
|
18
|
+
return <select {...rest} class={cc('jmc-select', cls)} onchange={this.onchange}>
|
|
19
|
+
{items.map(i => <option>{label(i)}</option>)}
|
|
20
|
+
</select>
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
mounted() { this.select() }
|
|
24
|
+
|
|
25
|
+
// runs before the render. the options exist only after it, so the selection is set after it
|
|
26
|
+
update() { queueMicrotask(this.select) }
|
|
27
|
+
|
|
28
|
+
// the options are plain, so the item is found by position. no value strings to match
|
|
29
|
+
select() {
|
|
30
|
+
(this.element as HTMLSelectElement).selectedIndex = this.props.items.indexOf(this.props.value as T)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
onchange(ev: Event) {
|
|
34
|
+
this.props.setvalue(this.props.items[(ev.target as HTMLSelectElement).selectedIndex])
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-tabs {
|
|
3
|
+
display: flex;
|
|
4
|
+
gap: 0.2em;
|
|
5
|
+
border-bottom: 1px solid var(--jmc-border, #cbd5e1);
|
|
6
|
+
|
|
7
|
+
button {
|
|
8
|
+
padding: var(--jmc-padding, 0.4em 0.9em);
|
|
9
|
+
font: inherit;
|
|
10
|
+
color: var(--jmc-color, inherit);
|
|
11
|
+
background: transparent;
|
|
12
|
+
border: none;
|
|
13
|
+
border-bottom: 2px solid transparent;
|
|
14
|
+
margin-bottom: -1px; /* the selected underline covers the bar's border */
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
|
|
17
|
+
&:hover { background: var(--jmc-bg-focus, #f0f7ff); }
|
|
18
|
+
&.selected { color: var(--jmc-accent, #3b82f6); border-bottom-color: var(--jmc-accent, #3b82f6); }
|
|
19
|
+
&:focus-visible { outline: none; color: #fff; background: var(--jmc-accent, #3b82f6); } /* after selected, so it wins */
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx } from '../h.js'
|
|
2
|
+
import { Component, cc } from '../lib.js'
|
|
3
|
+
import './tabs.css'
|
|
4
|
+
|
|
5
|
+
type Props<T> = {
|
|
6
|
+
items: T[]
|
|
7
|
+
value: T | undefined
|
|
8
|
+
setvalue: (item: T) => void
|
|
9
|
+
label?: (item: T) => any // default: String(item)
|
|
10
|
+
class?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** the tab bar only: the content below it belongs to the app, which shows what the selected tab says */
|
|
14
|
+
export class Tabs<T = any> extends Component<Props<T>> {
|
|
15
|
+
|
|
16
|
+
view() {
|
|
17
|
+
const { items, value, setvalue, label = String, class: cls } = this.props
|
|
18
|
+
return <nav role='tablist' class={cc('jmc-tabs', cls)}>
|
|
19
|
+
{items.map(i => <button type='button' role='tab' aria-selected={i === value} class={cc({ selected: i === value })} onclick={() => setvalue(i)}>{label(i)}</button>)}
|
|
20
|
+
</nav>
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-textarea {
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
width: 100%;
|
|
5
|
+
resize: none;
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
font: inherit;
|
|
8
|
+
padding: var(--jmc-padding, 0.35em 0.5em);
|
|
9
|
+
color: var(--jmc-color, inherit);
|
|
10
|
+
background: var(--jmc-bg, #fff);
|
|
11
|
+
border: 1px solid var(--jmc-border, #cbd5e1);
|
|
12
|
+
border-radius: var(--jmc-radius, 6px);
|
|
13
|
+
|
|
14
|
+
&:focus {
|
|
15
|
+
outline: none;
|
|
16
|
+
border-color: var(--jmc-accent, #3b82f6);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx } from '../h.js'
|
|
2
|
+
import type { TextareaHTMLAttributes } from '../jsx.js'
|
|
3
|
+
import { Component, cc } from '../lib.js'
|
|
4
|
+
import './textarea.css'
|
|
5
|
+
|
|
6
|
+
type Props = Omit<TextareaHTMLAttributes, 'value' | 'oninput'> & {
|
|
7
|
+
value: string
|
|
8
|
+
setvalue?: (value: string) => void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** a textarea that grows and shrinks with its text */
|
|
12
|
+
export class TextArea extends Component<Props> {
|
|
13
|
+
|
|
14
|
+
view() {
|
|
15
|
+
const { value, setvalue, class: cls, ...rest } = this.props
|
|
16
|
+
return <textarea rows={1} {...rest} class={cc('jmc-textarea', cls)} value={value} oninput={this.oninput} />
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mounted() {
|
|
20
|
+
// fires once the element has a size: when mounted, when shown after being hidden, and when its width changes (the text wraps anew)
|
|
21
|
+
new ResizeObserver(this.adjust).observe(this.element)
|
|
22
|
+
if (this.props.autofocus) this.element.focus()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// runs before the render. the new value is set by then, so the height is adjusted after it
|
|
26
|
+
update() {
|
|
27
|
+
queueMicrotask(this.adjust)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
oninput(ev: Event) {
|
|
31
|
+
this.props.setvalue?.((ev.target as HTMLTextAreaElement).value)
|
|
32
|
+
this.adjust()
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
adjust() {
|
|
36
|
+
const t = this.element as HTMLTextAreaElement
|
|
37
|
+
if (!t.clientHeight) return // hidden. the observer calls again when it is shown
|
|
38
|
+
t.style.height = 'auto' // so it shrinks too: scrollHeight is never below the current height
|
|
39
|
+
t.style.height = t.scrollHeight + t.offsetHeight - t.clientHeight + 'px' // plus the borders
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-toggle-group {
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
overflow: hidden;
|
|
5
|
+
border: 1px solid var(--jmc-border, #cbd5e1);
|
|
6
|
+
border-radius: var(--jmc-radius, 6px);
|
|
7
|
+
|
|
8
|
+
button {
|
|
9
|
+
display: inline-flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
justify-content: center;
|
|
12
|
+
padding: var(--jmc-padding, 0.3em 0.7em);
|
|
13
|
+
font: inherit;
|
|
14
|
+
color: var(--jmc-color, inherit);
|
|
15
|
+
background: var(--jmc-bg, #fff);
|
|
16
|
+
border: none;
|
|
17
|
+
border-left: 1px solid var(--jmc-border, #cbd5e1);
|
|
18
|
+
cursor: pointer;
|
|
19
|
+
|
|
20
|
+
&:first-child { border-left: none; }
|
|
21
|
+
&:hover:not(.selected) { background: var(--jmc-bg-focus, #f0f7ff); }
|
|
22
|
+
&.selected { color: #fff; background: var(--jmc-accent, #3b82f6); }
|
|
23
|
+
/* keyboard focus: the item takes the accent, a selected one gets darker. an outline would be clipped by the rounded corners */
|
|
24
|
+
&:focus-visible { outline: none; color: #fff; background: var(--jmc-accent, #3b82f6); }
|
|
25
|
+
&.selected:focus-visible { background: color-mix(in srgb, var(--jmc-accent, #3b82f6), #000 30%); }
|
|
26
|
+
&:disabled { opacity: 0.5; cursor: default; }
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx } from '../h.js'
|
|
2
|
+
import { Component, cc } from '../lib.js'
|
|
3
|
+
import './togglegroup.css'
|
|
4
|
+
|
|
5
|
+
type Props<T> = {
|
|
6
|
+
items: T[]
|
|
7
|
+
value: T | undefined
|
|
8
|
+
setvalue: (item: T) => void
|
|
9
|
+
label?: (item: T) => any // text or any view, such as an Icon. default: String(item)
|
|
10
|
+
class?: string
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** a row of buttons, of which exactly one is selected: a segmented control. keyboard accessible, as the items are buttons */
|
|
15
|
+
export class ToggleGroup<T = any> extends Component<Props<T>> {
|
|
16
|
+
|
|
17
|
+
view() {
|
|
18
|
+
const { items, value, setvalue, label = String, class: cls, disabled } = this.props
|
|
19
|
+
return <div role='radiogroup' class={cc('jmc-toggle-group', cls)}>
|
|
20
|
+
{items.map(i => <button type='button' role='radio' aria-checked={i === value} disabled={disabled} class={cc({ selected: i === value })} onclick={() => setvalue(i)}>{label(i)}</button>)}
|
|
21
|
+
</div>
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/jsx.ts
CHANGED
|
@@ -934,6 +934,7 @@ export interface InputHTMLAttributes extends HTMLAttributes {
|
|
|
934
934
|
formnovalidate?: boolean
|
|
935
935
|
formtarget?: string
|
|
936
936
|
height?: number | string
|
|
937
|
+
indeterminate?: boolean // a property only, there is no such attribute
|
|
937
938
|
list?: string
|
|
938
939
|
max?: number | string
|
|
939
940
|
maxlength?: number
|