UNPKG

867 BTypeScriptView Raw
1import * as React from 'react'
2
3export type IconSize = 'sm' | 'md' | 'lg' | 'tool'
4
5export interface IconProps {
6 name: string
7 size?: IconSize
8 style?: React.CSSProperties
9}
10
11function getSize(size?: IconSize): number {
12 if (size === 'sm') {
13 return 16
14 } else if (size === 'md') {
15 return 24
16 } else if (size === 'lg') {
17 return 32
18 } else if (size === 'tool') {
19 return 26
20 }
21
22 return 24
23}
24
25export function Icon({
26 children,
27 ...props
28}: React.PropsWithChildren<IconProps>) {
29 return React.isValidElement(children)
30 ? React.cloneElement(children, {
31 'aria-hidden': true,
32 'data-qa': `ci-${props.name}`,
33 ...props,
34 width: getSize(props.size),
35 height: getSize(props.size),
36 focusable: false,
37 style: {
38 ...props.style,
39 flex: '0 0 auto',
40 },
41 })
42 : null
43}