I use the css function when I create variants for a component:

that is variant switcher:

const sizeVariant: Record<NonNullable<StyledLogoProps['size']>, ReturnType<typeof css>> = {
  small: css`
    width: 44px;
    height: 44px;
  `,
  regular: css`
    width: 93px;
    height: 93px;
  `,
};

that is component was created by 'styled-components':

interface StyledLogoProps {
  size: 'small' | 'regular';
}

export const StyledLogo = styled.div<StyledLogoProps>`
  ${({ size }) => sizeVariant[size]}
`;

and this is the use in the react:

<>
  <StyledLogo size="regular" />
  <StyledLogo size="small" />
</>

quite a useful thing

Answer from CasperCarver on Stack Overflow
🌐
styled-components
styled-components.com › docs › basics
Styled Components Basic
Automatic critical CSS: styled-components keeps track of which components are rendered on a page and injects their styles and nothing else, fully automatically.
🌐
styled-components
styled-components.com
styled-components
The last step is that we need to define what a primary button looks like. To do that we also import { css } from styled-components and interpolate a function into our template literal, which gets passed the props of our component:
🌐
Josh W. Comeau
joshwcomeau.com › react › demystifying-styled-components
Demystifying styled-components • Josh W. Comeau
The helper methods are called with a chunk of CSS, using an obscure JavaScript feature known as “tagged template literals”. For now, you can pretend that it's written like this: ... These helper methods are little component factories. Every time we call them, we get a brand-new React component. ... // When I call this function… function h1(styles) { // …it generates a brand-new React component…
🌐
Smashing Magazine
smashingmagazine.com › 2020 › 07 › styled-components-react
How To Use Styled-Components In React — Smashing Magazine
July 23, 2020 - Wherever you choose to render your GlobalStyle, it will be injected when your component is rendered. Be careful: createGlobalStyles will only be rendered if and when it’s in the DOM. Already we’ve seen how to adapt styles based on props. What if we wanted to go a little further? The CSS helper function helps to achieve this.
🌐
LogRocket
blog.logrocket.com › home › 8 awesome features of styled-components
8 awesome features of styled-components - LogRocket Blog
June 4, 2024 - To turn this component into a styled component, pass it to the styled() function. Button = styled(Button)` padding: 2px 5px; border-radius: 3px; border: 1px solid palevioletred; ` This will style the button element in the Button component with ...
🌐
DEV Community
dev.to › elijahtrillionz › complete-guide-on-how-to-use-styled-components-in-react-360c
Complete Guide On How To Use Styled-components In React - DEV Community
February 19, 2022 - Oftentimes, we have styles that need to be applied globally to avoid repetition, for example, you could want that all elements should be a border-box, rather than repeating it over and over for each element, we would say in CSS ... Another example could be removing all underline from a tags, applying different specific font-family on p and h1-h6 tags, or applying a custom scrollbar for your web pages, and many others. To apply these styles in styled-components is simple, we simply create a GlobalStyles styled component and apply it to our app once. To create the GlobalStyles (you can give it any other name) we would need the createGlobalStyle function from styled-components.
🌐
Josh W. Comeau
joshwcomeau.com › css › styled-components
The styled-components Happy Path: my personal suite of “best practices” • Josh W. Comeau
January 25, 2021 - This article is primarily written for React developers of all experience levels who are already using styled-components, or another CSS-in-JS solution like Emotion. This article is not meant to serve as an introduction to styled-components, nor is it meant to compare or contrast it with other tools. Let's start with a fun little tip. Say we have a Backdrop component, and it takes props for opacity and color: ... function Backdrop({ opacity, color, children }) { return ( <Wrapper> {children} </Wrapper> ); } const Wrapper = styled.div` /* ??
Find elsewhere
🌐
GitHub
github.com › styled-components › styled-components
GitHub - styled-components/styled-components: Fast, expressive styling for React. Server components, client components, streaming SSR, React Native—one API.
Style React components with real CSS, scoped automatically and delivered only when needed.
Starred by 41K users
Forked by 2.5K users
Languages   TypeScript 91.2% | JavaScript 8.6%
🌐
Softchris
softchris.github.io › pages › react-styled-components.html
Styled components, the styling library for your React apps you don’t want to be without
We can tell the latter from the above code through our use of css function. Below we use the above construct add some styling that we should only apply if the primary attribute is present: const Button = styled.button` background: black; color: white; border-radius: 7px; padding: 20px; margin: 10px; font-size: 16px; :disabled { opacity: 0.4; } :hover { box-shadow: 0 0 10px yellow; } ${props => props.primary && css` background: green; color: white; `} `;
🌐
LogRocket
blog.logrocket.com › home › using styled-components in react
Using styled-components in React - LogRocket Blog
June 4, 2024 - The outer function in the Button component styles can now use that string to style the button. For the color and border properties, however, we used a function that returns a value we can use directly in our Button‘s styles string instead of just a string to be used by an outer function. This is where the css helper function comes in.
🌐
React School
react.school › styled-components
Styled Components | React School
The one lined statement we defined originally is just the above JavaScript simplified with ES6 shorthand: arrow functions & object destructuring. So anyway, this allows you to dynamically set style attributes of this component: <Block color="green">Ex B</Block>. This creates a Block with green text. You can utilize the CSS hover selector easily within a styled-component.
🌐
MUI
mui.com › system › styled
styled() - MUI System
If you inspect this element with the browser DevTools in development mode, you will notice that the class of the component now ends with the MyThemeComponent-root, which comes from the name and slot options that were provided. In addition to this, the color, sx, and variant props are not propagated to the generated div element. If you would like to remove some of the MUI System specific features, you can do it like this: const StyledComponent = styled('div', {}, { name: 'MuiStyled', slot: 'Root', - overridesResolver: (props, styles) => styles.root, // disables theme.components[name].styleOverrides + skipVariantsResolver: true, // disables theme.components[name].variants + skipSx: true, // disables the sx prop }); CopyCopied(or $keyC)
🌐
Gatsby
gatsbyjs.com › documentation › how-to guides › styling › using styled components
Styled Components | Gatsby
Styled-components are primarily used for a single CSS class that is isolated from other components. In some cases, you want to override global styling — for example, the default margins of your body element.
🌐
DEV Community
dev.to › saichai › thank-me-later-use-styled-components-s-css-helper-everywhere-2ni1
Thank Me Later: Use Styled Components's css helper everywhere - DEV Community
June 29, 2020 - To solve this, Styled Components added a helper function named simply css that also accepts a tagged template as its parameter. It forwards props to any interpolations and handles any interpolated functions, just like styled. In addition, many devs working with Styled Components will configure their linters to detect and resolve neglected nested interpolations.
🌐
freeCodeCamp
freecodecamp.org › news › styled-components-in-react
How to Use Styled Components in Your React Apps
October 16, 2024 - Styled-components is a library that allows you to write CSS in JS while building custom components in Reactjs. There are multiple options you can go with to style a React application.
🌐
DEV Community
dev.to › pancompany › styled-components-why-you-should-or-should-not-use-it-23c
Styled-Components: Why you should (or should not) use it - DEV Community
February 29, 2024 - That is possible because ... call a function with backticks). This is best explained by actually showing it. You make a styled-component out of a React element by defining it with the ‘styled’ object. Here you see a simple example of a div with red text and font size of 16px: import styled from 'styled-components'; const StyledTextBlock = styled.div` color: red; font-size: 16px; `; ... The local scoping is a major advantage compared to regular CSS, but it is ...
🌐
DEV Community
dev.to › stephencweiss › reusing-css-with-styled-components-3okn
Reusing CSS With Styled Components - DEV Community
September 17, 2020 - import styled from ‘styled-components’; export const SecondComponent = styled(DefaultInput)` /* make changes as needed*/ `; This would be ideal since I could simply extend the CSS I defined originally. Enter the CSS helper function from styled components!
🌐
GitHub
github.com › styled-components › styled-components › issues › 565
TypeScript Props with css function · Issue #565 · styled-components/styled-components
July 3, 2017 - The following throws a type error as the css function does not recoqnize the props.primary interpolation: import * as styledComponents from "styled-components"; import { ThemedStyledComponentsModule } from "styled-components"; interface Theme { primaryColor: string; secondaryColor: string; } const { css } = styledComponents as ThemedStyledComponentsModule<Theme>; export const MyCss = css` color: ${(props) => props.theme.primaryColor}; background: ${(props) => props.inverted ?
Author   victorandree
🌐
Medium
medium.com › building-crowdriff › styled-components-to-use-or-not-to-use-a6bb4a7ffc21
Styled Components: To Use or Not to Use? | by Talia Marcassa | Building CrowdRiff | Medium
June 7, 2018 - With Styled Components’ css function, you can use props to conditionally render css, which meant that we no longer had to render conditional class names based on props.