@stackshift-ui/heading 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/heading",
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,20 +29,20 @@
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/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/scripts": "6.0.3-beta.0",
38
+ "@stackshift-ui/system": "6.0.4-beta.0"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "@types/react": "16.8 - 19",
41
42
  "next": "10 - 14",
42
43
  "react": "16.8 - 19",
43
44
  "react-dom": "16.8 - 19",
44
- "@stackshift-ui/system": ">=0.0.0"
45
+ "@stackshift-ui/system": ">=6.0.4-beta.0"
45
46
  },
46
47
  "peerDependenciesMeta": {
47
48
  "next": {
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { Heading } from "./heading";
4
+
5
+ describe.concurrent("heading", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: Heading - test if renders without errors", ({ expect }) => {
9
+ const clx = "heading-class";
10
+ render(<Heading className={clx} />);
11
+ expect(screen.getByTestId("h1").classList).toContain(clx);
12
+ });
13
+ });
@@ -0,0 +1,97 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import cn from "classnames";
3
+ import type { ElementType, HTMLProps, ReactNode } from "react";
4
+
5
+ type StyleVariants<T extends string> = Record<T, string>;
6
+ type Type = "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
7
+ type fontSize = "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl" | "4xl";
8
+ type Weight =
9
+ | "thin"
10
+ | "extralight"
11
+ | "light"
12
+ | "normal"
13
+ | "semibold"
14
+ | "bold"
15
+ | "medium"
16
+ | "extrabold"
17
+ | "black";
18
+
19
+ export interface HeadingProps extends Omit<HTMLProps<HTMLElement>, "as"> {
20
+ type?: Type;
21
+ style?: React.CSSProperties;
22
+ muted?: boolean;
23
+ weight?: Weight;
24
+ fontSize?: fontSize;
25
+ children?: ReactNode;
26
+ className?: string;
27
+ // as?: ElementType;
28
+ }
29
+
30
+ const displayName = "Heading";
31
+
32
+ export const Heading: React.FC<HeadingProps> = ({
33
+ type = "h1",
34
+ style,
35
+ muted = false,
36
+ weight = "bold",
37
+ fontSize = "3xl",
38
+ children,
39
+ className,
40
+ // as,
41
+ ...props
42
+ }) => {
43
+ const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
44
+
45
+ const fontSizeMap = {
46
+ xs: "text-xs",
47
+ sm: "text-sm",
48
+ base: "text-base",
49
+ lg: "text-lg",
50
+ xl: "text-xl",
51
+ "2xl": "text-2xl",
52
+ "3xl": "text-3xl",
53
+ "4xl": "text-4xl",
54
+ };
55
+
56
+ const fontWeightMap = {
57
+ thin: "font-thin",
58
+ extralight: "font-extralight",
59
+ light: "font-light",
60
+ normal: "font-normal",
61
+ semibold: "font-semibold",
62
+ bold: "font-bold",
63
+ medium: "font-medium",
64
+ extrabold: "font-extrabold",
65
+ black: "font-black",
66
+ };
67
+
68
+ const size = fontSizeMap[fontSize];
69
+ const fontWeight = fontWeightMap[weight];
70
+ const commonClass = `text-primary ${muted && "text-gray-500"} ${
71
+ weight ? `${fontWeight}` : "font-bold"
72
+ } `;
73
+ const variants: StyleVariants<Type> = {
74
+ h1: `${commonClass} font-bold font-heading ${size ?? `text-4xl lg:text-5xl`} `,
75
+ h2: `${commonClass} ${size ?? `text-3xl lg:text-4xl`} font-bold`,
76
+ h3: `${commonClass} font-bold ${size ?? `text-2xl lg:text-3xl`}`,
77
+ h4: `${commonClass} font-bold text-2xl ${size}`,
78
+ h5: `${commonClass} font-medium text-xl ${size}`,
79
+ h6: `${commonClass} font-medium text-lg ${size}`,
80
+ };
81
+
82
+ const Element: Type = ["h1", "h2", "h3", "h4", "h5", "h6"].includes(type) ? type : "h1";
83
+
84
+ const variantClass = variants[Element] ?? variants.h1;
85
+
86
+ return (
87
+ <Component
88
+ as={type}
89
+ className={cn(variantClass, className)}
90
+ {...props}
91
+ data-testid={displayName}>
92
+ {children}
93
+ </Component>
94
+ );
95
+ };
96
+
97
+ Heading.displayName = displayName;
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./heading";