Skip to content

Commit 7955d0f

Browse files
committed
feat: add custom icon support and GLS SVG icon component
1 parent 280e67f commit 7955d0f

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from "react"
2+
import GlsIcon from "./gls.svg"
3+
4+
export type CustomIconProps = {
5+
size?: number | string
6+
color?: string
7+
} & Omit<React.SVGProps<SVGSVGElement>, "color">
8+
9+
/**
10+
* Wraps a raw SVG (loaded directly from its `.svg` file in this folder) into a
11+
* component that accepts the same `size` and `color` props as the Tabler/Simple
12+
* icons. The `fill` is applied on the root `<svg>` and inherited by the paths.
13+
*/
14+
const customIcon = (Svg: React.FC<React.SVGProps<SVGSVGElement>>): React.FC<CustomIconProps> =>
15+
function CustomIcon({size = 24, color = "currentColor", ...rest}) {
16+
return <Svg width={size} height={size} fill={color} {...rest}/>
17+
}
18+
19+
export const Gls = customIcon(GlsIcon)

src/packages/core/src/util/icons.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
import React from "react"
22
import * as TablerIcons from "@tabler/icons-react"
33
import * as SimpleIcons from "@icons-pack/react-simple-icons"
4+
import * as CodeZeroIcons from "@core/icons"
45

56
type TablerIcon = React.FC<TablerIcons.IconProps & React.RefAttributes<SVGSVGElement>>
67
type SimpleIcon = React.FC<Omit<SimpleIcons.IconType, '$$typeof'>>
7-
export type IconString = `${'tabler'}:${string}` | `${'simple'}:${string}`
8+
type CustomIcon = React.FC<CodeZeroIcons.CustomIconProps>
89

9-
export const icon = (icon?: IconString): TablerIcon | SimpleIcon => {
10+
export type IconString = `${'tabler'}:${string}` | `${'simple'}:${string}` | `${'codezero'}:${string}`
11+
12+
export const icon = (icon?: IconString): TablerIcon | SimpleIcon | CustomIcon => {
1013

1114
const fallbackIcon = TablerIcons.IconNote
1215

16+
if (icon?.startsWith("codezero:")) {
17+
const name = icon.replace("codezero:", "").trim()
18+
const normalizedName = `${name.charAt(0).toUpperCase() + name.slice(1)}`
19+
20+
const resolvedIcon = normalizedName in CodeZeroIcons
21+
? CodeZeroIcons[normalizedName as keyof typeof CodeZeroIcons]
22+
: fallbackIcon
23+
24+
return resolvedIcon as CustomIcon
25+
}
26+
1327
if (icon?.startsWith("simple:")) {
1428
const name = icon.replace("simple:", "").trim()
1529
const normalizedName = `Si${name.charAt(0).toUpperCase() + name.slice(1)}`

0 commit comments

Comments
 (0)