1
0
mirror of https://github.com/kremalicious/blog.git synced 2024-12-01 13:47:09 +01:00
blog/scripts/create-icons/toReactComponent.ts

36 lines
893 B
TypeScript
Raw Permalink Normal View History

2023-10-26 19:59:24 +02:00
export const toReactComponent = (innerSVG: string, title: string) => `
import type { Props } from './Props.d.ts';
export function Icon(props: Props) {
let {
size = '24px',
title,
width = size,
height = size
}: Props = {
'title': '${title}',
...props
}
const toAttributeSize = (size: number | string) =>
String(size).replace(/(?<=[0-9])x$/, 'em')
size = toAttributeSize(size)
width = toAttributeSize(width)
height = toAttributeSize(height)
2023-11-01 23:16:02 +01:00
const style = {
width: '1em',
height: '1em',
stroke: 'currentcolor',
strokeWidth: 'var(--border-width)',
strokeLinecap: 'round',
strokeLinejoin: 'round',
fill: 'none',
verticalAlign: 'baseline'
2023-10-26 19:59:24 +02:00
}
2023-11-01 23:16:02 +01:00
return <svg width={width} height={height} fill="none" viewBox="0 0 24 24" {...props} style={style as any}>{title ? (<title>{title}</title>) : ''}${innerSVG}</svg>
2023-10-26 19:59:24 +02:00
}
`