@stackshift-ui/button 6.0.11 → 6.1.0-beta.1

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/button.d.ts CHANGED
@@ -1,26 +1,11 @@
1
- import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from "react";
2
- import { type LabeledRoute } from "./types";
3
- type Variant = "outline" | "ghost" | "link" | "custom" | "solid" | "addToWishlist" | "unstyled" | "swiper_pagination" | "tab";
4
- type TextSize = "xs" | "sm" | "md" | "lg";
5
- type RadiusSize = "none" | "sm" | "md" | "base" | "lg" | "xl" | "2xl" | "full";
6
- interface BaseType {
7
- children?: ReactNode;
8
- variant?: Variant;
9
- radius?: RadiusSize;
10
- size?: TextSize;
11
- ariaLabel?: string;
12
- isActive?: boolean;
1
+ import { type VariantProps } from "class-variance-authority";
2
+ import * as React from "react";
3
+ declare const buttonVariants: (props?: ({
4
+ variant?: "unstyled" | "default" | "destructive" | "outline" | "secondary" | "ghost" | "link" | null | undefined;
5
+ size?: "default" | "sm" | "lg" | "icon" | null | undefined;
6
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
+ export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
8
+ asChild?: boolean;
13
9
  }
14
- interface LinkProps extends BaseType, Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "type"> {
15
- link: LabeledRoute;
16
- as: "link";
17
- }
18
- interface ButtonProps extends BaseType, ButtonHTMLAttributes<HTMLButtonElement> {
19
- as?: "button";
20
- loading?: boolean;
21
- disabled?: boolean;
22
- loadingComponent?: React.ReactNode;
23
- }
24
- type Props = ButtonProps | LinkProps;
25
- export declare function Button({ children, ...props }: Props): import("react/jsx-runtime").JSX.Element;
26
- export {};
10
+ declare const Button: React.ForwardRefExoticComponent<ButtonProps & React.RefAttributes<HTMLButtonElement>>;
11
+ export { Button, buttonVariants };
package/dist/button.js CHANGED
@@ -1 +1 @@
1
- "use strict";var O=Object.create;var d=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var G=(t,e)=>{for(var o in e)d(t,o,{get:e[o],enumerable:!0})},T=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!D.call(t,r)&&r!==o&&d(t,r,{get:()=>e[r],enumerable:!(s=U(e,r))||s.enumerable});return t};var J=(t,e,o)=>(o=t!=null?O(q(t)):{},T(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t)),K=t=>T(d({},"__esModule",{value:!0}),t);var X={};G(X,{Button:()=>Q});module.exports=K(X);var S=require("@stackshift-ui/link"),B=require("@stackshift-ui/system"),u=J(require("classnames")),w=require("react-icons/fa");var v=t=>{var e,o;return!(t!=null&&t.internalLink)&&!(t!=null&&t.externalLink)?"/page-not-found":(t==null?void 0:t.type)==="linkInternal"&&((o=(e=t==null?void 0:t.internalLink)==null?void 0:e.toLowerCase())!=null&&o.includes("home"))?"/":(t==null?void 0:t.type)==="linkInternal"?`/${t==null?void 0:t.internalLink}`:(t==null?void 0:t.type)==="linkExternal"?`${t==null?void 0:t.externalLink}`:"/"};var l=require("react/jsx-runtime"),R="Button";function Q({children:t,...e}){let{[R]:o="button"}=(0,B.useStackShiftUIComponents)(),s={xs:"py-1 px-3 text-xs",sm:"py-2 px-4 text-sm",default:"py-3 px-6 text-default",md:"py-3 px-6 text-base",lg:"py-4 px-7 text-lg"},r={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",base:"rounded-base",lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl",full:"rounded-full",global:"rounded-global"},{radius:x,size:p,variant:m,ariaLabel:f,className:g,isActive:L}=e,a=x?r[x]:"rounded-global",n=s[p!=null?p:"default"],i="inline-block font-default text-default transition duration-200",A=`${i} ${n} ${a} bg-primary hover:bg-primary/50 text-gray-50`,C=`inline-block bg-primary hover:bg-primary/50 ${n} ${a} text-gray-50 font-bold transition duration-200`,N=`${i} ${n} ${a} bg-white hover:bg-primary/50 outline outline-1 text-primary outline-primary`,z=`${i} ${a} ${n} bg-transparent hover:bg-primary/50 text-primary`,M=`transition-200 text-primary hover:text-primary/50 underline ${a} ${(0,u.default)(n,"px-0 py-0")}`,P="",H=`mr-1 ${L?"bg-primary":"bg-gray-200"} rounded-full p-1 focus:outline-none`,V=`mx-auto mb-1 w-auto px-4 py-2 rounded duration-200 transition focus:outline-none font-bold ${L?"bg-gray-50 text-primary shadow":"text-gray-700 hover:bg-secondary/50 hover:text-primary hover:shadow"}`,E=`${i} ${a} ${n} ml-auto sm:ml-0 flex-shrink-0 inline-flex items-center justify-center w-full rounded-md border hover:border-primary`,h={outline:N,ghost:z,link:M,custom:C,solid:A,addToWishlist:E,unstyled:P,swiper_pagination:H,tab:V}[m!=null?m:"solid"];if(e.as==="link"){let{link:b,...F}=e;return(0,l.jsx)(S.Link,{className:(0,u.default)(h,g),"aria-label":f,href:v(b),target:b.linkTarget,rel:b.linkTarget==="_blank"?"noopener noreferrer":"",...F,children:t})}let{loadingComponent:c,onClick:I,loading:$,disabled:y,type:_}=e,W=c!=null?c:(0,l.jsx)(w.FaSpinner,{className:"animate-spin",size:30});return(0,l.jsx)(o,{onClick:I,disabled:y!=null?y:$,className:(0,u.default)(h,g),"aria-label":f,"data-testid":R.toLowerCase(),type:_,children:$?W:t})}0&&(module.exports={Button});
1
+ "use strict";var v=Object.create;var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var n in t)s(e,n,{get:t[n],enumerable:!0})},a=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of y(t))!B.call(e,o)&&o!==n&&s(e,o,{get:()=>t[o],enumerable:!(i=h(t,o))||i.enumerable});return e};var k=(e,t,n)=>(n=e!=null?v(x(e)):{},a(t||!e||!e.__esModule?s(n,"default",{value:e,enumerable:!0}):n,e)),w=e=>a(s({},"__esModule",{value:!0}),e);var V={};C(V,{Button:()=>l,buttonVariants:()=>f});module.exports=w(V);var d=require("@radix-ui/react-slot"),u=require("class-variance-authority"),c=k(require("react")),r=require("@stackshift-ui/system"),g=require("react/jsx-runtime"),p="Button",f=(0,u.cva)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{unstyled:"bg-transparent p-0 border-none shadow-none hover:bg-transparent ring-0 outline-none text-inherit",default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),l=c.forwardRef(({className:e,variant:t,size:n,asChild:i=!1,...o},m)=>{let{[p]:b=r.DefaultComponent}=(0,r.useStackShiftUIComponents)();return(0,g.jsx)(b,{as:i?d.Slot:"button",className:(0,r.cn)(f({variant:t,size:n,className:e})),ref:m,...o})});l.displayName=p;0&&(module.exports={Button,buttonVariants});
package/dist/button.mjs CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-RVVB2H7S.mjs";import"./chunk-5BNLLVMY.mjs";export{a as Button};
1
+ import{a,b}from"./chunk-UMCCY4XB.mjs";export{b as Button,a as buttonVariants};
@@ -0,0 +1 @@
1
+ import{Slot as u}from"@radix-ui/react-slot";import{cva as c}from"class-variance-authority";import*as e from"react";import{cn as p,DefaultComponent as f,useStackShiftUIComponents as l}from"@stackshift-ui/system";import{jsx as b}from"react/jsx-runtime";var t="Button",g=c("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{unstyled:"bg-transparent p-0 border-none shadow-none hover:bg-transparent ring-0 outline-none text-inherit",default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),m=e.forwardRef(({className:n,variant:o,size:r,asChild:i=!1,...s},a)=>{let{[t]:d=f}=l();return b(d,{as:i?u:"button",className:p(g({variant:o,size:r,className:n})),ref:a,...s})});m.displayName=t;export{g as a,m as b};
@@ -1 +1 @@
1
- import{a}from"../chunk-5BNLLVMY.mjs";export{a as extractLink};
1
+ var a=e=>{var t,r;return!(e!=null&&e.internalLink)&&!(e!=null&&e.externalLink)?"/page-not-found":(e==null?void 0:e.type)==="linkInternal"&&((r=(t=e==null?void 0:e.internalLink)==null?void 0:t.toLowerCase())!=null&&r.includes("home"))?"/":(e==null?void 0:e.type)==="linkInternal"?`/${e==null?void 0:e.internalLink}`:(e==null?void 0:e.type)==="linkExternal"?`${e==null?void 0:e.externalLink}`:"/"};export{a as extractLink};
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";var O=Object.create;var d=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,D=Object.prototype.hasOwnProperty;var G=(t,e)=>{for(var o in e)d(t,o,{get:e[o],enumerable:!0})},T=(t,e,o,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!D.call(t,r)&&r!==o&&d(t,r,{get:()=>e[r],enumerable:!(s=U(e,r))||s.enumerable});return t};var J=(t,e,o)=>(o=t!=null?O(q(t)):{},T(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t)),K=t=>T(d({},"__esModule",{value:!0}),t);var X={};G(X,{Button:()=>Q});module.exports=K(X);var S=require("@stackshift-ui/link"),B=require("@stackshift-ui/system"),u=J(require("classnames")),w=require("react-icons/fa");var v=t=>{var e,o;return!(t!=null&&t.internalLink)&&!(t!=null&&t.externalLink)?"/page-not-found":(t==null?void 0:t.type)==="linkInternal"&&((o=(e=t==null?void 0:t.internalLink)==null?void 0:e.toLowerCase())!=null&&o.includes("home"))?"/":(t==null?void 0:t.type)==="linkInternal"?`/${t==null?void 0:t.internalLink}`:(t==null?void 0:t.type)==="linkExternal"?`${t==null?void 0:t.externalLink}`:"/"};var l=require("react/jsx-runtime"),R="Button";function Q({children:t,...e}){let{[R]:o="button"}=(0,B.useStackShiftUIComponents)(),s={xs:"py-1 px-3 text-xs",sm:"py-2 px-4 text-sm",default:"py-3 px-6 text-default",md:"py-3 px-6 text-base",lg:"py-4 px-7 text-lg"},r={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",base:"rounded-base",lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl",full:"rounded-full",global:"rounded-global"},{radius:x,size:p,variant:m,ariaLabel:f,className:g,isActive:L}=e,n=x?r[x]:"rounded-global",a=s[p!=null?p:"default"],i="inline-block font-default text-default transition duration-200",A=`${i} ${a} ${n} bg-primary hover:bg-primary/50 text-gray-50`,C=`inline-block bg-primary hover:bg-primary/50 ${a} ${n} text-gray-50 font-bold transition duration-200`,N=`${i} ${a} ${n} bg-white hover:bg-primary/50 outline outline-1 text-primary outline-primary`,z=`${i} ${n} ${a} bg-transparent hover:bg-primary/50 text-primary`,M=`transition-200 text-primary hover:text-primary/50 underline ${n} ${(0,u.default)(a,"px-0 py-0")}`,P="",H=`mr-1 ${L?"bg-primary":"bg-gray-200"} rounded-full p-1 focus:outline-none`,V=`mx-auto mb-1 w-auto px-4 py-2 rounded duration-200 transition focus:outline-none font-bold ${L?"bg-gray-50 text-primary shadow":"text-gray-700 hover:bg-secondary/50 hover:text-primary hover:shadow"}`,E=`${i} ${n} ${a} ml-auto sm:ml-0 flex-shrink-0 inline-flex items-center justify-center w-full rounded-md border hover:border-primary`,h={outline:N,ghost:z,link:M,custom:C,solid:A,addToWishlist:E,unstyled:P,swiper_pagination:H,tab:V}[m!=null?m:"solid"];if(e.as==="link"){let{link:b,...F}=e;return(0,l.jsx)(S.Link,{className:(0,u.default)(h,g),"aria-label":f,href:v(b),target:b.linkTarget,rel:b.linkTarget==="_blank"?"noopener noreferrer":"",...F,children:t})}let{loadingComponent:c,onClick:I,loading:$,disabled:y,type:_}=e,W=c!=null?c:(0,l.jsx)(w.FaSpinner,{className:"animate-spin",size:30});return(0,l.jsx)(o,{onClick:I,disabled:y!=null?y:$,className:(0,u.default)(h,g),"aria-label":f,"data-testid":R.toLowerCase(),type:_,children:$?W:t})}0&&(module.exports={Button});
2
+ "use strict";var v=Object.create;var s=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var x=Object.getPrototypeOf,B=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var o in t)s(e,o,{get:t[o],enumerable:!0})},a=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of y(t))!B.call(e,n)&&n!==o&&s(e,n,{get:()=>t[n],enumerable:!(i=h(t,n))||i.enumerable});return e};var k=(e,t,o)=>(o=e!=null?v(x(e)):{},a(t||!e||!e.__esModule?s(o,"default",{value:e,enumerable:!0}):o,e)),w=e=>a(s({},"__esModule",{value:!0}),e);var V={};C(V,{Button:()=>l,buttonVariants:()=>f});module.exports=w(V);var d=require("@radix-ui/react-slot"),u=require("class-variance-authority"),c=k(require("react")),r=require("@stackshift-ui/system"),g=require("react/jsx-runtime"),p="Button",f=(0,u.cva)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{unstyled:"bg-transparent p-0 border-none shadow-none hover:bg-transparent ring-0 outline-none text-inherit",default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),l=c.forwardRef(({className:e,variant:t,size:o,asChild:i=!1,...n},m)=>{let{[p]:b=r.DefaultComponent}=(0,r.useStackShiftUIComponents)();return(0,g.jsx)(b,{as:i?d.Slot:"button",className:(0,r.cn)(f({variant:t,size:o,className:e})),ref:m,...n})});l.displayName=p;0&&(module.exports={Button,buttonVariants});
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";import{a as e}from"./chunk-RVVB2H7S.mjs";import"./chunk-5BNLLVMY.mjs";export{e as Button};
2
+ "use strict";import{a as e,b as o}from"./chunk-UMCCY4XB.mjs";export{o as Button,e as buttonVariants};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackshift-ui/button",
3
- "version": "6.0.11",
3
+ "version": "6.1.0-beta.1",
4
4
  "private": false,
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -27,15 +27,17 @@
27
27
  "typescript": "^5.6.2",
28
28
  "vite-tsconfig-paths": "^5.0.1",
29
29
  "vitest": "^2.1.1",
30
- "@stackshift-ui/eslint-config": "6.0.10",
31
- "@stackshift-ui/typescript-config": "6.0.10"
30
+ "@stackshift-ui/typescript-config": "6.0.10",
31
+ "@stackshift-ui/eslint-config": "6.0.10"
32
32
  },
33
33
  "dependencies": {
34
+ "@radix-ui/react-slot": "^1.2.3",
35
+ "class-variance-authority": "^0.7.1",
34
36
  "classnames": "^2.5.1",
35
37
  "react-icons": "^5.3.0",
36
- "@stackshift-ui/scripts": "6.0.10",
37
- "@stackshift-ui/link": "6.0.11",
38
- "@stackshift-ui/system": "6.0.11"
38
+ "@stackshift-ui/system": "6.1.0-beta.1",
39
+ "@stackshift-ui/scripts": "6.1.0-beta.0",
40
+ "@stackshift-ui/link": "6.0.12-beta.1"
39
41
  },
40
42
  "peerDependencies": {
41
43
  "@types/react": "16.8 - 19",
@@ -7,7 +7,37 @@ describe.concurrent("button", () => {
7
7
 
8
8
  test("Common: Button - test if renders without errors", ({ expect }) => {
9
9
  const clx = "button-class";
10
- render(<Button className={clx} />);
11
- expect(screen.getByTestId("button").classList).toContain(clx);
10
+
11
+ const { unmount } = render(<Button className={clx}>Test Button</Button>);
12
+
13
+ const button = screen.getByRole("button", { name: "Test Button" });
14
+ expect(button.classList).toContain(clx);
15
+ expect(button.textContent).toBe("Test Button");
16
+ unmount();
17
+ });
18
+
19
+ test("Common: Button - test if renders as child", ({ expect }) => {
20
+ const { unmount } = render(
21
+ <Button asChild>
22
+ <a href="#" target="_blank" rel="noopener noreferrer">
23
+ External Link
24
+ </a>
25
+ </Button>,
26
+ );
27
+
28
+ const link = screen.getByRole("link", { name: "External Link" });
29
+ expect(link.tagName.toLowerCase()).toBe("a");
30
+ expect(link.getAttribute("href")).toBe("#");
31
+ expect(link.getAttribute("target")).toBe("_blank");
32
+ expect(link.getAttribute("rel")).toBe("noopener noreferrer");
33
+ unmount();
34
+ });
35
+
36
+ test("Common: Button - test if renders with correct variant", ({ expect }) => {
37
+ const { unmount } = render(<Button variant="destructive">Destructive Button</Button>);
38
+
39
+ const button = screen.getByRole("button", { name: "Destructive Button" });
40
+ expect(button.classList).toContain("bg-destructive");
41
+ unmount();
12
42
  });
13
43
  });
package/src/button.tsx CHANGED
@@ -1,135 +1,61 @@
1
- import { Link } from "@stackshift-ui/link";
2
- import { useStackShiftUIComponents } from "@stackshift-ui/system";
3
- import cn from "classnames";
4
- import type { AnchorHTMLAttributes, ButtonHTMLAttributes, ReactNode } from "react";
5
- import { FaSpinner } from "react-icons/fa";
6
- import { extractLink } from "./helper";
7
- import { type LabeledRoute, type StyleVariants } from "./types";
1
+ import { Slot } from "@radix-ui/react-slot";
2
+ import { cva, type VariantProps } from "class-variance-authority";
3
+ import * as React from "react";
8
4
 
9
- type Variant =
10
- | "outline"
11
- | "ghost"
12
- | "link"
13
- | "custom"
14
- | "solid"
15
- | "addToWishlist"
16
- | "unstyled"
17
- | "swiper_pagination"
18
- | "tab";
19
- type TextSize = "xs" | "sm" | "md" | "lg";
20
- type RadiusSize = "none" | "sm" | "md" | "base" | "lg" | "xl" | "2xl" | "full";
21
-
22
- interface BaseType {
23
- children?: ReactNode;
24
- variant?: Variant;
25
- radius?: RadiusSize;
26
- size?: TextSize;
27
- ariaLabel?: string;
28
- isActive?: boolean;
29
- }
30
-
31
- interface LinkProps extends BaseType, Omit<AnchorHTMLAttributes<HTMLAnchorElement>, "type"> {
32
- link: LabeledRoute;
33
- as: "link";
34
- }
35
-
36
- interface ButtonProps extends BaseType, ButtonHTMLAttributes<HTMLButtonElement> {
37
- as?: "button";
38
- loading?: boolean;
39
- disabled?: boolean;
40
- loadingComponent?: React.ReactNode;
41
- }
42
-
43
- type Props = ButtonProps | LinkProps;
5
+ import { cn, DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
44
6
 
45
7
  const displayName = "Button";
46
8
 
47
- export function Button({ children, ...props }: Props) {
48
- const { [displayName]: Component = "button" } = useStackShiftUIComponents();
49
-
50
- const sizes = {
51
- xs: "py-1 px-3 text-xs",
52
- sm: "py-2 px-4 text-sm",
53
- default: "py-3 px-6 text-default",
54
- md: "py-3 px-6 text-base",
55
- lg: "py-4 px-7 text-lg",
56
- };
57
-
58
- const borderRadiusMap = {
59
- none: "rounded-none",
60
- sm: "rounded-sm",
61
- md: "rounded-md",
62
- base: "rounded-base",
63
- lg: "rounded-lg",
64
- xl: "rounded-xl",
65
- "2xl": "rounded-2xl",
66
- full: "rounded-full",
67
- global: "rounded-global",
68
- };
69
-
70
- const { radius, size, variant, ariaLabel, className, isActive } = props;
71
-
72
- const buttonRadius = radius ? borderRadiusMap[radius] : "rounded-global";
73
- const buttonSize = sizes[size ?? "default"];
74
-
75
- const commonStyles = "inline-block font-default text-default transition duration-200";
76
- const solid = `${commonStyles} ${buttonSize} ${buttonRadius} bg-primary hover:bg-primary/50 text-gray-50`;
77
- const custom = `inline-block bg-primary hover:bg-primary/50 ${buttonSize} ${buttonRadius} text-gray-50 font-bold transition duration-200`;
78
- const outline = `${commonStyles} ${buttonSize} ${buttonRadius} bg-white hover:bg-primary/50 outline outline-1 text-primary outline-primary`;
79
- const ghost = `${commonStyles} ${buttonRadius} ${buttonSize} bg-transparent hover:bg-primary/50 text-primary`;
80
- const linkType = `transition-200 text-primary hover:text-primary/50 underline ${buttonRadius} ${cn(buttonSize, "px-0 py-0")}`;
81
- const unstyled = ``;
82
- const swiper_pagination = `mr-1 ${isActive ? "bg-primary" : "bg-gray-200"} rounded-full p-1 focus:outline-none`;
83
- const tab = `mx-auto mb-1 w-auto px-4 py-2 rounded duration-200 transition focus:outline-none font-bold ${
84
- isActive
85
- ? "bg-gray-50 text-primary shadow"
86
- : "text-gray-700 hover:bg-secondary/50 hover:text-primary hover:shadow"
87
- }`;
88
- const addToWishlist = `${commonStyles} ${buttonRadius} ${buttonSize} ml-auto sm:ml-0 flex-shrink-0 inline-flex items-center justify-center w-full rounded-md border hover:border-primary`;
89
-
90
- const variants: StyleVariants<Variant> = {
91
- outline,
92
- ghost,
93
- link: linkType,
94
- custom,
95
- solid,
96
- addToWishlist,
97
- unstyled,
98
- swiper_pagination,
99
- tab,
100
- };
9
+ const buttonVariants = cva(
10
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",
11
+ {
12
+ variants: {
13
+ variant: {
14
+ unstyled:
15
+ "bg-transparent p-0 border-none shadow-none hover:bg-transparent ring-0 outline-none text-inherit",
16
+ default: "bg-primary text-primary-foreground hover:bg-primary/90",
17
+ destructive: "bg-destructive text-destructive-foreground hover:bg-destructive/90",
18
+ outline: "border border-input bg-background hover:bg-accent hover:text-accent-foreground",
19
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
20
+ ghost: "hover:bg-accent hover:text-accent-foreground",
21
+ link: "text-primary underline-offset-4 hover:underline",
22
+ },
23
+ size: {
24
+ default: "h-10 px-4 py-2",
25
+ sm: "h-9 rounded-md px-3",
26
+ lg: "h-11 rounded-md px-8",
27
+ icon: "h-10 w-10",
28
+ },
29
+ },
30
+ defaultVariants: {
31
+ variant: "default",
32
+ size: "default",
33
+ },
34
+ },
35
+ );
36
+
37
+ export interface ButtonProps
38
+ extends React.ButtonHTMLAttributes<HTMLButtonElement>,
39
+ VariantProps<typeof buttonVariants> {
40
+ asChild?: boolean;
41
+ }
101
42
 
102
- const variantClass = variants[variant ?? "solid"];
43
+ const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
44
+ ({ className, variant, size, asChild = false, ...props }, ref) => {
45
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
103
46
 
104
- if (props.as === "link") {
105
- const { link, ...rest } = props as LinkProps;
47
+ const Comp = asChild ? Slot : "button";
106
48
 
107
49
  return (
108
- <Link
109
- className={cn(variantClass, className)}
110
- aria-label={ariaLabel}
111
- href={extractLink(link)}
112
- target={link.linkTarget}
113
- rel={link.linkTarget === "_blank" ? "noopener noreferrer" : ""}
114
- {...rest}>
115
- {children}
116
- </Link>
50
+ <Component
51
+ as={Comp}
52
+ className={cn(buttonVariants({ variant, size, className }))}
53
+ ref={ref}
54
+ {...props}
55
+ />
117
56
  );
118
- }
119
-
120
- const { loadingComponent, onClick, loading, disabled, type } = props;
57
+ },
58
+ );
59
+ Button.displayName = displayName;
121
60
 
122
- const Loader = loadingComponent ?? <FaSpinner className="animate-spin" size={30} />;
123
-
124
- return (
125
- <Component
126
- onClick={onClick}
127
- disabled={disabled ?? loading}
128
- className={cn(variantClass, className)}
129
- aria-label={ariaLabel}
130
- data-testid={displayName.toLowerCase()}
131
- type={type}>
132
- {loading ? Loader : children}
133
- </Component>
134
- );
135
- }
61
+ export { Button, buttonVariants };
package/src/index.ts CHANGED
@@ -2,3 +2,4 @@
2
2
 
3
3
  // component exports
4
4
  export * from "./button";
5
+
@@ -1 +0,0 @@
1
- var a=e=>{var t,r;return!(e!=null&&e.internalLink)&&!(e!=null&&e.externalLink)?"/page-not-found":(e==null?void 0:e.type)==="linkInternal"&&((r=(t=e==null?void 0:e.internalLink)==null?void 0:t.toLowerCase())!=null&&r.includes("home"))?"/":(e==null?void 0:e.type)==="linkInternal"?`/${e==null?void 0:e.internalLink}`:(e==null?void 0:e.type)==="linkExternal"?`${e==null?void 0:e.externalLink}`:"/"};export{a};
@@ -1 +0,0 @@
1
- import{a as f}from"./chunk-5BNLLVMY.mjs";import{Link as V}from"@stackshift-ui/link";import{useStackShiftUIComponents as _}from"@stackshift-ui/system";import d from"classnames";import{FaSpinner as E}from"react-icons/fa";import{jsx as u}from"react/jsx-runtime";var h="Button";function q({children:p,...o}){let{[h]:k="button"}=_(),L={xs:"py-1 px-3 text-xs",sm:"py-2 px-4 text-sm",default:"py-3 px-6 text-default",md:"py-3 px-6 text-base",lg:"py-4 px-7 text-lg"},$={none:"rounded-none",sm:"rounded-sm",md:"rounded-md",base:"rounded-base",lg:"rounded-lg",xl:"rounded-xl","2xl":"rounded-2xl",full:"rounded-full",global:"rounded-global"},{radius:m,size:r,variant:a,ariaLabel:c,className:y,isActive:b}=o,t=m?$[m]:"rounded-global",e=L[r!=null?r:"default"],n="inline-block font-default text-default transition duration-200",T=`${n} ${e} ${t} bg-primary hover:bg-primary/50 text-gray-50`,v=`inline-block bg-primary hover:bg-primary/50 ${e} ${t} text-gray-50 font-bold transition duration-200`,S=`${n} ${e} ${t} bg-white hover:bg-primary/50 outline outline-1 text-primary outline-primary`,B=`${n} ${t} ${e} bg-transparent hover:bg-primary/50 text-primary`,R=`transition-200 text-primary hover:text-primary/50 underline ${t} ${d(e,"px-0 py-0")}`,A="",w=`mr-1 ${b?"bg-primary":"bg-gray-200"} rounded-full p-1 focus:outline-none`,N=`mx-auto mb-1 w-auto px-4 py-2 rounded duration-200 transition focus:outline-none font-bold ${b?"bg-gray-50 text-primary shadow":"text-gray-700 hover:bg-secondary/50 hover:text-primary hover:shadow"}`,z=`${n} ${t} ${e} ml-auto sm:ml-0 flex-shrink-0 inline-flex items-center justify-center w-full rounded-md border hover:border-primary`,x={outline:S,ghost:B,link:R,custom:v,solid:T,addToWishlist:z,unstyled:A,swiper_pagination:w,tab:N}[a!=null?a:"solid"];if(o.as==="link"){let{link:l,...H}=o;return u(V,{className:d(x,y),"aria-label":c,href:f(l),target:l.linkTarget,rel:l.linkTarget==="_blank"?"noopener noreferrer":"",...H,children:p})}let{loadingComponent:i,onClick:C,loading:g,disabled:s,type:M}=o,P=i!=null?i:u(E,{className:"animate-spin",size:30});return u(k,{onClick:C,disabled:s!=null?s:g,className:d(x,y),"aria-label":c,"data-testid":h.toLowerCase(),type:M,children:g?P:p})}export{q as a};