diff options
| author | Pauline <git@ethanlibs.co> | 2023-11-26 17:13:07 -0500 |
|---|---|---|
| committer | Pauline <git@ethanlibs.co> | 2023-11-26 17:13:07 -0500 |
| commit | e9d485fe3b5db8c426ac03b30ed8917df0baa62d (patch) | |
| tree | 69a684d53abce6b636620cc0000a6e84846246d7 /apps/website/src/components/icons | |
| parent | 85c31ee8d278ac6fa1f0ba143b78d65e5f665f32 (diff) | |
| download | Nexus-e9d485fe3b5db8c426ac03b30ed8917df0baa62d.tar.gz Nexus-e9d485fe3b5db8c426ac03b30ed8917df0baa62d.tar.bz2 Nexus-e9d485fe3b5db8c426ac03b30ed8917df0baa62d.zip | |
feat(lint): switch to eslint config and formatting (use vscode for autoformat)
Diffstat (limited to 'apps/website/src/components/icons')
| -rw-r--r-- | apps/website/src/components/icons/Icon.astro | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/apps/website/src/components/icons/Icon.astro b/apps/website/src/components/icons/Icon.astro index bf2b362..b36d412 100644 --- a/apps/website/src/components/icons/Icon.astro +++ b/apps/website/src/components/icons/Icon.astro @@ -1,28 +1,26 @@ --- -export type Icons = "chevron-down" | "download" | "book-open"; - import { parse } from 'node-html-parser'; -import type { HTMLAttributes } from "astro/types"; +import type { HTMLAttributes } from 'astro/types'; + +export type Icons = 'chevron-down' | 'download' | 'book-open'; -interface Props extends HTMLAttributes<"svg"> { - icon: Icons; - size?: number | [number, number]; +interface Props extends HTMLAttributes<'svg'> { + icon: Icons + size?: number | [number, number] } async function getSVG(name: string) { const file = await import(`./impl/${name}.svg?raw` /* @vite-ignore */); - if (!file) { + if (!file) throw new Error(`${name} not found`); - } const content = parse(file.default); const svg = content.querySelector('svg'); - if (!svg) { + if (!svg) throw new Error(`${name} is not a valid SVG`); - } const { attributes, innerHTML } = svg; @@ -39,13 +37,12 @@ const { } = Astro.props as Props; let svgAttributes = {}; -let html = ""; +let html = ''; try { const sizeAttributes = () => { - if (!size) { + if (!size) return {}; - } if (Array.isArray(size)) { return { @@ -58,7 +55,7 @@ try { width: size, height: size, }; - } + }; const { attributes: baseAttributes, innerHTML } = await getSVG(icon); svgAttributes = { @@ -69,9 +66,10 @@ try { const colorRegex = /(fill|stroke)=\"([^"]*)\"/g; html = innerHTML.replaceAll(colorRegex, '$1="currentColor"'); -} catch (err) { - +} +catch (err) { + // ignored } --- -<svg {...svgAttributes} set:html={html}></svg> + <svg {...svgAttributes} set:html={html}></svg> |
