@stackshift-ui/swiper-button 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/swiper-button",
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": {
@@ -28,14 +29,14 @@
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/button": "6.0.2"
38
+ "@stackshift-ui/system": "6.0.3",
39
+ "@stackshift-ui/button": "6.0.3"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "@types/react": "16.8 - 19",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./swiper-button";
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { SwiperButton } from "./swiper-button";
4
+
5
+ describe.concurrent("swiper-button", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: Swiper Button - test if renders without errors", ({ expect }) => {
9
+ const clx = "swiperbtn-class";
10
+ render(<SwiperButton className={clx} />);
11
+ expect(screen.getByRole("button").classList).toContain(clx);
12
+ });
13
+ });
@@ -0,0 +1,136 @@
1
+ import { Button } from "@stackshift-ui/button";
2
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
3
+ import cn from "classnames";
4
+ import type { ElementType, HTMLProps, ReactNode } from "react";
5
+
6
+ type Variant = "variant_a" | "variant_b";
7
+
8
+ export interface SwiperButtonProps extends Omit<HTMLProps<HTMLElement>, "as" | "size"> {
9
+ variant?: Variant;
10
+ type?: "left" | "right";
11
+ onClick?: () => void;
12
+ ariaLabel?: string;
13
+ [key: string]: any;
14
+ children?: ReactNode;
15
+ className?: string;
16
+ as?: ElementType;
17
+ }
18
+
19
+ const displayName = "SwiperButton";
20
+
21
+ export const SwiperButton: React.FC<SwiperButtonProps> = ({
22
+ variant = "variant_a",
23
+ type = "left",
24
+ onClick,
25
+ ariaLabel,
26
+ children,
27
+ className,
28
+ as,
29
+ ...props
30
+ }) => {
31
+ const { [displayName]: Component = Button } = useStackShiftUIComponents();
32
+
33
+ const variantList = {
34
+ variant_a: VariantA,
35
+ variant_b: VariantB,
36
+ };
37
+
38
+ const Element = variantList[variant] || VariantA;
39
+ const commonStyle = "inline-block p-2 text-primary rounded-full shadow focus:outline-none";
40
+
41
+ const variantClasses = {
42
+ variant_a: commonStyle,
43
+ variant_b: commonStyle,
44
+ };
45
+
46
+ const classes = variantClasses[variant];
47
+
48
+ return (
49
+ <Component
50
+ as="button"
51
+ variant="unstyled"
52
+ onClick={onClick}
53
+ className={cn(classes, className)}
54
+ data-testid={displayName.toLowerCase()}
55
+ ariaLabel={ariaLabel}
56
+ {...props}>
57
+ {children ? children : <Element type={type} />}
58
+ </Component>
59
+ );
60
+ };
61
+
62
+ SwiperButton.displayName = displayName;
63
+
64
+ type VariantProps = {
65
+ type: "left" | "right";
66
+ };
67
+
68
+ const VariantA = ({ type }: VariantProps) => {
69
+ if (type === "right") {
70
+ return (
71
+ <svg
72
+ className="w-6 h-6"
73
+ xmlns="http://www.w3.org/2000/svg"
74
+ fill="none"
75
+ viewBox="0 0 24 24"
76
+ stroke="currentColor">
77
+ <path
78
+ strokeLinecap="round"
79
+ strokeLinejoin="round"
80
+ strokeWidth={2}
81
+ d="M14 5l7 7m0 0l-7 7m7-7H3"
82
+ />
83
+ </svg>
84
+ );
85
+ }
86
+
87
+ return (
88
+ <svg
89
+ className="w-6 h-6"
90
+ xmlns="http://www.w3.org/2000/svg"
91
+ fill="none"
92
+ viewBox="0 0 24 24"
93
+ stroke="currentColor">
94
+ <path
95
+ strokeLinecap="round"
96
+ strokeLinejoin="round"
97
+ strokeWidth={2}
98
+ d="M10 19l-7-7m0 0l7-7m-7 7h18"
99
+ />
100
+ </svg>
101
+ );
102
+ };
103
+
104
+ const VariantB = ({ type }: VariantProps) => {
105
+ if (type === "left") {
106
+ return (
107
+ <svg
108
+ width={36}
109
+ height={36}
110
+ viewBox="0 0 10 18"
111
+ fill="none"
112
+ xmlns="http://www.w3.org/2000/svg"
113
+ stroke="currentColor">
114
+ <path
115
+ d="M9 16.0185C9.268 16.2905 9.268 16.7275 9 16.9975C8.732 17.2675 8.299 17.2685 8.031 16.9975L0.201 9.0895C-0.067 8.8195 -0.067 8.3825 0.201 8.1105L8.031 0.2025C8.299 -0.0675 8.732 -0.0675 9 0.2025C9.268 0.4735 9.268 0.9115 9 1.1815L1.859 8.6005L9 16.0185Z"
116
+ fill="#0045d8"
117
+ />
118
+ </svg>
119
+ );
120
+ }
121
+
122
+ return (
123
+ <svg
124
+ width={36}
125
+ height={36}
126
+ viewBox="0 0 10 18"
127
+ fill="none"
128
+ xmlns="http://www.w3.org/2000/svg"
129
+ stroke="currentColor">
130
+ <path
131
+ d="M0.19922 1.1817C-0.0687795 0.909696 -0.0687794 0.472695 0.19922 0.202695C0.46722 -0.0673054 0.90022 -0.0683048 1.16822 0.202695L8.99822 8.11069C9.26622 8.3807 9.26622 8.81769 8.99822 9.08969L1.16822 16.9977C0.900219 17.2677 0.467218 17.2677 0.199219 16.9977C-0.0687809 16.7267 -0.0687808 16.2887 0.199219 16.0187L7.34022 8.5997L0.19922 1.1817Z"
132
+ fill="#0045d8"
133
+ />
134
+ </svg>
135
+ );
136
+ };