Skip to content

Instantly share code, notes, and snippets.

@aleyrizvi
Last active January 16, 2023 10:12
Show Gist options
  • Save aleyrizvi/036b05e948307c28affdb4e16045f2dc to your computer and use it in GitHub Desktop.
Save aleyrizvi/036b05e948307c28affdb4e16045f2dc to your computer and use it in GitHub Desktop.
Dynamic Tabler Icons import for react
import * as icons from "@tabler/icons"
interface Props {
icon: string
color?: string
size?: number
stroke?: number
}
export const TablerIcons = (props: Props): JSX.Element => {
const { icon, color = "gray", size = 6, stroke = 2 } = props
// @ts-ignore
const Icon: JSX.Element = icons[icon]
return (
// @ts-ignore
<Icon width={size} color={color} stroke={stroke} />
)
}
// usage
<TablerIcons icon={"IconBrandAmazon"} color={"..."} size={"..."} stroke={...} />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment