@spark-ui/checkbox 1.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/CHANGELOG.md +23 -0
- package/LICENSE +21 -0
- package/dist/Checkbox.d.ts +34 -0
- package/dist/Checkbox.variants.d.ts +5 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +226 -0
- package/package.json +19 -0
- package/tsconfig.json +4 -0
- package/vite.config.ts +6 -0
package/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
|
+
|
6
|
+
# 1.1.0 (2023-03-21)
|
7
|
+
|
8
|
+
### Bug Fixes
|
9
|
+
|
10
|
+
- **checkbox:** solve ts error ([e6fcea3](https://github.com/adevinta/spark/commit/e6fcea3a2ed9d5eb50be31f3e16af38e7b7a9b11))
|
11
|
+
|
12
|
+
### Features
|
13
|
+
|
14
|
+
- **checkbox:** add cva dependency ([866929e](https://github.com/adevinta/spark/commit/866929e4a6bfb0c2ed5a79e7fa6d7ed81549305a))
|
15
|
+
- **checkbox:** add intent prop and use opacity-dim-3 class for disabled components ([54ac320](https://github.com/adevinta/spark/commit/54ac32040d9982daa37ea7ec9ee1d663581170a9))
|
16
|
+
- **checkbox:** add to Form group ([3c89bf0](https://github.com/adevinta/spark/commit/3c89bf08c586e2fbf3bed805f65e4c62b78c2ad5))
|
17
|
+
- **checkbox:** apply PR suggestions to checkbox ([40f353a](https://github.com/adevinta/spark/commit/40f353a7eb99be04ae8753831839c907cd5c38f6))
|
18
|
+
- **checkbox:** basic checkbox component, checkbox disabled and default checked examples ([425f325](https://github.com/adevinta/spark/commit/425f325eb4d2fe02d707fc358fc98c9ef6ddd3fc))
|
19
|
+
- **checkbox:** basic component files ([5d6ab52](https://github.com/adevinta/spark/commit/5d6ab52be1ffbbd5a8fa0c38cdae0b92d48444d4))
|
20
|
+
- **checkbox:** change unchecked border colors for intent variant ([4da81b5](https://github.com/adevinta/spark/commit/4da81b55c9848d19deca5d7d5ed740266aa12d76))
|
21
|
+
- **checkbox:** do not override colors ([cf2a5e0](https://github.com/adevinta/spark/commit/cf2a5e0271a215ad9175894d8b4711a793cffe1c))
|
22
|
+
- **checkbox:** remove from Form directory ([222293b](https://github.com/adevinta/spark/commit/222293b90e7a3967667ed253d655dd1699fc9d61))
|
23
|
+
- **checkbox:** replace variantPrefix radix by spark ([3c8997b](https://github.com/adevinta/spark/commit/3c8997bd9835d7c6954faec68434365e92d0ae0e))
|
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) Meta Platforms, Inc. and affiliates.
|
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.
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
import { type StylesProps } from './Checkbox.variants';
|
3
|
+
interface CheckboxRadixProps {
|
4
|
+
/**
|
5
|
+
* The checked state of the checkbox when it is initially rendered. Use when you do not need to control its checked state.
|
6
|
+
*/
|
7
|
+
defaultChecked?: boolean;
|
8
|
+
/**
|
9
|
+
* The controlled checked state of the checkbox. Must be used in conjunction with onCheckedChange.
|
10
|
+
*/
|
11
|
+
checked?: boolean;
|
12
|
+
/**
|
13
|
+
* Event handler called when the checked state of the checkbox changes.
|
14
|
+
*/
|
15
|
+
onCheckedChange?: (checked: boolean) => void;
|
16
|
+
/**
|
17
|
+
* When true, prevents the user from interacting with the checkbox.
|
18
|
+
*/
|
19
|
+
disabled?: boolean;
|
20
|
+
/**
|
21
|
+
* When true, indicates that the user must check the checkbox before the owning form can be submitted.
|
22
|
+
*/
|
23
|
+
required?: boolean;
|
24
|
+
/**
|
25
|
+
* The name of the checkbox. Submitted with its owning form as part of a name/value pair.
|
26
|
+
*/
|
27
|
+
name?: string;
|
28
|
+
}
|
29
|
+
export interface CheckboxProps extends CheckboxRadixProps, // Radix props
|
30
|
+
StylesProps, // CVA props (variants)
|
31
|
+
Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'value'> {
|
32
|
+
}
|
33
|
+
export declare const Checkbox: React.ForwardRefExoticComponent<CheckboxProps & React.RefAttributes<HTMLButtonElement>>;
|
34
|
+
export {};
|
@@ -0,0 +1,5 @@
|
|
1
|
+
import { VariantProps } from 'class-variance-authority';
|
2
|
+
export declare const styles: (props?: ({
|
3
|
+
intent?: "primary" | "success" | "alert" | "error" | null | undefined;
|
4
|
+
} & import("class-variance-authority/dist/types").ClassProp) | undefined) => string;
|
5
|
+
export type StylesProps = VariantProps<typeof styles>;
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export { Checkbox } from './Checkbox';
|
package/dist/index.js
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),U=require("react-dom"),j=require("class-variance-authority");function g(){return g=Object.assign?Object.assign.bind():function(e){for(var o=1;o<arguments.length;o++){var t=arguments[o];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},g.apply(this,arguments)}function R(...e){return o=>e.forEach(t=>function(r,u){typeof r=="function"?r(u):r!=null&&(r.current=u)}(t,o))}function P(...e){return n.useCallback(R(...e),e)}function D(...e){const o=e[0];if(e.length===1)return o;const t=()=>{const r=e.map(u=>({useScope:u(),scopeName:u.scopeName}));return function(u){const s=r.reduce((a,{useScope:i,scopeName:c})=>({...a,...i(u)[`__scope${c}`]}),{});return n.useMemo(()=>({[`__scope${o.scopeName}`]:s}),[s])}};return t.scopeName=o.scopeName,t}function S(e,o,{checkForDefaultPrevented:t=!0}={}){return function(r){if(e?.(r),t===!1||!r.defaultPrevented)return o?.(r)}}function x(e){const o=n.useRef(e);return n.useEffect(()=>{o.current=e}),n.useMemo(()=>(...t)=>{var r;return(r=o.current)===null||r===void 0?void 0:r.call(o,...t)},[])}function z({prop:e,defaultProp:o,onChange:t=()=>{}}){const[r,u]=function({defaultProp:c,onChange:l}){const p=n.useState(c),[d]=p,h=n.useRef(d),y=x(l);return n.useEffect(()=>{h.current!==d&&(y(d),h.current=d)},[d,h,y]),p}({defaultProp:o,onChange:t}),s=e!==void 0,a=s?e:r,i=x(t);return[a,n.useCallback(c=>{if(s){const l=typeof c=="function"?c(e):c;l!==e&&i(l)}else u(c)},[s,e,u,i])]}const O=Boolean(globalThis?.document)?n.useLayoutEffect:()=>{},T=e=>{const{present:o,children:t}=e,r=function(a){const[i,c]=n.useState(),l=n.useRef({}),p=n.useRef(a),d=n.useRef("none"),h=a?"mounted":"unmounted",[y,v]=function(f,m){return n.useReducer((b,E)=>{const k=m[b][E];return k??b},f)}(h,{mounted:{UNMOUNT:"unmounted",ANIMATION_OUT:"unmountSuspended"},unmountSuspended:{MOUNT:"mounted",ANIMATION_END:"unmounted"},unmounted:{MOUNT:"mounted"}});return n.useEffect(()=>{const f=w(l.current);d.current=y==="mounted"?f:"none"},[y]),O(()=>{const f=l.current,m=p.current;if(m!==a){const b=d.current,E=w(f);a?v("MOUNT"):E==="none"||f?.display==="none"?v("UNMOUNT"):v(m&&b!==E?"ANIMATION_OUT":"UNMOUNT"),p.current=a}},[a,v]),O(()=>{if(i){const f=b=>{const E=w(l.current).includes(b.animationName);b.target===i&&E&&U.flushSync(()=>v("ANIMATION_END"))},m=b=>{b.target===i&&(d.current=w(l.current))};return i.addEventListener("animationstart",m),i.addEventListener("animationcancel",f),i.addEventListener("animationend",f),()=>{i.removeEventListener("animationstart",m),i.removeEventListener("animationcancel",f),i.removeEventListener("animationend",f)}}v("ANIMATION_END")},[i,v]),{isPresent:["mounted","unmountSuspended"].includes(y),ref:n.useCallback(f=>{f&&(l.current=getComputedStyle(f)),c(f)},[])}}(o),u=typeof t=="function"?t({present:r.isPresent}):n.Children.only(t),s=P(r.ref,u.ref);return typeof t=="function"||r.isPresent?n.cloneElement(u,{ref:s}):null};function w(e){return e?.animationName||"none"}T.displayName="Presence";const A=n.forwardRef((e,o)=>{const{children:t,...r}=e,u=n.Children.toArray(t),s=u.find($);if(s){const a=s.props.children,i=u.map(c=>c===s?n.Children.count(a)>1?n.Children.only(null):n.isValidElement(a)?a.props.children:null:c);return n.createElement(M,g({},r,{ref:o}),n.isValidElement(a)?n.cloneElement(a,void 0,i):null)}return n.createElement(M,g({},r,{ref:o}),t)});A.displayName="Slot";const M=n.forwardRef((e,o)=>{const{children:t,...r}=e;return n.isValidElement(t)?n.cloneElement(t,{...B(r,t.props),ref:R(o,t.ref)}):n.Children.count(t)>1?n.Children.only(null):null});M.displayName="SlotClone";const q=({children:e})=>n.createElement(n.Fragment,null,e);function $(e){return n.isValidElement(e)&&e.type===q}function B(e,o){const t={...o};for(const r in o){const u=e[r],s=o[r];/^on[A-Z]/.test(r)?u&&s?t[r]=(...a)=>{s(...a),u(...a)}:u&&(t[r]=u):r==="style"?t[r]={...u,...s}:r==="className"&&(t[r]=[u,s].filter(Boolean).join(" "))}return{...e,...t}}const _=["a","button","div","form","h2","h3","img","input","label","li","nav","ol","p","span","svg","ul"].reduce((e,o)=>{const t=n.forwardRef((r,u)=>{const{asChild:s,...a}=r,i=s?A:o;return n.useEffect(()=>{window[Symbol.for("radix-ui")]=!0},[]),n.createElement(i,g({},a,{ref:u}))});return t.displayName=`Primitive.${o}`,{...e,[o]:t}},{}),I="Checkbox",[V,Y]=function(e,o=[]){let t=[];const r=()=>{const u=t.map(s=>n.createContext(s));return function(s){const a=s?.[e]||u;return n.useMemo(()=>({[`__scope${e}`]:{...s,[e]:a}}),[s,a])}};return r.scopeName=e,[function(u,s){const a=n.createContext(s),i=t.length;function c(l){const{scope:p,children:d,...h}=l,y=p?.[e][i]||a,v=n.useMemo(()=>h,Object.values(h));return n.createElement(y.Provider,{value:v},d)}return t=[...t,s],c.displayName=u+"Provider",[c,function(l,p){const d=p?.[e][i]||a,h=n.useContext(d);if(h)return h;if(s!==void 0)return s;throw new Error(`\`${l}\` must be used within \`${u}\``)}]},D(r,...o)]}(I),[H,F]=V(I),K=n.forwardRef((e,o)=>{const{__scopeCheckbox:t,name:r,checked:u,defaultChecked:s,required:a,disabled:i,value:c="on",onCheckedChange:l,...p}=e,[d,h]=n.useState(null),y=P(o,k=>h(k)),v=n.useRef(!1),f=!d||Boolean(d.closest("form")),[m=!1,b]=z({prop:u,defaultProp:s,onChange:l}),E=n.useRef(m);return n.useEffect(()=>{const k=d?.form;if(k){const C=()=>b(E.current);return k.addEventListener("reset",C),()=>k.removeEventListener("reset",C)}},[d,b]),n.createElement(H,{scope:t,state:m,disabled:i},n.createElement(_.button,g({type:"button",role:"checkbox","aria-checked":N(m)?"mixed":m,"aria-required":a,"data-state":L(m),"data-disabled":i?"":void 0,disabled:i,value:c},p,{ref:y,onKeyDown:S(e.onKeyDown,k=>{k.key==="Enter"&&k.preventDefault()}),onClick:S(e.onClick,k=>{b(C=>!!N(C)||!C),f&&(v.current=k.isPropagationStopped(),v.current||k.stopPropagation())})})),f&&n.createElement(W,{control:d,bubbles:!v.current,name:r,value:c,checked:m,required:a,disabled:i,style:{transform:"translateX(-100%)"}}))}),W=e=>{const{control:o,checked:t,bubbles:r=!0,...u}=e,s=n.useRef(null),a=function(c){const l=n.useRef({value:c,previous:c});return n.useMemo(()=>(l.current.value!==c&&(l.current.previous=l.current.value,l.current.value=c),l.current.previous),[c])}(t),i=function(c){const[l,p]=n.useState(void 0);return O(()=>{if(c){p({width:c.offsetWidth,height:c.offsetHeight});const d=new ResizeObserver(h=>{if(!Array.isArray(h)||!h.length)return;const y=h[0];let v,f;if("borderBoxSize"in y){const m=y.borderBoxSize,b=Array.isArray(m)?m[0]:m;v=b.inlineSize,f=b.blockSize}else v=c.offsetWidth,f=c.offsetHeight;p({width:v,height:f})});return d.observe(c,{box:"border-box"}),()=>d.unobserve(c)}p(void 0)},[c]),l}(o);return n.useEffect(()=>{const c=s.current,l=window.HTMLInputElement.prototype,p=Object.getOwnPropertyDescriptor(l,"checked").set;if(a!==t&&p){const d=new Event("click",{bubbles:r});c.indeterminate=N(t),p.call(c,!N(t)&&t),c.dispatchEvent(d)}},[a,t,r]),n.createElement("input",g({type:"checkbox","aria-hidden":!0,defaultChecked:!N(t)&&t},u,{tabIndex:-1,ref:s,style:{...e.style,...i,position:"absolute",pointerEvents:"none",opacity:0,margin:0}}))};function N(e){return e==="indeterminate"}function L(e){return N(e)?"indeterminate":e?"checked":"unchecked"}const Z=K,X=n.forwardRef((e,o)=>{const{__scopeCheckbox:t,forceMount:r,...u}=e,s=F("CheckboxIndicator",t);return n.createElement(T,{present:r||N(s.state)||s.state===!0},n.createElement(_.span,g({"data-state":L(s.state),"data-disabled":s.disabled?"":void 0},u,{ref:o,style:{pointerEvents:"none",...e.style}})))}),G=j.cva(["peer h-sz-20 w-sz-20 rounded-sm border-md bg-transparent items-center justify-center","spark-disabled:opacity-dim-3 spark-disabled:cursor-not-allowed spark-disabled:hover:ring-0","focus-visible:outline-none focus-visible:ring-2 focus:ring-outline-high","hover:outline-none hover:ring-2 hover:border-primary-container"],{variants:{intent:{primary:["spark-state-unchecked:border-outline","spark-state-checked:border-primary spark-state-checked:bg-primary"],success:["spark-state-unchecked:border-success","spark-state-checked:border-success spark-state-checked:bg-success"],alert:["spark-state-unchecked:border-alert","spark-state-checked:border-alert spark-state-checked:bg-alert"],error:["spark-state-unchecked:border-error","spark-state-checked:border-error spark-state-checked:bg-error"]}},defaultVariants:{intent:"primary"}}),J=n.forwardRef(({intent:e,...o},t)=>n.createElement(Z,{ref:t,className:G({intent:e}),...o},n.createElement(X,{className:"flex items-center justify-center text-surface"},n.createElement(Q,null)))),Q=e=>n.createElement("svg",{width:14,height:10,fill:"none",xmlns:"http://www.w3.org/2000/svg",...e},n.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M5.645 9.696a1.076 1.076 0 0 1-1.499 0L.288 5.956A1.023 1.023 0 0 1 .31 4.511a1.077 1.077 0 0 1 1.476-.022l3.061 2.998 7.319-7.16a1.075 1.075 0 0 1 1.037-.294c.374.094.666.38.763.747.096.367-.02.756-.301 1.015l-8.02 7.901Z",fill:"currentColor"}));exports.Checkbox=J;
|
package/dist/index.mjs
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
import C, { useCallback as U, createContext as D, useMemo as P, createElement as y, useContext as Z, useRef as g, useEffect as O, useState as _, useLayoutEffect as V, Children as x, cloneElement as j, useReducer as X, forwardRef as T, isValidElement as M, Fragment as G } from "react";
|
2
|
+
import { flushSync as J } from "react-dom";
|
3
|
+
import { cva as Q } from "class-variance-authority";
|
4
|
+
function E() {
|
5
|
+
return E = Object.assign ? Object.assign.bind() : function(e) {
|
6
|
+
for (var r = 1; r < arguments.length; r++) {
|
7
|
+
var t = arguments[r];
|
8
|
+
for (var n in t)
|
9
|
+
Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
|
10
|
+
}
|
11
|
+
return e;
|
12
|
+
}, E.apply(this, arguments);
|
13
|
+
}
|
14
|
+
function $(...e) {
|
15
|
+
return (r) => e.forEach((t) => function(n, c) {
|
16
|
+
typeof n == "function" ? n(c) : n != null && (n.current = c);
|
17
|
+
}(t, r));
|
18
|
+
}
|
19
|
+
function B(...e) {
|
20
|
+
return U($(...e), e);
|
21
|
+
}
|
22
|
+
function Y(...e) {
|
23
|
+
const r = e[0];
|
24
|
+
if (e.length === 1)
|
25
|
+
return r;
|
26
|
+
const t = () => {
|
27
|
+
const n = e.map((c) => ({ useScope: c(), scopeName: c.scopeName }));
|
28
|
+
return function(c) {
|
29
|
+
const o = n.reduce((a, { useScope: i, scopeName: s }) => ({ ...a, ...i(c)[`__scope${s}`] }), {});
|
30
|
+
return P(() => ({ [`__scope${r.scopeName}`]: o }), [o]);
|
31
|
+
};
|
32
|
+
};
|
33
|
+
return t.scopeName = r.scopeName, t;
|
34
|
+
}
|
35
|
+
function z(e, r, { checkForDefaultPrevented: t = !0 } = {}) {
|
36
|
+
return function(n) {
|
37
|
+
if (e?.(n), t === !1 || !n.defaultPrevented)
|
38
|
+
return r?.(n);
|
39
|
+
};
|
40
|
+
}
|
41
|
+
function R(e) {
|
42
|
+
const r = g(e);
|
43
|
+
return O(() => {
|
44
|
+
r.current = e;
|
45
|
+
}), P(() => (...t) => {
|
46
|
+
var n;
|
47
|
+
return (n = r.current) === null || n === void 0 ? void 0 : n.call(r, ...t);
|
48
|
+
}, []);
|
49
|
+
}
|
50
|
+
function ee({ prop: e, defaultProp: r, onChange: t = () => {
|
51
|
+
} }) {
|
52
|
+
const [n, c] = function({ defaultProp: s, onChange: u }) {
|
53
|
+
const f = _(s), [l] = f, m = g(l), k = R(u);
|
54
|
+
return O(() => {
|
55
|
+
m.current !== l && (k(l), m.current = l);
|
56
|
+
}, [l, m, k]), f;
|
57
|
+
}({ defaultProp: r, onChange: t }), o = e !== void 0, a = o ? e : n, i = R(t);
|
58
|
+
return [a, U((s) => {
|
59
|
+
if (o) {
|
60
|
+
const u = typeof s == "function" ? s(e) : s;
|
61
|
+
u !== e && i(u);
|
62
|
+
} else
|
63
|
+
c(s);
|
64
|
+
}, [o, e, c, i])];
|
65
|
+
}
|
66
|
+
const I = Boolean(globalThis?.document) ? V : () => {
|
67
|
+
}, q = (e) => {
|
68
|
+
const { present: r, children: t } = e, n = function(a) {
|
69
|
+
const [i, s] = _(), u = g({}), f = g(a), l = g("none"), m = a ? "mounted" : "unmounted", [k, h] = function(d, p) {
|
70
|
+
return X((v, N) => {
|
71
|
+
const b = p[v][N];
|
72
|
+
return b ?? v;
|
73
|
+
}, d);
|
74
|
+
}(m, { mounted: { UNMOUNT: "unmounted", ANIMATION_OUT: "unmountSuspended" }, unmountSuspended: { MOUNT: "mounted", ANIMATION_END: "unmounted" }, unmounted: { MOUNT: "mounted" } });
|
75
|
+
return O(() => {
|
76
|
+
const d = S(u.current);
|
77
|
+
l.current = k === "mounted" ? d : "none";
|
78
|
+
}, [k]), I(() => {
|
79
|
+
const d = u.current, p = f.current;
|
80
|
+
if (p !== a) {
|
81
|
+
const v = l.current, N = S(d);
|
82
|
+
a ? h("MOUNT") : N === "none" || d?.display === "none" ? h("UNMOUNT") : h(p && v !== N ? "ANIMATION_OUT" : "UNMOUNT"), f.current = a;
|
83
|
+
}
|
84
|
+
}, [a, h]), I(() => {
|
85
|
+
if (i) {
|
86
|
+
const d = (v) => {
|
87
|
+
const N = S(u.current).includes(v.animationName);
|
88
|
+
v.target === i && N && J(() => h("ANIMATION_END"));
|
89
|
+
}, p = (v) => {
|
90
|
+
v.target === i && (l.current = S(u.current));
|
91
|
+
};
|
92
|
+
return i.addEventListener("animationstart", p), i.addEventListener("animationcancel", d), i.addEventListener("animationend", d), () => {
|
93
|
+
i.removeEventListener("animationstart", p), i.removeEventListener("animationcancel", d), i.removeEventListener("animationend", d);
|
94
|
+
};
|
95
|
+
}
|
96
|
+
h("ANIMATION_END");
|
97
|
+
}, [i, h]), { isPresent: ["mounted", "unmountSuspended"].includes(k), ref: U((d) => {
|
98
|
+
d && (u.current = getComputedStyle(d)), s(d);
|
99
|
+
}, []) };
|
100
|
+
}(r), c = typeof t == "function" ? t({ present: n.isPresent }) : x.only(t), o = B(n.ref, c.ref);
|
101
|
+
return typeof t == "function" || n.isPresent ? j(c, { ref: o }) : null;
|
102
|
+
};
|
103
|
+
function S(e) {
|
104
|
+
return e?.animationName || "none";
|
105
|
+
}
|
106
|
+
q.displayName = "Presence";
|
107
|
+
const H = T((e, r) => {
|
108
|
+
const { children: t, ...n } = e, c = x.toArray(t), o = c.find(ne);
|
109
|
+
if (o) {
|
110
|
+
const a = o.props.children, i = c.map((s) => s === o ? x.count(a) > 1 ? x.only(null) : M(a) ? a.props.children : null : s);
|
111
|
+
return y(L, E({}, n, { ref: r }), M(a) ? j(a, void 0, i) : null);
|
112
|
+
}
|
113
|
+
return y(L, E({}, n, { ref: r }), t);
|
114
|
+
});
|
115
|
+
H.displayName = "Slot";
|
116
|
+
const L = T((e, r) => {
|
117
|
+
const { children: t, ...n } = e;
|
118
|
+
return M(t) ? j(t, { ...re(n, t.props), ref: $(r, t.ref) }) : x.count(t) > 1 ? x.only(null) : null;
|
119
|
+
});
|
120
|
+
L.displayName = "SlotClone";
|
121
|
+
const te = ({ children: e }) => y(G, null, e);
|
122
|
+
function ne(e) {
|
123
|
+
return M(e) && e.type === te;
|
124
|
+
}
|
125
|
+
function re(e, r) {
|
126
|
+
const t = { ...r };
|
127
|
+
for (const n in r) {
|
128
|
+
const c = e[n], o = r[n];
|
129
|
+
/^on[A-Z]/.test(n) ? c && o ? t[n] = (...a) => {
|
130
|
+
o(...a), c(...a);
|
131
|
+
} : c && (t[n] = c) : n === "style" ? t[n] = { ...c, ...o } : n === "className" && (t[n] = [c, o].filter(Boolean).join(" "));
|
132
|
+
}
|
133
|
+
return { ...e, ...t };
|
134
|
+
}
|
135
|
+
const F = ["a", "button", "div", "form", "h2", "h3", "img", "input", "label", "li", "nav", "ol", "p", "span", "svg", "ul"].reduce((e, r) => {
|
136
|
+
const t = T((n, c) => {
|
137
|
+
const { asChild: o, ...a } = n, i = o ? H : r;
|
138
|
+
return O(() => {
|
139
|
+
window[Symbol.for("radix-ui")] = !0;
|
140
|
+
}, []), y(i, E({}, a, { ref: c }));
|
141
|
+
});
|
142
|
+
return t.displayName = `Primitive.${r}`, { ...e, [r]: t };
|
143
|
+
}, {}), K = "Checkbox", [oe, ve] = function(e, r = []) {
|
144
|
+
let t = [];
|
145
|
+
const n = () => {
|
146
|
+
const c = t.map((o) => D(o));
|
147
|
+
return function(o) {
|
148
|
+
const a = o?.[e] || c;
|
149
|
+
return P(() => ({ [`__scope${e}`]: { ...o, [e]: a } }), [o, a]);
|
150
|
+
};
|
151
|
+
};
|
152
|
+
return n.scopeName = e, [function(c, o) {
|
153
|
+
const a = D(o), i = t.length;
|
154
|
+
function s(u) {
|
155
|
+
const { scope: f, children: l, ...m } = u, k = f?.[e][i] || a, h = P(() => m, Object.values(m));
|
156
|
+
return y(k.Provider, { value: h }, l);
|
157
|
+
}
|
158
|
+
return t = [...t, o], s.displayName = c + "Provider", [s, function(u, f) {
|
159
|
+
const l = f?.[e][i] || a, m = Z(l);
|
160
|
+
if (m)
|
161
|
+
return m;
|
162
|
+
if (o !== void 0)
|
163
|
+
return o;
|
164
|
+
throw new Error(`\`${u}\` must be used within \`${c}\``);
|
165
|
+
}];
|
166
|
+
}, Y(n, ...r)];
|
167
|
+
}(K), [se, ce] = oe(K), ae = T((e, r) => {
|
168
|
+
const { __scopeCheckbox: t, name: n, checked: c, defaultChecked: o, required: a, disabled: i, value: s = "on", onCheckedChange: u, ...f } = e, [l, m] = _(null), k = B(r, (b) => m(b)), h = g(!1), d = !l || Boolean(l.closest("form")), [p = !1, v] = ee({ prop: c, defaultProp: o, onChange: u }), N = g(p);
|
169
|
+
return O(() => {
|
170
|
+
const b = l?.form;
|
171
|
+
if (b) {
|
172
|
+
const A = () => v(N.current);
|
173
|
+
return b.addEventListener("reset", A), () => b.removeEventListener("reset", A);
|
174
|
+
}
|
175
|
+
}, [l, v]), y(se, { scope: t, state: p, disabled: i }, y(F.button, E({ type: "button", role: "checkbox", "aria-checked": w(p) ? "mixed" : p, "aria-required": a, "data-state": W(p), "data-disabled": i ? "" : void 0, disabled: i, value: s }, f, { ref: k, onKeyDown: z(e.onKeyDown, (b) => {
|
176
|
+
b.key === "Enter" && b.preventDefault();
|
177
|
+
}), onClick: z(e.onClick, (b) => {
|
178
|
+
v((A) => !!w(A) || !A), d && (h.current = b.isPropagationStopped(), h.current || b.stopPropagation());
|
179
|
+
}) })), d && y(ie, { control: l, bubbles: !h.current, name: n, value: s, checked: p, required: a, disabled: i, style: { transform: "translateX(-100%)" } }));
|
180
|
+
}), ie = (e) => {
|
181
|
+
const { control: r, checked: t, bubbles: n = !0, ...c } = e, o = g(null), a = function(s) {
|
182
|
+
const u = g({ value: s, previous: s });
|
183
|
+
return P(() => (u.current.value !== s && (u.current.previous = u.current.value, u.current.value = s), u.current.previous), [s]);
|
184
|
+
}(t), i = function(s) {
|
185
|
+
const [u, f] = _(void 0);
|
186
|
+
return I(() => {
|
187
|
+
if (s) {
|
188
|
+
f({ width: s.offsetWidth, height: s.offsetHeight });
|
189
|
+
const l = new ResizeObserver((m) => {
|
190
|
+
if (!Array.isArray(m) || !m.length)
|
191
|
+
return;
|
192
|
+
const k = m[0];
|
193
|
+
let h, d;
|
194
|
+
if ("borderBoxSize" in k) {
|
195
|
+
const p = k.borderBoxSize, v = Array.isArray(p) ? p[0] : p;
|
196
|
+
h = v.inlineSize, d = v.blockSize;
|
197
|
+
} else
|
198
|
+
h = s.offsetWidth, d = s.offsetHeight;
|
199
|
+
f({ width: h, height: d });
|
200
|
+
});
|
201
|
+
return l.observe(s, { box: "border-box" }), () => l.unobserve(s);
|
202
|
+
}
|
203
|
+
f(void 0);
|
204
|
+
}, [s]), u;
|
205
|
+
}(r);
|
206
|
+
return O(() => {
|
207
|
+
const s = o.current, u = window.HTMLInputElement.prototype, f = Object.getOwnPropertyDescriptor(u, "checked").set;
|
208
|
+
if (a !== t && f) {
|
209
|
+
const l = new Event("click", { bubbles: n });
|
210
|
+
s.indeterminate = w(t), f.call(s, !w(t) && t), s.dispatchEvent(l);
|
211
|
+
}
|
212
|
+
}, [a, t, n]), y("input", E({ type: "checkbox", "aria-hidden": !0, defaultChecked: !w(t) && t }, c, { tabIndex: -1, ref: o, style: { ...e.style, ...i, position: "absolute", pointerEvents: "none", opacity: 0, margin: 0 } }));
|
213
|
+
};
|
214
|
+
function w(e) {
|
215
|
+
return e === "indeterminate";
|
216
|
+
}
|
217
|
+
function W(e) {
|
218
|
+
return w(e) ? "indeterminate" : e ? "checked" : "unchecked";
|
219
|
+
}
|
220
|
+
const ue = ae, le = T((e, r) => {
|
221
|
+
const { __scopeCheckbox: t, forceMount: n, ...c } = e, o = ce("CheckboxIndicator", t);
|
222
|
+
return y(q, { present: n || w(o.state) || o.state === !0 }, y(F.span, E({ "data-state": W(o.state), "data-disabled": o.disabled ? "" : void 0 }, c, { ref: r, style: { pointerEvents: "none", ...e.style } })));
|
223
|
+
}), de = Q(["peer h-sz-20 w-sz-20 rounded-sm border-md bg-transparent items-center justify-center", "spark-disabled:opacity-dim-3 spark-disabled:cursor-not-allowed spark-disabled:hover:ring-0", "focus-visible:outline-none focus-visible:ring-2 focus:ring-outline-high", "hover:outline-none hover:ring-2 hover:border-primary-container"], { variants: { intent: { primary: ["spark-state-unchecked:border-outline", "spark-state-checked:border-primary spark-state-checked:bg-primary"], success: ["spark-state-unchecked:border-success", "spark-state-checked:border-success spark-state-checked:bg-success"], alert: ["spark-state-unchecked:border-alert", "spark-state-checked:border-alert spark-state-checked:bg-alert"], error: ["spark-state-unchecked:border-error", "spark-state-checked:border-error spark-state-checked:bg-error"] } }, defaultVariants: { intent: "primary" } }), be = C.forwardRef(({ intent: e, ...r }, t) => C.createElement(ue, { ref: t, className: de({ intent: e }), ...r }, C.createElement(le, { className: "flex items-center justify-center text-surface" }, C.createElement(fe, null)))), fe = (e) => C.createElement("svg", { width: 14, height: 10, fill: "none", xmlns: "http://www.w3.org/2000/svg", ...e }, C.createElement("path", { fillRule: "evenodd", clipRule: "evenodd", d: "M5.645 9.696a1.076 1.076 0 0 1-1.499 0L.288 5.956A1.023 1.023 0 0 1 .31 4.511a1.077 1.077 0 0 1 1.476-.022l3.061 2.998 7.319-7.16a1.075 1.075 0 0 1 1.037-.294c.374.094.666.38.763.747.096.367-.02.756-.301 1.015l-8.02 7.901Z", fill: "currentColor" }));
|
224
|
+
export {
|
225
|
+
be as Checkbox
|
226
|
+
};
|
package/package.json
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
{
|
2
|
+
"name": "@spark-ui/checkbox",
|
3
|
+
"version": "1.1.0",
|
4
|
+
"description": "A control that allows the user to toggle between checked and not checked.",
|
5
|
+
"publishConfig": {
|
6
|
+
"access": "public"
|
7
|
+
},
|
8
|
+
"main": "./dist/index.js",
|
9
|
+
"module": "./dist/index.mjs",
|
10
|
+
"types": "./dist/index.d.ts",
|
11
|
+
"scripts": {
|
12
|
+
"build": "vite build"
|
13
|
+
},
|
14
|
+
"dependencies": {
|
15
|
+
"@radix-ui/react-checkbox": "1.0.3",
|
16
|
+
"class-variance-authority": "0.4.0"
|
17
|
+
},
|
18
|
+
"gitHead": "d78bcd4a3eeff74b426fc624a085b7ba35095a08"
|
19
|
+
}
|
package/tsconfig.json
ADDED