@stackshift-ui/section 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 +4 -3
- package/src/index.ts +4 -0
- package/src/section.test.tsx +13 -0
- package/src/section.tsx +53 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/section",
|
|
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": {
|
|
@@ -34,7 +35,7 @@
|
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"classnames": "^2.5.1",
|
|
36
37
|
"@stackshift-ui/scripts": "6.0.2",
|
|
37
|
-
"@stackshift-ui/system": "6.0.
|
|
38
|
+
"@stackshift-ui/system": "6.0.3"
|
|
38
39
|
},
|
|
39
40
|
"peerDependencies": {
|
|
40
41
|
"@stackshift-ui/system": ">=0.0.0",
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { Section } from "./section";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("section", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Layout: Section - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "section-class";
|
|
10
|
+
render(<Section className={clx} />);
|
|
11
|
+
expect(screen.getByTestId("div").classList).toContain(clx);
|
|
12
|
+
});
|
|
13
|
+
});
|
package/src/section.tsx
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
2
|
+
import type { ElementType, HTMLProps, ReactNode } from "react";
|
|
3
|
+
import cn from "classnames";
|
|
4
|
+
|
|
5
|
+
type Width = "sm" | "md" | "lg" | "xl" | "2xl" | "full" | number;
|
|
6
|
+
|
|
7
|
+
export interface SectionProps extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
className?: string;
|
|
10
|
+
maxWidth?: Width;
|
|
11
|
+
as?: ElementType;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const displayName = "Section";
|
|
15
|
+
|
|
16
|
+
export const Section: React.FC<SectionProps> = ({
|
|
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
|
+
|
|
37
|
+
const width = widthClass ?? "80rem";
|
|
38
|
+
|
|
39
|
+
const classes = "mx-auto w-full px-4";
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<Component
|
|
43
|
+
as={as}
|
|
44
|
+
className={cn(classes, className)}
|
|
45
|
+
style={{ maxWidth: width }}
|
|
46
|
+
{...props}
|
|
47
|
+
data-testid={displayName}>
|
|
48
|
+
{children}
|
|
49
|
+
</Component>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
Section.displayName = displayName;
|