@stackshift-ui/input-file 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.
@@ -0,0 +1 @@
1
+ import{DefaultComponent as x,useStackShiftUIComponents as C}from"@stackshift-ui/system";import F from"classnames";import{useState as N}from"react";import{jsx as r,jsxs as m}from"react/jsx-runtime";var e="InputFile",T=({required:d=!1,variant:c="primary",name:t,ariaLabel:n,children:I,className:u,as:S,...f})=>{var s;let{[e]:E=x}=C(),[y,o]=N(""),a="my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200",i=`${a} bg-primary-foreground hover:bg-primary`,g=`${a} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`,h=(s={primary:i,outline:g}[c])!=null?s:i,b=v=>{var p;let l=(p=v.target.files)==null?void 0:p[0];o(l?l.name:"")};return m("div",{className:"relative rounded-global bg-white px-2 w-full","data-testid":e==null?void 0:e.toLowerCase(),children:[r("input",{"aria-label":n!=null?n:"Attach file",className:"absolute w-full h-full opacity-0 cursor-pointer",type:"file",name:t,required:d,id:t,onChange:b,...f}),m("div",{className:"flex",children:[r("span",{className:"px-2 py-4 text-xs font-semibold leading-none",children:y}),r("label",{htmlFor:t,className:F(h,u),children:t})]})]})};T.displayName=e;export{T as a};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";var S=Object.create;var s=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},y=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!w.call(e,a)&&a!==n&&s(e,a,{get:()=>t[a],enumerable:!(o=E(t,a))||o.enumerable});return e};var M=(e,t,n)=>(n=e!=null?S(V(e)):{},y(t||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),P=e=>y(s({},"__esModule",{value:!0}),e);var k={};H(k,{InputFile:()=>x});module.exports=P(k);var l=require("@stackshift-ui/system"),g=M(require("classnames")),h=require("react"),r=require("react/jsx-runtime"),i="InputFile",x=({required:e=!1,variant:t="primary",name:n,ariaLabel:o,children:a,className:v,as:q,...b})=>{var d;let{[i]:L=l.DefaultComponent}=(0,l.useStackShiftUIComponents)(),[C,p]=(0,h.useState)(""),m="my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200",c=`${m} bg-primary-foreground hover:bg-primary`,F=`${m} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`,N=(d={primary:c,outline:F}[t])!=null?d:c,T=I=>{var f;let u=(f=I.target.files)==null?void 0:f[0];p(u?u.name:"")};return(0,r.jsxs)("div",{className:"relative rounded bg-white px-2 w-full","data-testid":i==null?void 0:i.toLowerCase(),children:[(0,r.jsx)("input",{"aria-label":o!=null?o:"Attach file",className:"absolute w-full h-full opacity-0 cursor-pointer",type:"file",name:n,required:e,id:n,onChange:T,...b}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"px-2 py-4 text-xs font-semibold leading-none",children:C}),(0,r.jsx)("label",{htmlFor:n,className:(0,g.default)(N,v),children:n})]})]})};x.displayName=i;0&&(module.exports={InputFile});
2
+ "use strict";var S=Object.create;var s=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},y=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!w.call(e,a)&&a!==n&&s(e,a,{get:()=>t[a],enumerable:!(o=E(t,a))||o.enumerable});return e};var M=(e,t,n)=>(n=e!=null?S(V(e)):{},y(t||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),P=e=>y(s({},"__esModule",{value:!0}),e);var k={};H(k,{InputFile:()=>x});module.exports=P(k);var l=require("@stackshift-ui/system"),g=M(require("classnames")),h=require("react"),r=require("react/jsx-runtime"),i="InputFile",x=({required:e=!1,variant:t="primary",name:n,ariaLabel:o,children:a,className:b,as:q,...v})=>{var d;let{[i]:L=l.DefaultComponent}=(0,l.useStackShiftUIComponents)(),[C,p]=(0,h.useState)(""),m="my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200",c=`${m} bg-primary-foreground hover:bg-primary`,F=`${m} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`,N=(d={primary:c,outline:F}[t])!=null?d:c,T=I=>{var f;let u=(f=I.target.files)==null?void 0:f[0];p(u?u.name:"")};return(0,r.jsxs)("div",{className:"relative rounded-global bg-white px-2 w-full","data-testid":i==null?void 0:i.toLowerCase(),children:[(0,r.jsx)("input",{"aria-label":o!=null?o:"Attach file",className:"absolute w-full h-full opacity-0 cursor-pointer",type:"file",name:n,required:e,id:n,onChange:T,...v}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"px-2 py-4 text-xs font-semibold leading-none",children:C}),(0,r.jsx)("label",{htmlFor:n,className:(0,g.default)(N,b),children:n})]})]})};x.displayName=i;0&&(module.exports={InputFile});
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";import{a as e}from"./chunk-QDTVWRJM.mjs";export{e as InputFile};
2
+ "use strict";import{a as e}from"./chunk-ALMEZKLK.mjs";export{e as InputFile};
@@ -1 +1 @@
1
- "use strict";var S=Object.create;var s=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},y=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!w.call(e,a)&&a!==n&&s(e,a,{get:()=>t[a],enumerable:!(o=E(t,a))||o.enumerable});return e};var M=(e,t,n)=>(n=e!=null?S(V(e)):{},y(t||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),P=e=>y(s({},"__esModule",{value:!0}),e);var k={};H(k,{InputFile:()=>v});module.exports=P(k);var l=require("@stackshift-ui/system"),g=M(require("classnames")),h=require("react"),r=require("react/jsx-runtime"),i="InputFile",v=({required:e=!1,variant:t="primary",name:n,ariaLabel:o,children:a,className:x,as:q,...b})=>{var c;let{[i]:L=l.DefaultComponent}=(0,l.useStackShiftUIComponents)(),[C,p]=(0,h.useState)(""),m="my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200",d=`${m} bg-primary-foreground hover:bg-primary`,F=`${m} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`,N=(c={primary:d,outline:F}[t])!=null?c:d,T=I=>{var f;let u=(f=I.target.files)==null?void 0:f[0];p(u?u.name:"")};return(0,r.jsxs)("div",{className:"relative rounded bg-white px-2 w-full","data-testid":i==null?void 0:i.toLowerCase(),children:[(0,r.jsx)("input",{"aria-label":o!=null?o:"Attach file",className:"absolute w-full h-full opacity-0 cursor-pointer",type:"file",name:n,required:e,id:n,onChange:T,...b}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"px-2 py-4 text-xs font-semibold leading-none",children:C}),(0,r.jsx)("label",{htmlFor:n,className:(0,g.default)(N,x),children:n})]})]})};v.displayName=i;0&&(module.exports={InputFile});
1
+ "use strict";var S=Object.create;var s=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var V=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},y=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of R(t))!w.call(e,a)&&a!==n&&s(e,a,{get:()=>t[a],enumerable:!(o=E(t,a))||o.enumerable});return e};var M=(e,t,n)=>(n=e!=null?S(V(e)):{},y(t||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),P=e=>y(s({},"__esModule",{value:!0}),e);var k={};H(k,{InputFile:()=>b});module.exports=P(k);var l=require("@stackshift-ui/system"),g=M(require("classnames")),h=require("react"),r=require("react/jsx-runtime"),i="InputFile",b=({required:e=!1,variant:t="primary",name:n,ariaLabel:o,children:a,className:v,as:q,...x})=>{var c;let{[i]:L=l.DefaultComponent}=(0,l.useStackShiftUIComponents)(),[C,p]=(0,h.useState)(""),m="my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200",d=`${m} bg-primary-foreground hover:bg-primary`,F=`${m} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`,N=(c={primary:d,outline:F}[t])!=null?c:d,T=I=>{var f;let u=(f=I.target.files)==null?void 0:f[0];p(u?u.name:"")};return(0,r.jsxs)("div",{className:"relative rounded-global bg-white px-2 w-full","data-testid":i==null?void 0:i.toLowerCase(),children:[(0,r.jsx)("input",{"aria-label":o!=null?o:"Attach file",className:"absolute w-full h-full opacity-0 cursor-pointer",type:"file",name:n,required:e,id:n,onChange:T,...x}),(0,r.jsxs)("div",{className:"flex",children:[(0,r.jsx)("span",{className:"px-2 py-4 text-xs font-semibold leading-none",children:C}),(0,r.jsx)("label",{htmlFor:n,className:(0,g.default)(N,v),children:n})]})]})};b.displayName=i;0&&(module.exports={InputFile});
@@ -1 +1 @@
1
- import{a}from"./chunk-QDTVWRJM.mjs";export{a as InputFile};
1
+ import{a}from"./chunk-ALMEZKLK.mjs";export{a as InputFile};
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/input-file",
3
3
  "description": "",
4
- "version": "6.0.2",
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/typescript-config": "6.0.2",
32
- "@stackshift-ui/eslint-config": "6.0.2"
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.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 "./input-file";
@@ -0,0 +1,15 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { InputFile } from "./input-file";
4
+
5
+ describe.concurrent("input-file", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: Input File - test if renders without errors", ({ expect }) => {
9
+ const clx = "inputfile-class";
10
+ render(
11
+ <InputFile className={clx} name="stackshift-inputfile" ariaLabel="stackshift input file" />,
12
+ );
13
+ expect(screen.getByTestId("inputfile").classList).toBeDefined();
14
+ });
15
+ });
@@ -0,0 +1,81 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import cn from "classnames";
3
+ import type { ElementType, HTMLProps, ReactNode } from "react";
4
+ import { useState } from "react";
5
+
6
+ type StyleVariants<T extends string> = Record<T, string>;
7
+ type Variant = "primary" | "outline";
8
+
9
+ export interface InputFileProps extends Omit<HTMLProps<HTMLInputElement>, "as"> {
10
+ required?: boolean;
11
+ variant?: Variant;
12
+ name: string;
13
+ ariaLabel: string;
14
+ [key: string]: any;
15
+ children?: ReactNode;
16
+ className?: string;
17
+ as?: ElementType;
18
+ }
19
+
20
+ const displayName = "InputFile";
21
+
22
+ export const InputFile: React.FC<InputFileProps> = ({
23
+ required = false,
24
+ variant = "primary",
25
+ name,
26
+ ariaLabel,
27
+ children,
28
+ className,
29
+ as,
30
+ ...props
31
+ }) => {
32
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
33
+
34
+ const [filename, setFilename] = useState("");
35
+
36
+ const commonStyle =
37
+ "my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200";
38
+ const primary = `${commonStyle} bg-primary-foreground hover:bg-primary`;
39
+ const outline = `${commonStyle} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`;
40
+
41
+ const variants: StyleVariants<Variant> = {
42
+ primary,
43
+ outline,
44
+ };
45
+
46
+ const variantClass = variants[variant] ?? primary;
47
+
48
+ const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
49
+ const file = event.target.files?.[0];
50
+ if (file) {
51
+ setFilename(file.name);
52
+ } else {
53
+ setFilename("");
54
+ }
55
+ };
56
+
57
+ return (
58
+ <div
59
+ className={"relative rounded-global bg-white px-2 w-full"}
60
+ data-testid={displayName?.toLowerCase()}>
61
+ <input
62
+ aria-label={ariaLabel ?? "Attach file"}
63
+ className="absolute w-full h-full opacity-0 cursor-pointer"
64
+ type="file"
65
+ name={name}
66
+ required={required}
67
+ id={name}
68
+ onChange={handleFileChange}
69
+ {...props}
70
+ />
71
+ <div className="flex">
72
+ <span className="px-2 py-4 text-xs font-semibold leading-none">{filename}</span>
73
+ <label htmlFor={name} className={cn(variantClass, className)}>
74
+ {name}
75
+ </label>
76
+ </div>
77
+ </div>
78
+ );
79
+ };
80
+
81
+ InputFile.displayName = displayName;
@@ -1 +0,0 @@
1
- import{DefaultComponent as b,useStackShiftUIComponents as C}from"@stackshift-ui/system";import F from"classnames";import{useState as N}from"react";import{jsx as r,jsxs as m}from"react/jsx-runtime";var e="InputFile",T=({required:d=!1,variant:c="primary",name:t,ariaLabel:n,children:I,className:u,as:S,...f})=>{var s;let{[e]:E=b}=C(),[y,o]=N(""),a="my-1 ml-auto cursor-pointer rounded px-4 py-3 text-xs font-semibold leading-none transition duration-200",i=`${a} bg-primary-foreground hover:bg-primary`,g=`${a} text-primary-foreground border border-solid border-primary-foreground hover:bg-slate-100`,h=(s={primary:i,outline:g}[c])!=null?s:i,v=x=>{var p;let l=(p=x.target.files)==null?void 0:p[0];o(l?l.name:"")};return m("div",{className:"relative rounded bg-white px-2 w-full","data-testid":e==null?void 0:e.toLowerCase(),children:[r("input",{"aria-label":n!=null?n:"Attach file",className:"absolute w-full h-full opacity-0 cursor-pointer",type:"file",name:t,required:d,id:t,onChange:v,...f}),m("div",{className:"flex",children:[r("span",{className:"px-2 py-4 text-xs font-semibold leading-none",children:y}),r("label",{htmlFor:t,className:F(h,u),children:t})]})]})};T.displayName=e;export{T as a};