@stackshift-ui/grid 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/grid",
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/eslint-config": "6.0.3-beta.0",
33
+ "@stackshift-ui/typescript-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/scripts": "6.0.3-beta.0",
38
+ "@stackshift-ui/system": "6.0.4-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 { Grid } from "./grid";
4
+
5
+ describe.concurrent("grid", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Layout: Grid - test if renders without errors", ({ expect }) => {
9
+ const clx = "grid-class";
10
+ render(<Grid className={clx} />);
11
+ expect(screen.getByTestId("div").classList).toContain(clx);
12
+ });
13
+ });
package/src/grid.tsx ADDED
@@ -0,0 +1,80 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import type { ElementType, HTMLProps, ReactNode } from "react";
3
+ import cn from "classnames";
4
+
5
+ export interface GridProps extends Omit<HTMLProps<HTMLElement>, "as"> {
6
+ columns?: Columns;
7
+ gap?: number;
8
+ align?: Align;
9
+ justify?: Justify;
10
+ children?: ReactNode;
11
+ className?: string;
12
+ as?: ElementType;
13
+ }
14
+
15
+ type Justify = "normal" | "start" | "end" | "center" | "between" | "around" | "evenly" | "stretch";
16
+ type Columns = "none" | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
17
+ type Align = "start" | "end" | "baseline" | "stretch" | "center";
18
+
19
+ const displayName = "Grid";
20
+
21
+ export const Grid: React.FC<GridProps> = ({
22
+ columns = 1,
23
+ gap = 0,
24
+ align = "stretch",
25
+ justify = "start",
26
+ children,
27
+ className,
28
+ as,
29
+ ...props
30
+ }) => {
31
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
32
+
33
+ const columnClass = {
34
+ none: "grid-cols-none",
35
+ 1: "grid-cols-1",
36
+ 2: "grid-cols-2",
37
+ 3: "grid-cols-3",
38
+ 4: "grid-cols-4",
39
+ 5: "grid-cols-5",
40
+ 6: "grid-cols-6",
41
+ 7: "grid-cols-7",
42
+ 8: "grid-cols-8",
43
+ 9: "grid-cols-9",
44
+ 10: "grid-cols-10",
45
+ 11: "grid-cols-1",
46
+ 12: "grid-cols-12",
47
+ };
48
+
49
+ const alignVariants = {
50
+ start: "items-start",
51
+ end: "items-end",
52
+ baseline: "items-baseline",
53
+ stretch: "items-stretch",
54
+ center: "items-center",
55
+ };
56
+
57
+ const justifyVariants = {
58
+ normal: "justify-items-normal",
59
+ start: "justify-items-start",
60
+ end: "justify-items-end",
61
+ center: "justify-items-center",
62
+ between: " justify-items-between",
63
+ around: "justify-items-around",
64
+ evenly: "justify-items-evenly",
65
+ stretch: "justify-items-stretch",
66
+ };
67
+
68
+ const column = columnClass[columns] || "grid-cols-1";
69
+ const alignClass = alignVariants[align];
70
+ const justifyClass = justifyVariants[justify];
71
+ const classes = `grid w-full ${column} ${alignClass} ${justifyClass} gap-${gap ?? 0}`;
72
+
73
+ return (
74
+ <Component as={as} className={cn(classes, className)} {...props} data-testid={displayName}>
75
+ {children}
76
+ </Component>
77
+ );
78
+ };
79
+
80
+ Grid.displayName = displayName;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./grid";