An open API service indexing awesome lists of open source software.

https://github.com/oxizen/babel-plugin-less-for-styled-components

Using LESS for styled-components
https://github.com/oxizen/babel-plugin-less-for-styled-components

babel emotion less styled-components

Last synced: 3 months ago
JSON representation

Using LESS for styled-components

Awesome Lists containing this project

README

          

[![npm](https://img.shields.io/npm/v/babel-plugin-less-for-styled-components.svg)](https://www.npmjs.com/package/babel-plugin-less-for-styled-components)

## LESS for styled-components
It's a babel plugin that can use LESS syntax in the style template of [styled-components](https://styled-components.com/) or [emotion](https://emotion.sh/docs/introduction).

- Template literal with props
```javascript
const Button = styled.button<{ disabled: boolean }>`
.color(${props => (props.disabled ? 'gray' : 'red')});
`
```

- Referring to other components
```javascript
const Link = styled.a`
.flex; .items-center; .p(5, 10);
`;

const Span = styled.span`
.c(red);
${Link}:hover & { .c(blue) }
`;
```

### global import option
- add global imports option, it can be referenced in all the style blocks.
```javascript
[
'babel-plugin-less-for-styled-components',
{ globalImports: ['src/less/proj'] }
]
```

### Cautions
- ~~When registering this plug-in, it must be registered before `babel-plugin-styled-components`~~ (improved since 1.2.0).

function to detect template is from [styless](https://github.com/jean343/styless.git).