Giter Club home page Giter Club logo

babel-plugin-polished's Introduction


Visual primitives for the component age. Use the best bits of ES6 and CSS to style your apps without stress ๐Ÿ’…

downloads: 600k/month Discord gzip size module formats: umd, cjs, esm Code Coverage

Upgrading from v5? See the migration guide.

Utilizing tagged template literals (a recent addition to JavaScript) and the power of CSS, styled-components allow you to write actual CSS code to style your components. It also removes the mapping between components and styles โ€“ using components as a low-level styling construct could not be easier!

const Button = styled.button`
  color: grey;
`;

Alternatively, you may use style objects. This allows for easy porting of CSS from inline styles, while still supporting the more advanced styled-components capabilities like component selectors and media queries.

const Button = styled.button({
  color: 'grey',
});

Equivalent to:

const Button = styled.button`
  color: grey;
`;

styled-components is compatible with both React (for web) and React Native โ€“ meaning it's the perfect choice even for truly universal apps! See the documentation about React Native for more information.

Supported by Front End Center. Thank you for making this possible!


See the documentation at styled-components.com/docs for more information about using styled-components!

Quicklinks to some of the most-visited pages:


Example

import React from 'react';

import styled from 'styled-components';

// Create a <Title> react component that renders an <h1> which is
// centered, palevioletred and sized at 1.5em
const Title = styled.h1`
  font-size: 1.5em;
  text-align: center;
  color: palevioletred;
`;

// Create a <Wrapper> react component that renders a <section> with
// some padding and a papayawhip background
const Wrapper = styled.section`
  padding: 4em;
  background: papayawhip;
`;

function MyUI() {
  return (
    // Use them like any other React component โ€“ except they're styled!
    <Wrapper>
      <Title>Hello World, this is my first styled component!</Title>
    </Wrapper>
  );
}

This is what you'll see in your browser:


Looking for v5?

The main branch is for the most-current version of styled-components, currently v6. For changes targeting v5, please point your PRs at the legacy-v5 branch.


Built with styled-components

A lot of hard work goes into community libraries, projects, and guides. A lot of them make it easier to get started or help you with your next project! There are also a whole lot of interesting apps and sites that people have built using styled-components.

Make sure to head over to awesome-styled-components to see them all! And please contribute and add your own work to the list so others can find it.


Contributing

If you want to contribute to styled-components please see our contributing and community guidelines, they'll help you get set up locally and explain the whole process.

Please also note that all repositories under the styled-components organization follow our Code of Conduct, make sure to review and follow it.


Badge

Let everyone know you're using styled-components โ†’ style: styled-components

[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components)

Contributors

This project exists thanks to all the people who contribute. [Contribute].


Backers

Thank you to all our backers! ๐Ÿ™ [Become a backer]


Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]


License

Licensed under the MIT License, Copyright ยฉ 2016-present Glen Maddern and Maximilian Stoiber.

See LICENSE for more information.


Acknowledgements

This project builds on a long line of earlier work by clever folks all around the world. We'd like to thank Charlie Somerville, Nik Graf, Sunil Pai, Michael Chan, Andrey Popp, Jed Watson & Andrey Sitnik who contributed ideas, code or inspiration.

Special thanks to @okonet for the fantastic logo.

babel-plugin-polished's People

Contributors

jamiebuilds avatar kitten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

babel-plugin-polished's Issues

Issues when integrating with istanbul

It's not my SO post, but this is essentially what I'm seeing: https://stackoverflow.com/questions/43940649/unexpected-node-type-error-sequenceexpression-with-jest

Essentially, istanbul and polished babel plugins don't play well with each other.

Here's out callstack:

SyntaxError: /next/app/components/FloatingActionButton/ui.tsx: Unexpected node type: SequenceExpression (This is an error on an internal node. Probably an internal error. Location has been estimated.)
  28 |   z-index: ${({ zIndex }) => zIndex || '2'};
  29 |   list-style-type: none;
> 30 |   background-color: ${({ theme, active }) => (active ? rgba(theme.colors.white, 0.5) : theme.colors.transparent)};
     |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  31 |   pointer-events: ${({ active }) => (active ? 'auto' : 'none')};
  32 |   -webkit-tap-highlight-color: ${({ theme }) => theme.colors.transparent};
  33 |
    at Array.filter (<anonymous>)
    at Array.filter (<anonymous>)

Our workaround was to only use the plugin on env.prod in the .babelrc.

Method does not exist: hideVisually

With the release of polished 1.9.0 a hideVisually mixin was added. When using this plugin and trying to import and use hideVisually I get the error:

Method does not exist: hideVisually

Without using the babel plugin hideVisually is found and works OK so I think it has to do with this plugin.

I'll try to find the problem and submit a PR but I've never worked with a babel plugin before so I figured I should submit the issue in case a more experienced person sees an issue.

Confirmation of expected outcome from using this package

The readme says "Compile away polished helpers" - can I just confirm that what this package does is strip-out/tree shake the polished helpers that I have not imported into my project?

Secondly, should the import in the 'In' code block be:

import { rem } from 'polished';

to fall in line with the example of how to import the polished helpers in the polished readme file?

Effectiveness of Library

I'm curious just how effective this is and how it handles dynamic usage scenarios.

For example, can something like this be handled?

css`
  ${props => rgba(normalizeColor('border', props.theme), 0.2)};
`

Plugin is incorrectly parsing intentional null values.

We have some mixins that intentionally take null to skip values. For example position:

position('absolute', '20px', '20px', null, null)

The babel plugin is stripping these null values out incorrectly and causing it to be parsed as:

position('absolute', '20px', '20px')

Which results in the incorrect final CSS:

position: absolute;
top: 20px;
right: 20px;
bottom: 20px;
left: 20px;

It should be:

position: absolute;
top: 20px;
right: 20px;

I imagine this is impacting anywhere we use null in this manner.

Plugin does not transform instances of a method when an argument is a non literal

Am very keen to make use of this plugin, but it doesn't do anything when added to my project.

I initially tried with babel 7 and then downgraded to 6 and it still did not work. Note, I tried polished and babel-plugin-polished as the values for the name in the .babelrc (you have it both ways in the documentation on github and on your website).

// .babelrc

  "plugins": [
    ["babel-plugin-styled-components", {
      "displayName": true,
      "ssr": true
    }],
    "babel-plugin-polished"
  ]

I also tried both ways of importing polished at the top of a given file.

// component.js

import * as polished from 'polished';
// as well as
import { rgba } from 'polished';

No combination makes any difference to the transpiled code that is output.

Please can you assist? Cheers.

Support dynamic values

I have some utilities that are able to derive the literal value of something, even across modules. I'm thinking of packaging this up into its own module. Would you be interested in adopting this in this plugin? I'd be happy to make a PR for it.

Method does not exist: math

Tried some new functions from polish today with some errors... Here I downloaded and added a test to your plugin (btw, please add jest as dev dep.)

  โ— polished โ€บ 2. math

    SyntaxError: unknown: Method does not exist: math
    > 1 | import { math } from 'polished';
        |         ^
      2 |
      3 | let a = math('12px + 12px')

      44 |
      45 |             if (!value) {
    > 46 |               throw imported.buildCodeFrameError('Method does not exist: ' + importedName);
         |                              ^
      47 |             }
{
      title: "math",
      code: `
        import { math } from 'polished';

        let a = math('12px + 12px')
      `,
      output: `
        let a = '14px';
      `
    }

Related to: Corjen/gatsby-plugin-polished#1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.