@stackshift-ui/flex 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/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/flex",
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,16 +29,16 @@
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": "6.0.2",
32
- "@stackshift-ui/typescript-config": "6.0.2"
32
+ "@stackshift-ui/typescript-config": "6.0.3-beta.0",
33
+ "@stackshift-ui/eslint-config": "6.0.3-beta.0"
33
34
  },
34
35
  "dependencies": {
35
36
  "classnames": "^2.5.1",
36
- "@stackshift-ui/scripts": "6.0.2",
37
- "@stackshift-ui/system": "6.0.2"
37
+ "@stackshift-ui/system": "6.0.4-beta.0",
38
+ "@stackshift-ui/scripts": "6.0.3-beta.0"
38
39
  },
39
40
  "peerDependencies": {
40
- "@stackshift-ui/system": ">=0.0.0",
41
+ "@stackshift-ui/system": ">=6.0.4-beta.0",
41
42
  "@types/react": "16.8 - 19",
42
43
  "next": "10 - 14",
43
44
  "react": "16.8 - 19",
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { Flex } from "./flex";
4
+
5
+ describe.concurrent("flex", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Dummy test - test if renders without errors", ({ expect }) => {
9
+ const clx = "my-class";
10
+ render(<Flex className={clx} />);
11
+ expect(screen.getByTestId("div").classList).toContain(clx);
12
+ });
13
+ });
package/src/flex.tsx ADDED
@@ -0,0 +1,76 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import cn from "classnames";
3
+ import type { ElementType, HTMLProps, ReactNode } from "react";
4
+
5
+ type Justify = "normal" | "start" | "end" | "center" | "between" | "around" | "evenly" | "stretch";
6
+ type Direction = "row" | "row-reverse" | "col" | "col-reverse";
7
+ type Align = "start" | "end" | "baseline" | "stretch" | "center";
8
+
9
+ export interface FlexProps extends Omit<HTMLProps<HTMLElement>, "as" | "wrap"> {
10
+ children?: ReactNode;
11
+ className?: string;
12
+ align?: Align;
13
+ direction?: Direction;
14
+ justify?: Justify;
15
+ wrap?: boolean;
16
+ gap?: number;
17
+ as?: ElementType;
18
+ [key: string]: any;
19
+ }
20
+
21
+ const displayName = "Flex";
22
+
23
+ export const Flex: React.FC<FlexProps> = ({
24
+ children,
25
+ className,
26
+ align = "start",
27
+ direction = "row",
28
+ justify = "start",
29
+ wrap = false,
30
+ gap,
31
+ as = "div",
32
+ ...props
33
+ }) => {
34
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
35
+
36
+ const directionVariants = {
37
+ row: "flex-row",
38
+ col: "flex-col",
39
+ "row-reverse": "flex-row-reverse",
40
+ "col-reverse": "flex-col-reverse",
41
+ };
42
+
43
+ const alignVariants = {
44
+ start: "items-start",
45
+ end: "items-end",
46
+ baseline: "items-baseline",
47
+ stretch: "items-stretch",
48
+ center: "items-center",
49
+ };
50
+
51
+ const justifyVariants = {
52
+ normal: "justify-normal",
53
+ start: "justify-start",
54
+ end: "justify-end",
55
+ center: "justify-center",
56
+ between: "justify-between",
57
+ around: "justify-around",
58
+ evenly: "justify-evenly",
59
+ stretch: "justify-stretch",
60
+ };
61
+
62
+ const directionClass = directionVariants[direction];
63
+ const alignClass = alignVariants[align];
64
+ const justifyClass = justifyVariants[justify];
65
+ const classes = `flex ${directionClass} ${alignClass} ${justifyClass} ${
66
+ wrap ? "flex-wrap" : ""
67
+ } gap-${gap ? gap : 0}`;
68
+
69
+ return (
70
+ <Component as={as} className={cn(classes, className)} {...props} data-testid="flex">
71
+ {children}
72
+ </Component>
73
+ );
74
+ };
75
+
76
+ Flex.displayName = displayName;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./flex";