@stackshift-ui/checkbox 6.0.2 → 6.0.4-beta.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/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/checkbox",
3
3
  "description": "",
4
- "version": "6.0.2",
4
+ "version": "6.0.4-beta.0",
5
5
  "private": false,
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.js",
8
8
  "module": "./dist/index.mjs",
9
9
  "types": "./dist/index.d.ts",
10
10
  "files": [
11
- "dist/**"
11
+ "dist/**",
12
+ "src"
12
13
  ],
13
14
  "author": "WebriQ <info@webriq.com>",
14
15
  "devDependencies": {
@@ -28,20 +29,20 @@
28
29
  "typescript": "^5.6.2",
29
30
  "vite-tsconfig-paths": "^5.0.1",
30
31
  "vitest": "^2.1.1",
31
- "@stackshift-ui/eslint-config": "6.0.2",
32
- "@stackshift-ui/typescript-config": "6.0.2"
32
+ "@stackshift-ui/eslint-config": "6.0.3-beta.0",
33
+ "@stackshift-ui/typescript-config": "6.0.3-beta.0"
33
34
  },
34
35
  "dependencies": {
35
36
  "classnames": "^2.5.1",
36
- "@stackshift-ui/scripts": "6.0.2",
37
- "@stackshift-ui/system": "6.0.2"
37
+ "@stackshift-ui/scripts": "6.0.3-beta.0",
38
+ "@stackshift-ui/system": "6.0.4-beta.0"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "@types/react": "16.8 - 19",
41
42
  "next": "10 - 14",
42
43
  "react": "16.8 - 19",
43
44
  "react-dom": "16.8 - 19",
44
- "@stackshift-ui/system": ">=0.0.0"
45
+ "@stackshift-ui/system": ">=6.0.4-beta.0"
45
46
  },
46
47
  "peerDependenciesMeta": {
47
48
  "next": {
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { Checkbox } from "./checkbox";
4
+
5
+ describe.concurrent("checkbox", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: Checkbox - test if renders without errors", ({ expect }) => {
9
+ const clx = "checkbox-class";
10
+ render(<Checkbox className={clx} />);
11
+ expect(screen.getByTestId("label").classList).toBeDefined();
12
+ });
13
+ });
@@ -0,0 +1,71 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import cn from "classnames";
3
+ import type { ElementType, HTMLProps } from "react";
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
+ }
20
+
21
+ const displayName = "Checkbox";
22
+
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
+ }) => {
36
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
37
+
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
+ return (
49
+ <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}
67
+ </Component>
68
+ );
69
+ };
70
+
71
+ Checkbox.displayName = displayName;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./checkbox";