@stackshift-ui/blockstyle 1.0.0 → 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 +11 -10
- package/src/blockstyle.test.tsx +14 -0
- package/src/blockstyle.tsx +31 -0
- package/src/defaultBlockStyle.tsx +85 -0
- package/src/index.ts +5 -0
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stackshift-ui/blockstyle",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "
|
|
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,17 +29,17 @@
|
|
|
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": "
|
|
32
|
-
"@stackshift-ui/typescript-config": "
|
|
32
|
+
"@stackshift-ui/eslint-config": "6.0.2",
|
|
33
|
+
"@stackshift-ui/typescript-config": "6.0.2"
|
|
33
34
|
},
|
|
34
35
|
"dependencies": {
|
|
35
36
|
"@portabletext/react": "^3.1.0",
|
|
36
|
-
"@stackshift-ui/
|
|
37
|
-
"@stackshift-ui/
|
|
38
|
-
"@stackshift-ui/
|
|
39
|
-
"@stackshift-ui/text": "
|
|
40
|
-
"@stackshift-ui/image": "
|
|
41
|
-
"@stackshift-ui/link": "
|
|
37
|
+
"@stackshift-ui/scripts": "6.0.2",
|
|
38
|
+
"@stackshift-ui/system": "6.0.3",
|
|
39
|
+
"@stackshift-ui/heading": "6.0.3",
|
|
40
|
+
"@stackshift-ui/text": "6.0.3",
|
|
41
|
+
"@stackshift-ui/image": "6.0.3",
|
|
42
|
+
"@stackshift-ui/link": "6.0.3"
|
|
42
43
|
},
|
|
43
44
|
"peerDependencies": {
|
|
44
45
|
"@stackshift-ui/system": ">=0.0.0",
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { cleanup, render, screen } from "@testing-library/react";
|
|
2
|
+
import { afterEach, describe, test } from "vitest";
|
|
3
|
+
import { Blockstyle } from "./blockstyle";
|
|
4
|
+
|
|
5
|
+
describe.concurrent("blockstyle", () => {
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
test("Common: Blockstyle - test if renders without errors", ({ expect }) => {
|
|
9
|
+
const clx = "blockStyle-class";
|
|
10
|
+
render(<Blockstyle className={clx} />);
|
|
11
|
+
|
|
12
|
+
expect(screen.getByTestId("div").classList).toContain(clx);
|
|
13
|
+
});
|
|
14
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DefaultComponent, useStackShiftUIComponents } from "@stackshift-ui/system";
|
|
2
|
+
import type { ElementType, HTMLProps, ReactNode } from "react";
|
|
3
|
+
import { PortableText } from "@portabletext/react";
|
|
4
|
+
import { defaultBlockStyle } from "./defaultBlockStyle";
|
|
5
|
+
|
|
6
|
+
export interface BlockstyleProps extends Omit<HTMLProps<HTMLElement>, "as"> {
|
|
7
|
+
children?: ReactNode;
|
|
8
|
+
className?: string;
|
|
9
|
+
as?: ElementType;
|
|
10
|
+
content?: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const displayName = "Blockstyle";
|
|
14
|
+
|
|
15
|
+
export const Blockstyle: React.FC<BlockstyleProps> = ({
|
|
16
|
+
children,
|
|
17
|
+
className,
|
|
18
|
+
as,
|
|
19
|
+
content,
|
|
20
|
+
...props
|
|
21
|
+
}) => {
|
|
22
|
+
const { [displayName]: Component = DefaultComponent } = useStackShiftUIComponents();
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<Component as={as} className={className} {...props} data-testid={displayName}>
|
|
26
|
+
{content ? <PortableText value={content} components={defaultBlockStyle} /> : children}
|
|
27
|
+
</Component>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
Blockstyle.displayName = displayName;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Heading } from "@stackshift-ui/heading";
|
|
2
|
+
import { Text } from "@stackshift-ui/text";
|
|
3
|
+
import { Link } from "@stackshift-ui/link";
|
|
4
|
+
import { Image } from "@stackshift-ui/image";
|
|
5
|
+
import { PortableTextComponents } from "@portabletext/react";
|
|
6
|
+
|
|
7
|
+
export type MyPortableTextComponents = PortableTextComponents & {
|
|
8
|
+
code?: ({ value }: { value: { language?: string; code?: string } }) => JSX.Element;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const defaultBlockStyle: MyPortableTextComponents = {
|
|
12
|
+
block: {
|
|
13
|
+
h1: ({ children }) => (
|
|
14
|
+
<Heading fontSize="3xl" weight="bold" className="mb-8 leading-normal text-black">
|
|
15
|
+
{children}
|
|
16
|
+
</Heading>
|
|
17
|
+
),
|
|
18
|
+
h2: ({ children }) => (
|
|
19
|
+
<Heading type="h2" weight="bold" fontSize="2xl" className="mb-8 text-black">
|
|
20
|
+
{children}
|
|
21
|
+
</Heading>
|
|
22
|
+
),
|
|
23
|
+
h3: ({ children }) => (
|
|
24
|
+
<Heading type="h3" fontSize="xl" weight="bold" className="mb-8 leading-normal text-black">
|
|
25
|
+
{children}
|
|
26
|
+
</Heading>
|
|
27
|
+
),
|
|
28
|
+
h4: ({ children }) => (
|
|
29
|
+
<Heading type="h4" weight="bold" fontSize="lg" className="mb-8 leading-normal text-black">
|
|
30
|
+
{children}
|
|
31
|
+
</Heading>
|
|
32
|
+
),
|
|
33
|
+
normal: ({ children }) => <Text className="mb-8 leading-relaxed">{children}</Text>,
|
|
34
|
+
blockquote: ({ children }) => (
|
|
35
|
+
<blockquote className="mb-6 italic leading-loose text-gray-500 px-14">
|
|
36
|
+
- {children}
|
|
37
|
+
</blockquote>
|
|
38
|
+
),
|
|
39
|
+
},
|
|
40
|
+
code: ({ value }) => (
|
|
41
|
+
<pre data-language={value.language}>
|
|
42
|
+
<code>{value.code}</code>
|
|
43
|
+
</pre>
|
|
44
|
+
),
|
|
45
|
+
list: {
|
|
46
|
+
bullet: ({ children }) => (
|
|
47
|
+
<ul className="flex flex-col pl-10 mb-8 space-y-4 leading-relaxed list-disc">{children}</ul>
|
|
48
|
+
),
|
|
49
|
+
number: ({ children }) => (
|
|
50
|
+
<ol className="flex flex-col pl-10 mb-8 space-y-4 leading-relaxed list-decimal">
|
|
51
|
+
{children}
|
|
52
|
+
</ol>
|
|
53
|
+
),
|
|
54
|
+
},
|
|
55
|
+
listItem: {
|
|
56
|
+
bullet: ({ children }) => <li className="leading-relaxed">{children}</li>,
|
|
57
|
+
number: ({ children }) => <li className="leading-relaxed">{children}</li>,
|
|
58
|
+
},
|
|
59
|
+
marks: {
|
|
60
|
+
strong: ({ children }) => <strong>{children}</strong>,
|
|
61
|
+
em: ({ children }) => <em>{children}</em>,
|
|
62
|
+
code: ({ children }) => <code>{children}</code>,
|
|
63
|
+
link: ({ children, value }) => (
|
|
64
|
+
<Link
|
|
65
|
+
className="hover:text-primary-foreground text-primary"
|
|
66
|
+
href={value.href}
|
|
67
|
+
target="_blank"
|
|
68
|
+
rel="noopener noreferrer">
|
|
69
|
+
{children}
|
|
70
|
+
</Link>
|
|
71
|
+
),
|
|
72
|
+
},
|
|
73
|
+
types: {
|
|
74
|
+
addImage: ({ value }) => (
|
|
75
|
+
<Image
|
|
76
|
+
className="w-full h-full mb-5"
|
|
77
|
+
width={500}
|
|
78
|
+
height={500}
|
|
79
|
+
sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
|
|
80
|
+
src={value?.image}
|
|
81
|
+
alt={value?.alt ?? value?.image?.asset?._ref}
|
|
82
|
+
/>
|
|
83
|
+
),
|
|
84
|
+
},
|
|
85
|
+
};
|