@drawnagency/primitives 0.1.30 → 0.1.31

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@drawnagency/primitives",
3
- "version": "0.1.30",
3
+ "version": "0.1.31",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./package.json": "./package.json",
@@ -81,12 +81,23 @@ function ColorsView({
81
81
  showLabel?: boolean;
82
82
  }) {
83
83
  const [expanded, setExpanded] = useState(!collapsing);
84
- const [copiedValue, setCopiedValue] = useState<string | null>(null);
84
+ const [copiedIndex, setCopiedIndex] = useState<number | null>(null);
85
85
 
86
- const handleCopy = (value: string) => {
87
- navigator.clipboard.writeText(value);
88
- setCopiedValue(value);
89
- setTimeout(() => setCopiedValue(null), 1500);
86
+ const handleCopy = (value: string, colorIndex: number) => {
87
+ if (navigator.clipboard?.writeText) {
88
+ navigator.clipboard.writeText(value);
89
+ } else {
90
+ const ta = document.createElement("textarea");
91
+ ta.value = value;
92
+ ta.style.position = "fixed";
93
+ ta.style.opacity = "0";
94
+ document.body.appendChild(ta);
95
+ ta.select();
96
+ document.execCommand("copy");
97
+ document.body.removeChild(ta);
98
+ }
99
+ setCopiedIndex(colorIndex);
100
+ setTimeout(() => setCopiedIndex(null), 1500);
90
101
  };
91
102
 
92
103
  return (
@@ -114,17 +125,25 @@ function ColorsView({
114
125
  const contrast = getContrastClass(hex);
115
126
  return (
116
127
  <div key={i} className="overflow-hidden rounded-md border border-base-200">
117
- <div className={cn("flex min-h-[80px] items-end p-3", contrast)} style={{ backgroundColor: hex || "#ccc" }}>
128
+ <div className={cn("relative flex min-h-[80px] items-end p-3", contrast)} style={{ backgroundColor: hex || "#ccc" }}>
118
129
  {color.name && <span className="text-sm font-bold">{color.name}</span>}
130
+ {copiedIndex === i && (
131
+ <span className={cn(
132
+ "absolute top-2 right-2 rounded-full px-2.5 py-0.5 text-xs font-medium",
133
+ getContrastClass(hex) === "text-black" ? "bg-black/15 text-black" : "bg-white/25 text-white",
134
+ )}>
135
+ Copied!
136
+ </span>
137
+ )}
119
138
  </div>
120
139
  {expanded && (
121
140
  <div className="space-y-1 bg-base-accent p-3 text-sm">
122
141
  {color.spaces.map((space, j) =>
123
142
  Object.entries(space).map(([key, value]) =>
124
143
  value ? (
125
- <button key={`${j}-${key}`} onClick={() => handleCopy(value)} className="cursor-pointer flex w-full justify-between hover:text-primary">
144
+ <button key={`${j}-${key}`} onClick={() => handleCopy(value, i)} className="cursor-pointer flex w-full justify-between hover:text-primary">
126
145
  <span className="font-medium uppercase">{key}</span>
127
- <span>{copiedValue === value ? "Copied!" : value}</span>
146
+ <span>{value}</span>
128
147
  </button>
129
148
  ) : null
130
149
  )