Skip to content

Commit f8c4e94

Browse files
committed
feat(angular-jss): theme options
`createTheme` and `createPalette`
1 parent 7cab251 commit f8c4e94

17 files changed

Lines changed: 236 additions & 39 deletions

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
- [x] Component decorator `Styled`
1717
- [x] Theming with `Theme`
18+
- [ ] Theme switching (dark/light mode)
1819
- [x] Server Side Rendering with Angular Universal
20+
- [ ] Critical CSS
1921

2022
## Table of Contents
2123

@@ -107,6 +109,45 @@ export class AppComponent {
107109

108110
## Config options
109111

112+
```ts
113+
import { create, Jss } from 'jss';
114+
import extend from 'jss-plugin-extend';
115+
import propsSort from 'jss-plugin-props-sort';
116+
import { JssOptions } from '@design4pro/angular-jss';
117+
118+
const jss: Jss = create({
119+
// additional JSS plugins @see https://cssinjs.org/plugins?v=v10.9.0
120+
plugins: [
121+
extend(),
122+
propsSort()
123+
],
124+
});
125+
126+
const jssOptions: JssOptions = {
127+
jss: jss,
128+
normalize: false // disable normalizing (normalize.css)
129+
};
130+
131+
const theme: Theme = {
132+
palette: {
133+
primary: {
134+
main: '#00bcd4' // use in decorator `theme.palette?.primary?.main`
135+
},
136+
secondary: {
137+
main: '#f50057'
138+
}
139+
}
140+
};
141+
142+
@NgModule({
143+
declarations: [AppComponent],
144+
imports: [BrowserModule, AngularJssModule.forRoot(jssOptions, theme)],
145+
providers: [],
146+
bootstrap: [AppComponent],
147+
})
148+
export class AppModule {}
149+
```
150+
110151
## License
111152

112153
[MIT](https://github.com/design4pro/angular-jss/blob/master/LICENSE.md) © DESIGN4 ᴾ ᴿ ᴼ

libs/angular-jss/README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@
1313

1414
## Features
1515

16+
- [x] Component decorator `Styled`
17+
- [x] Theming with `Theme`
18+
- [ ] Theme switching (dark/light mode)
19+
- [x] Server Side Rendering with Angular Universal
20+
- [ ] Critical CSS
21+
1622
## Table of Contents
1723

1824
- [Installation](#installation)
@@ -103,6 +109,45 @@ export class AppComponent {
103109

104110
## Config options
105111

112+
```ts
113+
import { create, Jss } from 'jss';
114+
import extend from 'jss-plugin-extend';
115+
import propsSort from 'jss-plugin-props-sort';
116+
import { JssOptions } from '@design4pro/angular-jss';
117+
118+
const jss: Jss = create({
119+
// additional JSS plugins @see https://cssinjs.org/plugins?v=v10.9.0
120+
plugins: [
121+
extend(),
122+
propsSort()
123+
],
124+
});
125+
126+
const jssOptions: JssOptions = {
127+
jss: jss,
128+
normalize: false // disable normalizing (normalize.css)
129+
};
130+
131+
const theme: Theme = {
132+
palette: {
133+
primary: {
134+
main: '#00bcd4' // use in decorator `theme.palette?.primary?.main`
135+
},
136+
secondary: {
137+
main: '#f50057'
138+
}
139+
}
140+
};
141+
142+
@NgModule({
143+
declarations: [AppComponent],
144+
imports: [BrowserModule, AngularJssModule.forRoot(jssOptions, theme)],
145+
providers: [],
146+
bootstrap: [AppComponent],
147+
})
148+
export class AppModule {}
149+
```
150+
106151
## License
107152

108153
[MIT](https://github.com/design4pro/angular-jss/blob/master/LICENSE.md) © DESIGN4 ᴾ ᴿ ᴼ

libs/angular-jss/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ export * from './lib/angular-jss.service';
44
export * from './lib/angular-jss.types';
55
export * from './lib/ssr';
66
export * from './lib/styled';
7+
export * from './lib/theme';

libs/angular-jss/src/lib/angular-jss.types.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { JssOptions } from './jss/types';
2+
import { ColorCommon } from './theme/colors/common';
23

34
export interface Options extends JssOptions {
45
normalize?: boolean;
@@ -7,8 +8,7 @@ export interface Options extends JssOptions {
78
export interface Theme {
89
breakpoints?: ThemeBreakpoints;
910
direction?: string;
10-
overrides?: object;
11-
props?: object;
11+
palette?: ThemePalette;
1212
}
1313

1414
export interface ThemeBreakpoints {
@@ -24,3 +24,14 @@ export interface ThemeBreakpoints {
2424
unit?: string;
2525
step?: number;
2626
}
27+
28+
export type ThemeType = string | 'auto' | 'light' | 'dark';
29+
30+
export interface ThemePaletteCommonColor {
31+
[key: string]: ColorCommon;
32+
}
33+
34+
export interface ThemePalette {
35+
mode: ThemeType;
36+
common: typeof ColorCommon;
37+
}

libs/angular-jss/src/lib/jss/utils/sheets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getDynamicStyles, StyleSheet, StyleSheetFactoryOptions } from 'jss';
22
import { Theme } from '../../angular-jss.types';
3-
import { StyledProps } from '../../styled/styled.interface';
3+
import { StyledProps } from '../../styled/styled.types';
44
import { ThemeContext } from '../../theme/theme-context';
55
import { JssContext } from '../context';
66
import { getManager } from '../managers';

libs/angular-jss/src/lib/styled/create-use-styles.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
updateDynamicRules,
1616
} from '../jss/utils/sheets';
1717
import { ThemeContext } from '../theme/theme-context';
18-
import { StyledProps } from './styled.interface';
18+
import { StyledProps } from './styled.types';
1919

2020
const createUseStyles =
2121
(doCheck: BehaviorSubject<StyledProps>, onDestroy: Subject<void>) =>

libs/angular-jss/src/lib/styled/internals.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
DirectiveDef,
1010
DirectiveType,
1111
} from './ivy';
12-
import { StyledProps } from './styled.interface';
12+
import { StyledProps } from './styled.types';
1313

1414
/**
1515
* Applied to definitions and informs that class is decorated

libs/angular-jss/src/lib/styled/styled.decorator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'reflect-metadata';
22
import { BehaviorSubject, Subject } from 'rxjs';
33
import { generateStyles, markAsDecorated, STYLED_PROPS } from './internals';
44
import { ComponentType, DirectiveType } from './ivy';
5-
import { StyledProps } from './styled.interface';
5+
import { StyledProps } from './styled.types';
66

77
// eslint-disable-next-line @typescript-eslint/naming-convention
88
export function StyledProp<T>(): PropertyDecorator {

libs/angular-jss/src/lib/styled/styled.interface.ts renamed to libs/angular-jss/src/lib/styled/styled.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { HookOptions, Styles } from '../jss/types';
21
import { Theme } from '../angular-jss.types';
2+
import { HookOptions, Styles } from '../jss/types';
33

44
// eslint-disable-next-line @typescript-eslint/no-explicit-any
55
export type StyledProps = (context: StyledContext) => any;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export enum ColorCommon {
2+
black = '#000',
3+
white = '#fff',
4+
};
5+
6+
export default ColorCommon;

0 commit comments

Comments
 (0)