@stackshift-ui/checkbox 6.0.11 → 6.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.
@@ -1,17 +1,4 @@
1
- import type { ElementType, HTMLProps } from "react";
2
- export type StyleVariants<T extends string> = Record<T, string>;
3
- type Variant = "primary";
4
- export interface CheckboxProps extends Omit<HTMLProps<HTMLInputElement>, "as"> {
5
- required?: boolean;
6
- name?: string;
7
- ariaLabel?: string;
8
- label?: string;
9
- labelClass?: string;
10
- item?: string;
11
- variant?: Variant;
12
- onChange?: () => void;
13
- className?: string;
14
- as?: ElementType;
15
- }
16
- export declare const Checkbox: React.FC<CheckboxProps>;
17
- export {};
1
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
2
+ import * as React from "react";
3
+ declare const Checkbox: React.ForwardRefExoticComponent<Omit<CheckboxPrimitive.CheckboxProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
4
+ export { Checkbox };
package/dist/checkbox.js CHANGED
@@ -1 +1 @@
1
- "use strict";var k=Object.create;var o=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var V=(e,a)=>{for(var t in a)o(e,t,{get:a[t],enumerable:!0})},b=(e,a,t,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of L(a))!N.call(e,n)&&n!==t&&o(e,n,{get:()=>a[n],enumerable:!(s=v(a,n))||s.enumerable});return e};var P=(e,a,t)=>(t=e!=null?k(S(e)):{},b(a||!e||!e.__esModule?o(t,"default",{value:e,enumerable:!0}):t,e)),E=e=>b(o({},"__esModule",{value:!0}),e);var H={};V(H,{Checkbox:()=>d});module.exports=E(H);var l=require("@stackshift-ui/system"),m=P(require("classnames")),i=require("react/jsx-runtime"),p="Checkbox",d=({required:e=!1,name:a,ariaLabel:t,label:s,labelClass:n,item:r,variant:g="primary",onChange:f,className:x,as:h="label",...c})=>{var C;let{[p]:u=l.DefaultComponent}=(0,l.useStackShiftUIComponents)(),y="",T=(C={primary:y}[g])!=null?C:y;return(0,i.jsxs)(u,{as:h,htmlFor:r,className:(0,m.default)("flex gap-2 items-center",n),...c,"data-testid":p,children:[(0,i.jsx)("input",{"aria-label":t||a,className:(0,m.default)(T,x),name:a,type:"checkbox",value:r,required:e,onChange:f,id:r,...c}),s||r]})};d.displayName=p;0&&(module.exports={Checkbox});
1
+ "use strict";var h=Object.create;var a=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var v=(e,o)=>{for(var t in o)a(e,t,{get:o[t],enumerable:!0})},m=(e,o,t,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of u(o))!x.call(e,r)&&r!==t&&a(e,r,{get:()=>o[r],enumerable:!(c=k(o,r))||c.enumerable});return e};var f=(e,o,t)=>(t=e!=null?h(C(e)):{},m(o||!e||!e.__esModule?a(t,"default",{value:e,enumerable:!0}):t,e)),R=e=>m(a({},"__esModule",{value:!0}),e);var y={};v(y,{Checkbox:()=>l});module.exports=R(y);var n=f(require("@radix-ui/react-checkbox")),d=require("lucide-react"),p=f(require("react")),i=require("@stackshift-ui/system"),s=require("react/jsx-runtime"),b="Checkbox",l=p.forwardRef(({className:e,...o},t)=>{let{[b]:c=i.DefaultComponent}=(0,i.useStackShiftUIComponents)();return(0,s.jsx)(c,{as:n.Root,ref:t,className:(0,i.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...o,children:(0,s.jsx)(n.Indicator,{className:(0,i.cn)("flex items-center justify-center text-current"),children:(0,s.jsx)(d.Check,{className:"h-4 w-4"})})})});l.displayName=b;0&&(module.exports={Checkbox});
package/dist/checkbox.mjs CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-3O2SYB7X.mjs";export{a as Checkbox};
1
+ import{a}from"./chunk-GHOTKBI3.mjs";export{a as Checkbox};
@@ -0,0 +1 @@
1
+ import*as e from"@radix-ui/react-checkbox";import{Check as m}from"lucide-react";import*as i from"react";import{cn as t,DefaultComponent as f,useStackShiftUIComponents as d}from"@stackshift-ui/system";import{jsx as o}from"react/jsx-runtime";var r="Checkbox",p=i.forwardRef(({className:c,...a},s)=>{let{[r]:n=f}=d();return o(n,{as:e.Root,ref:s,className:t("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",c),...a,children:o(e.Indicator,{className:t("flex items-center justify-center text-current"),children:o(m,{className:"h-4 w-4"})})})});p.displayName=r;export{p as a};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";var k=Object.create;var o=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var L=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var V=(e,a)=>{for(var t in a)o(e,t,{get:a[t],enumerable:!0})},b=(e,a,t,s)=>{if(a&&typeof a=="object"||typeof a=="function")for(let n of L(a))!N.call(e,n)&&n!==t&&o(e,n,{get:()=>a[n],enumerable:!(s=v(a,n))||s.enumerable});return e};var P=(e,a,t)=>(t=e!=null?k(S(e)):{},b(a||!e||!e.__esModule?o(t,"default",{value:e,enumerable:!0}):t,e)),E=e=>b(o({},"__esModule",{value:!0}),e);var H={};V(H,{Checkbox:()=>d});module.exports=E(H);var l=require("@stackshift-ui/system"),m=P(require("classnames")),i=require("react/jsx-runtime"),p="Checkbox",d=({required:e=!1,name:a,ariaLabel:t,label:s,labelClass:n,item:r,variant:f="primary",onChange:g,className:x,as:u="label",...c})=>{var C;let{[p]:h=l.DefaultComponent}=(0,l.useStackShiftUIComponents)(),y="",T=(C={primary:y}[f])!=null?C:y;return(0,i.jsxs)(h,{as:u,htmlFor:r,className:(0,m.default)("flex gap-2 items-center",n),...c,"data-testid":p,children:[(0,i.jsx)("input",{"aria-label":t||a,className:(0,m.default)(T,x),name:a,type:"checkbox",value:r,required:e,onChange:g,id:r,...c}),s||r]})};d.displayName=p;0&&(module.exports={Checkbox});
2
+ "use strict";var h=Object.create;var s=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var k=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,x=Object.prototype.hasOwnProperty;var v=(e,o)=>{for(var t in o)s(e,t,{get:o[t],enumerable:!0})},m=(e,o,t,c)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of k(o))!x.call(e,r)&&r!==t&&s(e,r,{get:()=>o[r],enumerable:!(c=u(o,r))||c.enumerable});return e};var f=(e,o,t)=>(t=e!=null?h(C(e)):{},m(o||!e||!e.__esModule?s(t,"default",{value:e,enumerable:!0}):t,e)),R=e=>m(s({},"__esModule",{value:!0}),e);var y={};v(y,{Checkbox:()=>l});module.exports=R(y);var n=f(require("@radix-ui/react-checkbox")),p=require("lucide-react"),d=f(require("react")),i=require("@stackshift-ui/system"),a=require("react/jsx-runtime"),b="Checkbox",l=d.forwardRef(({className:e,...o},t)=>{let{[b]:c=i.DefaultComponent}=(0,i.useStackShiftUIComponents)();return(0,a.jsx)(c,{as:n.Root,ref:t,className:(0,i.cn)("peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...o,children:(0,a.jsx)(n.Indicator,{className:(0,i.cn)("flex items-center justify-center text-current"),children:(0,a.jsx)(p.Check,{className:"h-4 w-4"})})})});l.displayName=b;0&&(module.exports={Checkbox});
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";import{a as e}from"./chunk-3O2SYB7X.mjs";export{e as Checkbox};
2
+ "use strict";import{a as e}from"./chunk-GHOTKBI3.mjs";export{e as Checkbox};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stackshift-ui/checkbox",
3
3
  "description": "",
4
- "version": "6.0.11",
4
+ "version": "6.1.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.js",
@@ -29,20 +29,23 @@
29
29
  "typescript": "^5.6.2",
30
30
  "vite-tsconfig-paths": "^5.0.1",
31
31
  "vitest": "^2.1.1",
32
- "@stackshift-ui/typescript-config": "6.0.10",
33
- "@stackshift-ui/eslint-config": "6.0.10"
32
+ "@stackshift-ui/eslint-config": "6.0.10",
33
+ "@stackshift-ui/typescript-config": "6.0.10"
34
34
  },
35
35
  "dependencies": {
36
+ "@radix-ui/react-checkbox": "^1.3.2",
37
+ "@testing-library/user-event": "^14.6.1",
36
38
  "classnames": "^2.5.1",
37
- "@stackshift-ui/scripts": "6.0.10",
38
- "@stackshift-ui/system": "6.0.11"
39
+ "lucide-react": "^0.468.0",
40
+ "@stackshift-ui/scripts": "6.1.0",
41
+ "@stackshift-ui/system": "6.1.0"
39
42
  },
40
43
  "peerDependencies": {
44
+ "@stackshift-ui/system": ">=7.0.0",
41
45
  "@types/react": "16.8 - 19",
42
46
  "next": "10 - 14",
43
47
  "react": "16.8 - 19",
44
- "react-dom": "16.8 - 19",
45
- "@stackshift-ui/system": ">=6.0.11"
48
+ "react-dom": "16.8 - 19"
46
49
  },
47
50
  "peerDependenciesMeta": {
48
51
  "next": {
@@ -1,4 +1,5 @@
1
- import { cleanup, render, screen } from "@testing-library/react";
1
+ import { cleanup, render, screen, waitFor } from "@testing-library/react";
2
+ import userEvent from "@testing-library/user-event";
2
3
  import { afterEach, describe, test } from "vitest";
3
4
  import { Checkbox } from "./checkbox";
4
5
 
@@ -7,7 +8,36 @@ describe.concurrent("checkbox", () => {
7
8
 
8
9
  test("Common: Checkbox - test if renders without errors", ({ expect }) => {
9
10
  const clx = "checkbox-class";
10
- render(<Checkbox className={clx} />);
11
- expect(screen.getByTestId("label").classList).toBeDefined();
11
+ const { unmount } = render(<Checkbox aria-label="Test checkbox" className={clx} />);
12
+
13
+ const checkbox = screen.getByRole("checkbox");
14
+ expect(checkbox.classList).toContain(clx);
15
+ expect(checkbox.ariaLabel).toBe("Test checkbox");
16
+ unmount();
17
+ });
18
+
19
+ test("Common: Checkbox - test if renders with correct state", ({ expect }) => {
20
+ const { unmount } = render(
21
+ <Checkbox data-testid="checked-checkbox" aria-label="Test checkbox" defaultChecked />,
22
+ );
23
+
24
+ const checkbox = screen.getByTestId<HTMLButtonElement>("checked-checkbox");
25
+ expect(checkbox.getAttribute("aria-checked")).toBe("true");
26
+ unmount();
27
+ });
28
+
29
+ test("Common: Checkbox - test if clicking checkbox changes state", async ({ expect }) => {
30
+ const user = userEvent.setup();
31
+ const { unmount } = render(
32
+ <Checkbox data-testid="unchecked-checkbox" aria-label="Test checkbox" />,
33
+ );
34
+
35
+ const checkbox = screen.getByTestId<HTMLButtonElement>("unchecked-checkbox");
36
+ expect(checkbox.getAttribute("aria-checked")).toBe("false");
37
+
38
+ await user.click(checkbox);
39
+
40
+ waitFor(() => expect(checkbox.getAttribute("aria-checked")).toBe("true"));
41
+ unmount();
12
42
  });
13
43
  });
package/src/checkbox.tsx CHANGED
@@ -1,71 +1,32 @@
1
- import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
- import cn from "classnames";
3
- import type { ElementType, HTMLProps } from "react";
1
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
2
+ import { Check } from "lucide-react";
3
+ import * as React from "react";
4
4
 
5
- export type StyleVariants<T extends string> = Record<T, string>;
6
- type Variant = "primary";
7
-
8
- export interface CheckboxProps extends Omit<HTMLProps<HTMLInputElement>, "as"> {
9
- required?: boolean;
10
- name?: string;
11
- ariaLabel?: string;
12
- label?: string;
13
- labelClass?: string;
14
- item?: string;
15
- variant?: Variant;
16
- onChange?: () => void;
17
- className?: string;
18
- as?: ElementType;
19
- }
5
+ import { cn, DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
20
6
 
21
7
  const displayName = "Checkbox";
22
8
 
23
- export const Checkbox: React.FC<CheckboxProps> = ({
24
- required = false,
25
- name,
26
- ariaLabel,
27
- label,
28
- labelClass,
29
- item,
30
- variant = "primary",
31
- onChange,
32
- className,
33
- as = "label",
34
- ...props
35
- }) => {
9
+ const Checkbox = React.forwardRef<
10
+ React.ElementRef<typeof CheckboxPrimitive.Root>,
11
+ React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
12
+ >(({ className, ...props }, ref) => {
36
13
  const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
37
14
 
38
- const commonStyle = "";
39
- const primary = `${commonStyle}`;
40
-
41
- const variants: StyleVariants<Variant> = {
42
- primary,
43
- };
44
-
45
- const variantClass = variants[variant] ?? primary;
46
- const defaultLabelClass = "flex gap-2 items-center";
47
-
48
15
  return (
49
16
  <Component
50
- as={as}
51
- htmlFor={item}
52
- className={cn(defaultLabelClass, labelClass)}
53
- {...props}
54
- data-testid={displayName}>
55
- <input
56
- aria-label={ariaLabel || name}
57
- className={cn(variantClass, className)}
58
- name={name}
59
- type="checkbox"
60
- value={item}
61
- required={required}
62
- onChange={onChange}
63
- id={item}
64
- {...props}
65
- />
66
- {label || item}
17
+ as={CheckboxPrimitive.Root}
18
+ ref={ref}
19
+ className={cn(
20
+ "peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
21
+ className,
22
+ )}
23
+ {...props}>
24
+ <CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}>
25
+ <Check className="h-4 w-4" />
26
+ </CheckboxPrimitive.Indicator>
67
27
  </Component>
68
28
  );
69
- };
70
-
29
+ });
71
30
  Checkbox.displayName = displayName;
31
+
32
+ export { Checkbox };
@@ -1 +0,0 @@
1
- import{DefaultComponent as f,useStackShiftUIComponents as x}from"@stackshift-ui/system";import o from"classnames";import{jsx as u,jsxs as T}from"react/jsx-runtime";var a="Checkbox",h=({required:l=!1,name:t,ariaLabel:i,label:m,labelClass:p,item:e,variant:c="primary",onChange:y,className:C,as:b="label",...n})=>{var r;let{[a]:d=f}=x(),s="",g=(r={primary:s}[c])!=null?r:s;return T(d,{as:b,htmlFor:e,className:o("flex gap-2 items-center",p),...n,"data-testid":a,children:[u("input",{"aria-label":i||t,className:o(g,C),name:t,type:"checkbox",value:e,required:l,onChange:y,id:e,...n}),m||e]})};h.displayName=a;export{h as a};