Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/salamaashoush/ngx-styled

Simple Decorator to integrate emotion with angular components
https://github.com/salamaashoush/ngx-styled

angular angular-components cssinjs decorator emotion jss style styled-components

Last synced: about 1 month ago
JSON representation

Simple Decorator to integrate emotion with angular components

Awesome Lists containing this project

README

        

# NgxStyled

[![npm version](https://badge.fury.io/js/ngx-styled.svg)](https://badge.fury.io/js/ngx-styled)

This is a simple decorator to integrate [emotion](https://emotion.sh/docs/emotion) with angular components

```typescript
import { Styled } from 'ngx-styled';
import { Component } from '@angular/core'

@Component({
template: '

Change Color
',
})
@Styled(({ component, css, injectGlobal }) => {
// tslint:disable-next-line: no-unused-expression
injectGlobal`
body {
background: ${component.color};
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
`;
return css({
'& button': {
padding: 10,
border: 'none',
color: 'white',
background: '#2c3e50'
}
});
})
class SimpleComponent {
classes: string; // managed by ngx-styled
color = 'green';

changeColor(){
// styles will be updated with component changes
this.color = 'red';
}
}
```