Socket
Socket
Sign inDemoInstall

@emotion/styled

Package Overview
Dependencies
63
Maintainers
4
Versions
100
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emotion/styled

styled API for emotion


Version published
Maintainers
4
Weekly downloads
5,823,049
decreased by-1.66%
Install size
6.24 MB

Weekly downloads

Package description

What is @emotion/styled?

The @emotion/styled npm package is a library for styling React components using tagged template literals. It allows developers to write CSS code in JavaScript and attach styles directly to components, providing a more seamless integration of styles within JS code. It leverages the power of Emotion, a performant and flexible CSS-in-JS library.

What are @emotion/styled's main functionalities?

Creating styled components

This feature allows you to create a new React component with a set of styles attached to it using a template literal. The styles are scoped to the component, and pseudo-classes and media queries can be used within the template literal.

import styled from '@emotion/styled';

const Button = styled.button`
  background-color: hotpink;
  padding: 16px;
  border-radius: 8px;
  color: white;
  font-size: 1em;
  &:hover {
    opacity: 0.9;
  }
`;

<Button>Click me</Button>

Theming

This feature allows you to define a theme object and use it to style components. The ThemeProvider component makes the theme available to all styled components, which can access the theme via props.

import styled from '@emotion/styled';
import { ThemeProvider } from '@emotion/react';

const theme = {
  colors: {
    primary: 'hotpink'
  }
};

const Button = styled.button`
  background-color: ${props => props.theme.colors.primary};
  /* other styles */
`;

<ThemeProvider theme={theme}>
  <Button>Themed Button</Button>
</ThemeProvider>

Dynamic styling

This feature allows you to pass props to your styled components to dynamically change their styles based on the props received. This is useful for creating variations of a component, such as primary and secondary buttons.

import styled from '@emotion/styled';

const Button = styled.button`
  color: ${props => props.primary ? 'hotpink' : 'black'};
  /* other styles */
`;

<Button primary>Primary Button</Button>
<Button>Default Button</Button>

Other packages similar to @emotion/styled

Readme

Source

@emotion/styled

The styled API for @emotion/react

Install

yarn add @emotion/react @emotion/styled

Usage

import styled from '@emotion/styled'

let SomeComp = styled.div({
  color: 'hotpink'
})

let AnotherComp = styled.div`
  color: ${props => props.color};
`

render(
  <SomeComp>
    <AnotherComp color="green" />
  </SomeComp>
)

More documentation is available at https://emotion.sh/docs/styled.

FAQs

Last updated on 29 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc