mirror of
https://github.com/tiennm99/HugoBlox-kit.git
synced 2026-10-13 04:14:41 +00:00
fix(blocks): Feature widget off-center Preact icons
This commit is contained in:
1 parent
9916ea5d2a
commit
bf41049de2
1 file changed
+4
-8
@@ -9,6 +9,7 @@ import { h } from "preact";
|
||||
export const Icon = ({ svg, attributes }) => {
|
||||
if (!svg) return null;
|
||||
|
||||
// Clean the SVG string: decode HTML entities and TRIM whitespace
|
||||
let decoded = String(svg)
|
||||
.replace(/\\u003c/gi, "<")
|
||||
.replace(/\\u003e/gi, ">")
|
||||
@@ -17,20 +18,15 @@ export const Icon = ({ svg, attributes }) => {
|
||||
.replace(/>/gi, ">")
|
||||
.replace(/"/gi, '"')
|
||||
.replace(/"/gi, '"')
|
||||
.replace(/&/gi, "&");
|
||||
.replace(/&/gi, "&")
|
||||
.trim();
|
||||
|
||||
const hasWrapper = /<svg[\s>]/i.test(decoded);
|
||||
|
||||
if (hasWrapper) {
|
||||
if (/<svg[^>]*class=/i.test(decoded)) {
|
||||
decoded = decoded.replace(/<svg([^>]*?)class="([^"]*)"([^>]*)>/i, '<svg$1class="$2 inline-block w-4 h-4"$3>');
|
||||
} else {
|
||||
decoded = decoded.replace(/<svg\b/i, '<svg class="inline-block w-4 h-4"');
|
||||
}
|
||||
|
||||
const wrapperProps = {
|
||||
...attributes,
|
||||
class: `inline-block ${attributes?.class || ""}`.trim(),
|
||||
class: `flex items-center justify-center ${attributes?.class || ""}`.trim(),
|
||||
};
|
||||
|
||||
// eslint-disable-next-line lint/security/noDangerouslySetInnerHtml
|
||||
|
||||
Reference in new issue
Block a user