@stackshift-ui/container 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 +7 -6
- package/src/container.test.tsx +13 -0
- package/src/container.tsx +52 -0
- package/src/index.ts +4 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/container",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "6.0.
|
|
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,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/
|
|
32
|
-
"@stackshift-ui/
|
|
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
|
-
"@stackshift-ui/
|
|
37
|
-
"@stackshift-ui/
|
|
37
|
+
"@stackshift-ui/scripts": "6.0.2",
|
|
38
|
+
"@stackshift-ui/system": "6.0.3"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"@stackshift-ui/system": ">=0.0.0",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { Container } from "./container";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("container", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Layout: Container - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "container-class";
|
|
10
|
+
render(<Container className={clx} />);
|
|
11
|
+
expect(screen.getByTestId("div").classList).toContain(clx);
|
|
12
|
+
});
|
|
13
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
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 ContainerProps extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
className?: string;
|
|
8
|
+
maxWidth?: Width;
|
|
9
|
+
as?: ElementType;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type Width = "sm" | "md" | "lg" | "xl" | "2xl" | "full" | number;
|
|
13
|
+
|
|
14
|
+
const displayName = "Container";
|
|
15
|
+
|
|
16
|
+
export const Container: React.FC<ContainerProps> = ({
|
|
17
|
+
children,
|
|
18
|
+
className,
|
|
19
|
+
maxWidth = "full",
|
|
20
|
+
as,
|
|
21
|
+
...props
|
|
22
|
+
}) => {
|
|
23
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
24
|
+
|
|
25
|
+
const widthVariants = {
|
|
26
|
+
sm: "384px",
|
|
27
|
+
md: "448px",
|
|
28
|
+
lg: "512px",
|
|
29
|
+
xl: "576px",
|
|
30
|
+
"2xl": "672px",
|
|
31
|
+
full: "100%",
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const widthClass =
|
|
35
|
+
typeof maxWidth === "number" ? `${maxWidth.toString()}px` : widthVariants[maxWidth];
|
|
36
|
+
const width = widthClass ?? "80rem";
|
|
37
|
+
|
|
38
|
+
const classes = "mx-auto w-full px-4";
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Component
|
|
42
|
+
as={as}
|
|
43
|
+
className={cn(classes, className)}
|
|
44
|
+
style={{ maxWidth: width }}
|
|
45
|
+
{...props}
|
|
46
|
+
data-testid={displayName}>
|
|
47
|
+
{children}
|
|
48
|
+
</Component>
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
Container.displayName = displayName;
|
package/src/index.ts
ADDED