File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 11import React from "react"
22import * as TablerIcons from "@tabler/icons-react"
33import * as SimpleIcons from "@icons-pack/react-simple-icons"
4+ import * as CodeZeroIcons from "@core/icons"
45
56type TablerIcon = React . FC < TablerIcons . IconProps & React . RefAttributes < SVGSVGElement > >
67type 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 ) } `
You can’t perform that action at this time.
0 commit comments