mirror of
https://github.com/stefanpejcic/openpanel
synced 2025-06-26 18:28:26 +00:00
Update index.tsx
This commit is contained in:
parent
75b450927e
commit
1a78321ccc
@ -1,22 +1,32 @@
|
|||||||
import React, { useState } from "react";
|
import React, { useState, useEffect } from "react";
|
||||||
import Head from "@docusaurus/Head";
|
import Head from "@docusaurus/Head";
|
||||||
import { BlogFooter } from "@site/src/refine-theme/blog-footer";
|
import { BlogFooter } from "@site/src/refine-theme/blog-footer";
|
||||||
import { CommonHeader } from "@site/src/refine-theme/common-header";
|
import { CommonHeader } from "@site/src/refine-theme/common-header";
|
||||||
import { CommonLayout } from "@site/src/refine-theme/common-layout";
|
import { CommonLayout } from "@site/src/refine-theme/common-layout";
|
||||||
|
|
||||||
const Assets: React.FC = () => {
|
const Assets: React.FC = () => {
|
||||||
const [color, setColor] = useState("#000000"); // Default color set to black
|
const [color, setColor] = useState("#000000"); // Default color
|
||||||
const assets = [
|
const [assets, setAssets] = useState([
|
||||||
{ name: "Logo Icon", svgUrl: "/img/svg/openpanel_logo.svg", downloadUrl: "/img/svg/openpanel_logo.svg" },
|
{ name: "Logo Icon", svgUrl: "/img/svg/openpanel_logo.svg", svgContent: null },
|
||||||
//{ name: "White Logo Icon", svgUrl: "/img/svg/openpanel_white_logo.svg", downloadUrl: "/img/svg/openpanel_white_logo.svg" },
|
//{ name: "White Logo Icon", svgUrl: "/img/svg/openpanel_white_logo.svg", svgContent: null },
|
||||||
// more here..
|
]);
|
||||||
];
|
|
||||||
|
|
||||||
const handleCopySVGCode = async (svgUrl: string, color: string) => {
|
// Fetch SVG content for each asset
|
||||||
const response = await fetch(svgUrl);
|
useEffect(() => {
|
||||||
let svgCode = await response.text();
|
assets.forEach((asset, index) => {
|
||||||
svgCode = svgCode.replace(/fill="currentColor"/g, `fill="${color}"`); // Replace fill color
|
fetch(asset.svgUrl)
|
||||||
navigator.clipboard.writeText(svgCode).then(
|
.then(response => response.text())
|
||||||
|
.then(svgContent => {
|
||||||
|
const updatedAssets = [...assets];
|
||||||
|
updatedAssets[index] = { ...asset, svgContent: svgContent.replace(/fill="currentColor"/g, `fill="${color}"`) };
|
||||||
|
setAssets(updatedAssets);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}, [color]); // Re-fetch when color changes
|
||||||
|
|
||||||
|
const handleCopySVGCode = async (svgContent: string) => {
|
||||||
|
const modifiedSVG = svgContent.replace(/fill="#[0-9A-Fa-f]{6}"/g, `fill="${color}"`);
|
||||||
|
navigator.clipboard.writeText(modifiedSVG).then(
|
||||||
() => console.log('SVG code copied to clipboard'),
|
() => console.log('SVG code copied to clipboard'),
|
||||||
(err) => console.error('Error copying SVG code: ', err)
|
(err) => console.error('Error copying SVG code: ', err)
|
||||||
);
|
);
|
||||||
@ -36,18 +46,16 @@ const Assets: React.FC = () => {
|
|||||||
<div className="grid grid-cols-2 gap-4">
|
<div className="grid grid-cols-2 gap-4">
|
||||||
{assets.map((asset, index) => (
|
{assets.map((asset, index) => (
|
||||||
<div key={index} className="flex items-center space-x-4">
|
<div key={index} className="flex items-center space-x-4">
|
||||||
<div className="bg-[#f8f9fa] p-4 rounded-lg">
|
<div className="bg-[#f8f9fa] p-4 rounded-lg" dangerouslySetInnerHTML={{ __html: asset.svgContent }} />
|
||||||
<img src={asset.svgUrl} alt={asset.name} className="w-20 h-20" />
|
|
||||||
</div>
|
|
||||||
<div>
|
<div>
|
||||||
<a href={asset.downloadUrl} target="_blank" rel="noopener noreferrer" className="block bg-blue-500 text-white px-4 py-2 mb-2">Download</a>
|
<a href={asset.svgUrl} target="_blank" rel="noopener noreferrer" className="block bg-blue-500 text-white px-4 py-2 mb-2">Download</a>
|
||||||
<input
|
<input
|
||||||
type="color"
|
type="color"
|
||||||
value={color}
|
value={color}
|
||||||
onChange={(e) => setColor(e.target.value)}
|
onChange={(e) => setColor(e.target.value)}
|
||||||
className="mb-2"
|
className="mb-2"
|
||||||
/>
|
/>
|
||||||
<button onClick={() => handleCopySVGCode(asset.svgUrl, color)} className="bg-gray-500 text-white px-4 py-2">Copy SVG</button>
|
<button onClick={() => handleCopySVGCode(asset.svgContent)} className="bg-gray-500 text-white px-4 py-2">Copy SVG</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
Loading…
Reference in New Issue
Block a user