npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

babel-plugin-styless

v1.4.25

Published

Style your components declaratively with familiar less syntax

Downloads

1,111

Readme

Build Status npm semantic-release style: styled-components

:gem:Styless:gem:

Styless enables less syntax in your styled-components

Installation

$ yarn add --dev babel-plugin-styless

.babelrc

{
  "plugins": ["babel-plugin-styless"]
}

Note that styless should appear before babel-plugin-styled-components if used.

Key features

  • Simplifies the code

    use @main instead of ${props => props.theme.main}

  • Uses variables directly in your styled components

    @size: if(@small, 4px, 10px);
  • Uses operations directly in your styled components

    use @size * 3 instead of ${props => parseFloat(props.size) * 3 + "px"}

  • Uses functions directly in your styled components.

    color: darken(@highlight, 5%);
There is no need to import `darken`.
  • Supports rgb, hsl and hsv color spaces
    color: hsv(90, 100%, 50%);
  • Migrate less to styled-components seamlessly.

    There is no confusion when transitioning from less to styled-components caused by width: 3px * 2.

  • Supports variable overwritten

    const Button = styled.button`
        @highlight: blue;                           // can be overwritten by theme or props
        background: darken(@highlight, 5%);         // make green darken by 5%
    `;
    <ThemeProvider theme={{highlight: "red"}}>
        <Button highlight="green">click me</Button> // green (set in props) overwrites red (set in theme)
    </ThemeProvider>
  • Supports imports and mixins
    const Button = styled.button`
        @import (reference) "variables";
        .bg-light-blue;
    `;
  • Supports css props
    <button css="color: @color;"/>
    <button css={`color: @color;`}/>
    <button css={css`color: @color;`}/>
  • Still supports the styled-components syntax for more complex jobs!
    `${props => props.main}`

Your first Styless component

const Button = styled.button`
    @main: palevioletred;
    @size: 1em;
    
    font-size: @size;
    margin: @size;
    padding: @size / 4 @size;
    border-radius: @size / 2;
    
    color: @main;
    border: 2px solid @main;
    background-color: white;
`;
<Button>Normal</Button>
<Button main="mediumseagreen">Themed</Button>
<Button main="mediumseagreen" size="1.5em">Themed large</Button>

This is what you'll see in your browser :tada:, play with it on codesandbox

Advanced Styless component example

const Button = styled.button`
    @faded: fade(black, 21%);
    @size: if(@small, 4px, 10px);
    cursor: pointer;
    cursor: if(@disabled, not-allowed);
    color: hsv(0, 0%, 99%);
    padding: @size @size * 3;
    border: 1px solid @faded;
    border-bottom: 4px solid @faded;
    border-radius: ${4}px;
    text-shadow: 0 1px 0 @faded;
    background: linear-gradient(@highlight 0%, darken(@highlight, 5%) 100%);
    &:active {
        background: darken(@highlight, 10%);
    }
`;
// Notice that the @highlight variable is resolved from the theme, and overwritten from a props in the second button.
<ThemeProvider theme={{highlight: "palevioletred"}}>
    <Button>Click me</Button>
    <Button highlight="hsl(153, 100%, 33%)">Or me</Button>
    <Button disabled small>But not me</Button>
</ThemeProvider>

This is what you'll see in your browser :tada:, play with it on codesandbox

Note that with webstorm-styled-components, we get syntax highlighting, color preview and ctrl+click access to variables!

FAQ

  • How to refer to a constants.less file, see the receipe for theme.
  • Cool, how does it work? Head over to the explanations.
  • Why less? The @color systax reduces the confusion from $color when comparing to the SC syntax ${props}. If there is enough demand, a scss plugin could be created.
  • The styled-components mixins such as ${hover}; must be terminated with a semi colon. The following will not work.
const Button = styled.button`
  ${hover}
  color: red;
`;
  • How to import a less files for all components? As SC components are small in nature, it can be convenient to have a common less file be imported in all components. Add the following to your .babelrc to have common.less imported automatically.
[
  "styless",
  {
    "cwd": "babelrc",
    "import": "../less/common.less"
  }
]