@stackone/malachite 2.94.1 → 2.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { FOCUS_RING as
|
|
3
|
-
const
|
|
1
|
+
import { jsx as a, jsxs as p, Fragment as M } from "react/jsx-runtime";
|
|
2
|
+
import { FOCUS_RING as $ } from "./focusRing.js";
|
|
3
|
+
const k = {
|
|
4
|
+
default: "var(--malachite-accent-background, rgb(0, 175, 102))",
|
|
5
|
+
warning: "var(--malachite-warning-foreground, rgb(150, 88, 10))"
|
|
6
|
+
}, C = ({
|
|
4
7
|
checked: o,
|
|
5
|
-
indeterminate:
|
|
6
|
-
onChange:
|
|
7
|
-
disabled:
|
|
8
|
+
indeterminate: t = !1,
|
|
9
|
+
onChange: l,
|
|
10
|
+
disabled: e = !1,
|
|
8
11
|
size: r = 14,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"aria-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
tone: i = "default",
|
|
13
|
+
presentational: x = !1,
|
|
14
|
+
"aria-label": f,
|
|
15
|
+
"aria-labelledby": g,
|
|
16
|
+
className: d = "",
|
|
17
|
+
id: y
|
|
14
18
|
}) => {
|
|
15
|
-
const c = o && !
|
|
19
|
+
const c = o && !t, s = Math.max(3, Math.round(r * 0.36)), h = Math.round(r * 0.57), n = k[i], m = t || o || i !== "default" ? n : "var(--malachite-text-placeholder, rgb(187, 187, 187))", u = {
|
|
16
20
|
position: "relative",
|
|
17
21
|
flexShrink: 0,
|
|
18
22
|
display: "inline-flex",
|
|
@@ -21,16 +25,16 @@ const $ = ({
|
|
|
21
25
|
width: `${r}px`,
|
|
22
26
|
height: `${r}px`,
|
|
23
27
|
padding: 0,
|
|
24
|
-
borderRadius: `${
|
|
28
|
+
borderRadius: `${s}px`,
|
|
25
29
|
borderWidth: "1px",
|
|
26
30
|
borderStyle: "solid",
|
|
27
|
-
borderColor:
|
|
28
|
-
backgroundColor: c ?
|
|
31
|
+
borderColor: m,
|
|
32
|
+
backgroundColor: c ? n : "transparent",
|
|
29
33
|
color: "#fff",
|
|
30
|
-
opacity:
|
|
34
|
+
opacity: e ? 0.5 : 1,
|
|
31
35
|
transition: "background-color 150ms ease, border-color 150ms ease"
|
|
32
|
-
},
|
|
33
|
-
c && /* @__PURE__ */
|
|
36
|
+
}, b = /* @__PURE__ */ p(M, { children: [
|
|
37
|
+
c && /* @__PURE__ */ p(
|
|
34
38
|
"svg",
|
|
35
39
|
{
|
|
36
40
|
width: Math.round(r * 0.78),
|
|
@@ -38,42 +42,42 @@ const $ = ({
|
|
|
38
42
|
viewBox: "0 0 24 24",
|
|
39
43
|
"aria-hidden": "true",
|
|
40
44
|
children: [
|
|
41
|
-
/* @__PURE__ */
|
|
42
|
-
/* @__PURE__ */
|
|
45
|
+
/* @__PURE__ */ a("title", { children: "checked" }),
|
|
46
|
+
/* @__PURE__ */ a("path", { d: "M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" })
|
|
43
47
|
]
|
|
44
48
|
}
|
|
45
49
|
),
|
|
46
|
-
|
|
50
|
+
t && /* @__PURE__ */ a(
|
|
47
51
|
"span",
|
|
48
52
|
{
|
|
49
53
|
style: {
|
|
50
|
-
width: `${
|
|
51
|
-
height: `${
|
|
52
|
-
borderRadius: `${Math.max(2, Math.round(
|
|
53
|
-
backgroundColor:
|
|
54
|
+
width: `${h}px`,
|
|
55
|
+
height: `${h}px`,
|
|
56
|
+
borderRadius: `${Math.max(2, Math.round(s * 0.6))}px`,
|
|
57
|
+
backgroundColor: n
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
)
|
|
57
61
|
] });
|
|
58
|
-
return
|
|
62
|
+
return x ? /* @__PURE__ */ a("span", { "aria-hidden": "true", className: d, style: u, children: b }) : /* @__PURE__ */ a(
|
|
59
63
|
"button",
|
|
60
64
|
{
|
|
61
65
|
type: "button",
|
|
62
66
|
role: "checkbox",
|
|
63
|
-
id:
|
|
64
|
-
"aria-checked":
|
|
65
|
-
"aria-label":
|
|
66
|
-
"aria-labelledby":
|
|
67
|
-
disabled:
|
|
68
|
-
onClick: () =>
|
|
69
|
-
className: `${
|
|
70
|
-
style: { ...
|
|
71
|
-
children:
|
|
67
|
+
id: y,
|
|
68
|
+
"aria-checked": t ? "mixed" : o,
|
|
69
|
+
"aria-label": f,
|
|
70
|
+
"aria-labelledby": g,
|
|
71
|
+
disabled: e,
|
|
72
|
+
onClick: () => l == null ? void 0 : l(t ? !0 : !o),
|
|
73
|
+
className: `${$} ${d}`,
|
|
74
|
+
style: { ...u, cursor: e ? "not-allowed" : "pointer" },
|
|
75
|
+
children: b
|
|
72
76
|
}
|
|
73
77
|
);
|
|
74
78
|
};
|
|
75
79
|
export {
|
|
76
|
-
|
|
77
|
-
|
|
80
|
+
C as Checkbox,
|
|
81
|
+
C as default
|
|
78
82
|
};
|
|
79
83
|
//# sourceMappingURL=Checkbox.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Checkbox.js","sources":["../../src/components/Checkbox.tsx"],"sourcesContent":["import React from 'react';\nimport { FOCUS_RING } from './focusRing';\n\ninterface CheckboxProps {\n checked: boolean;\n /** Tri-state \"partial\" look — overrides the checked tick with a square. */\n indeterminate?: boolean;\n /** Optional when `presentational` — a presentational checkbox is a visual indicator only. */\n onChange?: (checked: boolean) => void;\n disabled?: boolean;\n size?: number;\n /**\n * Render a visual-only indicator (a non-interactive, non-focusable `<span>`,\n * `aria-hidden`) instead of an interactive checkbox. Use this inside a clickable\n * row/card whose wrapper is the real control, so there's a single tab stop.\n */\n presentational?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n id?: string;\n}\n\nconst Checkbox: React.FC<CheckboxProps> = ({\n checked,\n indeterminate = false,\n onChange,\n disabled = false,\n size = 14,\n presentational = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n id,\n}) => {\n const isFilled = checked && !indeterminate;\n const radius = Math.max(3, Math.round(size * 0.36));\n const innerSize = Math.round(size * 0.57);\n\n // Indeterminate shares the checked border rather than a fainter one, so \"some selected\"\n // never reads weaker than \"nothing selected\"; the transparent fill separates the states.\n const borderColor =\n indeterminate || checked
|
|
1
|
+
{"version":3,"file":"Checkbox.js","sources":["../../src/components/Checkbox.tsx"],"sourcesContent":["import React from 'react';\nimport { FOCUS_RING } from './focusRing';\n\ntype CheckboxTone = 'default' | 'warning';\n\ninterface CheckboxProps {\n checked: boolean;\n /** Tri-state \"partial\" look — overrides the checked tick with a square. */\n indeterminate?: boolean;\n /** Optional when `presentational` — a presentational checkbox is a visual indicator only. */\n onChange?: (checked: boolean) => void;\n disabled?: boolean;\n size?: number;\n /**\n * `warning` draws attention to this box in every state, unchecked included, for a choice\n * that needs a second look such as an unsaved change.\n */\n tone?: CheckboxTone;\n /**\n * Render a visual-only indicator (a non-interactive, non-focusable `<span>`,\n * `aria-hidden`) instead of an interactive checkbox. Use this inside a clickable\n * row/card whose wrapper is the real control, so there's a single tab stop.\n */\n presentational?: boolean;\n 'aria-label'?: string;\n 'aria-labelledby'?: string;\n className?: string;\n id?: string;\n}\n\n// `warning` takes the foreground token: white on the warning background is under 3:1.\nconst TONE_COLOR: Record<CheckboxTone, string> = {\n default: 'var(--malachite-accent-background, rgb(0, 175, 102))',\n warning: 'var(--malachite-warning-foreground, rgb(150, 88, 10))',\n};\n\nconst Checkbox: React.FC<CheckboxProps> = ({\n checked,\n indeterminate = false,\n onChange,\n disabled = false,\n size = 14,\n tone = 'default',\n presentational = false,\n 'aria-label': ariaLabel,\n 'aria-labelledby': ariaLabelledBy,\n className = '',\n id,\n}) => {\n const isFilled = checked && !indeterminate;\n const radius = Math.max(3, Math.round(size * 0.36));\n const innerSize = Math.round(size * 0.57);\n\n // Indeterminate shares the checked border rather than a fainter one, so \"some selected\"\n // never reads weaker than \"nothing selected\"; the transparent fill separates the states.\n const toneColor = TONE_COLOR[tone];\n const borderColor =\n indeterminate || checked || tone !== 'default'\n ? toneColor\n : 'var(--malachite-text-placeholder, rgb(187, 187, 187))';\n\n const boxStyle: React.CSSProperties = {\n position: 'relative',\n flexShrink: 0,\n display: 'inline-flex',\n alignItems: 'center',\n justifyContent: 'center',\n width: `${size}px`,\n height: `${size}px`,\n padding: 0,\n borderRadius: `${radius}px`,\n borderWidth: '1px',\n borderStyle: 'solid',\n borderColor,\n backgroundColor: isFilled ? toneColor : 'transparent',\n color: '#fff',\n opacity: disabled ? 0.5 : 1,\n transition: 'background-color 150ms ease, border-color 150ms ease',\n };\n\n const glyph = (\n <>\n {isFilled && (\n <svg\n width={Math.round(size * 0.78)}\n height={Math.round(size * 0.78)}\n viewBox=\"0 0 24 24\"\n aria-hidden=\"true\"\n >\n <title>checked</title>\n {/* Filled glyph — the library forces `svg path { fill: currentColor }` */}\n <path d=\"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z\" />\n </svg>\n )}\n {indeterminate && (\n <span\n style={{\n width: `${innerSize}px`,\n height: `${innerSize}px`,\n borderRadius: `${Math.max(2, Math.round(radius * 0.6))}px`,\n backgroundColor: toneColor,\n }}\n />\n )}\n </>\n );\n\n if (presentational) {\n return (\n <span aria-hidden=\"true\" className={className} style={boxStyle}>\n {glyph}\n </span>\n );\n }\n\n return (\n <button\n type=\"button\"\n role=\"checkbox\"\n id={id}\n aria-checked={indeterminate ? 'mixed' : checked}\n aria-label={ariaLabel}\n aria-labelledby={ariaLabelledBy}\n disabled={disabled}\n onClick={() => onChange?.(indeterminate ? true : !checked)}\n className={`${FOCUS_RING} ${className}`}\n style={{ ...boxStyle, cursor: disabled ? 'not-allowed' : 'pointer' }}\n >\n {glyph}\n </button>\n );\n};\n\nexport default Checkbox;\nexport { Checkbox };\nexport type { CheckboxProps, CheckboxTone };\n"],"names":["TONE_COLOR","Checkbox","checked","indeterminate","onChange","disabled","size","tone","presentational","ariaLabel","ariaLabelledBy","className","id","isFilled","radius","innerSize","toneColor","borderColor","boxStyle","glyph","jsxs","Fragment","jsx","FOCUS_RING"],"mappings":";;AA+BA,MAAMA,IAA2C;AAAA,EAC7C,SAAS;AAAA,EACT,SAAS;AACb,GAEMC,IAAoC,CAAC;AAAA,EACvC,SAAAC;AAAA,EACA,eAAAC,IAAgB;AAAA,EAChB,UAAAC;AAAA,EACA,UAAAC,IAAW;AAAA,EACX,MAAAC,IAAO;AAAA,EACP,MAAAC,IAAO;AAAA,EACP,gBAAAC,IAAiB;AAAA,EACjB,cAAcC;AAAA,EACd,mBAAmBC;AAAA,EACnB,WAAAC,IAAY;AAAA,EACZ,IAAAC;AACJ,MAAM;AACF,QAAMC,IAAWX,KAAW,CAACC,GACvBW,IAAS,KAAK,IAAI,GAAG,KAAK,MAAMR,IAAO,IAAI,CAAC,GAC5CS,IAAY,KAAK,MAAMT,IAAO,IAAI,GAIlCU,IAAYhB,EAAWO,CAAI,GAC3BU,IACFd,KAAiBD,KAAWK,MAAS,YAC/BS,IACA,yDAEJE,IAAgC;AAAA,IAClC,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,OAAO,GAAGZ,CAAI;AAAA,IACd,QAAQ,GAAGA,CAAI;AAAA,IACf,SAAS;AAAA,IACT,cAAc,GAAGQ,CAAM;AAAA,IACvB,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAAG;AAAA,IACA,iBAAiBJ,IAAWG,IAAY;AAAA,IACxC,OAAO;AAAA,IACP,SAASX,IAAW,MAAM;AAAA,IAC1B,YAAY;AAAA,EAAA,GAGVc,IACF,gBAAAC,EAAAC,GAAA,EACK,UAAA;AAAA,IAAAR,KACG,gBAAAO;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,OAAO,KAAK,MAAMd,IAAO,IAAI;AAAA,QAC7B,QAAQ,KAAK,MAAMA,IAAO,IAAI;AAAA,QAC9B,SAAQ;AAAA,QACR,eAAY;AAAA,QAEZ,UAAA;AAAA,UAAA,gBAAAgB,EAAC,WAAM,UAAA,UAAA,CAAO;AAAA,UAEd,gBAAAA,EAAC,QAAA,EAAK,GAAE,oDAAA,CAAoD;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,IAGnEnB,KACG,gBAAAmB;AAAA,MAAC;AAAA,MAAA;AAAA,QACG,OAAO;AAAA,UACH,OAAO,GAAGP,CAAS;AAAA,UACnB,QAAQ,GAAGA,CAAS;AAAA,UACpB,cAAc,GAAG,KAAK,IAAI,GAAG,KAAK,MAAMD,IAAS,GAAG,CAAC,CAAC;AAAA,UACtD,iBAAiBE;AAAA,QAAA;AAAA,MACrB;AAAA,IAAA;AAAA,EACJ,GAER;AAGJ,SAAIR,sBAEK,QAAA,EAAK,eAAY,QAAO,WAAAG,GAAsB,OAAOO,GACjD,UAAAC,GACL,IAKJ,gBAAAG;AAAA,IAAC;AAAA,IAAA;AAAA,MACG,MAAK;AAAA,MACL,MAAK;AAAA,MACL,IAAAV;AAAA,MACA,gBAAcT,IAAgB,UAAUD;AAAA,MACxC,cAAYO;AAAA,MACZ,mBAAiBC;AAAA,MACjB,UAAAL;AAAA,MACA,SAAS,MAAMD,KAAA,gBAAAA,EAAWD,IAAgB,KAAO,CAACD;AAAA,MAClD,WAAW,GAAGqB,CAAU,IAAIZ,CAAS;AAAA,MACrC,OAAO,EAAE,GAAGO,GAAU,QAAQb,IAAW,gBAAgB,UAAA;AAAA,MAExD,UAAAc;AAAA,IAAA;AAAA,EAAA;AAGb;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1036,6 +1036,11 @@ export declare interface CheckboxProps {
|
|
|
1036
1036
|
onChange?: (checked: boolean) => void;
|
|
1037
1037
|
disabled?: boolean;
|
|
1038
1038
|
size?: number;
|
|
1039
|
+
/**
|
|
1040
|
+
* `warning` draws attention to this box in every state, unchecked included, for a choice
|
|
1041
|
+
* that needs a second look such as an unsaved change.
|
|
1042
|
+
*/
|
|
1043
|
+
tone?: CheckboxTone;
|
|
1039
1044
|
/**
|
|
1040
1045
|
* Render a visual-only indicator (a non-interactive, non-focusable `<span>`,
|
|
1041
1046
|
* `aria-hidden`) instead of an interactive checkbox. Use this inside a clickable
|
|
@@ -1048,6 +1053,8 @@ export declare interface CheckboxProps {
|
|
|
1048
1053
|
id?: string;
|
|
1049
1054
|
}
|
|
1050
1055
|
|
|
1056
|
+
export declare type CheckboxTone = 'default' | 'warning';
|
|
1057
|
+
|
|
1051
1058
|
export declare const CheckCircleFilled: React.FC<IconProps_24>;
|
|
1052
1059
|
|
|
1053
1060
|
export declare const CheckIcon: React.FC<IconProps_25>;
|
package/package.json
CHANGED