MCPcopy Create free account
hub / github.com/adobe/react-spectrum / createIcon

Function createIcon

packages/@react-spectrum/s2/src/Icon.tsx:99–152  ·  view source on GitHub ↗
(
  Component: ComponentType<SVGProps<SVGSVGElement>>,
  context: Context<ContextValue<IconContextValue, SVGElement>> = IconContext
)

Source from the content-addressed store, hash-verified

97);
98
99export 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
154const illustrationStyles = style(
155 {

Callers 11

Sidebar.tsxFile · 0.90
CodePlatter.tsxFile · 0.90
NpmLogo.tsxFile · 0.90
Esbuild.tsxFile · 0.90
Parcel.tsxFile · 0.90
ReactRouter.tsxFile · 0.90
Nextjs.tsxFile · 0.90
Webpack.tsxFile · 0.90
GithubLogo.tsxFile · 0.90
Vite.tsxFile · 0.90
Rollup.tsxFile · 0.90

Calls 4

useSpectrumContextPropsFunction · 0.90
useSkeletonIconFunction · 0.90
mergeStylesFunction · 0.90
renderFunction · 0.70

Tested by

no test coverage detected