@glob-ui/checkbox 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +16 -2
- package/dist/index.d.mts +15 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +174 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +149 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +65 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Martínez E
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @glob-ui/checkbox
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A native checkbox with a label, sizes, and an indeterminate state for groups.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @glob-ui/checkbox
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
Full docs, examples and the accessibility table: [Checkbox](https://github.com/kevin-martineze/GlobUI/tree/main/apps/docs/content/docs/components/checkbox.mdx).
|
|
14
|
+
|
|
15
|
+
## License
|
|
16
|
+
|
|
17
|
+
MIT. See [LICENSE](./LICENSE).
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
declare const checkboxVariants: (props?: ({
|
|
6
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
7
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
8
|
+
interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size">, VariantProps<typeof checkboxVariants> {
|
|
9
|
+
/** Shows a dash instead of a check. Not a checked state; the browser clears it on click. */
|
|
10
|
+
indeterminate?: boolean;
|
|
11
|
+
label?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare const Checkbox: react.ForwardRefExoticComponent<CheckboxProps & react.RefAttributes<HTMLInputElement>>;
|
|
14
|
+
|
|
15
|
+
export { Checkbox, type CheckboxProps, checkboxVariants };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import * as class_variance_authority_types from 'class-variance-authority/types';
|
|
3
|
+
import { VariantProps } from 'class-variance-authority';
|
|
4
|
+
|
|
5
|
+
declare const checkboxVariants: (props?: ({
|
|
6
|
+
size?: "sm" | "md" | "lg" | null | undefined;
|
|
7
|
+
} & class_variance_authority_types.ClassProp) | undefined) => string;
|
|
8
|
+
interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "type" | "size">, VariantProps<typeof checkboxVariants> {
|
|
9
|
+
/** Shows a dash instead of a check. Not a checked state; the browser clears it on click. */
|
|
10
|
+
indeterminate?: boolean;
|
|
11
|
+
label?: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
declare const Checkbox: react.ForwardRefExoticComponent<CheckboxProps & react.RefAttributes<HTMLInputElement>>;
|
|
14
|
+
|
|
15
|
+
export { Checkbox, type CheckboxProps, checkboxVariants };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __export = (target, all) => {
|
|
34
|
+
for (var name in all)
|
|
35
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
36
|
+
};
|
|
37
|
+
var __copyProps = (to, from, except, desc) => {
|
|
38
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
+
for (let key of __getOwnPropNames(from))
|
|
40
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
41
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
42
|
+
}
|
|
43
|
+
return to;
|
|
44
|
+
};
|
|
45
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
+
|
|
47
|
+
// src/index.ts
|
|
48
|
+
var index_exports = {};
|
|
49
|
+
__export(index_exports, {
|
|
50
|
+
Checkbox: () => Checkbox,
|
|
51
|
+
checkboxVariants: () => checkboxVariants
|
|
52
|
+
});
|
|
53
|
+
module.exports = __toCommonJS(index_exports);
|
|
54
|
+
|
|
55
|
+
// src/checkbox.tsx
|
|
56
|
+
var import_react = require("react");
|
|
57
|
+
var import_class_variance_authority = require("class-variance-authority");
|
|
58
|
+
var import_utils = require("@glob-ui/utils");
|
|
59
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
60
|
+
var checkboxVariants = (0, import_class_variance_authority.cva)(
|
|
61
|
+
"peer shrink-0 cursor-pointer appearance-none rounded-glob-sm border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary indeterminate:border-glob-primary indeterminate:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-glob-danger",
|
|
62
|
+
{
|
|
63
|
+
variants: {
|
|
64
|
+
size: {
|
|
65
|
+
sm: "h-4 w-4",
|
|
66
|
+
md: "h-5 w-5",
|
|
67
|
+
lg: "h-6 w-6"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
defaultVariants: {
|
|
71
|
+
size: "md"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
);
|
|
75
|
+
var labelSize = {
|
|
76
|
+
sm: "text-xs",
|
|
77
|
+
md: "text-sm",
|
|
78
|
+
lg: "text-base"
|
|
79
|
+
};
|
|
80
|
+
var Checkbox = (0, import_react.forwardRef)(
|
|
81
|
+
(_a, ref) => {
|
|
82
|
+
var _b = _a, {
|
|
83
|
+
className,
|
|
84
|
+
size,
|
|
85
|
+
indeterminate = false,
|
|
86
|
+
label,
|
|
87
|
+
id,
|
|
88
|
+
disabled,
|
|
89
|
+
"aria-labelledby": labelledByProp
|
|
90
|
+
} = _b, props = __objRest(_b, [
|
|
91
|
+
"className",
|
|
92
|
+
"size",
|
|
93
|
+
"indeterminate",
|
|
94
|
+
"label",
|
|
95
|
+
"id",
|
|
96
|
+
"disabled",
|
|
97
|
+
"aria-labelledby"
|
|
98
|
+
]);
|
|
99
|
+
const innerRef = (0, import_react.useRef)(null);
|
|
100
|
+
(0, import_react.useImperativeHandle)(ref, () => innerRef.current);
|
|
101
|
+
(0, import_react.useEffect)(() => {
|
|
102
|
+
if (innerRef.current) innerRef.current.indeterminate = indeterminate;
|
|
103
|
+
}, [indeterminate]);
|
|
104
|
+
const autoId = (0, import_react.useId)();
|
|
105
|
+
const inputId = id != null ? id : autoId;
|
|
106
|
+
const labelId = `${inputId}-label`;
|
|
107
|
+
const labelledBy = labelledByProp && label ? `${labelledByProp} ${labelId}` : labelledByProp;
|
|
108
|
+
const s = size != null ? size : "md";
|
|
109
|
+
const control = /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "relative inline-flex shrink-0", children: [
|
|
110
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
111
|
+
"input",
|
|
112
|
+
__spreadValues({
|
|
113
|
+
ref: innerRef,
|
|
114
|
+
type: "checkbox",
|
|
115
|
+
id: inputId,
|
|
116
|
+
disabled,
|
|
117
|
+
"aria-labelledby": labelledBy,
|
|
118
|
+
className: (0, import_utils.cn)(checkboxVariants({ size, className }))
|
|
119
|
+
}, props)
|
|
120
|
+
),
|
|
121
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
122
|
+
"svg",
|
|
123
|
+
{
|
|
124
|
+
"aria-hidden": "true",
|
|
125
|
+
viewBox: "0 0 24 24",
|
|
126
|
+
fill: "none",
|
|
127
|
+
stroke: "currentColor",
|
|
128
|
+
strokeWidth: "3",
|
|
129
|
+
strokeLinecap: "round",
|
|
130
|
+
strokeLinejoin: "round",
|
|
131
|
+
className: "pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-[:checked:not(:indeterminate)]:block",
|
|
132
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 12l5 5 9-10" })
|
|
133
|
+
}
|
|
134
|
+
),
|
|
135
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
136
|
+
"svg",
|
|
137
|
+
{
|
|
138
|
+
"aria-hidden": "true",
|
|
139
|
+
viewBox: "0 0 24 24",
|
|
140
|
+
fill: "none",
|
|
141
|
+
stroke: "currentColor",
|
|
142
|
+
strokeWidth: "3",
|
|
143
|
+
strokeLinecap: "round",
|
|
144
|
+
className: "pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-indeterminate:block",
|
|
145
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M6 12h12" })
|
|
146
|
+
}
|
|
147
|
+
)
|
|
148
|
+
] });
|
|
149
|
+
if (!label) return control;
|
|
150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "inline-flex items-center gap-2", children: [
|
|
151
|
+
control,
|
|
152
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
153
|
+
"label",
|
|
154
|
+
{
|
|
155
|
+
id: labelId,
|
|
156
|
+
htmlFor: inputId,
|
|
157
|
+
className: (0, import_utils.cn)(
|
|
158
|
+
"cursor-pointer text-glob-text",
|
|
159
|
+
labelSize[s],
|
|
160
|
+
disabled && "cursor-not-allowed opacity-50"
|
|
161
|
+
),
|
|
162
|
+
children: label
|
|
163
|
+
}
|
|
164
|
+
)
|
|
165
|
+
] });
|
|
166
|
+
}
|
|
167
|
+
);
|
|
168
|
+
Checkbox.displayName = "Checkbox";
|
|
169
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
170
|
+
0 && (module.exports = {
|
|
171
|
+
Checkbox,
|
|
172
|
+
checkboxVariants
|
|
173
|
+
});
|
|
174
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/checkbox.tsx"],"sourcesContent":["export { Checkbox, checkboxVariants } from \"./checkbox\"\nexport type { CheckboxProps } from \"./checkbox\"\n","\"use client\"\n\nimport { forwardRef, useEffect, useId, useImperativeHandle, useRef } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\n\nconst checkboxVariants = cva(\n \"peer shrink-0 cursor-pointer appearance-none rounded-glob-sm border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary indeterminate:border-glob-primary indeterminate:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-glob-danger\",\n {\n variants: {\n size: {\n sm: \"h-4 w-4\",\n md: \"h-5 w-5\",\n lg: \"h-6 w-6\",\n },\n },\n defaultVariants: {\n size: \"md\",\n },\n }\n)\n\nconst labelSize = {\n sm: \"text-xs\",\n md: \"text-sm\",\n lg: \"text-base\",\n}\n\nexport interface CheckboxProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"type\" | \"size\">,\n VariantProps<typeof checkboxVariants> {\n /** Shows a dash instead of a check. Not a checked state; the browser clears it on click. */\n indeterminate?: boolean\n label?: React.ReactNode\n}\n\nconst Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(\n (\n {\n className,\n size,\n indeterminate = false,\n label,\n id,\n disabled,\n \"aria-labelledby\": labelledByProp,\n ...props\n },\n ref\n ) => {\n const innerRef = useRef<HTMLInputElement>(null)\n useImperativeHandle(ref, () => innerRef.current as HTMLInputElement)\n\n // `indeterminate` only exists as a DOM property, not an HTML attribute.\n useEffect(() => {\n if (innerRef.current) innerRef.current.indeterminate = indeterminate\n }, [indeterminate])\n\n const autoId = useId()\n const inputId = id ?? autoId\n const labelId = `${inputId}-label`\n // aria-labelledby (e.g. from Field) replaces the native <label for> name. Append our own\n // label so the name stays \"Field label + checkbox label\", like several <label for> would.\n const labelledBy = labelledByProp && label ? `${labelledByProp} ${labelId}` : labelledByProp\n const s = size ?? \"md\"\n\n const control = (\n <span className=\"relative inline-flex shrink-0\">\n <input\n ref={innerRef}\n type=\"checkbox\"\n id={inputId}\n disabled={disabled}\n aria-labelledby={labelledBy}\n className={cn(checkboxVariants({ size, className }))}\n {...props}\n />\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-[:checked:not(:indeterminate)]:block\"\n >\n <path d=\"M5 12l5 5 9-10\" />\n </svg>\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n className=\"pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-indeterminate:block\"\n >\n <path d=\"M6 12h12\" />\n </svg>\n </span>\n )\n\n if (!label) return control\n\n return (\n <span className=\"inline-flex items-center gap-2\">\n {control}\n <label\n id={labelId}\n htmlFor={inputId}\n className={cn(\n \"cursor-pointer text-glob-text\",\n labelSize[s],\n disabled && \"cursor-not-allowed opacity-50\"\n )}\n >\n {label}\n </label>\n </span>\n )\n }\n)\nCheckbox.displayName = \"Checkbox\"\n\nexport { Checkbox, checkboxVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,mBAA0E;AAC1E,sCAAuC;AACvC,mBAAmB;AA+Db;AA7DN,IAAM,uBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,IAAM,YAAY;AAAA,EAChB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAUA,IAAM,eAAW;AAAA,EACf,CACE,IAUA,QACG;AAXH,iBACE;AAAA;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA,IA7CzB,IAsCI,IAQK,kBARL,IAQK;AAAA,MAPH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAKF,UAAM,eAAW,qBAAyB,IAAI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AAA,MACH;AAAA,OACF;AAAA,EAEJ;AACF;AACA,SAAS,cAAc;","names":[]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
7
|
+
var __spreadValues = (a, b) => {
|
|
8
|
+
for (var prop in b || (b = {}))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
11
|
+
if (__getOwnPropSymbols)
|
|
12
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
}
|
|
16
|
+
return a;
|
|
17
|
+
};
|
|
18
|
+
var __objRest = (source, exclude) => {
|
|
19
|
+
var target = {};
|
|
20
|
+
for (var prop in source)
|
|
21
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
22
|
+
target[prop] = source[prop];
|
|
23
|
+
if (source != null && __getOwnPropSymbols)
|
|
24
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
25
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
26
|
+
target[prop] = source[prop];
|
|
27
|
+
}
|
|
28
|
+
return target;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/checkbox.tsx
|
|
32
|
+
import { forwardRef, useEffect, useId, useImperativeHandle, useRef } from "react";
|
|
33
|
+
import { cva } from "class-variance-authority";
|
|
34
|
+
import { cn } from "@glob-ui/utils";
|
|
35
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
36
|
+
var checkboxVariants = cva(
|
|
37
|
+
"peer shrink-0 cursor-pointer appearance-none rounded-glob-sm border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary indeterminate:border-glob-primary indeterminate:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-glob-danger",
|
|
38
|
+
{
|
|
39
|
+
variants: {
|
|
40
|
+
size: {
|
|
41
|
+
sm: "h-4 w-4",
|
|
42
|
+
md: "h-5 w-5",
|
|
43
|
+
lg: "h-6 w-6"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
defaultVariants: {
|
|
47
|
+
size: "md"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
var labelSize = {
|
|
52
|
+
sm: "text-xs",
|
|
53
|
+
md: "text-sm",
|
|
54
|
+
lg: "text-base"
|
|
55
|
+
};
|
|
56
|
+
var Checkbox = forwardRef(
|
|
57
|
+
(_a, ref) => {
|
|
58
|
+
var _b = _a, {
|
|
59
|
+
className,
|
|
60
|
+
size,
|
|
61
|
+
indeterminate = false,
|
|
62
|
+
label,
|
|
63
|
+
id,
|
|
64
|
+
disabled,
|
|
65
|
+
"aria-labelledby": labelledByProp
|
|
66
|
+
} = _b, props = __objRest(_b, [
|
|
67
|
+
"className",
|
|
68
|
+
"size",
|
|
69
|
+
"indeterminate",
|
|
70
|
+
"label",
|
|
71
|
+
"id",
|
|
72
|
+
"disabled",
|
|
73
|
+
"aria-labelledby"
|
|
74
|
+
]);
|
|
75
|
+
const innerRef = useRef(null);
|
|
76
|
+
useImperativeHandle(ref, () => innerRef.current);
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (innerRef.current) innerRef.current.indeterminate = indeterminate;
|
|
79
|
+
}, [indeterminate]);
|
|
80
|
+
const autoId = useId();
|
|
81
|
+
const inputId = id != null ? id : autoId;
|
|
82
|
+
const labelId = `${inputId}-label`;
|
|
83
|
+
const labelledBy = labelledByProp && label ? `${labelledByProp} ${labelId}` : labelledByProp;
|
|
84
|
+
const s = size != null ? size : "md";
|
|
85
|
+
const control = /* @__PURE__ */ jsxs("span", { className: "relative inline-flex shrink-0", children: [
|
|
86
|
+
/* @__PURE__ */ jsx(
|
|
87
|
+
"input",
|
|
88
|
+
__spreadValues({
|
|
89
|
+
ref: innerRef,
|
|
90
|
+
type: "checkbox",
|
|
91
|
+
id: inputId,
|
|
92
|
+
disabled,
|
|
93
|
+
"aria-labelledby": labelledBy,
|
|
94
|
+
className: cn(checkboxVariants({ size, className }))
|
|
95
|
+
}, props)
|
|
96
|
+
),
|
|
97
|
+
/* @__PURE__ */ jsx(
|
|
98
|
+
"svg",
|
|
99
|
+
{
|
|
100
|
+
"aria-hidden": "true",
|
|
101
|
+
viewBox: "0 0 24 24",
|
|
102
|
+
fill: "none",
|
|
103
|
+
stroke: "currentColor",
|
|
104
|
+
strokeWidth: "3",
|
|
105
|
+
strokeLinecap: "round",
|
|
106
|
+
strokeLinejoin: "round",
|
|
107
|
+
className: "pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-[:checked:not(:indeterminate)]:block",
|
|
108
|
+
children: /* @__PURE__ */ jsx("path", { d: "M5 12l5 5 9-10" })
|
|
109
|
+
}
|
|
110
|
+
),
|
|
111
|
+
/* @__PURE__ */ jsx(
|
|
112
|
+
"svg",
|
|
113
|
+
{
|
|
114
|
+
"aria-hidden": "true",
|
|
115
|
+
viewBox: "0 0 24 24",
|
|
116
|
+
fill: "none",
|
|
117
|
+
stroke: "currentColor",
|
|
118
|
+
strokeWidth: "3",
|
|
119
|
+
strokeLinecap: "round",
|
|
120
|
+
className: "pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-indeterminate:block",
|
|
121
|
+
children: /* @__PURE__ */ jsx("path", { d: "M6 12h12" })
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] });
|
|
125
|
+
if (!label) return control;
|
|
126
|
+
return /* @__PURE__ */ jsxs("span", { className: "inline-flex items-center gap-2", children: [
|
|
127
|
+
control,
|
|
128
|
+
/* @__PURE__ */ jsx(
|
|
129
|
+
"label",
|
|
130
|
+
{
|
|
131
|
+
id: labelId,
|
|
132
|
+
htmlFor: inputId,
|
|
133
|
+
className: cn(
|
|
134
|
+
"cursor-pointer text-glob-text",
|
|
135
|
+
labelSize[s],
|
|
136
|
+
disabled && "cursor-not-allowed opacity-50"
|
|
137
|
+
),
|
|
138
|
+
children: label
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
] });
|
|
142
|
+
}
|
|
143
|
+
);
|
|
144
|
+
Checkbox.displayName = "Checkbox";
|
|
145
|
+
export {
|
|
146
|
+
Checkbox,
|
|
147
|
+
checkboxVariants
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/checkbox.tsx"],"sourcesContent":["\"use client\"\n\nimport { forwardRef, useEffect, useId, useImperativeHandle, useRef } from \"react\"\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport { cn } from \"@glob-ui/utils\"\n\nconst checkboxVariants = cva(\n \"peer shrink-0 cursor-pointer appearance-none rounded-glob-sm border border-glob-border-strong bg-glob-surface transition-colors checked:border-glob-primary checked:bg-glob-primary indeterminate:border-glob-primary indeterminate:bg-glob-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-glob-ring disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-glob-danger\",\n {\n variants: {\n size: {\n sm: \"h-4 w-4\",\n md: \"h-5 w-5\",\n lg: \"h-6 w-6\",\n },\n },\n defaultVariants: {\n size: \"md\",\n },\n }\n)\n\nconst labelSize = {\n sm: \"text-xs\",\n md: \"text-sm\",\n lg: \"text-base\",\n}\n\nexport interface CheckboxProps\n extends Omit<React.InputHTMLAttributes<HTMLInputElement>, \"type\" | \"size\">,\n VariantProps<typeof checkboxVariants> {\n /** Shows a dash instead of a check. Not a checked state; the browser clears it on click. */\n indeterminate?: boolean\n label?: React.ReactNode\n}\n\nconst Checkbox = forwardRef<HTMLInputElement, CheckboxProps>(\n (\n {\n className,\n size,\n indeterminate = false,\n label,\n id,\n disabled,\n \"aria-labelledby\": labelledByProp,\n ...props\n },\n ref\n ) => {\n const innerRef = useRef<HTMLInputElement>(null)\n useImperativeHandle(ref, () => innerRef.current as HTMLInputElement)\n\n // `indeterminate` only exists as a DOM property, not an HTML attribute.\n useEffect(() => {\n if (innerRef.current) innerRef.current.indeterminate = indeterminate\n }, [indeterminate])\n\n const autoId = useId()\n const inputId = id ?? autoId\n const labelId = `${inputId}-label`\n // aria-labelledby (e.g. from Field) replaces the native <label for> name. Append our own\n // label so the name stays \"Field label + checkbox label\", like several <label for> would.\n const labelledBy = labelledByProp && label ? `${labelledByProp} ${labelId}` : labelledByProp\n const s = size ?? \"md\"\n\n const control = (\n <span className=\"relative inline-flex shrink-0\">\n <input\n ref={innerRef}\n type=\"checkbox\"\n id={inputId}\n disabled={disabled}\n aria-labelledby={labelledBy}\n className={cn(checkboxVariants({ size, className }))}\n {...props}\n />\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n className=\"pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-[:checked:not(:indeterminate)]:block\"\n >\n <path d=\"M5 12l5 5 9-10\" />\n </svg>\n <svg\n aria-hidden=\"true\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"3\"\n strokeLinecap=\"round\"\n className=\"pointer-events-none absolute inset-0 m-auto hidden h-3/4 w-3/4 text-glob-primary-foreground peer-indeterminate:block\"\n >\n <path d=\"M6 12h12\" />\n </svg>\n </span>\n )\n\n if (!label) return control\n\n return (\n <span className=\"inline-flex items-center gap-2\">\n {control}\n <label\n id={labelId}\n htmlFor={inputId}\n className={cn(\n \"cursor-pointer text-glob-text\",\n labelSize[s],\n disabled && \"cursor-not-allowed opacity-50\"\n )}\n >\n {label}\n </label>\n </span>\n )\n }\n)\nCheckbox.displayName = \"Checkbox\"\n\nexport { Checkbox, checkboxVariants }\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,YAAY,WAAW,OAAO,qBAAqB,cAAc;AAC1E,SAAS,WAA8B;AACvC,SAAS,UAAU;AA+Db,SACE,KADF;AA7DN,IAAM,mBAAmB;AAAA,EACvB;AAAA,EACA;AAAA,IACE,UAAU;AAAA,MACR,MAAM;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,QACJ,IAAI;AAAA,MACN;AAAA,IACF;AAAA,IACA,iBAAiB;AAAA,MACf,MAAM;AAAA,IACR;AAAA,EACF;AACF;AAEA,IAAM,YAAY;AAAA,EAChB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AACN;AAUA,IAAM,WAAW;AAAA,EACf,CACE,IAUA,QACG;AAXH,iBACE;AAAA;AAAA,MACA;AAAA,MACA,gBAAgB;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA,IA7CzB,IAsCI,IAQK,kBARL,IAQK;AAAA,MAPH;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAKF,UAAM,WAAW,OAAyB,IAAI;AAC9C,wBAAoB,KAAK,MAAM,SAAS,OAA2B;AAGnE,cAAU,MAAM;AACd,UAAI,SAAS,QAAS,UAAS,QAAQ,gBAAgB;AAAA,IACzD,GAAG,CAAC,aAAa,CAAC;AAElB,UAAM,SAAS,MAAM;AACrB,UAAM,UAAU,kBAAM;AACtB,UAAM,UAAU,GAAG,OAAO;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
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"module": "./dist/index.mjs",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.mts",
|
|
11
|
+
"default": "./dist/index.mjs"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/",
|
|
22
|
+
"LICENSE",
|
|
23
|
+
"README.md"
|
|
24
|
+
],
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "^19"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@glob-ui/utils": "0.1.0",
|
|
30
|
+
"class-variance-authority": "^0.7.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"tsup": "^8.5.1"
|
|
34
|
+
},
|
|
35
|
+
"description": "A native checkbox with a label, sizes, and an indeterminate state for groups.",
|
|
36
|
+
"keywords": [
|
|
37
|
+
"react",
|
|
38
|
+
"glob-ui",
|
|
39
|
+
"components",
|
|
40
|
+
"accessible",
|
|
41
|
+
"tailwind",
|
|
42
|
+
"checkbox"
|
|
43
|
+
],
|
|
44
|
+
"license": "MIT",
|
|
45
|
+
"author": "Kevin Martínez E",
|
|
46
|
+
"repository": {
|
|
47
|
+
"type": "git",
|
|
48
|
+
"url": "git+https://github.com/kevin-martineze/GlobUI.git",
|
|
49
|
+
"directory": "packages/checkbox"
|
|
50
|
+
},
|
|
51
|
+
"homepage": "https://github.com/kevin-martineze/GlobUI#readme",
|
|
52
|
+
"bugs": {
|
|
53
|
+
"url": "https://github.com/kevin-martineze/GlobUI/issues"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public",
|
|
57
|
+
"provenance": true
|
|
58
|
+
},
|
|
59
|
+
"sideEffects": false,
|
|
60
|
+
"type": "commonjs",
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=18.18"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup",
|
|
66
|
+
"dev": "tsup --watch --no-clean"
|
|
67
|
+
}
|
|
6
68
|
}
|