( Component: ComponentType<SVGProps<SVGSVGElement>>, context: Context<ContextValue<IconContextValue, SVGElement>> = IconContext )
| 97 | ); |
| 98 | |
| 99 | export function createIcon( |
| 100 | Component: ComponentType<SVGProps<SVGSVGElement>>, |
| 101 | context: Context<ContextValue<IconContextValue, SVGElement>> = IconContext |
| 102 | ): FunctionComponent<IconProps> { |
| 103 | return (props: IconProps) => { |
| 104 | let ref = useRef<SVGElement>(null); |
| 105 | let ctx; |
| 106 | // TODO: remove this default once we release RAC and use DEFAULT_SLOT. |
| 107 | [ctx, ref] = useSpectrumContextProps( |
| 108 | {slot: props.slot || 'icon'} as IconContextValue, |
| 109 | ref, |
| 110 | context |
| 111 | ); |
| 112 | let {render, styles: ctxStyles} = ctx; |
| 113 | let { |
| 114 | UNSAFE_className, |
| 115 | UNSAFE_style, |
| 116 | slot, |
| 117 | 'aria-label': ariaLabel, |
| 118 | 'aria-hidden': ariaHidden, |
| 119 | styles, |
| 120 | ...otherProps |
| 121 | } = props; |
| 122 | |
| 123 | if (!ariaHidden) { |
| 124 | ariaHidden = undefined; |
| 125 | } |
| 126 | |
| 127 | let svg = ( |
| 128 | <SkeletonWrapper> |
| 129 | <Component |
| 130 | {...otherProps} |
| 131 | focusable={false} |
| 132 | aria-label={ariaLabel} |
| 133 | aria-hidden={ariaLabel ? ariaHidden || undefined : true} |
| 134 | role="img" |
| 135 | data-slot={slot} |
| 136 | className={ |
| 137 | (UNSAFE_className ?? '') + |
| 138 | ' ' + |
| 139 | useSkeletonIcon(mergeStyles(iconStyles(null, styles), ctxStyles)) |
| 140 | } |
| 141 | style={UNSAFE_style} |
| 142 | /> |
| 143 | </SkeletonWrapper> |
| 144 | ); |
| 145 | |
| 146 | if (render) { |
| 147 | return render(svg); |
| 148 | } |
| 149 | |
| 150 | return svg; |
| 151 | }; |
| 152 | } |
| 153 | |
| 154 | const illustrationStyles = style( |
| 155 | { |
no test coverage detected