@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.
@@ -1,45 +1,134 @@
1
- import React from "react";
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 default function ColorPreview({
4
- colorName,
5
- colorCode,
6
- isSmall,
7
- }: {
8
- colorName: string;
9
- colorCode: string;
10
- isSmall: boolean;
11
- }) {
12
- if (isSmall) {
13
- return (
14
- <div className=" flex-1 h-[120px] flex flex-col rounded-xl shadow-lg overflow-hidden">
15
- <div className="flex flex-1" style={{ backgroundColor: colorCode }} />
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
- className={
18
- "bg-white p-3 px-3 flex flex-col justify-center items-start"
19
- }
65
+ style={{
66
+ fontSize: 12,
67
+ textTransform: "uppercase",
68
+ whiteSpace: "pre",
69
+ }}
20
70
  >
21
- <h3 className="text-black leading-3 p-0">{colorName}</h3>
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-1 h-[160px] flex flex-col rounded-xl shadow-lg overflow-hidden">
29
- <div className="flex flex-1" style={{ backgroundColor: colorCode }} />
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
- "bg-white p-3 px-6 flex flex-col justify-center items-start"
33
- }
125
+ className={` gap-2 mt-3 ${gridColumnsClass}`}
126
+ style={{ marginTop: 12 }}
34
127
  >
35
- <h3 className="text-black leading-3 p-0 text-error">{colorName}</h3>
36
- <div
37
- className="text-gray-600 leading-1 p-0 m-0"
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
+ };
@@ -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
  {
@@ -74,6 +74,9 @@ module.exports = plugin(function ({ addUtilities }) {
74
74
  ".typography-small8": {
75
75
  "@apply text-small8": {},
76
76
  },
77
+ ".typography-small9": {
78
+ "@apply text-small9": {},
79
+ },
77
80
  ".typography-label1": {
78
81
  "@apply text-label1": {},
79
82
  },
@@ -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
+ };