MCPcopy
hub / github.com/mui/material-ui / styled

Function styled

packages/mui-styled-engine/src/index.ts:18–43  ·  view source on GitHub ↗
(tag: React.ElementType, options?: StyledOptions<any>)

Source from the content-addressed store, hash-verified

16export type { CreateStyled, StyledComponent, StyledOptions, StyledTags } from '@emotion/styled';
17
18function styled(tag: React.ElementType, options?: StyledOptions<any>) {
19 // Emotion's `styled` overloads each expect a specific tag/component shape;
20 // none accept the broadened `React.ElementType` union, so cast the passthrough.
21 const stylesFactory = emStyled(tag as any, options);
22
23 if (process.env.NODE_ENV !== 'production') {
24 return (...styles: any[]) => {
25 const component = typeof tag === 'string' ? `"${tag}"` : 'component';
26 if (styles.length === 0) {
27 console.error(
28 [
29 `MUI: Seems like you called \`styled(${component})()\` without a \`style\` argument.`,
30 'You must provide a `styles` argument: `styled("div")(styleYouForgotToPass)`.',
31 ].join('\n'),
32 );
33 } else if (styles.some((style) => style === undefined)) {
34 console.error(
35 `MUI: the styled(${component})(...args) API requires all its args to be defined.`,
36 );
37 }
38 return stylesFactory(...styles);
39 };
40 }
41
42 return stylesFactory;
43}
44
45export default styled as unknown as CreateStyled;
46

Callers 15

styled.test.tsFile · 0.70
AvatarGroup.jsFile · 0.50
CardActionArea.jsFile · 0.50
Select.jsFile · 0.50
SelectInput.jsFile · 0.50
List.jsFile · 0.50

Calls

no outgoing calls

Tested by 1

variantsAPIFunction · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…