diff --git a/package.json b/package.json index d56afb2..7731277 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@phosphor-icons/homepage", - "version": "2.0.5", + "version": "2.0.6", "license": "MIT", "homepage": "https://phosphoricons.com", "author": { diff --git a/src/components/IconGrid/Panel.tsx b/src/components/IconGrid/Panel.tsx index 4cf40a1..043d01b 100644 --- a/src/components/IconGrid/Panel.tsx +++ b/src/components/IconGrid/Panel.tsx @@ -54,6 +54,7 @@ const RENDERED_SNIPPETS = [ SnippetType.VUE, SnippetType.FLUTTER, SnippetType.ELM, + SnippetType.SWIFT, ]; enum CopyType { @@ -186,7 +187,7 @@ const Panel = () => { ); return [snippets, tabs]; - }, [entry, weight, size, copied, isDark]); + }, [entry, weight, size, color, copied, isDark]); useHotkeys("esc", () => setSelectionEntry(null)); diff --git a/src/lib/index.ts b/src/lib/index.ts index f03970b..d3a8a29 100644 --- a/src/lib/index.ts +++ b/src/lib/index.ts @@ -11,4 +11,5 @@ export enum SnippetType { HTML = "Web", FLUTTER = "Flutter", ELM = "Elm", + SWIFT = "Swift", } diff --git a/src/utils/index.ts b/src/utils/index.ts index bb28914..23b7389 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,15 @@ import { IconStyle } from "@phosphor-icons/core"; +import TinyColor from "tinycolor2"; import { SnippetType } from "@/lib"; +function u8ToCGFloatStr(value: number): string { + return (value / 255).toLocaleString("en-US", { + minimumFractionDigits: 0, + maximumFractionDigits: 4, + }); +} + export function getCodeSnippets({ name, displayName, @@ -17,8 +25,9 @@ export function getCodeSnippets({ }): Record { const isDefaultWeight = weight === "regular"; const isDefaultColor = color === "#000000"; - const elmName = displayName.replace(/^\w/, (c) => c.toLowerCase()); - const elmWeight = weight.replace(/^\w/, (c) => c.toUpperCase()); + const camelName = displayName.replace(/^\w/, (c) => c.toLowerCase()); + const pascalWeight = weight.replace(/^\w/, (c) => c.toUpperCase()); + const { r, g, b } = TinyColor(color).toRgb(); return { [SnippetType.HTML]: ` withSize ${size} |> withSizeUnit "px" |> toHtml []`, + [SnippetType.SWIFT]: `Ph.${camelName}.${weight}${ + !isDefaultColor + ? `\n .color(red: ${u8ToCGFloatStr(r)}, green: ${u8ToCGFloatStr( + g + )}, blue: ${u8ToCGFloatStr(b)})` + : "" + } + .frame(width: ${size}, height: ${size}) + `, }; }