@react-cupertino-ui/checkbox 1.0.1
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 +24 -0
- package/dist/index.css +123 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +23 -0
- package/dist/index.scss +128 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Anderson Lima
|
|
4
|
+
|
|
5
|
+
This project is inspired by Apple's design principles but is not affiliated with, endorsed, or sponsored by Apple Inc.
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in all
|
|
16
|
+
copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
24
|
+
SOFTWARE.
|
package/dist/index.css
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
.react-cupertino-ui-checkbox {
|
|
2
|
+
--checkbox-size: 1.4rem;
|
|
3
|
+
--checkbox-padding: 0.45rem;
|
|
4
|
+
--checkbox-gap: 0.75rem;
|
|
5
|
+
display: inline-flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
gap: var(--checkbox-gap);
|
|
8
|
+
cursor: pointer;
|
|
9
|
+
user-select: none;
|
|
10
|
+
position: relative;
|
|
11
|
+
}
|
|
12
|
+
.react-cupertino-ui-checkbox[data-disabled=true] {
|
|
13
|
+
opacity: 0.55;
|
|
14
|
+
cursor: not-allowed;
|
|
15
|
+
}
|
|
16
|
+
.react-cupertino-ui-checkbox__input {
|
|
17
|
+
position: absolute;
|
|
18
|
+
opacity: 0;
|
|
19
|
+
pointer-events: none;
|
|
20
|
+
}
|
|
21
|
+
.react-cupertino-ui-checkbox__control {
|
|
22
|
+
width: var(--checkbox-size);
|
|
23
|
+
height: var(--checkbox-size);
|
|
24
|
+
border-radius: 0.65rem;
|
|
25
|
+
position: relative;
|
|
26
|
+
display: inline-flex;
|
|
27
|
+
align-items: center;
|
|
28
|
+
justify-content: center;
|
|
29
|
+
padding: var(--checkbox-padding);
|
|
30
|
+
}
|
|
31
|
+
.react-cupertino-ui-checkbox__box {
|
|
32
|
+
width: 100%;
|
|
33
|
+
height: 100%;
|
|
34
|
+
border-radius: inherit;
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
justify-content: center;
|
|
38
|
+
position: relative;
|
|
39
|
+
transition: background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
|
|
40
|
+
background: rgba(255, 255, 255, 0.55);
|
|
41
|
+
backdrop-filter: blur(28px) saturate(var(--glass-saturation, 180%));
|
|
42
|
+
-webkit-backdrop-filter: blur(28px) saturate(var(--glass-saturation, 180%));
|
|
43
|
+
border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.18));
|
|
44
|
+
box-shadow: var(--glass-shadow, 0 8px 32px rgba(0, 0, 0, 0.12));
|
|
45
|
+
position: relative;
|
|
46
|
+
overflow: hidden;
|
|
47
|
+
}
|
|
48
|
+
.react-cupertino-ui-checkbox__box::before {
|
|
49
|
+
content: "";
|
|
50
|
+
position: absolute;
|
|
51
|
+
inset: 0;
|
|
52
|
+
background: var(--glass-highlight, linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, transparent 55%));
|
|
53
|
+
border-radius: inherit;
|
|
54
|
+
opacity: var(--glass-highlight-opacity, 0.95);
|
|
55
|
+
pointer-events: none;
|
|
56
|
+
mix-blend-mode: screen;
|
|
57
|
+
}
|
|
58
|
+
.react-cupertino-ui-checkbox__icon {
|
|
59
|
+
width: 0.9rem;
|
|
60
|
+
height: 0.9rem;
|
|
61
|
+
color: #0a0a0a;
|
|
62
|
+
opacity: 0;
|
|
63
|
+
transform: scale(0.4);
|
|
64
|
+
transition: opacity 180ms ease, transform 180ms ease;
|
|
65
|
+
}
|
|
66
|
+
.react-cupertino-ui-checkbox__text {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-direction: column;
|
|
69
|
+
gap: 0.15rem;
|
|
70
|
+
}
|
|
71
|
+
.react-cupertino-ui-checkbox__label {
|
|
72
|
+
font-size: 0.95rem;
|
|
73
|
+
font-weight: 600;
|
|
74
|
+
color: hsl(var(--foreground));
|
|
75
|
+
}
|
|
76
|
+
.react-cupertino-ui-checkbox__helper {
|
|
77
|
+
font-size: 0.8rem;
|
|
78
|
+
color: hsl(var(--muted-foreground));
|
|
79
|
+
}
|
|
80
|
+
.react-cupertino-ui-checkbox__error {
|
|
81
|
+
font-size: 0.8rem;
|
|
82
|
+
color: var(--pink);
|
|
83
|
+
}
|
|
84
|
+
.react-cupertino-ui-checkbox.size-sm {
|
|
85
|
+
--checkbox-size: 1.15rem;
|
|
86
|
+
--checkbox-padding: 0.35rem;
|
|
87
|
+
--checkbox-gap: 0.6rem;
|
|
88
|
+
}
|
|
89
|
+
.react-cupertino-ui-checkbox.size-sm__label {
|
|
90
|
+
font-size: 0.85rem;
|
|
91
|
+
}
|
|
92
|
+
.react-cupertino-ui-checkbox.size-lg {
|
|
93
|
+
--checkbox-size: 1.7rem;
|
|
94
|
+
--checkbox-padding: 0.55rem;
|
|
95
|
+
--checkbox-gap: 0.85rem;
|
|
96
|
+
}
|
|
97
|
+
.react-cupertino-ui-checkbox.size-lg__label {
|
|
98
|
+
font-size: 1.05rem;
|
|
99
|
+
}
|
|
100
|
+
.react-cupertino-ui-checkbox.variant-solid .react-cupertino-ui-checkbox__box {
|
|
101
|
+
background: linear-gradient(120deg, rgba(10, 132, 255, 0.95), rgba(90, 200, 250, 0.95));
|
|
102
|
+
box-shadow: 0 8px 25px rgba(10, 132, 255, 0.35);
|
|
103
|
+
}
|
|
104
|
+
.react-cupertino-ui-checkbox.variant-outline .react-cupertino-ui-checkbox__box {
|
|
105
|
+
background: rgba(255, 255, 255, 0.1);
|
|
106
|
+
border: 1px solid rgba(255, 255, 255, 0.4);
|
|
107
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
|
|
108
|
+
}
|
|
109
|
+
.react-cupertino-ui-checkbox[data-error=true] .react-cupertino-ui-checkbox__box {
|
|
110
|
+
box-shadow: 0 0 0 2px rgba(255, 45, 85, 0.25);
|
|
111
|
+
}
|
|
112
|
+
.react-cupertino-ui-checkbox:focus-within .react-cupertino-ui-checkbox__box {
|
|
113
|
+
box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.25);
|
|
114
|
+
}
|
|
115
|
+
.react-cupertino-ui-checkbox__input:checked ~ .react-cupertino-ui-checkbox__control .react-cupertino-ui-checkbox__box, .react-cupertino-ui-checkbox__input:indeterminate ~ .react-cupertino-ui-checkbox__control .react-cupertino-ui-checkbox__box {
|
|
116
|
+
background: linear-gradient(120deg, rgba(10, 132, 255, 0.95), rgba(90, 200, 250, 0.95));
|
|
117
|
+
border-color: transparent;
|
|
118
|
+
box-shadow: 0 8px 25px rgba(10, 132, 255, 0.35);
|
|
119
|
+
}
|
|
120
|
+
.react-cupertino-ui-checkbox__input:checked ~ .react-cupertino-ui-checkbox__control .react-cupertino-ui-checkbox__icon, .react-cupertino-ui-checkbox__input:indeterminate ~ .react-cupertino-ui-checkbox__control .react-cupertino-ui-checkbox__icon {
|
|
121
|
+
opacity: 1;
|
|
122
|
+
transform: scale(1);
|
|
123
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import "./index.scss";
|
|
3
|
+
export interface CheckboxProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "size" | "onBlur" | "onFocus"> {
|
|
4
|
+
className?: string;
|
|
5
|
+
size?: "default" | "sm" | "lg";
|
|
6
|
+
label?: string;
|
|
7
|
+
helperText?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
variant?: "glass" | "solid" | "outline";
|
|
10
|
+
onFocus?: React.FocusEventHandler<HTMLInputElement>;
|
|
11
|
+
onBlur?: React.FocusEventHandler<HTMLInputElement>;
|
|
12
|
+
indeterminate?: boolean;
|
|
13
|
+
}
|
|
14
|
+
declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLInputElement>>;
|
|
15
|
+
export { Checkbox };
|
|
16
|
+
export default Checkbox;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Check } from "lucide-react";
|
|
4
|
+
import { cn } from "@react-cupertino-ui/shared/lib/utils";
|
|
5
|
+
import "./index.scss";
|
|
6
|
+
const Checkbox = React.forwardRef(({ className, size = "default", variant = "glass", label, helperText, error, id, disabled, onFocus, onBlur, indeterminate, ...props }, forwardedRef) => {
|
|
7
|
+
const generatedId = React.useId();
|
|
8
|
+
const checkboxId = id ?? `checkbox-${generatedId}`;
|
|
9
|
+
const helperId = helperText ? `${checkboxId}-helper` : undefined;
|
|
10
|
+
const errorId = error ? `${checkboxId}-error` : undefined;
|
|
11
|
+
const messageId = error ? errorId : helperId;
|
|
12
|
+
const internalRef = React.useRef(null);
|
|
13
|
+
React.useImperativeHandle(forwardedRef, () => internalRef.current);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
if (internalRef.current) {
|
|
16
|
+
internalRef.current.indeterminate = Boolean(indeterminate);
|
|
17
|
+
}
|
|
18
|
+
}, [indeterminate]);
|
|
19
|
+
return (_jsxs("label", { className: cn("react-cupertino-ui-checkbox", `size-${size}`, `variant-${variant}`, className), "data-disabled": disabled ? "true" : undefined, "data-error": error ? "true" : undefined, htmlFor: checkboxId, children: [_jsx("input", { ref: internalRef, id: checkboxId, type: "checkbox", className: "react-cupertino-ui-checkbox__input", disabled: disabled, "aria-describedby": messageId, onFocus: onFocus, onBlur: onBlur, ...props }), _jsx("span", { className: "react-cupertino-ui-checkbox__control", "aria-hidden": "true", children: _jsx("span", { className: "react-cupertino-ui-checkbox__box", children: _jsx(Check, { className: "react-cupertino-ui-checkbox__icon" }) }) }), (label || helperText || error) && (_jsxs("span", { className: "react-cupertino-ui-checkbox__text", children: [label && _jsx("span", { className: "react-cupertino-ui-checkbox__label", children: label }), helperText && !error && (_jsx("span", { id: helperId, className: "react-cupertino-ui-checkbox__helper", children: helperText })), error && (_jsx("span", { id: errorId, className: "react-cupertino-ui-checkbox__error", role: "alert", children: error }))] }))] }));
|
|
20
|
+
});
|
|
21
|
+
Checkbox.displayName = "Checkbox";
|
|
22
|
+
export { Checkbox };
|
|
23
|
+
export default Checkbox;
|
package/dist/index.scss
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
@use "@/styles/mixins/glass" as glass;
|
|
2
|
+
|
|
3
|
+
.react-cupertino-ui-checkbox {
|
|
4
|
+
--checkbox-size: 1.4rem;
|
|
5
|
+
--checkbox-padding: 0.45rem;
|
|
6
|
+
--checkbox-gap: 0.75rem;
|
|
7
|
+
display: inline-flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
gap: var(--checkbox-gap);
|
|
10
|
+
cursor: pointer;
|
|
11
|
+
user-select: none;
|
|
12
|
+
position: relative;
|
|
13
|
+
|
|
14
|
+
&[data-disabled="true"] {
|
|
15
|
+
opacity: 0.55;
|
|
16
|
+
cursor: not-allowed;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&__input {
|
|
20
|
+
position: absolute;
|
|
21
|
+
opacity: 0;
|
|
22
|
+
pointer-events: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
&__control {
|
|
26
|
+
width: var(--checkbox-size);
|
|
27
|
+
height: var(--checkbox-size);
|
|
28
|
+
border-radius: 0.65rem;
|
|
29
|
+
position: relative;
|
|
30
|
+
display: inline-flex;
|
|
31
|
+
align-items: center;
|
|
32
|
+
justify-content: center;
|
|
33
|
+
padding: var(--checkbox-padding);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
&__box {
|
|
37
|
+
width: 100%;
|
|
38
|
+
height: 100%;
|
|
39
|
+
border-radius: inherit;
|
|
40
|
+
display: inline-flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
position: relative;
|
|
44
|
+
transition: background 200ms ease, border-color 200ms ease, box-shadow 200ms ease;
|
|
45
|
+
@include glass.glass-panel(light, 28px, 0.55);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
&__icon {
|
|
49
|
+
width: 0.9rem;
|
|
50
|
+
height: 0.9rem;
|
|
51
|
+
color: #0a0a0a;
|
|
52
|
+
opacity: 0;
|
|
53
|
+
transform: scale(0.4);
|
|
54
|
+
transition: opacity 180ms ease, transform 180ms ease;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
&__text {
|
|
58
|
+
display: flex;
|
|
59
|
+
flex-direction: column;
|
|
60
|
+
gap: 0.15rem;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&__label {
|
|
64
|
+
font-size: 0.95rem;
|
|
65
|
+
font-weight: 600;
|
|
66
|
+
color: hsl(var(--foreground));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
&__helper {
|
|
70
|
+
font-size: 0.8rem;
|
|
71
|
+
color: hsl(var(--muted-foreground));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
&__error {
|
|
75
|
+
font-size: 0.8rem;
|
|
76
|
+
color: var(--pink);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
&.size-sm {
|
|
80
|
+
--checkbox-size: 1.15rem;
|
|
81
|
+
--checkbox-padding: 0.35rem;
|
|
82
|
+
--checkbox-gap: 0.6rem;
|
|
83
|
+
&__label {
|
|
84
|
+
font-size: 0.85rem;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
&.size-lg {
|
|
89
|
+
--checkbox-size: 1.7rem;
|
|
90
|
+
--checkbox-padding: 0.55rem;
|
|
91
|
+
--checkbox-gap: 0.85rem;
|
|
92
|
+
&__label {
|
|
93
|
+
font-size: 1.05rem;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
&.variant-solid &__box {
|
|
98
|
+
background: linear-gradient(120deg, rgba(10, 132, 255, 0.95), rgba(90, 200, 250, 0.95));
|
|
99
|
+
box-shadow: 0 8px 25px rgba(10, 132, 255, 0.35);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&.variant-outline &__box {
|
|
103
|
+
background: rgba(255, 255, 255, 0.1);
|
|
104
|
+
border: 1px solid rgba(255, 255, 255, 0.4);
|
|
105
|
+
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
&[data-error="true"] &__box {
|
|
109
|
+
box-shadow: 0 0 0 2px rgba(255, 45, 85, 0.25);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
&:focus-within &__box {
|
|
113
|
+
box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.25);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
&__input:checked ~ &__control &__box,
|
|
117
|
+
&__input:indeterminate ~ &__control &__box {
|
|
118
|
+
background: linear-gradient(120deg, rgba(10, 132, 255, 0.95), rgba(90, 200, 250, 0.95));
|
|
119
|
+
border-color: transparent;
|
|
120
|
+
box-shadow: 0 8px 25px rgba(10, 132, 255, 0.35);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
&__input:checked ~ &__control &__icon,
|
|
124
|
+
&__input:indeterminate ~ &__control &__icon {
|
|
125
|
+
opacity: 1;
|
|
126
|
+
transform: scale(1);
|
|
127
|
+
}
|
|
128
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-cupertino-ui/checkbox",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Checkbox component from React Cupertino UI",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./dist/**/*.css",
|
|
14
|
+
"./dist/**/*.scss"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsc -p tsconfig.build.json && npm run build:styles",
|
|
18
|
+
"build:styles": "node ../../../scripts/build-styles.mjs"
|
|
19
|
+
},
|
|
20
|
+
"peerDependencies": {
|
|
21
|
+
"react": "^18.3.1",
|
|
22
|
+
"react-dom": "^18.3.1"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@react-cupertino-ui/shared": "workspace:*",
|
|
26
|
+
"lucide-react": "^0.417.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"typescript": "^5.2.2"
|
|
30
|
+
},
|
|
31
|
+
"gitHead": "3f53987bdb936a331665691b517c2ba9984777f8",
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
}
|
|
35
|
+
}
|