@stackshift-ui/select 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/dist/chunk-VCJRWWZ5.mjs +1 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/select.js +1 -1
- package/dist/select.mjs +1 -1
- package/package.json +6 -5
- package/src/index.ts +4 -0
- package/src/select.test.tsx +20 -0
- package/src/select.tsx +86 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{DefaultComponent as N,useStackShiftUIComponents as T}from"@stackshift-ui/system";import V from"classnames";import{Fragment as L,jsx as n,jsxs as x}from"react/jsx-runtime";var r="Select",v=({defaultValue:i,variant:c="primary",label:m,labelClass:p,onChange:d,required:g=!1,name:e,items:t,ariaLabel:P,noLabel:y=!1,children:R,className:u,as:b="select",...f})=>{var s;let{[r]:S=N}=T(),o="w-full rounded-global bg-white p-4 text-xs font-semibold leading-none outline-none",l=`${o}`,C=`${o} border border-solid border-primary-foreground`,h=(s={primary:l,outline:C}[c])!=null?s:l;return x(L,{children:[!y&&n("label",{htmlFor:e,className:p,children:m||e}),n(S,{onChange:d,name:e,defaultValue:i,required:g,as:b,className:V(h,u),...f,"data-testid":r,children:t&&t.length>0&&t.map(a=>n("option",{value:a,children:a},a))})]})};v.displayName=r;export{v as a};
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var L=Object.create;var l=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})},
|
|
2
|
+
"use strict";var L=Object.create;var l=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})},y=(e,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of R(t))!E.call(e,r)&&r!==a&&l(e,r,{get:()=>t[r],enumerable:!(o=P(t,r))||o.enumerable});return e};var M=(e,t,a)=>(a=e!=null?L(k(e)):{},y(t||!e||!e.__esModule?l(a,"default",{value:e,enumerable:!0}):a,e)),q=e=>y(l({},"__esModule",{value:!0}),e);var w={};H(w,{Select:()=>f});module.exports=q(w);var s=require("@stackshift-ui/system"),b=M(require("classnames")),n=require("react/jsx-runtime"),p="Select",f=({defaultValue:e,variant:t="primary",label:a,labelClass:o,onChange:r,required:S=!1,name:i,items:c,ariaLabel:F,noLabel:C=!1,children:$,className:h,as:N="select",...T})=>{var u;let{[p]:V=s.DefaultComponent}=(0,s.useStackShiftUIComponents)(),d="w-full rounded-global bg-white p-4 text-xs font-semibold leading-none outline-none",g=`${d}`,v=`${d} border border-solid border-primary-foreground`,x=(u={primary:g,outline:v}[t])!=null?u:g;return(0,n.jsxs)(n.Fragment,{children:[!C&&(0,n.jsx)("label",{htmlFor:i,className:o,children:a||i}),(0,n.jsx)(V,{onChange:r,name:i,defaultValue:e,required:S,as:N,className:(0,b.default)(x,h),...T,"data-testid":p,children:c&&c.length>0&&c.map(m=>(0,n.jsx)("option",{value:m,children:m},m))})]})};f.displayName=p;0&&(module.exports={Select});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";import{a as e}from"./chunk-
|
|
2
|
+
"use strict";import{a as e}from"./chunk-VCJRWWZ5.mjs";export{e as Select};
|
package/dist/select.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var x=Object.create;var l=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})},u=(e,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of R(t))!E.call(e,r)&&r!==a&&l(e,r,{get:()=>t[r],enumerable:!(o=P(t,r))||o.enumerable});return e};var M=(e,t,a)=>(a=e!=null?x(k(e)):{},u(t||!e||!e.__esModule?l(a,"default",{value:e,enumerable:!0}):a,e)),q=e=>u(l({},"__esModule",{value:!0}),e);var w={};H(w,{Select:()=>f});module.exports=q(w);var s=require("@stackshift-ui/system"),b=M(require("classnames")),n=require("react/jsx-runtime"),p="Select",f=({defaultValue:e,variant:t="primary",label:a,labelClass:o,onChange:r,required:S=!1,name:i,items:c,ariaLabel:F,noLabel:C=!1,children:$,className:h,as:N="select",...T})=>{var
|
|
1
|
+
"use strict";var x=Object.create;var l=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var a in t)l(e,a,{get:t[a],enumerable:!0})},u=(e,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of R(t))!E.call(e,r)&&r!==a&&l(e,r,{get:()=>t[r],enumerable:!(o=P(t,r))||o.enumerable});return e};var M=(e,t,a)=>(a=e!=null?x(k(e)):{},u(t||!e||!e.__esModule?l(a,"default",{value:e,enumerable:!0}):a,e)),q=e=>u(l({},"__esModule",{value:!0}),e);var w={};H(w,{Select:()=>f});module.exports=q(w);var s=require("@stackshift-ui/system"),b=M(require("classnames")),n=require("react/jsx-runtime"),p="Select",f=({defaultValue:e,variant:t="primary",label:a,labelClass:o,onChange:r,required:S=!1,name:i,items:c,ariaLabel:F,noLabel:C=!1,children:$,className:h,as:N="select",...T})=>{var y;let{[p]:V=s.DefaultComponent}=(0,s.useStackShiftUIComponents)(),d="w-full rounded-global bg-white p-4 text-xs font-semibold leading-none outline-none",g=`${d}`,v=`${d} border border-solid border-primary-foreground`,L=(y={primary:g,outline:v}[t])!=null?y:g;return(0,n.jsxs)(n.Fragment,{children:[!C&&(0,n.jsx)("label",{htmlFor:i,className:o,children:a||i}),(0,n.jsx)(V,{onChange:r,name:i,defaultValue:e,required:S,as:N,className:(0,b.default)(L,h),...T,"data-testid":p,children:c&&c.length>0&&c.map(m=>(0,n.jsx)("option",{value:m,children:m},m))})]})};f.displayName=p;0&&(module.exports={Select});
|
package/dist/select.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a}from"./chunk-
|
|
1
|
+
import{a}from"./chunk-VCJRWWZ5.mjs";export{a as Select};
|
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/select",
|
|
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,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/
|
|
32
|
-
"@stackshift-ui/
|
|
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
37
|
"@stackshift-ui/scripts": "6.0.2",
|
|
37
|
-
"@stackshift-ui/system": "6.0.
|
|
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,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,86 @@
|
|
|
1
|
+
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
2
|
+
import cn from "classnames";
|
|
3
|
+
import type { ElementType, HTMLProps, ReactNode } from "react";
|
|
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 =
|
|
46
|
+
"w-full rounded-global bg-white p-4 text-xs font-semibold leading-none outline-none";
|
|
47
|
+
const primary = `${commonStyle}`;
|
|
48
|
+
const outline = `${commonStyle} border border-solid border-primary-foreground`;
|
|
49
|
+
|
|
50
|
+
const variants: StyleVariants<Variant> = {
|
|
51
|
+
primary,
|
|
52
|
+
outline,
|
|
53
|
+
};
|
|
54
|
+
const variantClass = variants[variant] ?? primary;
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
{!noLabel && (
|
|
59
|
+
<label htmlFor={name} className={labelClass}>
|
|
60
|
+
{label || name}
|
|
61
|
+
</label>
|
|
62
|
+
)}
|
|
63
|
+
<Component
|
|
64
|
+
onChange={onChange}
|
|
65
|
+
name={name}
|
|
66
|
+
defaultValue={defaultValue}
|
|
67
|
+
required={required}
|
|
68
|
+
as={as}
|
|
69
|
+
className={cn(variantClass, className)}
|
|
70
|
+
{...props}
|
|
71
|
+
data-testid={displayName}>
|
|
72
|
+
{items &&
|
|
73
|
+
items.length > 0 &&
|
|
74
|
+
items.map(opt => {
|
|
75
|
+
return (
|
|
76
|
+
<option value={opt} key={opt}>
|
|
77
|
+
{opt}
|
|
78
|
+
</option>
|
|
79
|
+
);
|
|
80
|
+
})}
|
|
81
|
+
</Component>
|
|
82
|
+
</>
|
|
83
|
+
);
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
Select.displayName = displayName;
|