Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@emotion/styled

Package Overview
Dependencies
Maintainers
2
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emotion/styled

styled API for emotion

  • 10.0.0-beta.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.3M
decreased by-1.93%
Maintainers
2
Weekly downloads
 
Created

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

FAQs

Package last updated on 17 Oct 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc