@stackshift-ui/radio-group 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 +8 -7
- package/src/index.ts +4 -0
- package/src/radio-group.test.tsx +13 -0
- package/src/radio-group.tsx +59 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/radio-group",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "6.0.
|
|
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/
|
|
32
|
-
"@stackshift-ui/
|
|
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/system": "6.0.
|
|
37
|
-
"@stackshift-ui/scripts": "6.0.
|
|
37
|
+
"@stackshift-ui/system": "6.0.4-beta.0",
|
|
38
|
+
"@stackshift-ui/scripts": "6.0.3-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": ">=
|
|
45
|
+
"@stackshift-ui/system": ">=6.0.4-beta.0"
|
|
45
46
|
},
|
|
46
47
|
"peerDependenciesMeta": {
|
|
47
48
|
"next": {
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { RadioGroup } from "./radio-group";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("radio-group", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Common: Radio Group - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "radiogroup-class";
|
|
10
|
+
render(<RadioGroup className={clx} name="stackshift-radiogroup" />);
|
|
11
|
+
expect(screen.getByTestId("div").classList).toContain(clx);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
2
|
+
import type { ElementType, HTMLProps, ReactNode } from "react";
|
|
3
|
+
import cn from "classnames";
|
|
4
|
+
|
|
5
|
+
type StyleVariants<T extends string> = Record<T, string>;
|
|
6
|
+
type Variant = "primary" | "inline";
|
|
7
|
+
|
|
8
|
+
export interface RadioGroupProps extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
9
|
+
variant?: Variant;
|
|
10
|
+
label?: string;
|
|
11
|
+
name: string;
|
|
12
|
+
labelClass?: string;
|
|
13
|
+
noLabel?: boolean;
|
|
14
|
+
children?: ReactNode;
|
|
15
|
+
className?: string;
|
|
16
|
+
as?: ElementType;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const displayName = "RadioGroup";
|
|
20
|
+
|
|
21
|
+
export const RadioGroup: React.FC<RadioGroupProps> = ({
|
|
22
|
+
variant = "primary",
|
|
23
|
+
label,
|
|
24
|
+
name,
|
|
25
|
+
labelClass,
|
|
26
|
+
noLabel = false,
|
|
27
|
+
children,
|
|
28
|
+
className,
|
|
29
|
+
as,
|
|
30
|
+
...props
|
|
31
|
+
}) => {
|
|
32
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
33
|
+
|
|
34
|
+
const commonClass = "ml-2";
|
|
35
|
+
const primary = `${commonClass}`;
|
|
36
|
+
const inline = `${commonClass} flex items-center gap-2`;
|
|
37
|
+
|
|
38
|
+
const variants: StyleVariants<Variant> = {
|
|
39
|
+
primary,
|
|
40
|
+
inline,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const variantClass = variants[variant] ?? primary;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<div>
|
|
47
|
+
{!noLabel && <p className={labelClass}>{label || name}</p>}
|
|
48
|
+
<Component
|
|
49
|
+
as={as}
|
|
50
|
+
className={cn(variantClass, className)}
|
|
51
|
+
{...props}
|
|
52
|
+
data-testid={displayName}>
|
|
53
|
+
{children}
|
|
54
|
+
</Component>
|
|
55
|
+
</div>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
RadioGroup.displayName = displayName;
|