|
1 | 1 |
|
2 | | -# AngularJss |
| 2 | +# Angular JSS |
| 3 | + |
| 4 | +<img width="20%" height="20%" src="./logo.svg"> |
| 5 | + |
| 6 | +> [JSS](https://cssinjs.org/) integration with Angular |
| 7 | +
|
| 8 | +[](https://npmjs.org/package/@design4pro/angular-jss) |
| 9 | +[](https://github.com/design4pro/angular-jss/jss/blob/master/LICENSE.md) |
| 10 | +[](https://npmjs.org/package/@design4pro/angular-jss) |
| 11 | +[](https://npmjs.org/package/@design4pro/angular-jss) |
| 12 | +[](https://github.com/design4pro/) |
| 13 | + |
| 14 | +## Features |
| 15 | + |
| 16 | +## Table of Contents |
| 17 | + |
| 18 | +- [Installation](#installation) |
| 19 | +- [Usage](#usage) |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | +Using `npm`: |
| 24 | + |
| 25 | +```sh |
| 26 | +npm install @design4pro/angular-jss |
| 27 | +``` |
| 28 | + |
| 29 | +or using `yarn`: |
| 30 | + |
| 31 | +```sh |
| 32 | +yarn add @design4pro/angular-jss |
| 33 | +``` |
| 34 | + |
| 35 | +## Usage |
| 36 | + |
| 37 | +Inject the `AngularJssModule` module into your root module: |
| 38 | + |
| 39 | +```ts |
| 40 | +import { NgModule } from '@angular/core'; |
| 41 | +import { BrowserModule } from '@angular/platform-browser'; |
| 42 | +import { AngularJssModule } from '@design4pro/angular-jss'; |
| 43 | +import { AppComponent } from './app.component'; |
| 44 | + |
| 45 | +@NgModule({ |
| 46 | + declarations: [AppComponent], |
| 47 | + imports: [BrowserModule, AngularJssModule.forRoot()], |
| 48 | + providers: [], |
| 49 | + bootstrap: [AppComponent], |
| 50 | +}) |
| 51 | +export class AppModule {} |
| 52 | +``` |
| 53 | + |
| 54 | +Use class decorator `Styled` to add styles to your component: |
| 55 | + |
| 56 | +```ts |
| 57 | +import { Component } from '@angular/core'; |
| 58 | +import { Styled, StyledProp, Theme } from '@design4pro/angular-jss'; |
| 59 | + |
| 60 | +@Component({ |
| 61 | + selector: 'angular-jss-root', |
| 62 | + templateUrl: './app.component.html', |
| 63 | + styleUrls: ['./app.component.css'], |
| 64 | +}) |
| 65 | +@Styled(({ css, injectGlobal }) => { |
| 66 | + // global styles |
| 67 | + injectGlobal({ |
| 68 | + '@global': { |
| 69 | + ':root': { |
| 70 | + '--background-color': (data: { backgroundColor: string }) => data.backgroundColor, |
| 71 | + }, |
| 72 | + }, |
| 73 | + }); |
| 74 | + |
| 75 | + // element styles |
| 76 | + return css( |
| 77 | + (theme: Theme) => ({ |
| 78 | + root: { |
| 79 | + color: '#fff', |
| 80 | + backgroundColor: 'var(--background-color)', |
| 81 | + padding: '20px', |
| 82 | + direction: theme.direction, |
| 83 | + }, |
| 84 | + }), |
| 85 | + { name: 'first' } |
| 86 | + ); |
| 87 | +}) |
| 88 | +export class AppComponent { |
| 89 | + classes: any; // required to use `[ngClass]="classes.root"` in html template |
| 90 | + |
| 91 | + @StyledProp() // mark property as styled property |
| 92 | + backgroundColor = 'red'; |
| 93 | + |
| 94 | + click() { |
| 95 | + this.backgroundColor = this.backgroundColor === 'red' ? 'green' : 'red'; |
| 96 | + } |
| 97 | +} |
| 98 | +``` |
| 99 | + |
| 100 | +```html |
| 101 | +<div [ngClass]="classes.root"></div> |
| 102 | +``` |
| 103 | + |
| 104 | +## Config options |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +[MIT](https://github.com/design4pro/angular-jss/blob/master/LICENSE.md) © DESIGN4 ᴾ ᴿ ᴼ |
0 commit comments