@stackshift-ui/checkbox-group 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.
- package/dist/checkbox-group.d.ts +1 -1
- package/dist/checkbox-group.js +1 -1
- package/dist/checkbox-group.mjs +1 -1
- package/dist/chunk-3EYN2AKU.mjs +1 -0
- package/dist/chunk-4O7QC542.mjs +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/setupTests.d.ts +2 -0
- package/dist/setupTests.js +47 -0
- package/dist/setupTests.mjs +47 -0
- package/package.json +7 -5
- package/src/checkbox-group.test.tsx +58 -1
- package/src/checkbox-group.tsx +19 -20
- package/src/setupTests.ts +4 -0
- package/dist/chunk-AVWGONOP.mjs +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/checkbox-group",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "6.0
|
|
4
|
+
"version": "6.1.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",
|
|
@@ -34,15 +36,15 @@
|
|
|
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",
|
|
40
|
+
"@stackshift-ui/scripts": "6.1.0"
|
|
39
41
|
},
|
|
40
42
|
"peerDependencies": {
|
|
43
|
+
"@stackshift-ui/system": ">=7.0.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,42 +19,41 @@ 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";
|
|
36
38
|
const primary = `${commonClass} block`;
|
|
37
39
|
const inline = `${commonClass} flex gap-4`;
|
|
40
|
+
const combinedLabelClass = `mb-2 ${labelClass}`;
|
|
38
41
|
|
|
39
42
|
const variants: StyleVariants<Variant> = {
|
|
40
43
|
primary,
|
|
41
44
|
inline,
|
|
42
45
|
};
|
|
43
46
|
|
|
44
|
-
const variantClass = variants[variant] ?? primary;
|
|
47
|
+
const variantClass = variants[variant as Variant] ?? primary;
|
|
45
48
|
|
|
46
49
|
return (
|
|
47
50
|
<Fragment>
|
|
48
|
-
{!noLabel && <p className={
|
|
49
|
-
<Component
|
|
50
|
-
as={as}
|
|
51
|
-
className={cn(variantClass, className)}
|
|
52
|
-
{...props}
|
|
53
|
-
data-testid={displayName}>
|
|
51
|
+
{!noLabel && <p className={combinedLabelClass}>{label || name}</p>}
|
|
52
|
+
<Component ref={ref} as={as} className={cn(variantClass, className)} {...rest}>
|
|
54
53
|
{children}
|
|
55
54
|
</Component>
|
|
56
55
|
</Fragment>
|
|
57
56
|
);
|
|
58
|
-
};
|
|
57
|
+
});
|
|
59
58
|
|
|
60
59
|
CheckboxGroup.displayName = displayName;
|
package/dist/chunk-AVWGONOP.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{DefaultComponent as f,useStackShiftUIComponents as x}from"@stackshift-ui/system";import{Fragment as k}from"react";import N from"classnames";import{jsx as o,jsxs as h}from"react/jsx-runtime";var e="CheckboxGroup",T=({variant:s="primary",name:r,label:i,noLabel:p=!1,labelClass:l,children:m,className:c,as:y,...C})=>{var n;let{[e]:d=f}=x(),t="ml-2",a=`${t} block`,g=`${t} flex gap-4`,b=(n={primary:a,inline:g}[s])!=null?n:a;return h(k,{children:[!p&&o("p",{className:l,children:i||r}),o(d,{as:y,className:N(b,c),...C,"data-testid":e,children:m})]})};T.displayName=e;export{T as a};
|