Socket
Socket
Sign inDemoInstall

@emotion/babel-preset-css-prop

Package Overview
Dependencies
Maintainers
3
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


Version published
Weekly downloads
225K
increased by6.6%
Maintainers
3
Weekly downloads
 
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 22 Dec 2019

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