All Projects → jean343 → styless

jean343 / styless

Licence: MIT license
Style your components declaratively with familiar less syntax

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to styless

Vscode Stylelint
A Visual Studio Code extension to lint CSS/SCSS/Less with stylelint
Stars: ✭ 260 (+306.25%)
Mutual labels:  less, styled-components
Prejss
Get the power of PostCSS with plugins in your JSS styles. 🎨 Just put CSS into JS and get it as JSS object.
Stars: ✭ 238 (+271.88%)
Mutual labels:  less, styled-components
WPKirk
A WP Bones skeleton Plugin
Stars: ✭ 28 (-56.25%)
Mutual labels:  less, styled-components
YASCC
Yet Another SoundCloud Client
Stars: ✭ 30 (-53.12%)
Mutual labels:  styled-components
aspnet-core-react-redux-playground-template
SPA template built with ASP.NET Core 6.0 + React + Redux + TypeScript + Hot Module Replacement (HMR)
Stars: ✭ 78 (+21.88%)
Mutual labels:  styled-components
Online-News-Portal-with-Django
Daily News For You is an online news portal developed by Django and SQLite
Stars: ✭ 45 (-29.69%)
Mutual labels:  less
react-2048
A React implementation of 2048 game built with typescript and styled-components
Stars: ✭ 66 (+3.13%)
Mutual labels:  styled-components
less-plugin-functions
Write custom Less functions in Less itself
Stars: ✭ 111 (+73.44%)
Mutual labels:  less
dashboard
🐥 McHacks dashboard
Stars: ✭ 28 (-56.25%)
Mutual labels:  styled-components
vue-wechat-desktop
🔥Vue 全家桶仿mac微信
Stars: ✭ 22 (-65.62%)
Mutual labels:  less
react-native-awesome-starter
⚛️ react-native initial development environment setting
Stars: ✭ 30 (-53.12%)
Mutual labels:  styled-components
leo-ui
UI组件库
Stars: ✭ 16 (-75%)
Mutual labels:  less
babel-plugin-object-styles-to-template
Babel plugin to transpile object styles to template literal
Stars: ✭ 33 (-48.44%)
Mutual labels:  styled-components
GoBarber
💈 Aplicação de agendamento para serviços de beleza, entre provedores e clientes.
Stars: ✭ 84 (+31.25%)
Mutual labels:  styled-components
chat
💬 A React single page chat application (SPA), implementing Socket.io.
Stars: ✭ 98 (+53.13%)
Mutual labels:  styled-components
react-functional-select
Micro-sized & micro-optimized select component for React.js
Stars: ✭ 165 (+157.81%)
Mutual labels:  styled-components
generator-speedseed
Oriented to components, allow create/choice template, multiple configuration with easy maintenance
Stars: ✭ 13 (-79.69%)
Mutual labels:  less
Styled-Responsive-Media-Queries
Responsive Media Queries for Emotion styled or styled-components — Standard size from Chrome DevTools.
Stars: ✭ 33 (-48.44%)
Mutual labels:  styled-components
SAAS-Starter-Kit-Pro
🚀A boilerplate for building Software-as-Service (SAAS) apps with Reactjs, and Nodejs
Stars: ✭ 313 (+389.06%)
Mutual labels:  styled-components
static-html-template
静态页面网站快速开发环境,支持自动刷新页面,less样式预处理。
Stars: ✭ 19 (-70.31%)
Mutual labels:  less

Build Status npm semantic-release style: styled-components

💎Styless💎

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 🎉, 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 🎉, 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"
  }
]
[
  "styless",
  {
    "import": "~antd/lib/style/themes/default.less",
    "lessOptions": {
      "javascriptEnabled": true
    }
  }
]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].