@stackshift-ui/select 1.0.0 → 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 +7 -6
- package/src/index.ts +4 -0
- package/src/select.test.tsx +20 -0
- package/src/select.tsx +85 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/select",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "
|
|
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": {
|
|
@@ -28,13 +29,13 @@
|
|
|
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": "
|
|
32
|
-
"@stackshift-ui/typescript-config": "
|
|
32
|
+
"@stackshift-ui/eslint-config": "6.0.2",
|
|
33
|
+
"@stackshift-ui/typescript-config": "6.0.2"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"classnames": "^2.5.1",
|
|
36
|
-
"@stackshift-ui/
|
|
37
|
-
"@stackshift-ui/
|
|
37
|
+
"@stackshift-ui/system": "6.0.3",
|
|
38
|
+
"@stackshift-ui/scripts": "6.0.2"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"@types/react": "16.8 - 19",
|
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 { Select } from "./select";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("select", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Common: Select - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "select-class";
|
|
10
|
+
render(
|
|
11
|
+
<Select
|
|
12
|
+
className={clx}
|
|
13
|
+
name="stackshift-select"
|
|
14
|
+
ariaLabel="stackshift select"
|
|
15
|
+
items={["Option 1", "Option 2", "Option 3"]}
|
|
16
|
+
/>,
|
|
17
|
+
);
|
|
18
|
+
expect(screen.getByTestId("select").classList).toContain(clx);
|
|
19
|
+
});
|
|
20
|
+
});
|
package/src/select.tsx
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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" | "outline";
|
|
7
|
+
|
|
8
|
+
export interface SelectProps extends Omit<HTMLProps<HTMLSelectElement>, "as"> {
|
|
9
|
+
defaultValue?: string;
|
|
10
|
+
variant?: Variant;
|
|
11
|
+
label?: string;
|
|
12
|
+
labelClass?: string;
|
|
13
|
+
onChange?: () => void;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
name: string;
|
|
16
|
+
items: string[];
|
|
17
|
+
ariaLabel: string;
|
|
18
|
+
noLabel?: boolean;
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
children?: ReactNode;
|
|
21
|
+
className?: string;
|
|
22
|
+
as?: ElementType;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const displayName = "Select";
|
|
26
|
+
|
|
27
|
+
export const Select: React.FC<SelectProps> = ({
|
|
28
|
+
defaultValue,
|
|
29
|
+
variant = "primary",
|
|
30
|
+
label,
|
|
31
|
+
labelClass,
|
|
32
|
+
onChange,
|
|
33
|
+
required = false,
|
|
34
|
+
name,
|
|
35
|
+
items,
|
|
36
|
+
ariaLabel,
|
|
37
|
+
noLabel = false,
|
|
38
|
+
children,
|
|
39
|
+
className,
|
|
40
|
+
as = "select",
|
|
41
|
+
...props
|
|
42
|
+
}) => {
|
|
43
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
44
|
+
|
|
45
|
+
const commonStyle = "w-full rounded bg-white p-4 text-xs font-semibold leading-none outline-none";
|
|
46
|
+
const primary = `${commonStyle}`;
|
|
47
|
+
const outline = `${commonStyle} border border-solid border-primary-foreground`;
|
|
48
|
+
|
|
49
|
+
const variants: StyleVariants<Variant> = {
|
|
50
|
+
primary,
|
|
51
|
+
outline,
|
|
52
|
+
};
|
|
53
|
+
const variantClass = variants[variant] ?? primary;
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<>
|
|
57
|
+
{!noLabel && (
|
|
58
|
+
<label htmlFor={name} className={labelClass}>
|
|
59
|
+
{label || name}
|
|
60
|
+
</label>
|
|
61
|
+
)}
|
|
62
|
+
<Component
|
|
63
|
+
onChange={onChange}
|
|
64
|
+
name={name}
|
|
65
|
+
defaultValue={defaultValue}
|
|
66
|
+
required={required}
|
|
67
|
+
as={as}
|
|
68
|
+
className={cn(variantClass, className)}
|
|
69
|
+
{...props}
|
|
70
|
+
data-testid={displayName}>
|
|
71
|
+
{items &&
|
|
72
|
+
items.length > 0 &&
|
|
73
|
+
items.map(opt => {
|
|
74
|
+
return (
|
|
75
|
+
<option value={opt} key={opt}>
|
|
76
|
+
{opt}
|
|
77
|
+
</option>
|
|
78
|
+
);
|
|
79
|
+
})}
|
|
80
|
+
</Component>
|
|
81
|
+
</>
|
|
82
|
+
);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
Select.displayName = displayName;
|