@stackshift-ui/radio-group 6.0.2 → 6.0.3

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/radio-group",
3
3
  "description": "",
4
- "version": "6.0.2",
4
+ "version": "6.0.3",
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": {
@@ -33,8 +34,8 @@
33
34
  },
34
35
  "dependencies": {
35
36
  "classnames": "^2.5.1",
36
- "@stackshift-ui/system": "6.0.2",
37
- "@stackshift-ui/scripts": "6.0.2"
37
+ "@stackshift-ui/scripts": "6.0.2",
38
+ "@stackshift-ui/system": "6.0.3"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "@types/react": "16.8 - 19",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./radio-group";
@@ -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;