@stackshift-ui/radio 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.test.tsx +20 -0
- package/src/radio.tsx +67 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/radio",
|
|
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/eslint-config": "6.0.
|
|
32
|
-
"@stackshift-ui/typescript-config": "6.0.
|
|
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.
|
|
37
|
-
"@stackshift-ui/system": "6.0.
|
|
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": ">=
|
|
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,20 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { Radio } from "./radio";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("radio", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Common: Radio - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "my-class";
|
|
10
|
+
render(
|
|
11
|
+
<Radio
|
|
12
|
+
className={clx}
|
|
13
|
+
name="stackshift-radio"
|
|
14
|
+
ariaLabel="stackshift radio input"
|
|
15
|
+
item="StackShift"
|
|
16
|
+
/>,
|
|
17
|
+
);
|
|
18
|
+
expect(screen.getByTestId("label").classList).toBeDefined();
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/radio.tsx
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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";
|
|
7
|
+
|
|
8
|
+
export interface RadioProps extends Omit<HTMLProps<HTMLInputElement>, "as"> {
|
|
9
|
+
name: string;
|
|
10
|
+
ariaLabel: string;
|
|
11
|
+
variant?: Variant;
|
|
12
|
+
item: string;
|
|
13
|
+
labelClass?: string;
|
|
14
|
+
onChange?: () => void;
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
children?: ReactNode;
|
|
17
|
+
className?: string;
|
|
18
|
+
as?: ElementType;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const displayName = "Radio";
|
|
22
|
+
|
|
23
|
+
export const Radio: React.FC<RadioProps> = ({
|
|
24
|
+
name,
|
|
25
|
+
ariaLabel,
|
|
26
|
+
variant = "primary",
|
|
27
|
+
item,
|
|
28
|
+
labelClass,
|
|
29
|
+
onChange,
|
|
30
|
+
children,
|
|
31
|
+
className,
|
|
32
|
+
as = "label",
|
|
33
|
+
...props
|
|
34
|
+
}) => {
|
|
35
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
36
|
+
|
|
37
|
+
const commonStyle = "";
|
|
38
|
+
const primary = `${commonStyle}`;
|
|
39
|
+
|
|
40
|
+
const variants: StyleVariants<Variant> = {
|
|
41
|
+
primary,
|
|
42
|
+
};
|
|
43
|
+
const variantClass = variants[variant] ?? primary;
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<Component
|
|
47
|
+
htmlFor={item}
|
|
48
|
+
as={as}
|
|
49
|
+
className={cn("flex items-center gap-2", labelClass)}
|
|
50
|
+
{...props}
|
|
51
|
+
data-testid={displayName}>
|
|
52
|
+
<input
|
|
53
|
+
onChange={onChange}
|
|
54
|
+
className={cn(variantClass, className)}
|
|
55
|
+
name={name}
|
|
56
|
+
value={item}
|
|
57
|
+
type="radio"
|
|
58
|
+
aria-label={ariaLabel || name}
|
|
59
|
+
id={item}
|
|
60
|
+
{...props}
|
|
61
|
+
/>
|
|
62
|
+
{item}
|
|
63
|
+
</Component>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
Radio.displayName = displayName;
|