@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,6 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { cc } from '../lib.js';
|
|
3
|
+
import './icon.css';
|
|
4
|
+
/** an svg icon from a lucide icon node. it is drawn in the text color and sized by size, in px */
|
|
5
|
+
export const Icon = ({ icon, size = 18, stroke = 2, class: cls }) => jsx("svg", { class: cc('jmc-icon', cls), xmlns: 'http://www.w3.org/2000/svg', width: size, height: size, viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', "stroke-width": stroke, "stroke-linecap": 'round', "stroke-linejoin": 'round' }, icon.map(([tag, attrs]) => jsx(tag, attrs)));
|
|
6
|
+
//# sourceMappingURL=icon.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon.js","sourceRoot":"","sources":["../../src/comps/icon.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AAC9B,OAAO,YAAY,CAAA;AAKnB,kGAAkG;AAClG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,GAAG,EAAE,EAAE,MAAM,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,EAAsE,EAAE,EAAE,CACpI,aAAK,KAAK,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,EAAE,KAAK,EAAC,4BAA4B,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAC,WAAW,EAC9G,IAAI,EAAC,MAAM,EAAC,MAAM,EAAC,cAAc,kBAAe,MAAM,oBAAiB,OAAO,qBAAiB,OAAO,IACrG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAC1C,CAAA","sourcesContent":["import { jsx } from '../h.js'\nimport { cc } from '../lib.js'\nimport './icon.css'\n\n/** the icon format of lucide (IconNode): a list of [tag, attributes] */\nexport type IconNode = [tag: string, attrs: Record<string, string | number>][]\n\n/** an svg icon from a lucide icon node. it is drawn in the text color and sized by size, in px */\nexport const Icon = ({ icon, size = 18, stroke = 2, class: cls }: { icon: IconNode, size?: number, stroke?: number, class?: string }) =>\n <svg class={cc('jmc-icon', cls)} xmlns='http://www.w3.org/2000/svg' width={size} height={size} viewBox='0 0 24 24'\n fill='none' stroke='currentColor' stroke-width={stroke} stroke-linecap='round' stroke-linejoin='round'>\n {icon.map(([tag, attrs]) => jsx(tag, attrs))}\n </svg>\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './checkbox.js';
|
|
2
|
+
export * from './combobox.js';
|
|
3
|
+
export * from './datalistinput.js';
|
|
4
|
+
export * from './icon.js';
|
|
5
|
+
export * from './numberstepper.js';
|
|
6
|
+
export * from './radiogroup.js';
|
|
7
|
+
export * from './rangeslider.js';
|
|
8
|
+
export * from './select.js';
|
|
9
|
+
export * from './tabs.js';
|
|
10
|
+
export * from './textarea.js';
|
|
11
|
+
export * from './togglegroup.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/comps/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './checkbox.js';
|
|
2
|
+
export * from './combobox.js';
|
|
3
|
+
export * from './datalistinput.js';
|
|
4
|
+
export * from './icon.js';
|
|
5
|
+
export * from './numberstepper.js';
|
|
6
|
+
export * from './radiogroup.js';
|
|
7
|
+
export * from './rangeslider.js';
|
|
8
|
+
export * from './select.js';
|
|
9
|
+
export * from './tabs.js';
|
|
10
|
+
export * from './textarea.js';
|
|
11
|
+
export * from './togglegroup.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/comps/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,oBAAoB,CAAA;AAClC,cAAc,WAAW,CAAA;AACzB,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA","sourcesContent":["export * from './checkbox.js'\nexport * from './combobox.js'\nexport * from './datalistinput.js'\nexport * from './icon.js'\nexport * from './numberstepper.js'\nexport * from './radiogroup.js'\nexport * from './rangeslider.js'\nexport * from './select.js'\nexport * from './tabs.js'\nexport * from './textarea.js'\nexport * from './togglegroup.js'\n"]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-stepper {
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
align-items: stretch;
|
|
5
|
+
width: var(--jmc-stepper-width, 5.5rem);
|
|
6
|
+
overflow: hidden;
|
|
7
|
+
font: inherit;
|
|
8
|
+
color: var(--jmc-color, inherit);
|
|
9
|
+
background: var(--jmc-bg, #fff);
|
|
10
|
+
border: 1px solid var(--jmc-border, #cbd5e1);
|
|
11
|
+
border-radius: var(--jmc-radius, 6px);
|
|
12
|
+
|
|
13
|
+
button {
|
|
14
|
+
padding: 0 0.4em;
|
|
15
|
+
font: inherit;
|
|
16
|
+
color: inherit;
|
|
17
|
+
background: var(--jmc-bg-button, #eee);
|
|
18
|
+
border: none;
|
|
19
|
+
cursor: pointer;
|
|
20
|
+
user-select: none;
|
|
21
|
+
|
|
22
|
+
&:hover:not(:disabled) { opacity: 0.6; }
|
|
23
|
+
&:disabled { cursor: default; }
|
|
24
|
+
&:focus-visible { outline: none; color: #fff; background: var(--jmc-accent, #3b82f6); } /* the control's border shows the focus. a ring would be clipped by the rounded corners */
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
input {
|
|
28
|
+
flex: 1;
|
|
29
|
+
min-width: 0;
|
|
30
|
+
padding: 0;
|
|
31
|
+
font: inherit;
|
|
32
|
+
text-align: center;
|
|
33
|
+
color: inherit;
|
|
34
|
+
background: transparent;
|
|
35
|
+
border: none;
|
|
36
|
+
outline: none;
|
|
37
|
+
|
|
38
|
+
&:focus { background: var(--jmc-bg-focus, #f0f7ff); }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
&:focus-within { border-color: var(--jmc-accent, #3b82f6); }
|
|
42
|
+
&.disabled { opacity: 0.5; }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Component } from '../lib.js';
|
|
2
|
+
import './numberstepper.css';
|
|
3
|
+
type Props = {
|
|
4
|
+
value: number;
|
|
5
|
+
setvalue: (value: number) => void;
|
|
6
|
+
min?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
step?: number;
|
|
9
|
+
decimals?: number;
|
|
10
|
+
class?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/** a number input with minus and plus buttons */
|
|
14
|
+
export declare class NumberStepper extends Component<Props> {
|
|
15
|
+
view(): any;
|
|
16
|
+
get step(): number;
|
|
17
|
+
get decimals(): number;
|
|
18
|
+
get text(): string;
|
|
19
|
+
increment(by: number): void;
|
|
20
|
+
onchange(ev: Event): void;
|
|
21
|
+
onkeydown(ev: KeyboardEvent): void;
|
|
22
|
+
onincrement(): void;
|
|
23
|
+
ondecrement(): void;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=numberstepper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numberstepper.d.ts","sourceRoot":"","sources":["../../src/comps/numberstepper.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,qBAAqB,CAAA;AAE5B,KAAK,KAAK,GAAG;IACT,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AASD,iDAAiD;AACjD,qBAAa,aAAc,SAAQ,SAAS,CAAC,KAAK,CAAC;IAE/C,IAAI;IASJ,IAAI,IAAI,WAAkC;IAC1C,IAAI,QAAQ,WAA0D;IACtE,IAAI,IAAI,WAAqD;IAI7D,SAAS,CAAC,EAAE,EAAE,MAAM;IAQpB,QAAQ,CAAC,EAAE,EAAE,KAAK;IAOlB,SAAS,CAAC,EAAE,EAAE,aAAa;IAe3B,WAAW;IACX,WAAW;CACd"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { Component, cc } from '../lib.js';
|
|
3
|
+
import './numberstepper.css';
|
|
4
|
+
const decimalsof = (x) => (String(x).split('.')[1] ?? '').length;
|
|
5
|
+
const round = (v, decimals) => {
|
|
6
|
+
const factor = 10 ** decimals;
|
|
7
|
+
return Math.round((v + Number.EPSILON) * factor) / factor;
|
|
8
|
+
};
|
|
9
|
+
/** a number input with minus and plus buttons */
|
|
10
|
+
export class NumberStepper extends Component {
|
|
11
|
+
view() {
|
|
12
|
+
const { disabled, class: cls } = this.props;
|
|
13
|
+
return jsx("div", { class: cc('jmc-stepper', { disabled }, cls) },
|
|
14
|
+
jsx("button", { type: 'button', disabled: disabled, onclick: this.ondecrement }, "\u2212"),
|
|
15
|
+
jsx("input", { type: 'text', disabled: disabled, value: this.text, onchange: this.onchange, onkeydown: this.onkeydown }),
|
|
16
|
+
jsx("button", { type: 'button', disabled: disabled, onclick: this.onincrement }, "+"));
|
|
17
|
+
}
|
|
18
|
+
get step() { return this.props.step ?? 1; }
|
|
19
|
+
get decimals() { return this.props.decimals ?? decimalsof(this.step); }
|
|
20
|
+
get text() { return this.props.value.toFixed(this.decimals); }
|
|
21
|
+
// min and max bound the buttons only while the value is inside them. typed text may leave the range,
|
|
22
|
+
// and from there the buttons step freely
|
|
23
|
+
increment(by) {
|
|
24
|
+
const { value, min = -Infinity, max = Infinity } = this.props;
|
|
25
|
+
let v = round(value + by, this.decimals);
|
|
26
|
+
if (value >= min && value <= max)
|
|
27
|
+
v = Math.min(max, Math.max(min, v));
|
|
28
|
+
this.props.setvalue(v);
|
|
29
|
+
}
|
|
30
|
+
// fires on blur and enter. invalid text reverts to the current value, valid text is taken unclamped
|
|
31
|
+
onchange(ev) {
|
|
32
|
+
const i = ev.target;
|
|
33
|
+
const v = Number(i.value.trim().replace(',', '.'));
|
|
34
|
+
if (i.value.trim() && Number.isFinite(v))
|
|
35
|
+
this.props.setvalue(round(v, this.decimals));
|
|
36
|
+
i.value = this.text; // jmc only writes a value when it changed, so rejected or rounded text would stay otherwise
|
|
37
|
+
}
|
|
38
|
+
onkeydown(ev) {
|
|
39
|
+
const i = ev.target;
|
|
40
|
+
switch (ev.key) {
|
|
41
|
+
case 'Enter':
|
|
42
|
+
ev.preventDefault();
|
|
43
|
+
i.blur();
|
|
44
|
+
break; // blur fires change. preventDefault keeps a form from submitting
|
|
45
|
+
case 'Escape':
|
|
46
|
+
i.value = this.text;
|
|
47
|
+
i.blur();
|
|
48
|
+
break;
|
|
49
|
+
// steps commit pending text first, so they count from what was typed
|
|
50
|
+
case '+':
|
|
51
|
+
case 'ArrowUp':
|
|
52
|
+
ev.preventDefault();
|
|
53
|
+
this.onchange(ev);
|
|
54
|
+
this.onincrement();
|
|
55
|
+
i.value = this.text;
|
|
56
|
+
break;
|
|
57
|
+
case '-':
|
|
58
|
+
case 'ArrowDown':
|
|
59
|
+
ev.preventDefault();
|
|
60
|
+
this.onchange(ev);
|
|
61
|
+
this.ondecrement();
|
|
62
|
+
i.value = this.text;
|
|
63
|
+
break;
|
|
64
|
+
// digits and decimal separators only. other single chars are dropped, shortcuts (ctrl, meta) and named keys pass
|
|
65
|
+
default: if (ev.key.length == 1 && !ev.ctrlKey && !ev.metaKey && !/[\d.,]/.test(ev.key))
|
|
66
|
+
ev.preventDefault();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
onincrement() { this.increment(this.step); }
|
|
70
|
+
ondecrement() { this.increment(-this.step); }
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=numberstepper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"numberstepper.js","sourceRoot":"","sources":["../../src/comps/numberstepper.tsx"],"names":[],"mappings":"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","sourcesContent":["import { jsx } from '../h.js'\nimport { Component, cc } from '../lib.js'\nimport './numberstepper.css'\n\ntype Props = {\n value: number\n setvalue: (value: number) => void\n min?: number\n max?: number\n step?: number // default 1\n decimals?: number // default: the decimals of step\n class?: string\n disabled?: boolean\n}\n\nconst decimalsof = (x: number) => (String(x).split('.')[1] ?? '').length\n\nconst round = (v: number, decimals: number) => {\n const factor = 10 ** decimals\n return Math.round((v + Number.EPSILON) * factor) / factor\n}\n\n/** a number input with minus and plus buttons */\nexport class NumberStepper extends Component<Props> {\n\n view() {\n const { disabled, class: cls } = this.props\n return <div class={cc('jmc-stepper', { disabled }, cls)}>\n <button type='button' disabled={disabled} onclick={this.ondecrement}>−</button>\n <input type='text' disabled={disabled} value={this.text} onchange={this.onchange} onkeydown={this.onkeydown} />\n <button type='button' disabled={disabled} onclick={this.onincrement}>+</button>\n </div>\n }\n\n get step() { return this.props.step ?? 1 }\n get decimals() { return this.props.decimals ?? decimalsof(this.step) }\n get text() { return this.props.value.toFixed(this.decimals) }\n\n // min and max bound the buttons only while the value is inside them. typed text may leave the range,\n // and from there the buttons step freely\n increment(by: number) {\n const { value, min = -Infinity, max = Infinity } = this.props\n let v = round(value + by, this.decimals)\n if (value >= min && value <= max) v = Math.min(max, Math.max(min, v))\n this.props.setvalue(v)\n }\n\n // fires on blur and enter. invalid text reverts to the current value, valid text is taken unclamped\n onchange(ev: Event) {\n const i = ev.target as HTMLInputElement\n const v = Number(i.value.trim().replace(',', '.'))\n if (i.value.trim() && Number.isFinite(v)) this.props.setvalue(round(v, this.decimals))\n i.value = this.text // jmc only writes a value when it changed, so rejected or rounded text would stay otherwise\n }\n\n onkeydown(ev: KeyboardEvent) {\n const i = ev.target as HTMLInputElement\n switch (ev.key) {\n case 'Enter': ev.preventDefault(); i.blur(); break // blur fires change. preventDefault keeps a form from submitting\n case 'Escape': i.value = this.text; i.blur(); break\n // steps commit pending text first, so they count from what was typed\n case '+':\n case 'ArrowUp': ev.preventDefault(); this.onchange(ev); this.onincrement(); i.value = this.text; break\n case '-':\n case 'ArrowDown': ev.preventDefault(); this.onchange(ev); this.ondecrement(); i.value = this.text; break\n // digits and decimal separators only. other single chars are dropped, shortcuts (ctrl, meta) and named keys pass\n default: if (ev.key.length == 1 && !ev.ctrlKey && !ev.metaKey && !/[\\d.,]/.test(ev.key)) ev.preventDefault()\n }\n }\n\n onincrement() { this.increment(this.step) }\n ondecrement() { this.increment(-this.step) }\n}\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
@layer jmc {
|
|
2
|
+
.jmc-radio-group {
|
|
3
|
+
display: inline-flex;
|
|
4
|
+
flex-wrap: wrap;
|
|
5
|
+
gap: 0.3em 1em;
|
|
6
|
+
|
|
7
|
+
label {
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: 0.4em;
|
|
11
|
+
cursor: pointer;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
input {
|
|
15
|
+
margin: 0;
|
|
16
|
+
accent-color: var(--jmc-accent, #3b82f6);
|
|
17
|
+
cursor: inherit;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Component } from '../lib.js';
|
|
2
|
+
import './radiogroup.css';
|
|
3
|
+
type Props<T> = {
|
|
4
|
+
items: T[];
|
|
5
|
+
value: T | undefined;
|
|
6
|
+
setvalue: (item: T) => void;
|
|
7
|
+
label?: (item: T) => any;
|
|
8
|
+
color?: (item: T) => string | undefined;
|
|
9
|
+
class?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** native radio inputs, one per item, in a row. a radio needs a group name to be exclusive, unique per instance */
|
|
13
|
+
export declare class RadioGroup<T = any> extends Component<Props<T>> {
|
|
14
|
+
name: string;
|
|
15
|
+
view(): any;
|
|
16
|
+
onchange(item: T): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=radiogroup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radiogroup.d.ts","sourceRoot":"","sources":["../../src/comps/radiogroup.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,kBAAkB,CAAA;AAEzB,KAAK,KAAK,CAAC,CAAC,IAAI;IACZ,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,KAAK,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,CAAA;IACxB,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,CAAA;IACvC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAID,mHAAmH;AACnH,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAExD,IAAI,SAA2B;IAE/B,IAAI;IAYJ,QAAQ,CAAC,IAAI,EAAE,CAAC;CAMnB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { Component, cc } from '../lib.js';
|
|
3
|
+
import './radiogroup.css';
|
|
4
|
+
let counter = 0;
|
|
5
|
+
/** native radio inputs, one per item, in a row. a radio needs a group name to be exclusive, unique per instance */
|
|
6
|
+
export class RadioGroup extends Component {
|
|
7
|
+
name = `jmc-radio-${counter++}`;
|
|
8
|
+
view() {
|
|
9
|
+
const { items, value, setvalue, label = String, color, class: cls, disabled } = this.props;
|
|
10
|
+
return jsx("div", { role: 'radiogroup', class: cc('jmc-radio-group', cls) }, items.map(i => jsx("label", null,
|
|
11
|
+
jsx("input", { type: 'radio', name: this.name, checked: i === value, disabled: disabled, style: color?.(i) ? `accent-color:${color(i)}` : undefined, onchange: () => this.onchange(i) }),
|
|
12
|
+
label(i))));
|
|
13
|
+
}
|
|
14
|
+
onchange(item) {
|
|
15
|
+
this.props.setvalue(item);
|
|
16
|
+
// the click checked the radio. jmc writes only props that changed, so show what the model decided
|
|
17
|
+
const { items, value } = this.props;
|
|
18
|
+
this.element.querySelectorAll('input').forEach((r, n) => r.checked = items[n] === value);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=radiogroup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"radiogroup.js","sourceRoot":"","sources":["../../src/comps/radiogroup.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,kBAAkB,CAAA;AAYzB,IAAI,OAAO,GAAG,CAAC,CAAA;AAEf,mHAAmH;AACnH,MAAM,OAAO,UAAoB,SAAQ,SAAmB;IAExD,IAAI,GAAG,aAAa,OAAO,EAAE,EAAE,CAAA;IAE/B,IAAI;QACA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC1F,OAAO,aAAK,IAAI,EAAC,YAAY,EAAC,KAAK,EAAE,EAAE,CAAC,iBAAiB,EAAE,GAAG,CAAC,IAC1D,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CACX;YACI,eAAO,IAAI,EAAC,OAAO,EAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,CAAC,KAAK,KAAK,EAAE,QAAQ,EAAE,QAAQ,EACzE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,gBAAgB,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,GAAI;YACnG,KAAK,CAAC,CAAC,CAAC,CACL,CAAC,CACX,CAAA;IACV,CAAC;IAED,QAAQ,CAAC,IAAO;QACZ,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAA;QACzB,kGAAkG;QAClG,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QACnC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAA;IAC5F,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport { Component, cc } from '../lib.js'\nimport './radiogroup.css'\n\ntype Props<T> = {\n items: T[]\n value: T | undefined\n setvalue: (item: T) => void\n label?: (item: T) => any // default: String(item)\n color?: (item: T) => string | undefined // tints the item's radio\n class?: string\n disabled?: boolean\n}\n\nlet counter = 0\n\n/** native radio inputs, one per item, in a row. a radio needs a group name to be exclusive, unique per instance */\nexport class RadioGroup<T = any> extends Component<Props<T>> {\n\n name = `jmc-radio-${counter++}`\n\n view() {\n const { items, value, setvalue, label = String, color, class: cls, disabled } = this.props\n return <div role='radiogroup' class={cc('jmc-radio-group', cls)}>\n {items.map(i =>\n <label>\n <input type='radio' name={this.name} checked={i === value} disabled={disabled}\n style={color?.(i) ? `accent-color:${color(i)}` : undefined} onchange={() => this.onchange(i)} />\n {label(i)}\n </label>)}\n </div>\n }\n\n onchange(item: T) {\n this.props.setvalue(item)\n // the click checked the radio. jmc writes only props that changed, so show what the model decided\n const { items, value } = this.props\n this.element.querySelectorAll('input').forEach((r, n) => r.checked = items[n] === value)\n }\n}\n"]}
|
|
@@ -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,18 @@
|
|
|
1
|
+
import { Component } from '../lib.js';
|
|
2
|
+
import './rangeslider.css';
|
|
3
|
+
type Props = {
|
|
4
|
+
value: number;
|
|
5
|
+
setvalue: (value: number) => void;
|
|
6
|
+
min?: number;
|
|
7
|
+
max?: number;
|
|
8
|
+
step?: number;
|
|
9
|
+
class?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** a styled native range input. setvalue is called while dragging */
|
|
13
|
+
export declare class RangeSlider extends Component<Props> {
|
|
14
|
+
view(): any;
|
|
15
|
+
oninput(ev: Event): void;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=rangeslider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rangeslider.d.ts","sourceRoot":"","sources":["../../src/comps/rangeslider.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,mBAAmB,CAAA;AAE1B,KAAK,KAAK,GAAG;IACT,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;CACrB,CAAA;AAED,qEAAqE;AACrE,qBAAa,WAAY,SAAQ,SAAS,CAAC,KAAK,CAAC;IAE7C,IAAI;IAMJ,OAAO,CAAC,EAAE,EAAE,KAAK;CAGpB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { Component, cc } from '../lib.js';
|
|
3
|
+
import './rangeslider.css';
|
|
4
|
+
/** a styled native range input. setvalue is called while dragging */
|
|
5
|
+
export class RangeSlider extends Component {
|
|
6
|
+
view() {
|
|
7
|
+
const { value, min, max, step, class: cls, disabled } = this.props;
|
|
8
|
+
// value comes last: the browser clamps it to the range, so min, max and step must be set before
|
|
9
|
+
return jsx("input", { type: 'range', class: cc('jmc-range-slider', cls), disabled: disabled, min: min, max: max, step: step, value: value, oninput: this.oninput });
|
|
10
|
+
}
|
|
11
|
+
oninput(ev) {
|
|
12
|
+
this.props.setvalue(parseFloat(ev.target.value));
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=rangeslider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rangeslider.js","sourceRoot":"","sources":["../../src/comps/rangeslider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,mBAAmB,CAAA;AAY1B,qEAAqE;AACrE,MAAM,OAAO,WAAY,SAAQ,SAAgB;IAE7C,IAAI;QACA,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAClE,gGAAgG;QAChG,OAAO,eAAO,IAAI,EAAC,OAAO,EAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,GAAI,CAAA;IAC9J,CAAC;IAED,OAAO,CAAC,EAAS;QACb,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAE,EAAE,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAC,CAAA;IAC1E,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport { Component, cc } from '../lib.js'\nimport './rangeslider.css'\n\ntype Props = {\n value: number\n setvalue: (value: number) => void\n min?: number\n max?: number\n step?: number\n class?: string\n disabled?: boolean\n}\n\n/** a styled native range input. setvalue is called while dragging */\nexport class RangeSlider extends Component<Props> {\n\n view() {\n const { value, min, max, step, class: cls, disabled } = this.props\n // value comes last: the browser clamps it to the range, so min, max and step must be set before\n return <input type='range' class={cc('jmc-range-slider', cls)} disabled={disabled} min={min} max={max} step={step} value={value} oninput={this.oninput} />\n }\n\n oninput(ev: Event) {\n this.props.setvalue(parseFloat((ev.target as HTMLInputElement).value))\n }\n}\n"]}
|
|
@@ -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,19 @@
|
|
|
1
|
+
import type { SelectHTMLAttributes } from '../jsx.js';
|
|
2
|
+
import { Component } from '../lib.js';
|
|
3
|
+
import './select.css';
|
|
4
|
+
type Props<T> = Omit<SelectHTMLAttributes, 'value' | 'onchange' | 'oninput'> & {
|
|
5
|
+
items: T[];
|
|
6
|
+
value: T | undefined;
|
|
7
|
+
setvalue: (item: T) => void;
|
|
8
|
+
label?: (item: T) => string;
|
|
9
|
+
};
|
|
10
|
+
/** a native select over any items. it hands out the item, not text */
|
|
11
|
+
export declare class Select<T = any> extends Component<Props<T>> {
|
|
12
|
+
view(): any;
|
|
13
|
+
mounted(): void;
|
|
14
|
+
update(): void;
|
|
15
|
+
select(): void;
|
|
16
|
+
onchange(ev: Event): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=select.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.d.ts","sourceRoot":"","sources":["../../src/comps/select.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,cAAc,CAAA;AAErB,KAAK,KAAK,CAAC,CAAC,IAAI,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC,GAAG;IAC3E,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,KAAK,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAA;CAC9B,CAAA;AAED,sEAAsE;AACtE,qBAAa,MAAM,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEpD,IAAI;IAOJ,OAAO;IAGP,MAAM;IAGN,MAAM;IAIN,QAAQ,CAAC,EAAE,EAAE,KAAK;CAGrB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { Component, cc } from '../lib.js';
|
|
3
|
+
import './select.css';
|
|
4
|
+
/** a native select over any items. it hands out the item, not text */
|
|
5
|
+
export class Select extends Component {
|
|
6
|
+
view() {
|
|
7
|
+
const { items, value, setvalue, label = String, class: cls, ...rest } = this.props;
|
|
8
|
+
return jsx("select", { ...rest, class: cc('jmc-select', cls), onchange: this.onchange }, items.map(i => jsx("option", null, label(i))));
|
|
9
|
+
}
|
|
10
|
+
mounted() { this.select(); }
|
|
11
|
+
// runs before the render. the options exist only after it, so the selection is set after it
|
|
12
|
+
update() { queueMicrotask(this.select); }
|
|
13
|
+
// the options are plain, so the item is found by position. no value strings to match
|
|
14
|
+
select() {
|
|
15
|
+
this.element.selectedIndex = this.props.items.indexOf(this.props.value);
|
|
16
|
+
}
|
|
17
|
+
onchange(ev) {
|
|
18
|
+
this.props.setvalue(this.props.items[ev.target.selectedIndex]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select.js","sourceRoot":"","sources":["../../src/comps/select.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAE7B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,cAAc,CAAA;AASrB,sEAAsE;AACtE,MAAM,OAAO,MAAgB,SAAQ,SAAmB;IAEpD,IAAI;QACA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAClF,OAAO,mBAAY,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,YAAY,EAAE,GAAG,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,IACzE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,oBAAS,KAAK,CAAC,CAAC,CAAC,CAAU,CAAC,CACvC,CAAA;IACb,CAAC;IAED,OAAO,KAAK,IAAI,CAAC,MAAM,EAAE,CAAA,CAAC,CAAC;IAE3B,4FAA4F;IAC5F,MAAM,KAAK,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA,CAAC,CAAC;IAExC,qFAAqF;IACrF,MAAM;QACD,IAAI,CAAC,OAA6B,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,KAAU,CAAC,CAAA;IACvG,CAAC;IAED,QAAQ,CAAC,EAAS;QACd,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAE,EAAE,CAAC,MAA4B,CAAC,aAAa,CAAC,CAAC,CAAA;IACzF,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport type { SelectHTMLAttributes } from '../jsx.js'\nimport { Component, cc } from '../lib.js'\nimport './select.css'\n\ntype Props<T> = Omit<SelectHTMLAttributes, 'value' | 'onchange' | 'oninput'> & {\n items: T[]\n value: T | undefined\n setvalue: (item: T) => void\n label?: (item: T) => string // default: String(item)\n}\n\n/** a native select over any items. it hands out the item, not text */\nexport class Select<T = any> extends Component<Props<T>> {\n\n view() {\n const { items, value, setvalue, label = String, class: cls, ...rest } = this.props\n return <select {...rest} class={cc('jmc-select', cls)} onchange={this.onchange}>\n {items.map(i => <option>{label(i)}</option>)}\n </select>\n }\n\n mounted() { this.select() }\n\n // runs before the render. the options exist only after it, so the selection is set after it\n update() { queueMicrotask(this.select) }\n\n // the options are plain, so the item is found by position. no value strings to match\n select() {\n (this.element as HTMLSelectElement).selectedIndex = this.props.items.indexOf(this.props.value as T)\n }\n\n onchange(ev: Event) {\n this.props.setvalue(this.props.items[(ev.target as HTMLSelectElement).selectedIndex])\n }\n}\n"]}
|
|
@@ -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,15 @@
|
|
|
1
|
+
import { Component } from '../lib.js';
|
|
2
|
+
import './tabs.css';
|
|
3
|
+
type Props<T> = {
|
|
4
|
+
items: T[];
|
|
5
|
+
value: T | undefined;
|
|
6
|
+
setvalue: (item: T) => void;
|
|
7
|
+
label?: (item: T) => any;
|
|
8
|
+
class?: string;
|
|
9
|
+
};
|
|
10
|
+
/** the tab bar only: the content below it belongs to the app, which shows what the selected tab says */
|
|
11
|
+
export declare class Tabs<T = any> extends Component<Props<T>> {
|
|
12
|
+
view(): any;
|
|
13
|
+
}
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=tabs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.d.ts","sourceRoot":"","sources":["../../src/comps/tabs.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,YAAY,CAAA;AAEnB,KAAK,KAAK,CAAC,CAAC,IAAI;IACZ,KAAK,EAAE,CAAC,EAAE,CAAA;IACV,KAAK,EAAE,CAAC,GAAG,SAAS,CAAA;IACpB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,GAAG,CAAA;IACxB,KAAK,CAAC,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,wGAAwG;AACxG,qBAAa,IAAI,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAElD,IAAI;CAMP"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { Component, cc } from '../lib.js';
|
|
3
|
+
import './tabs.css';
|
|
4
|
+
/** the tab bar only: the content below it belongs to the app, which shows what the selected tab says */
|
|
5
|
+
export class Tabs extends Component {
|
|
6
|
+
view() {
|
|
7
|
+
const { items, value, setvalue, label = String, class: cls } = this.props;
|
|
8
|
+
return jsx("nav", { role: 'tablist', class: cc('jmc-tabs', cls) }, items.map(i => jsx("button", { type: 'button', role: 'tab', "aria-selected": i === value, class: cc({ selected: i === value }), onclick: () => setvalue(i) }, label(i))));
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tabs.js","sourceRoot":"","sources":["../../src/comps/tabs.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,YAAY,CAAA;AAUnB,wGAAwG;AACxG,MAAM,OAAO,IAAc,SAAQ,SAAmB;IAElD,IAAI;QACA,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QACzE,OAAO,aAAK,IAAI,EAAC,SAAS,EAAC,KAAK,EAAE,EAAE,CAAC,UAAU,EAAE,GAAG,CAAC,IAChD,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,gBAAQ,IAAI,EAAC,QAAQ,EAAC,IAAI,EAAC,KAAK,mBAAgB,CAAC,KAAK,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAG,KAAK,CAAC,CAAC,CAAC,CAAU,CAAC,CACjK,CAAA;IACV,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport { Component, cc } from '../lib.js'\nimport './tabs.css'\n\ntype Props<T> = {\n items: T[]\n value: T | undefined\n setvalue: (item: T) => void\n label?: (item: T) => any // default: String(item)\n class?: string\n}\n\n/** the tab bar only: the content below it belongs to the app, which shows what the selected tab says */\nexport class Tabs<T = any> extends Component<Props<T>> {\n\n view() {\n const { items, value, setvalue, label = String, class: cls } = this.props\n return <nav role='tablist' class={cc('jmc-tabs', cls)}>\n {items.map(i => <button type='button' role='tab' aria-selected={i === value} class={cc({ selected: i === value })} onclick={() => setvalue(i)}>{label(i)}</button>)}\n </nav>\n }\n}\n"]}
|
|
@@ -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,17 @@
|
|
|
1
|
+
import type { TextareaHTMLAttributes } from '../jsx.js';
|
|
2
|
+
import { Component } from '../lib.js';
|
|
3
|
+
import './textarea.css';
|
|
4
|
+
type Props = Omit<TextareaHTMLAttributes, 'value' | 'oninput'> & {
|
|
5
|
+
value: string;
|
|
6
|
+
setvalue?: (value: string) => void;
|
|
7
|
+
};
|
|
8
|
+
/** a textarea that grows and shrinks with its text */
|
|
9
|
+
export declare class TextArea extends Component<Props> {
|
|
10
|
+
view(): any;
|
|
11
|
+
mounted(): void;
|
|
12
|
+
update(): void;
|
|
13
|
+
oninput(ev: Event): void;
|
|
14
|
+
adjust(): void;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=textarea.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.d.ts","sourceRoot":"","sources":["../../src/comps/textarea.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAA;AACvD,OAAO,EAAE,SAAS,EAAM,MAAM,WAAW,CAAA;AACzC,OAAO,gBAAgB,CAAA;AAEvB,KAAK,KAAK,GAAG,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,SAAS,CAAC,GAAG;IAC7D,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAA;CACrC,CAAA;AAED,sDAAsD;AACtD,qBAAa,QAAS,SAAQ,SAAS,CAAC,KAAK,CAAC;IAE1C,IAAI;IAKJ,OAAO;IAOP,MAAM;IAIN,OAAO,CAAC,EAAE,EAAE,KAAK;IAKjB,MAAM;CAMT"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx } from '../h.js';
|
|
2
|
+
import { Component, cc } from '../lib.js';
|
|
3
|
+
import './textarea.css';
|
|
4
|
+
/** a textarea that grows and shrinks with its text */
|
|
5
|
+
export class TextArea extends Component {
|
|
6
|
+
view() {
|
|
7
|
+
const { value, setvalue, class: cls, ...rest } = this.props;
|
|
8
|
+
return jsx("textarea", { rows: 1, ...rest, class: cc('jmc-textarea', cls), value: value, oninput: this.oninput });
|
|
9
|
+
}
|
|
10
|
+
mounted() {
|
|
11
|
+
// fires once the element has a size: when mounted, when shown after being hidden, and when its width changes (the text wraps anew)
|
|
12
|
+
new ResizeObserver(this.adjust).observe(this.element);
|
|
13
|
+
if (this.props.autofocus)
|
|
14
|
+
this.element.focus();
|
|
15
|
+
}
|
|
16
|
+
// runs before the render. the new value is set by then, so the height is adjusted after it
|
|
17
|
+
update() {
|
|
18
|
+
queueMicrotask(this.adjust);
|
|
19
|
+
}
|
|
20
|
+
oninput(ev) {
|
|
21
|
+
this.props.setvalue?.(ev.target.value);
|
|
22
|
+
this.adjust();
|
|
23
|
+
}
|
|
24
|
+
adjust() {
|
|
25
|
+
const t = this.element;
|
|
26
|
+
if (!t.clientHeight)
|
|
27
|
+
return; // hidden. the observer calls again when it is shown
|
|
28
|
+
t.style.height = 'auto'; // so it shrinks too: scrollHeight is never below the current height
|
|
29
|
+
t.style.height = t.scrollHeight + t.offsetHeight - t.clientHeight + 'px'; // plus the borders
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=textarea.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textarea.js","sourceRoot":"","sources":["../../src/comps/textarea.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;AAOvB,sDAAsD;AACtD,MAAM,OAAO,QAAS,SAAQ,SAAgB;IAE1C,IAAI;QACA,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QAC3D,OAAO,kBAAU,IAAI,EAAE,CAAC,KAAM,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,cAAc,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,GAAI,CAAA;IAC/G,CAAC;IAED,OAAO;QACH,mIAAmI;QACnI,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QACrD,IAAI,IAAI,CAAC,KAAK,CAAC,SAAS;YAAE,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;IAClD,CAAC;IAED,2FAA2F;IAC3F,MAAM;QACF,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAC/B,CAAC;IAED,OAAO,CAAC,EAAS;QACb,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAE,EAAE,CAAC,MAA8B,CAAC,KAAK,CAAC,CAAA;QAC/D,IAAI,CAAC,MAAM,EAAE,CAAA;IACjB,CAAC;IAED,MAAM;QACF,MAAM,CAAC,GAAG,IAAI,CAAC,OAA8B,CAAA;QAC7C,IAAI,CAAC,CAAC,CAAC,YAAY;YAAE,OAAM,CAAC,oDAAoD;QAChF,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAA,CAAC,oEAAoE;QAC5F,CAAC,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,GAAG,CAAC,CAAC,YAAY,GAAG,IAAI,CAAA,CAAC,mBAAmB;IAChG,CAAC;CACJ","sourcesContent":["import { jsx } from '../h.js'\nimport type { TextareaHTMLAttributes } from '../jsx.js'\nimport { Component, cc } from '../lib.js'\nimport './textarea.css'\n\ntype Props = Omit<TextareaHTMLAttributes, 'value' | 'oninput'> & {\n value: string\n setvalue?: (value: string) => void\n}\n\n/** a textarea that grows and shrinks with its text */\nexport class TextArea extends Component<Props> {\n\n view() {\n const { value, setvalue, class: cls, ...rest } = this.props\n return <textarea rows={1} {...rest} class={cc('jmc-textarea', cls)} value={value} oninput={this.oninput} />\n }\n\n mounted() {\n // fires once the element has a size: when mounted, when shown after being hidden, and when its width changes (the text wraps anew)\n new ResizeObserver(this.adjust).observe(this.element)\n if (this.props.autofocus) this.element.focus()\n }\n\n // runs before the render. the new value is set by then, so the height is adjusted after it\n update() {\n queueMicrotask(this.adjust)\n }\n\n oninput(ev: Event) {\n this.props.setvalue?.((ev.target as HTMLTextAreaElement).value)\n this.adjust()\n }\n\n adjust() {\n const t = this.element as HTMLTextAreaElement\n if (!t.clientHeight) return // hidden. the observer calls again when it is shown\n t.style.height = 'auto' // so it shrinks too: scrollHeight is never below the current height\n t.style.height = t.scrollHeight + t.offsetHeight - t.clientHeight + 'px' // plus the borders\n }\n}\n"]}
|