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

@emotion/babel-preset-css-prop

Package Overview
Dependencies
Maintainers
4
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@emotion/babel-preset-css-prop

A babel preset to automatically enable emotion's css prop

  • 10.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created

What is @emotion/babel-preset-css-prop?

@emotion/babel-preset-css-prop is a Babel preset that allows you to use the css prop when writing React components. This preset makes it easier to style components using Emotion's powerful CSS-in-JS library, enabling you to write CSS directly within your JavaScript code.

What are @emotion/babel-preset-css-prop's main functionalities?

Using css prop for styling

This feature allows you to use the css prop to style React components directly. The css prop accepts a CSS-in-JS object or template literal, making it easy to apply styles.

import React from 'react';
/** @jsxImportSource @emotion/react */
import { css } from '@emotion/react';

const buttonStyle = css`
  background-color: hotpink;
  color: white;
  border: none;
  padding: 10px 20px;
  cursor: pointer;
`;

const Button = () => (
  <button css={buttonStyle}>Click Me</button>
);

export default Button;

Theming with css prop

This feature demonstrates how to use the css prop in conjunction with Emotion's ThemeProvider to apply theme-based styles. The theme object can be accessed within the css prop to dynamically style components based on the current theme.

import React from 'react';
/** @jsxImportSource @emotion/react */
import { css, ThemeProvider } from '@emotion/react';

const theme = {
  colors: {
    primary: 'hotpink',
    secondary: 'blue'
  }
};

const buttonStyle = theme => css`
  background-color: ${theme.colors.primary};
  color: white;
  border: none;
  padding: 10px 20px;
  cursor: pointer;
`;

const Button = () => (
  <button css={buttonStyle}>Click Me</button>
);

const App = () => (
  <ThemeProvider theme={theme}>
    <Button />
  </ThemeProvider>
);

export default App;

Other packages similar to @emotion/babel-preset-css-prop

FAQs

Package last updated on 10 Nov 2020

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