@stackshift-ui/text 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 CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "@stackshift-ui/text",
3
3
  "description": "",
4
- "version": "6.0.2",
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": {
@@ -33,8 +34,8 @@
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.3",
38
+ "@stackshift-ui/scripts": "6.0.2"
38
39
  },
39
40
  "peerDependencies": {
40
41
  "@types/react": "16.8 - 19",
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // component exports
4
+ export * from "./text";
@@ -0,0 +1,13 @@
1
+ import { cleanup, render, screen } from "@testing-library/react";
2
+ import { afterEach, describe, test } from "vitest";
3
+ import { Text } from "./text";
4
+
5
+ describe.concurrent("text", () => {
6
+ afterEach(cleanup);
7
+
8
+ test("Common: Text - test if renders without errors", ({ expect }) => {
9
+ const clx = "text-class";
10
+ render(<Text className={clx} />);
11
+ expect(screen.getByTestId("p").classList).toContain(clx);
12
+ });
13
+ });
package/src/text.tsx ADDED
@@ -0,0 +1,91 @@
1
+ import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
2
+ import cn from "classnames";
3
+ import type { ElementType, HTMLProps, ReactNode } from "react";
4
+
5
+ type VariantType = "p";
6
+ type fontSize = "xs" | "sm" | "base" | "lg" | "xl" | "2xl" | "3xl" | "4xl" | "5xl" | "6xl";
7
+ type Weight =
8
+ | "thin"
9
+ | "extralight"
10
+ | "light"
11
+ | "normal"
12
+ | "semibold"
13
+ | "bold"
14
+ | "medium"
15
+ | "extrabold"
16
+ | "black";
17
+
18
+ export interface TextProps extends Omit<HTMLProps<HTMLElement>, "as"> {
19
+ type?: string;
20
+ style?: React.CSSProperties;
21
+ muted?: boolean;
22
+ weight?: Weight;
23
+ fontSize?: fontSize;
24
+ [key: string]: any;
25
+ children?: ReactNode;
26
+ className?: string;
27
+ as?: ElementType;
28
+ }
29
+
30
+ const displayName = "Text";
31
+
32
+ export const Text: React.FC<TextProps> = ({
33
+ type = "p",
34
+ style,
35
+ muted = false,
36
+ weight = "normal",
37
+ fontSize = "base",
38
+ children,
39
+ className,
40
+ as = "p",
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
+ "5xl": "text-5xl",
55
+ "6xl": "text-6xl",
56
+ };
57
+
58
+ const fontWeightMap = {
59
+ thin: "font-thin",
60
+ extralight: "font-extralight",
61
+ light: "font-light",
62
+ normal: "font-normal",
63
+ semibold: "font-semibold",
64
+ bold: "font-bold",
65
+ medium: "font-mediun",
66
+ extrabold: "font-extrabold",
67
+ black: "font-black",
68
+ };
69
+ const size = fontSizeMap[fontSize] || "text-base";
70
+ const fontWeight = fontWeightMap[weight] || "font-normal";
71
+ const commonClass = `${size} ${fontWeight} ${muted && "text-gray-500"}`;
72
+
73
+ const variants: Record<VariantType, string> = {
74
+ p: commonClass,
75
+ };
76
+
77
+ const variantClass = variants[type as VariantType] ?? variants.p;
78
+
79
+ return (
80
+ <Component
81
+ as={as}
82
+ className={cn(variantClass, className)}
83
+ style={style}
84
+ {...props}
85
+ data-testid={displayName}>
86
+ {children}
87
+ </Component>
88
+ );
89
+ };
90
+
91
+ Text.displayName = displayName;