@behivetech/atoms.checkbox 0.0.0-stage → 0.4.2
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/README.md +27 -2
- package/checkbox.example.tsx +71 -0
- package/checkbox.module.scss +117 -0
- package/checkbox.tsx +71 -0
- package/dist/index.cjs +208 -0
- package/dist/index.css +88 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +194 -0
- package/docs.json +29 -0
- package/index.ts +2 -0
- package/package.json +59 -3
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Checkbox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A bare checkbox control (built on Radix's `Checkbox`) — the Radix checkbox button is this component's own root element. It has no built-in label/hint/error; wrap it in `FormField` for that chrome.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```jsx
|
|
8
|
+
import { Checkbox } from '@behivetech/atoms.checkbox';
|
|
9
|
+
import { FormField } from '@behivetech/forms.form-field';
|
|
10
|
+
|
|
11
|
+
const [checked, setChecked] = useState(false);
|
|
12
|
+
|
|
13
|
+
<Checkbox checked={checked} onCheckedChange={setChecked} />
|
|
14
|
+
|
|
15
|
+
<FormField label="Accept terms" htmlFor="terms" required>
|
|
16
|
+
<Checkbox id="terms" required checked={checked} onCheckedChange={setChecked} />
|
|
17
|
+
</FormField>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Pass `aria-invalid="true"` to visually mark the checkbox as invalid (pair with `FormField`'s `error` prop for the message).
|
|
21
|
+
|
|
22
|
+
## Props
|
|
23
|
+
|
|
24
|
+
Extends Radix's own `CheckboxProps` (`checked`, `defaultChecked`, `onCheckedChange`, `disabled`, `required`, `name`, `value`, `id`, plus any standard button/ARIA attribute) with:
|
|
25
|
+
|
|
26
|
+
| Prop | Type | Default | Description |
|
|
27
|
+
| ----------- | -------- | ------- | ---------------------- |
|
|
28
|
+
| `className` | `string` | — | Additional class names |
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
import { FormField } from "@behivetech/forms.form-field";
|
|
3
|
+
import { Checkbox } from "./checkbox.js";
|
|
4
|
+
|
|
5
|
+
export const BasicCheckbox = () => {
|
|
6
|
+
const [checked, setChecked] = useState(false);
|
|
7
|
+
return (
|
|
8
|
+
<Checkbox
|
|
9
|
+
checked={checked}
|
|
10
|
+
onCheckedChange={(val) => setChecked(val === true)}
|
|
11
|
+
/>
|
|
12
|
+
);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const CheckboxWithFormField = () => {
|
|
16
|
+
const [checked, setChecked] = useState(false);
|
|
17
|
+
return (
|
|
18
|
+
<FormField
|
|
19
|
+
label="Accept terms and conditions"
|
|
20
|
+
htmlFor="accept-terms"
|
|
21
|
+
hint="You can withdraw consent at any time."
|
|
22
|
+
>
|
|
23
|
+
<Checkbox
|
|
24
|
+
id="accept-terms"
|
|
25
|
+
checked={checked}
|
|
26
|
+
onCheckedChange={(val) => setChecked(val === true)}
|
|
27
|
+
/>
|
|
28
|
+
</FormField>
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export const CheckboxWithError = () => (
|
|
33
|
+
<FormField
|
|
34
|
+
label="Agree to terms"
|
|
35
|
+
htmlFor="agree"
|
|
36
|
+
error="You must agree to continue"
|
|
37
|
+
>
|
|
38
|
+
<Checkbox
|
|
39
|
+
id="agree"
|
|
40
|
+
aria-invalid="true"
|
|
41
|
+
checked={false}
|
|
42
|
+
onCheckedChange={() => {}}
|
|
43
|
+
/>
|
|
44
|
+
</FormField>
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
export const IndeterminateCheckbox = () => (
|
|
48
|
+
<Checkbox checked="indeterminate" onCheckedChange={() => {}} />
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
export const DisabledCheckbox = () => (
|
|
52
|
+
<Checkbox disabled checked={false} onCheckedChange={() => {}} />
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
export const RequiredCheckbox = () => {
|
|
56
|
+
const [checked, setChecked] = useState(false);
|
|
57
|
+
return (
|
|
58
|
+
<FormField
|
|
59
|
+
label="I have read the privacy policy"
|
|
60
|
+
htmlFor="privacy"
|
|
61
|
+
required
|
|
62
|
+
>
|
|
63
|
+
<Checkbox
|
|
64
|
+
id="privacy"
|
|
65
|
+
required
|
|
66
|
+
checked={checked}
|
|
67
|
+
onCheckedChange={(val) => setChecked(val === true)}
|
|
68
|
+
/>
|
|
69
|
+
</FormField>
|
|
70
|
+
);
|
|
71
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Material Design 3 checkbox.
|
|
2
|
+
//
|
|
3
|
+
// `color` on the root is not used for text — it is the state layer's tint
|
|
4
|
+
// (`currentColor` in ::after), so it tracks the box: on-surface-variant when
|
|
5
|
+
// unchecked, primary when checked, error when invalid.
|
|
6
|
+
|
|
7
|
+
.BHT__Checkbox {
|
|
8
|
+
// Radix renders as <button role="checkbox">
|
|
9
|
+
position: relative;
|
|
10
|
+
width: 1rem;
|
|
11
|
+
height: 1rem;
|
|
12
|
+
flex-shrink: 0;
|
|
13
|
+
border: 2px solid
|
|
14
|
+
var(--md-sys-color-on-surface-variant, var(--color-border-strong));
|
|
15
|
+
border-radius: 2px;
|
|
16
|
+
background: transparent;
|
|
17
|
+
color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
|
|
18
|
+
display: inline-flex;
|
|
19
|
+
align-items: center;
|
|
20
|
+
justify-content: center;
|
|
21
|
+
padding: 0;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
transition:
|
|
24
|
+
background var(--md-sys-motion-duration-short-3, 150ms)
|
|
25
|
+
var(--md-sys-motion-easing-standard, ease),
|
|
26
|
+
border-color var(--md-sys-motion-duration-short-3, 150ms)
|
|
27
|
+
var(--md-sys-motion-easing-standard, ease);
|
|
28
|
+
|
|
29
|
+
// Touch target: a 48px square hit area around the 16px box, without
|
|
30
|
+
// changing its drawn size. px on purpose — a finger doesn't scale with type.
|
|
31
|
+
&::before {
|
|
32
|
+
content: "";
|
|
33
|
+
position: absolute;
|
|
34
|
+
top: 50%;
|
|
35
|
+
left: 50%;
|
|
36
|
+
translate: -50% -50%;
|
|
37
|
+
width: 48px;
|
|
38
|
+
height: 48px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// State layer: MD3 draws it as a circle around the box, not on the box.
|
|
42
|
+
&::after {
|
|
43
|
+
content: "";
|
|
44
|
+
position: absolute;
|
|
45
|
+
top: 50%;
|
|
46
|
+
left: 50%;
|
|
47
|
+
translate: -50% -50%;
|
|
48
|
+
width: 2.5rem;
|
|
49
|
+
height: 2.5rem;
|
|
50
|
+
border-radius: var(--md-sys-shape-corner-full, 9999px);
|
|
51
|
+
background: currentColor;
|
|
52
|
+
opacity: 0;
|
|
53
|
+
pointer-events: none;
|
|
54
|
+
transition: opacity var(--md-sys-motion-duration-short-2, 100ms)
|
|
55
|
+
var(--md-sys-motion-easing-standard, ease);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&:hover:not(:disabled)::after {
|
|
59
|
+
opacity: var(--md-sys-state-hover-opacity, 0.08);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
&:focus-visible::after {
|
|
63
|
+
opacity: var(--md-sys-state-focus-opacity, 0.1);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&:active:not(:disabled)::after {
|
|
67
|
+
opacity: var(--md-sys-state-pressed-opacity, 0.1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
&[data-state="checked"],
|
|
71
|
+
&[data-state="indeterminate"] {
|
|
72
|
+
background: var(--md-sys-color-primary, var(--color-primary));
|
|
73
|
+
border-color: var(--md-sys-color-primary, var(--color-primary));
|
|
74
|
+
color: var(--md-sys-color-primary, var(--color-primary));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
&:focus-visible {
|
|
78
|
+
outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
|
|
79
|
+
outline-offset: 2px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&:disabled {
|
|
83
|
+
opacity: 0.5;
|
|
84
|
+
cursor: not-allowed;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
&[aria-invalid="true"] {
|
|
88
|
+
border-color: var(--md-sys-color-error, var(--color-error));
|
|
89
|
+
color: var(--md-sys-color-error, var(--color-error));
|
|
90
|
+
|
|
91
|
+
&[data-state="checked"],
|
|
92
|
+
&[data-state="indeterminate"] {
|
|
93
|
+
background: var(--md-sys-color-error, var(--color-error));
|
|
94
|
+
border-color: var(--md-sys-color-error, var(--color-error));
|
|
95
|
+
|
|
96
|
+
.BHT__Checkbox {
|
|
97
|
+
&__indicator {
|
|
98
|
+
color: var(--md-sys-color-on-error, var(--color-on-primary));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
&__indicator {
|
|
105
|
+
color: var(--md-sys-color-on-primary, var(--color-on-primary));
|
|
106
|
+
display: flex;
|
|
107
|
+
align-items: center;
|
|
108
|
+
justify-content: center;
|
|
109
|
+
width: 0.625rem;
|
|
110
|
+
height: 0.625rem;
|
|
111
|
+
|
|
112
|
+
svg {
|
|
113
|
+
width: 100%;
|
|
114
|
+
height: 100%;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
package/checkbox.tsx
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as RadixCheckbox from "@radix-ui/react-checkbox";
|
|
2
|
+
import { useId } from "react";
|
|
3
|
+
import { getClassName } from "@bht-component-registry/class-names";
|
|
4
|
+
import styles from "./checkbox.module.scss";
|
|
5
|
+
|
|
6
|
+
export type { CheckedState } from "@radix-ui/react-checkbox";
|
|
7
|
+
|
|
8
|
+
export interface CheckboxProps extends Omit<
|
|
9
|
+
RadixCheckbox.CheckboxProps,
|
|
10
|
+
"className"
|
|
11
|
+
> {
|
|
12
|
+
/** Additional class names to merge with the component root element */
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Bare checkbox control — the Radix checkbox button is this component's own
|
|
18
|
+
* root element, no built-in label/hint/error. Wrap it in `FormField` for
|
|
19
|
+
* that chrome: `<FormField label="..." htmlFor="x"><Checkbox id="x" /></FormField>`.
|
|
20
|
+
*/
|
|
21
|
+
export const Checkbox = ({
|
|
22
|
+
className,
|
|
23
|
+
id,
|
|
24
|
+
checked,
|
|
25
|
+
...rest
|
|
26
|
+
}: CheckboxProps) => {
|
|
27
|
+
const generatedId = useId();
|
|
28
|
+
const checkboxId = id ?? generatedId;
|
|
29
|
+
|
|
30
|
+
const [rootClass, getChildClass] = getClassName({
|
|
31
|
+
className,
|
|
32
|
+
rootClass: "BHT__Checkbox",
|
|
33
|
+
styles,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<RadixCheckbox.Root
|
|
38
|
+
{...rest}
|
|
39
|
+
id={checkboxId}
|
|
40
|
+
checked={checked}
|
|
41
|
+
className={rootClass}
|
|
42
|
+
>
|
|
43
|
+
<RadixCheckbox.Indicator className={getChildClass("indicator")}>
|
|
44
|
+
{checked === "indeterminate" ? (
|
|
45
|
+
<svg
|
|
46
|
+
viewBox="0 0 12 4"
|
|
47
|
+
fill="none"
|
|
48
|
+
stroke="currentColor"
|
|
49
|
+
strokeWidth="2.5"
|
|
50
|
+
strokeLinecap="round"
|
|
51
|
+
aria-hidden="true"
|
|
52
|
+
>
|
|
53
|
+
<path d="M1 2H11" />
|
|
54
|
+
</svg>
|
|
55
|
+
) : (
|
|
56
|
+
<svg
|
|
57
|
+
viewBox="0 0 12 10"
|
|
58
|
+
fill="none"
|
|
59
|
+
stroke="currentColor"
|
|
60
|
+
strokeWidth="2.5"
|
|
61
|
+
strokeLinecap="round"
|
|
62
|
+
strokeLinejoin="round"
|
|
63
|
+
aria-hidden="true"
|
|
64
|
+
>
|
|
65
|
+
<path d="M1 5L4.5 8.5L11 1" />
|
|
66
|
+
</svg>
|
|
67
|
+
)}
|
|
68
|
+
</RadixCheckbox.Indicator>
|
|
69
|
+
</RadixCheckbox.Root>
|
|
70
|
+
);
|
|
71
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
34
|
+
var require_classnames = __commonJS({
|
|
35
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports2, module2) {
|
|
36
|
+
"use strict";
|
|
37
|
+
(function() {
|
|
38
|
+
"use strict";
|
|
39
|
+
var hasOwn = {}.hasOwnProperty;
|
|
40
|
+
function classNames() {
|
|
41
|
+
var classes = "";
|
|
42
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
43
|
+
var arg = arguments[i];
|
|
44
|
+
if (arg) {
|
|
45
|
+
classes = appendClass(classes, parseValue(arg));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return classes;
|
|
49
|
+
}
|
|
50
|
+
function parseValue(arg) {
|
|
51
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
52
|
+
return arg;
|
|
53
|
+
}
|
|
54
|
+
if (typeof arg !== "object") {
|
|
55
|
+
return "";
|
|
56
|
+
}
|
|
57
|
+
if (Array.isArray(arg)) {
|
|
58
|
+
return classNames.apply(null, arg);
|
|
59
|
+
}
|
|
60
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
61
|
+
return arg.toString();
|
|
62
|
+
}
|
|
63
|
+
var classes = "";
|
|
64
|
+
for (var key in arg) {
|
|
65
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
66
|
+
classes = appendClass(classes, key);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return classes;
|
|
70
|
+
}
|
|
71
|
+
function appendClass(value, newClass) {
|
|
72
|
+
if (!newClass) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
if (value) {
|
|
76
|
+
return value + " " + newClass;
|
|
77
|
+
}
|
|
78
|
+
return value + newClass;
|
|
79
|
+
}
|
|
80
|
+
if (typeof module2 !== "undefined" && module2.exports) {
|
|
81
|
+
classNames.default = classNames;
|
|
82
|
+
module2.exports = classNames;
|
|
83
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
84
|
+
define("classnames", [], function() {
|
|
85
|
+
return classNames;
|
|
86
|
+
});
|
|
87
|
+
} else {
|
|
88
|
+
window.classNames = classNames;
|
|
89
|
+
}
|
|
90
|
+
})();
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// index.ts
|
|
95
|
+
var index_exports = {};
|
|
96
|
+
__export(index_exports, {
|
|
97
|
+
Checkbox: () => Checkbox
|
|
98
|
+
});
|
|
99
|
+
module.exports = __toCommonJS(index_exports);
|
|
100
|
+
|
|
101
|
+
// checkbox.tsx
|
|
102
|
+
var RadixCheckbox = __toESM(require("@radix-ui/react-checkbox"), 1);
|
|
103
|
+
var import_react = require("react");
|
|
104
|
+
|
|
105
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
106
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
107
|
+
var getClassName = ({
|
|
108
|
+
className,
|
|
109
|
+
modifiers = {},
|
|
110
|
+
rootClass,
|
|
111
|
+
styles = {}
|
|
112
|
+
}) => {
|
|
113
|
+
function getModifiers() {
|
|
114
|
+
const updatedModifiers = {};
|
|
115
|
+
const modifierKeys = Object.keys(modifiers);
|
|
116
|
+
if (modifierKeys.length) {
|
|
117
|
+
modifierKeys.forEach((modKey) => {
|
|
118
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
119
|
+
const newClassName = styles[classKey] || classKey;
|
|
120
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
return updatedModifiers;
|
|
124
|
+
}
|
|
125
|
+
function getChildClass(childClassName) {
|
|
126
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
127
|
+
return styles[classKey] || classKey;
|
|
128
|
+
}
|
|
129
|
+
function getRootStyles() {
|
|
130
|
+
return (0, import_classnames.default)(
|
|
131
|
+
className,
|
|
132
|
+
{
|
|
133
|
+
...getModifiers()
|
|
134
|
+
},
|
|
135
|
+
styles[rootClass] || rootClass
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return [getRootStyles(), getChildClass];
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// checkbox.module.scss
|
|
142
|
+
var checkbox_module_default = {
|
|
143
|
+
"BHT__Checkbox": "BHT__Checkbox",
|
|
144
|
+
"BHT__Checkbox__indicator": "BHT__Checkbox__indicator"
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
// checkbox.tsx
|
|
148
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
149
|
+
var Checkbox = ({
|
|
150
|
+
className,
|
|
151
|
+
id,
|
|
152
|
+
checked,
|
|
153
|
+
...rest
|
|
154
|
+
}) => {
|
|
155
|
+
const generatedId = (0, import_react.useId)();
|
|
156
|
+
const checkboxId = id ?? generatedId;
|
|
157
|
+
const [rootClass, getChildClass] = getClassName({
|
|
158
|
+
className,
|
|
159
|
+
rootClass: "BHT__Checkbox",
|
|
160
|
+
styles: checkbox_module_default
|
|
161
|
+
});
|
|
162
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
163
|
+
RadixCheckbox.Root,
|
|
164
|
+
{
|
|
165
|
+
...rest,
|
|
166
|
+
id: checkboxId,
|
|
167
|
+
checked,
|
|
168
|
+
className: rootClass,
|
|
169
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RadixCheckbox.Indicator, { className: getChildClass("indicator"), children: checked === "indeterminate" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
170
|
+
"svg",
|
|
171
|
+
{
|
|
172
|
+
viewBox: "0 0 12 4",
|
|
173
|
+
fill: "none",
|
|
174
|
+
stroke: "currentColor",
|
|
175
|
+
strokeWidth: "2.5",
|
|
176
|
+
strokeLinecap: "round",
|
|
177
|
+
"aria-hidden": "true",
|
|
178
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M1 2H11" })
|
|
179
|
+
}
|
|
180
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
181
|
+
"svg",
|
|
182
|
+
{
|
|
183
|
+
viewBox: "0 0 12 10",
|
|
184
|
+
fill: "none",
|
|
185
|
+
stroke: "currentColor",
|
|
186
|
+
strokeWidth: "2.5",
|
|
187
|
+
strokeLinecap: "round",
|
|
188
|
+
strokeLinejoin: "round",
|
|
189
|
+
"aria-hidden": "true",
|
|
190
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M1 5L4.5 8.5L11 1" })
|
|
191
|
+
}
|
|
192
|
+
) })
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
197
|
+
0 && (module.exports = {
|
|
198
|
+
Checkbox
|
|
199
|
+
});
|
|
200
|
+
/*! Bundled license information:
|
|
201
|
+
|
|
202
|
+
classnames/index.js:
|
|
203
|
+
(*!
|
|
204
|
+
Copyright (c) 2018 Jed Watson.
|
|
205
|
+
Licensed under the MIT License (MIT), see
|
|
206
|
+
http://jedwatson.github.io/classnames
|
|
207
|
+
*)
|
|
208
|
+
*/
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/* esbuild-sass-plugin:css-chunkcheckbox.module.scss */
|
|
2
|
+
.BHT__Checkbox {
|
|
3
|
+
position: relative;
|
|
4
|
+
width: 1rem;
|
|
5
|
+
height: 1rem;
|
|
6
|
+
flex-shrink: 0;
|
|
7
|
+
border: 2px solid var(--md-sys-color-on-surface-variant, var(--color-border-strong));
|
|
8
|
+
border-radius: 2px;
|
|
9
|
+
background: transparent;
|
|
10
|
+
color: var(--md-sys-color-on-surface-variant, var(--color-text-muted));
|
|
11
|
+
display: inline-flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
justify-content: center;
|
|
14
|
+
padding: 0;
|
|
15
|
+
cursor: pointer;
|
|
16
|
+
transition: background var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard, ease), border-color var(--md-sys-motion-duration-short-3, 150ms) var(--md-sys-motion-easing-standard, ease);
|
|
17
|
+
}
|
|
18
|
+
.BHT__Checkbox::before {
|
|
19
|
+
content: "";
|
|
20
|
+
position: absolute;
|
|
21
|
+
top: 50%;
|
|
22
|
+
left: 50%;
|
|
23
|
+
translate: -50% -50%;
|
|
24
|
+
width: 48px;
|
|
25
|
+
height: 48px;
|
|
26
|
+
}
|
|
27
|
+
.BHT__Checkbox::after {
|
|
28
|
+
content: "";
|
|
29
|
+
position: absolute;
|
|
30
|
+
top: 50%;
|
|
31
|
+
left: 50%;
|
|
32
|
+
translate: -50% -50%;
|
|
33
|
+
width: 2.5rem;
|
|
34
|
+
height: 2.5rem;
|
|
35
|
+
border-radius: var(--md-sys-shape-corner-full, 9999px);
|
|
36
|
+
background: currentColor;
|
|
37
|
+
opacity: 0;
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
transition: opacity var(--md-sys-motion-duration-short-2, 100ms) var(--md-sys-motion-easing-standard, ease);
|
|
40
|
+
}
|
|
41
|
+
.BHT__Checkbox:hover:not(:disabled)::after {
|
|
42
|
+
opacity: var(--md-sys-state-hover-opacity, 0.08);
|
|
43
|
+
}
|
|
44
|
+
.BHT__Checkbox:focus-visible::after {
|
|
45
|
+
opacity: var(--md-sys-state-focus-opacity, 0.1);
|
|
46
|
+
}
|
|
47
|
+
.BHT__Checkbox:active:not(:disabled)::after {
|
|
48
|
+
opacity: var(--md-sys-state-pressed-opacity, 0.1);
|
|
49
|
+
}
|
|
50
|
+
.BHT__Checkbox[data-state=checked],
|
|
51
|
+
.BHT__Checkbox[data-state=indeterminate] {
|
|
52
|
+
background: var(--md-sys-color-primary, var(--color-primary));
|
|
53
|
+
border-color: var(--md-sys-color-primary, var(--color-primary));
|
|
54
|
+
color: var(--md-sys-color-primary, var(--color-primary));
|
|
55
|
+
}
|
|
56
|
+
.BHT__Checkbox:focus-visible {
|
|
57
|
+
outline: 3px solid var(--md-sys-color-secondary, var(--color-border-focus));
|
|
58
|
+
outline-offset: 2px;
|
|
59
|
+
}
|
|
60
|
+
.BHT__Checkbox:disabled {
|
|
61
|
+
opacity: 0.5;
|
|
62
|
+
cursor: not-allowed;
|
|
63
|
+
}
|
|
64
|
+
.BHT__Checkbox[aria-invalid=true] {
|
|
65
|
+
border-color: var(--md-sys-color-error, var(--color-error));
|
|
66
|
+
color: var(--md-sys-color-error, var(--color-error));
|
|
67
|
+
}
|
|
68
|
+
.BHT__Checkbox[aria-invalid=true][data-state=checked],
|
|
69
|
+
.BHT__Checkbox[aria-invalid=true][data-state=indeterminate] {
|
|
70
|
+
background: var(--md-sys-color-error, var(--color-error));
|
|
71
|
+
border-color: var(--md-sys-color-error, var(--color-error));
|
|
72
|
+
}
|
|
73
|
+
.BHT__Checkbox[aria-invalid=true][data-state=checked] .BHT__Checkbox__indicator,
|
|
74
|
+
.BHT__Checkbox[aria-invalid=true][data-state=indeterminate] .BHT__Checkbox__indicator {
|
|
75
|
+
color: var(--md-sys-color-on-error, var(--color-on-primary));
|
|
76
|
+
}
|
|
77
|
+
.BHT__Checkbox__indicator {
|
|
78
|
+
color: var(--md-sys-color-on-primary, var(--color-on-primary));
|
|
79
|
+
display: flex;
|
|
80
|
+
align-items: center;
|
|
81
|
+
justify-content: center;
|
|
82
|
+
width: 0.625rem;
|
|
83
|
+
height: 0.625rem;
|
|
84
|
+
}
|
|
85
|
+
.BHT__Checkbox__indicator svg {
|
|
86
|
+
width: 100%;
|
|
87
|
+
height: 100%;
|
|
88
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as RadixCheckbox from '@radix-ui/react-checkbox';
|
|
3
|
+
export { CheckedState } from '@radix-ui/react-checkbox';
|
|
4
|
+
|
|
5
|
+
interface CheckboxProps extends Omit<RadixCheckbox.CheckboxProps, "className"> {
|
|
6
|
+
/** Additional class names to merge with the component root element */
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Bare checkbox control — the Radix checkbox button is this component's own
|
|
11
|
+
* root element, no built-in label/hint/error. Wrap it in `FormField` for
|
|
12
|
+
* that chrome: `<FormField label="..." htmlFor="x"><Checkbox id="x" /></FormField>`.
|
|
13
|
+
*/
|
|
14
|
+
declare const Checkbox: ({ className, id, checked, ...rest }: CheckboxProps) => react.JSX.Element;
|
|
15
|
+
|
|
16
|
+
export { Checkbox, type CheckboxProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
8
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
19
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
20
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
21
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
22
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
23
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
24
|
+
mod
|
|
25
|
+
));
|
|
26
|
+
|
|
27
|
+
// ../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js
|
|
28
|
+
var require_classnames = __commonJS({
|
|
29
|
+
"../../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.js"(exports, module) {
|
|
30
|
+
"use strict";
|
|
31
|
+
(function() {
|
|
32
|
+
"use strict";
|
|
33
|
+
var hasOwn = {}.hasOwnProperty;
|
|
34
|
+
function classNames() {
|
|
35
|
+
var classes = "";
|
|
36
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
37
|
+
var arg = arguments[i];
|
|
38
|
+
if (arg) {
|
|
39
|
+
classes = appendClass(classes, parseValue(arg));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return classes;
|
|
43
|
+
}
|
|
44
|
+
function parseValue(arg) {
|
|
45
|
+
if (typeof arg === "string" || typeof arg === "number") {
|
|
46
|
+
return arg;
|
|
47
|
+
}
|
|
48
|
+
if (typeof arg !== "object") {
|
|
49
|
+
return "";
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(arg)) {
|
|
52
|
+
return classNames.apply(null, arg);
|
|
53
|
+
}
|
|
54
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
|
|
55
|
+
return arg.toString();
|
|
56
|
+
}
|
|
57
|
+
var classes = "";
|
|
58
|
+
for (var key in arg) {
|
|
59
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
60
|
+
classes = appendClass(classes, key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return classes;
|
|
64
|
+
}
|
|
65
|
+
function appendClass(value, newClass) {
|
|
66
|
+
if (!newClass) {
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
if (value) {
|
|
70
|
+
return value + " " + newClass;
|
|
71
|
+
}
|
|
72
|
+
return value + newClass;
|
|
73
|
+
}
|
|
74
|
+
if (typeof module !== "undefined" && module.exports) {
|
|
75
|
+
classNames.default = classNames;
|
|
76
|
+
module.exports = classNames;
|
|
77
|
+
} else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
|
|
78
|
+
define("classnames", [], function() {
|
|
79
|
+
return classNames;
|
|
80
|
+
});
|
|
81
|
+
} else {
|
|
82
|
+
window.classNames = classNames;
|
|
83
|
+
}
|
|
84
|
+
})();
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// checkbox.tsx
|
|
89
|
+
import * as RadixCheckbox from "@radix-ui/react-checkbox";
|
|
90
|
+
import { useId } from "react";
|
|
91
|
+
|
|
92
|
+
// ../../../../packages/registry/class-names/dist/index.js
|
|
93
|
+
var import_classnames = __toESM(require_classnames(), 1);
|
|
94
|
+
var getClassName = ({
|
|
95
|
+
className,
|
|
96
|
+
modifiers = {},
|
|
97
|
+
rootClass,
|
|
98
|
+
styles = {}
|
|
99
|
+
}) => {
|
|
100
|
+
function getModifiers() {
|
|
101
|
+
const updatedModifiers = {};
|
|
102
|
+
const modifierKeys = Object.keys(modifiers);
|
|
103
|
+
if (modifierKeys.length) {
|
|
104
|
+
modifierKeys.forEach((modKey) => {
|
|
105
|
+
const classKey = `${rootClass}--${modKey}`;
|
|
106
|
+
const newClassName = styles[classKey] || classKey;
|
|
107
|
+
updatedModifiers[newClassName] = modifiers[modKey] ?? false;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return updatedModifiers;
|
|
111
|
+
}
|
|
112
|
+
function getChildClass(childClassName) {
|
|
113
|
+
const classKey = `${rootClass}__${childClassName}`;
|
|
114
|
+
return styles[classKey] || classKey;
|
|
115
|
+
}
|
|
116
|
+
function getRootStyles() {
|
|
117
|
+
return (0, import_classnames.default)(
|
|
118
|
+
className,
|
|
119
|
+
{
|
|
120
|
+
...getModifiers()
|
|
121
|
+
},
|
|
122
|
+
styles[rootClass] || rootClass
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
return [getRootStyles(), getChildClass];
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// checkbox.module.scss
|
|
129
|
+
var checkbox_module_default = {
|
|
130
|
+
"BHT__Checkbox": "BHT__Checkbox",
|
|
131
|
+
"BHT__Checkbox__indicator": "BHT__Checkbox__indicator"
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// checkbox.tsx
|
|
135
|
+
import { jsx } from "react/jsx-runtime";
|
|
136
|
+
var Checkbox = ({
|
|
137
|
+
className,
|
|
138
|
+
id,
|
|
139
|
+
checked,
|
|
140
|
+
...rest
|
|
141
|
+
}) => {
|
|
142
|
+
const generatedId = useId();
|
|
143
|
+
const checkboxId = id ?? generatedId;
|
|
144
|
+
const [rootClass, getChildClass] = getClassName({
|
|
145
|
+
className,
|
|
146
|
+
rootClass: "BHT__Checkbox",
|
|
147
|
+
styles: checkbox_module_default
|
|
148
|
+
});
|
|
149
|
+
return /* @__PURE__ */ jsx(
|
|
150
|
+
RadixCheckbox.Root,
|
|
151
|
+
{
|
|
152
|
+
...rest,
|
|
153
|
+
id: checkboxId,
|
|
154
|
+
checked,
|
|
155
|
+
className: rootClass,
|
|
156
|
+
children: /* @__PURE__ */ jsx(RadixCheckbox.Indicator, { className: getChildClass("indicator"), children: checked === "indeterminate" ? /* @__PURE__ */ jsx(
|
|
157
|
+
"svg",
|
|
158
|
+
{
|
|
159
|
+
viewBox: "0 0 12 4",
|
|
160
|
+
fill: "none",
|
|
161
|
+
stroke: "currentColor",
|
|
162
|
+
strokeWidth: "2.5",
|
|
163
|
+
strokeLinecap: "round",
|
|
164
|
+
"aria-hidden": "true",
|
|
165
|
+
children: /* @__PURE__ */ jsx("path", { d: "M1 2H11" })
|
|
166
|
+
}
|
|
167
|
+
) : /* @__PURE__ */ jsx(
|
|
168
|
+
"svg",
|
|
169
|
+
{
|
|
170
|
+
viewBox: "0 0 12 10",
|
|
171
|
+
fill: "none",
|
|
172
|
+
stroke: "currentColor",
|
|
173
|
+
strokeWidth: "2.5",
|
|
174
|
+
strokeLinecap: "round",
|
|
175
|
+
strokeLinejoin: "round",
|
|
176
|
+
"aria-hidden": "true",
|
|
177
|
+
children: /* @__PURE__ */ jsx("path", { d: "M1 5L4.5 8.5L11 1" })
|
|
178
|
+
}
|
|
179
|
+
) })
|
|
180
|
+
}
|
|
181
|
+
);
|
|
182
|
+
};
|
|
183
|
+
export {
|
|
184
|
+
Checkbox
|
|
185
|
+
};
|
|
186
|
+
/*! Bundled license information:
|
|
187
|
+
|
|
188
|
+
classnames/index.js:
|
|
189
|
+
(*!
|
|
190
|
+
Copyright (c) 2018 Jed Watson.
|
|
191
|
+
Licensed under the MIT License (MIT), see
|
|
192
|
+
http://jedwatson.github.io/classnames
|
|
193
|
+
*)
|
|
194
|
+
*/
|
package/docs.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://github.com/behivetech/bht-component-registry/docs.schema.json",
|
|
3
|
+
"version": 2,
|
|
4
|
+
"generatedAt": "2026-10-20T05:49:55.942Z",
|
|
5
|
+
"docs": [
|
|
6
|
+
{
|
|
7
|
+
"displayName": "Checkbox",
|
|
8
|
+
"description": "Bare checkbox control — the Radix checkbox button is this component's own\nroot element, no built-in label/hint/error. Wrap it in `FormField` for\nthat chrome: `<FormField label=\"...\" htmlFor=\"x\"><Checkbox id=\"x\" /></FormField>`.",
|
|
9
|
+
"extendsNative": true,
|
|
10
|
+
"props": [
|
|
11
|
+
{
|
|
12
|
+
"name": "asChild",
|
|
13
|
+
"type": "boolean",
|
|
14
|
+
"required": false,
|
|
15
|
+
"defaultValue": null,
|
|
16
|
+
"description": ""
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
"name": "className",
|
|
20
|
+
"type": "string",
|
|
21
|
+
"required": false,
|
|
22
|
+
"defaultValue": null,
|
|
23
|
+
"description": "Additional class names to merge with the component root element"
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
],
|
|
28
|
+
"functions": []
|
|
29
|
+
}
|
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@behivetech/atoms.checkbox",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.4.2",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
|
+
},
|
|
13
|
+
"./styles.css": "./dist/index.css"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"index.ts",
|
|
19
|
+
"checkbox.tsx",
|
|
20
|
+
"checkbox.module.scss",
|
|
21
|
+
"*.example.tsx",
|
|
22
|
+
"docs.json"
|
|
23
|
+
],
|
|
24
|
+
"registry": {
|
|
25
|
+
"status": "stable",
|
|
26
|
+
"tags": []
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@radix-ui/react-checkbox": "^1.1.0",
|
|
30
|
+
"react": "^19.2.7",
|
|
31
|
+
"react-dom": "^19.2.7"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@radix-ui/react-checkbox": "^1.3.11",
|
|
35
|
+
"@types/react": "19.2.17",
|
|
36
|
+
"@types/react-dom": "19.2.3",
|
|
37
|
+
"eslint": "^9.39.5",
|
|
38
|
+
"tsup": "^8.5.1",
|
|
39
|
+
"typescript": "^6.0.3",
|
|
40
|
+
"vitest": "^4.1.10",
|
|
41
|
+
"@behivetech/forms.form-field": "0.3.2",
|
|
42
|
+
"@bht-component-registry/class-names": "0.0.6",
|
|
43
|
+
"@bht-component-registry/env": "0.1.0"
|
|
44
|
+
},
|
|
45
|
+
"repository": {
|
|
46
|
+
"type": "git",
|
|
47
|
+
"url": "https://github.com/behivetech/bht-galaxy.git",
|
|
48
|
+
"directory": "registry/behivetech/atoms/checkbox"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"registry": "https://registry.npmjs.org",
|
|
52
|
+
"access": "public",
|
|
53
|
+
"provenance": true
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "tsup && bht-registry-docgen",
|
|
57
|
+
"dev": "tsup --watch",
|
|
58
|
+
"lint": "eslint . --max-warnings 0",
|
|
59
|
+
"check-types": "tsc --noEmit",
|
|
60
|
+
"test": "vitest run"
|
|
61
|
+
}
|
|
6
62
|
}
|