@rovula/ui 0.0.31 → 0.0.32
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/dist/cjs/bundle.css +920 -20
- package/dist/cjs/types/stories/ColorPreview.d.ts +9 -5
- package/dist/cjs/types/utils/colors.d.ts +1 -0
- package/dist/components/Text/Text.stories.js +5 -1
- package/dist/esm/bundle.css +920 -20
- package/dist/esm/types/stories/ColorPreview.d.ts +9 -5
- package/dist/esm/types/utils/colors.d.ts +1 -0
- package/dist/src/theme/global.css +1343 -217
- package/dist/stories/ColorGroupPreview.js +282 -472
- package/dist/stories/ColorPreview.js +76 -6
- package/dist/theme/main-preset.js +8 -0
- package/dist/theme/plugins/utilities/typography.js +3 -0
- package/dist/theme/presets/colors.js +0 -3
- package/dist/utils/colors.js +31 -0
- package/package.json +1 -1
- package/src/components/Text/Text.stories.tsx +5 -1
- package/src/stories/ColorGroupPreview.tsx +394 -486
- package/src/stories/ColorPreview.tsx +122 -33
- package/src/theme/main-preset.js +8 -0
- package/src/theme/plugins/utilities/typography.js +3 -0
- package/src/theme/presets/colors.js +0 -3
- package/src/utils/colors.ts +33 -0
|
@@ -1,45 +1,134 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { srgbToHex } from "@/utils/colors";
|
|
2
|
+
import React, { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { Popover, PopoverContent, PopoverTrigger } from "..";
|
|
2
4
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
export const ColorBox = ({ className }: { className: string }) => {
|
|
6
|
+
const boxRef = useRef<HTMLDivElement>(null);
|
|
7
|
+
const [hex, setHex] = useState("");
|
|
8
|
+
const [isOpen, setOpen] = useState(false);
|
|
9
|
+
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
if (boxRef.current) {
|
|
12
|
+
const bgColor = window.getComputedStyle(boxRef.current).backgroundColor;
|
|
13
|
+
const hexColor = srgbToHex(bgColor);
|
|
14
|
+
|
|
15
|
+
setHex(hexColor);
|
|
16
|
+
}
|
|
17
|
+
}, []);
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
let time: NodeJS.Timeout | undefined;
|
|
21
|
+
|
|
22
|
+
if (isOpen) {
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
setOpen(false);
|
|
25
|
+
}, 1000);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
if (time) {
|
|
30
|
+
clearTimeout(time);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
}, [isOpen]);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div className="flex flex-1 flex-col gap-1">
|
|
37
|
+
<Popover open={isOpen}>
|
|
38
|
+
<PopoverTrigger
|
|
39
|
+
onClick={() => {
|
|
40
|
+
if (className) {
|
|
41
|
+
navigator.clipboard
|
|
42
|
+
.writeText(className)
|
|
43
|
+
.then(() => {
|
|
44
|
+
console.log("ClassName copied to clipboard");
|
|
45
|
+
})
|
|
46
|
+
.catch((err) => {
|
|
47
|
+
console.error("Failed to copy className: ", err);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
setOpen(true);
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<div
|
|
54
|
+
ref={boxRef}
|
|
55
|
+
className={`${className} h-12 rounded border shadow`}
|
|
56
|
+
/>
|
|
57
|
+
</PopoverTrigger>
|
|
58
|
+
<PopoverContent className="p-3 w-fit min-w-fit">
|
|
59
|
+
Copied to clipboard
|
|
60
|
+
</PopoverContent>
|
|
61
|
+
</Popover>
|
|
62
|
+
<div className="text-gray-500 flex flex-col justify-center items-center">
|
|
63
|
+
<div style={{ fontSize: 12, whiteSpace: "pre" }}>{className}</div>
|
|
16
64
|
<div
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
65
|
+
style={{
|
|
66
|
+
fontSize: 12,
|
|
67
|
+
textTransform: "uppercase",
|
|
68
|
+
whiteSpace: "pre",
|
|
69
|
+
}}
|
|
20
70
|
>
|
|
21
|
-
|
|
71
|
+
{hex || "Loading..."}
|
|
22
72
|
</div>
|
|
23
73
|
</div>
|
|
24
|
-
|
|
25
|
-
|
|
74
|
+
</div>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
export const ColorItems = ({
|
|
79
|
+
title,
|
|
80
|
+
subTitle,
|
|
81
|
+
colors,
|
|
82
|
+
col = -1,
|
|
83
|
+
}: {
|
|
84
|
+
title?: string;
|
|
85
|
+
subTitle?: string;
|
|
86
|
+
colors: string[];
|
|
87
|
+
col?: number;
|
|
88
|
+
}) => {
|
|
89
|
+
const gridColumnsClass = useMemo(() => {
|
|
90
|
+
if (col !== undefined) {
|
|
91
|
+
switch (col) {
|
|
92
|
+
case 1:
|
|
93
|
+
return "grid grid-cols-1";
|
|
94
|
+
case 2:
|
|
95
|
+
return "grid grid-cols-2";
|
|
96
|
+
case 3:
|
|
97
|
+
return "grid grid-cols-3";
|
|
98
|
+
case 4:
|
|
99
|
+
return "grid grid-cols-4";
|
|
100
|
+
case 5:
|
|
101
|
+
return "grid grid-cols-5";
|
|
102
|
+
case 6:
|
|
103
|
+
return "grid grid-cols-6";
|
|
104
|
+
case 7:
|
|
105
|
+
return "grid grid-cols-7";
|
|
106
|
+
case 8:
|
|
107
|
+
return "grid grid-cols-8";
|
|
108
|
+
case 9:
|
|
109
|
+
return "grid grid-cols-9";
|
|
110
|
+
case 10:
|
|
111
|
+
return "grid grid-cols-10";
|
|
112
|
+
default:
|
|
113
|
+
return colors.length >= 8 ? "grid grid-cols-4" : `flex `;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, [col]);
|
|
26
117
|
|
|
27
118
|
return (
|
|
28
|
-
<div className=" flex-
|
|
29
|
-
<div
|
|
119
|
+
<div className="flex flex-wrap flex-col">
|
|
120
|
+
{title && <div style={{ fontSize: 16, fontWeight: "600" }}>{title}</div>}
|
|
121
|
+
{subTitle && (
|
|
122
|
+
<div style={{ fontSize: 14, fontWeight: "600" }}>{subTitle}</div>
|
|
123
|
+
)}
|
|
30
124
|
<div
|
|
31
|
-
className={
|
|
32
|
-
|
|
33
|
-
}
|
|
125
|
+
className={` gap-2 mt-3 ${gridColumnsClass}`}
|
|
126
|
+
style={{ marginTop: 12 }}
|
|
34
127
|
>
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
style={{ fontSize: "8px" }}
|
|
39
|
-
>
|
|
40
|
-
{colorCode}
|
|
41
|
-
</div>
|
|
128
|
+
{colors.map((color) => (
|
|
129
|
+
<ColorBox key={color} className={color} />
|
|
130
|
+
))}
|
|
42
131
|
</div>
|
|
43
132
|
</div>
|
|
44
133
|
);
|
|
45
|
-
}
|
|
134
|
+
};
|
package/src/theme/main-preset.js
CHANGED
|
@@ -204,6 +204,14 @@ module.exports = {
|
|
|
204
204
|
fontFamily: "var(--small8-family, 'Poppins')",
|
|
205
205
|
},
|
|
206
206
|
],
|
|
207
|
+
small9: [
|
|
208
|
+
"var(--small9-size, 8px)",
|
|
209
|
+
{
|
|
210
|
+
lineHeight: "var(--small9-line-height, 10px)",
|
|
211
|
+
fontWeight: "var(--small9-weight, 400)",
|
|
212
|
+
fontFamily: "var(--small9-family, 'Poppins')",
|
|
213
|
+
},
|
|
214
|
+
],
|
|
207
215
|
label1: [
|
|
208
216
|
"var(--label-label1-size, 12px)",
|
|
209
217
|
{
|
|
@@ -76,9 +76,6 @@ module.exports = {
|
|
|
76
76
|
"function-default-hover-bg": withColorMixin(
|
|
77
77
|
"--function-default-hover-bg"
|
|
78
78
|
),
|
|
79
|
-
"function-default-hover-bg": withColorMixin(
|
|
80
|
-
"--function-default-hover-bg"
|
|
81
|
-
),
|
|
82
79
|
"function-default-stroke": withColorMixin("--function-default-stroke"),
|
|
83
80
|
"function-default-icon": withColorMixin("--function-default-icon"),
|
|
84
81
|
"function-default-outline": withColorMixin(
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const srgbToHex = (color: string) => {
|
|
2
|
+
if (color.startsWith("color(")) {
|
|
3
|
+
const rgbValues = color.match(/([\d.]+)/g);
|
|
4
|
+
|
|
5
|
+
if (rgbValues && rgbValues.length >= 3) {
|
|
6
|
+
const [r, g, b] = rgbValues
|
|
7
|
+
.slice(0, 3)
|
|
8
|
+
.map((x) => Math.round(parseFloat(x) * 255));
|
|
9
|
+
let hex = `#${[r, g, b]
|
|
10
|
+
.map((x) => ("0" + x.toString(16)).slice(-2))
|
|
11
|
+
.join("")}`;
|
|
12
|
+
|
|
13
|
+
if (rgbValues.length === 4) {
|
|
14
|
+
const alpha = Math.round(parseFloat(rgbValues[3]) * 255);
|
|
15
|
+
hex += ("0" + alpha.toString(16)).slice(-2);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return hex;
|
|
19
|
+
}
|
|
20
|
+
} else if (color.startsWith("#")) {
|
|
21
|
+
return color;
|
|
22
|
+
} else {
|
|
23
|
+
const rgbValues = color.match(/\d+/g);
|
|
24
|
+
if (rgbValues && rgbValues.length >= 3) {
|
|
25
|
+
return `#${rgbValues
|
|
26
|
+
.slice(0, 3)
|
|
27
|
+
.map((x) => ("0" + parseInt(x).toString(16)).slice(-2))
|
|
28
|
+
.join("")}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return color;
|
|
33
|
+
};
|