@studiocubics/components 0.0.23 → 0.0.25
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.
|
@@ -11,7 +11,7 @@ interface CheckboxGroupProps {
|
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
onChange?: (checked: Record<string, boolean>) => void;
|
|
13
13
|
}
|
|
14
|
-
export declare const CheckboxGroupContext: import("react").Context<CheckboxGroupContextProps
|
|
15
|
-
export declare const useCheckbox: () => CheckboxGroupContextProps
|
|
14
|
+
export declare const CheckboxGroupContext: import("react").Context<CheckboxGroupContextProps>;
|
|
15
|
+
export declare const useCheckbox: () => CheckboxGroupContextProps;
|
|
16
16
|
export declare function CheckboxProvider({ children, onChange }: CheckboxGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
17
17
|
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsx as e}from"react/jsx-runtime";import{createContext as
|
|
1
|
+
"use client";import{jsx as e}from"react/jsx-runtime";import{createContext as t,useContext as r,useState as n,useRef as c}from"react";function s(){console.log("Function not implemented.")}const o=t({values:{},selected:[],register:s,update:s,setAll:s,reset:s}),l=()=>r(o);function i({children:t,onChange:r}){const[s,l]=n({}),[i,u]=n(0),a=c(-1),d=Object.keys(s).filter((e,t)=>Object.values(s)[t]);return e(o.Provider,{value:{values:s,selected:d,register:e=>{l(t=>({...t,[e]:!1}))},update:(e,t)=>{l(n=>{const c={...n,[e]:t};return r?.(c),c})},setAll:e=>{l(t=>{const n=Object.fromEntries(Object.keys(t).map(t=>[t,e]));return r?.(n),n})},reset:()=>{a.current=-1,l({}),u(e=>e+1)}},children:e("div",{children:t},i)})}export{o as CheckboxGroupContext,i as CheckboxProvider,l as useCheckbox};
|
|
2
2
|
//# sourceMappingURL=CheckboxProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CheckboxProvider.js","sources":["../../../src/Inputs/Checkbox/CheckboxProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useContext,\n useRef,\n useState,\n} from \"react\";\n\ninterface CheckboxGroupContextProps {\n values: Record<string, boolean>;\n selected: string[];\n register: (id: string) => void;\n update: (id: string, checked: boolean) => void;\n setAll: (checked: boolean) => void;\n reset: () => void;\n}\n\ninterface CheckboxGroupProps {\n children: ReactNode;\n onChange?: (checked: Record<string, boolean>) => void;\n}\n\nexport const CheckboxGroupContext
|
|
1
|
+
{"version":3,"file":"CheckboxProvider.js","sources":["../../../src/Inputs/Checkbox/CheckboxProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n type ReactNode,\n useContext,\n useRef,\n useState,\n} from \"react\";\n\ninterface CheckboxGroupContextProps {\n values: Record<string, boolean>;\n selected: string[];\n register: (id: string) => void;\n update: (id: string, checked: boolean) => void;\n setAll: (checked: boolean) => void;\n reset: () => void;\n}\n\ninterface CheckboxGroupProps {\n children: ReactNode;\n onChange?: (checked: Record<string, boolean>) => void;\n}\nfunction notImplemented(): void {\n console.log(\"Function not implemented.\");\n}\nexport const CheckboxGroupContext = createContext<CheckboxGroupContextProps>({\n values: {},\n selected: [],\n register: notImplemented,\n update: notImplemented,\n setAll: notImplemented,\n reset: notImplemented,\n});\n\nexport const useCheckbox = () => {\n const c = useContext(CheckboxGroupContext);\n return c;\n};\n\nexport function CheckboxProvider({ children, onChange }: CheckboxGroupProps) {\n const [values, setValues] = useState<Record<string, boolean>>({});\n const [resetKey, setResetKey] = useState(0);\n const indexRef = useRef(-1);\n const selected = Object.keys(values).filter(\n (_, i) => Object.values(values)[i],\n );\n\n const register = (id: string) => {\n setValues((prev) => ({ ...prev, [id]: false }));\n };\n\n const update = (id: string, checked: boolean) => {\n setValues((prev) => {\n const next = { ...prev, [id]: checked };\n onChange?.(next);\n return next;\n });\n };\n\n const setAll = (checked: boolean) => {\n setValues((prev) => {\n const next = Object.fromEntries(\n Object.keys(prev).map((k) => [k, checked]),\n );\n onChange?.(next);\n return next;\n });\n };\n\n const reset = () => {\n indexRef.current = -1;\n setValues({});\n setResetKey((k) => k + 1);\n };\n return (\n <CheckboxGroupContext.Provider\n value={{ values, selected, register, update, setAll, reset }}\n >\n {/* resetKey forces all non-skipGroup checkboxes to remount and re-register */}\n <div key={resetKey}>{children}</div>\n </CheckboxGroupContext.Provider>\n );\n}\n"],"names":["notImplemented","console","log","CheckboxGroupContext","createContext","values","selected","register","update","setAll","reset","useCheckbox","useContext","CheckboxProvider","children","onChange","setValues","useState","resetKey","setResetKey","indexRef","useRef","Object","keys","filter","_","i","_jsx","Provider","value","id","prev","checked","next","fromEntries","map","k","current"],"mappings":"qIAuBA,SAASA,IACPC,QAAQC,IAAI,4BACd,CACO,MAAMC,EAAuBC,EAAyC,CAC3EC,OAAQ,CAAA,EACRC,SAAU,GACVC,SAAUP,EACVQ,OAAQR,EACRS,OAAQT,EACRU,MAAOV,IAGIW,EAAc,IACfC,EAAWT,YAIPU,GAAiBC,SAAEA,EAAQC,SAAEA,IAC3C,MAAOV,EAAQW,GAAaC,EAAkC,CAAA,IACvDC,EAAUC,GAAeF,EAAS,GACnCG,EAAWC,MACXf,EAAWgB,OAAOC,KAAKlB,GAAQmB,OACnC,CAACC,EAAGC,IAAMJ,OAAOjB,OAAOA,GAAQqB,IA8BlC,OACEC,EAACxB,EAAqByB,SAAQ,CAC5BC,MAAO,CAAExB,SAAQC,WAAUC,SA7BbuB,IAChBd,EAAWe,QAAeA,EAAMD,CAACA,IAAK,MA4BCtB,OAzB1B,CAACsB,EAAYE,KAC1BhB,EAAWe,IACT,MAAME,EAAO,IAAKF,EAAMD,CAACA,GAAKE,GAE9B,OADAjB,IAAWkB,GACJA,KAqBsCxB,OAjBjCuB,IACdhB,EAAWe,IACT,MAAME,EAAOX,OAAOY,YAClBZ,OAAOC,KAAKQ,GAAMI,IAAKC,GAAM,CAACA,EAAGJ,KAGnC,OADAjB,IAAWkB,GACJA,KAW8CvB,MAP3C,KACZU,EAASiB,SAAU,EACnBrB,EAAU,CAAA,GACVG,EAAaiB,GAAMA,EAAI,KAIuCtB,SAG5Da,EAAA,MAAA,CAAAb,SAAqBA,GAAXI,IAGhB"}
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
7
|
"private": false,
|
|
8
|
-
"version": "0.0.
|
|
8
|
+
"version": "0.0.25",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"@studiocubics",
|
|
11
11
|
"cubics",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"react-dom": ">= 19"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@studiocubics/hooks": "^0.0.
|
|
38
|
-
"@studiocubics/types": "^0.0.
|
|
39
|
-
"@studiocubics/utils": "^0.0.
|
|
37
|
+
"@studiocubics/hooks": "^0.0.25",
|
|
38
|
+
"@studiocubics/types": "^0.0.25",
|
|
39
|
+
"@studiocubics/utils": "^0.0.25"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@eslint/js": "^9.39.1",
|