@stackshift-ui/checkbox-group 6.0.11 → 7.0.0-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 +9 -7
- package/src/checkbox-group.test.tsx +58 -1
- package/src/checkbox-group.tsx +17 -19
- package/src/setupTests.ts +4 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/checkbox-group",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "7.0.0-beta.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"main": "./dist/index.js",
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
],
|
|
14
14
|
"author": "WebriQ <info@webriq.com>",
|
|
15
15
|
"devDependencies": {
|
|
16
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
16
17
|
"@testing-library/react": "^16.0.1",
|
|
18
|
+
"@testing-library/user-event": "^14.6.1",
|
|
17
19
|
"@types/node": "^22.7.0",
|
|
18
20
|
"@types/react": "^18.3.9",
|
|
19
21
|
"@types/react-dom": "^18.3.0",
|
|
@@ -29,20 +31,20 @@
|
|
|
29
31
|
"typescript": "^5.6.2",
|
|
30
32
|
"vite-tsconfig-paths": "^5.0.1",
|
|
31
33
|
"vitest": "^2.1.1",
|
|
32
|
-
"@stackshift-ui/
|
|
33
|
-
"@stackshift-ui/
|
|
34
|
+
"@stackshift-ui/typescript-config": "6.0.10",
|
|
35
|
+
"@stackshift-ui/eslint-config": "6.0.10"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
38
|
"classnames": "^2.5.1",
|
|
37
|
-
"@stackshift-ui/system": "6.0.
|
|
38
|
-
"@stackshift-ui/scripts": "6.0.
|
|
39
|
+
"@stackshift-ui/system": "6.1.0-beta.0",
|
|
40
|
+
"@stackshift-ui/scripts": "6.1.0-beta.0"
|
|
39
41
|
},
|
|
40
42
|
"peerDependencies": {
|
|
43
|
+
"@stackshift-ui/system": ">=6.1.0-beta.0",
|
|
41
44
|
"@types/react": "16.8 - 19",
|
|
42
45
|
"next": "10 - 14",
|
|
43
46
|
"react": "16.8 - 19",
|
|
44
|
-
"react-dom": "16.8 - 19"
|
|
45
|
-
"@stackshift-ui/system": ">=6.0.11"
|
|
47
|
+
"react-dom": "16.8 - 19"
|
|
46
48
|
},
|
|
47
49
|
"peerDependenciesMeta": {
|
|
48
50
|
"next": {
|
|
@@ -7,7 +7,64 @@ describe.concurrent("checkbox-group", () => {
|
|
|
7
7
|
|
|
8
8
|
test("Common: Checkbox Group - test if renders without errors", ({ expect }) => {
|
|
9
9
|
const clx = "my-class";
|
|
10
|
-
render(<CheckboxGroup className={clx} />);
|
|
10
|
+
const { unmount } = render(<CheckboxGroup data-testid="div" className={clx} />);
|
|
11
11
|
expect(screen.getByTestId("div").classList).toContain(clx);
|
|
12
|
+
unmount();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("Common: Checkbox Group - test if renders with correct label", ({ expect }) => {
|
|
16
|
+
const label = "My Label";
|
|
17
|
+
const { unmount } = render(<CheckboxGroup label={label} />);
|
|
18
|
+
expect(screen.getByText(label)).toBeInTheDocument();
|
|
19
|
+
unmount();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("Common: Checkbox Group - test if renders with correct variant", ({ expect }) => {
|
|
23
|
+
const clx = "w-full";
|
|
24
|
+
const { unmount: unmountPrimary } = render(
|
|
25
|
+
<CheckboxGroup
|
|
26
|
+
data-testid="primary-checkbox-group"
|
|
27
|
+
variant="primary"
|
|
28
|
+
label="Primary"
|
|
29
|
+
className={clx}
|
|
30
|
+
/>,
|
|
31
|
+
);
|
|
32
|
+
const checkboxGroup = screen.getByTestId("primary-checkbox-group");
|
|
33
|
+
screen.debug(checkboxGroup);
|
|
34
|
+
expect(checkboxGroup.classList).toContain(clx);
|
|
35
|
+
expect(checkboxGroup.classList).toContain("block");
|
|
36
|
+
expect(screen.getByText("Primary")).toBeInTheDocument();
|
|
37
|
+
|
|
38
|
+
const { unmount: unmountInline } = render(
|
|
39
|
+
<CheckboxGroup
|
|
40
|
+
data-testid="inline-checkbox-group"
|
|
41
|
+
variant="inline"
|
|
42
|
+
label="Inline"
|
|
43
|
+
className={clx}
|
|
44
|
+
/>,
|
|
45
|
+
);
|
|
46
|
+
const inlineCheckboxGroup = screen.getByTestId("inline-checkbox-group");
|
|
47
|
+
expect(inlineCheckboxGroup.classList).toContain(clx);
|
|
48
|
+
expect(inlineCheckboxGroup.classList).toContain("flex");
|
|
49
|
+
expect(inlineCheckboxGroup.classList).toContain("gap-4");
|
|
50
|
+
expect(screen.getByText("Inline")).toBeInTheDocument();
|
|
51
|
+
|
|
52
|
+
unmountPrimary();
|
|
53
|
+
unmountInline();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("Common: Checkbox Group - test render with checkboxes", ({ expect }) => {
|
|
57
|
+
const { unmount } = render(
|
|
58
|
+
<CheckboxGroup>
|
|
59
|
+
<input type="checkbox" id="1" name="1" value="1" />
|
|
60
|
+
<label htmlFor="1">Option 1</label>
|
|
61
|
+
<input type="checkbox" id="2" name="2" value="2" />
|
|
62
|
+
<label htmlFor="2">Option 2</label>
|
|
63
|
+
</CheckboxGroup>,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
expect(screen.getByLabelText("Option 1")).toBeInTheDocument();
|
|
67
|
+
expect(screen.getByLabelText("Option 2")).toBeInTheDocument();
|
|
68
|
+
unmount();
|
|
12
69
|
});
|
|
13
70
|
});
|
package/src/checkbox-group.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
2
|
-
import { Fragment, type ElementType, type HTMLProps, type ReactNode } from "react";
|
|
3
2
|
import cn from "classnames";
|
|
3
|
+
import { forwardRef, Fragment, type ElementType, type HTMLProps, type ReactNode } from "react";
|
|
4
4
|
|
|
5
5
|
type StyleVariants<T extends string> = Record<T, string>;
|
|
6
6
|
type Variant = "primary" | "inline";
|
|
@@ -19,17 +19,19 @@ export interface CheckboxGroupProps extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
|
19
19
|
|
|
20
20
|
const displayName = "CheckboxGroup";
|
|
21
21
|
|
|
22
|
-
export const CheckboxGroup
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
export const CheckboxGroup = forwardRef<HTMLDivElement, CheckboxGroupProps>((props, ref) => {
|
|
23
|
+
const {
|
|
24
|
+
variant = "primary",
|
|
25
|
+
name,
|
|
26
|
+
label,
|
|
27
|
+
noLabel = false,
|
|
28
|
+
labelClass,
|
|
29
|
+
children,
|
|
30
|
+
className,
|
|
31
|
+
as,
|
|
32
|
+
...rest
|
|
33
|
+
} = props;
|
|
34
|
+
|
|
33
35
|
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
34
36
|
|
|
35
37
|
const commonClass = "ml-2";
|
|
@@ -41,20 +43,16 @@ export const CheckboxGroup: React.FC<CheckboxGroupProps> = ({
|
|
|
41
43
|
inline,
|
|
42
44
|
};
|
|
43
45
|
|
|
44
|
-
const variantClass = variants[variant] ?? primary;
|
|
46
|
+
const variantClass = variants[variant as Variant] ?? primary;
|
|
45
47
|
|
|
46
48
|
return (
|
|
47
49
|
<Fragment>
|
|
48
50
|
{!noLabel && <p className={labelClass}>{label || name}</p>}
|
|
49
|
-
<Component
|
|
50
|
-
as={as}
|
|
51
|
-
className={cn(variantClass, className)}
|
|
52
|
-
{...props}
|
|
53
|
-
data-testid={displayName}>
|
|
51
|
+
<Component ref={ref} as={as} className={cn(variantClass, className)} {...rest}>
|
|
54
52
|
{children}
|
|
55
53
|
</Component>
|
|
56
54
|
</Fragment>
|
|
57
55
|
);
|
|
58
|
-
};
|
|
56
|
+
});
|
|
59
57
|
|
|
60
58
|
CheckboxGroup.displayName = displayName;
|