Skip to content

Commit

Permalink
feat(core): support to use more of '&' in multiple styles
Browse files Browse the repository at this point in the history
  • Loading branch information
alyleui committed Oct 20, 2018
1 parent 8593a73 commit fc2cb75
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 68 deletions.
123 changes: 58 additions & 65 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,73 @@
import { Component, ChangeDetectionStrategy, Renderer2, Inject, OnInit, ViewChild, ViewEncapsulation, ElementRef } from '@angular/core';
import { Component, ChangeDetectionStrategy, Renderer2, OnInit, ViewChild, ViewEncapsulation, ElementRef } from '@angular/core';
import { Router } from '@angular/router';
import { AUI_VERSION, LyTheme2, ThemeVariables } from '@alyle/ui';
import { RoutesAppService } from './components/routes-app.service';
import { LyIconService } from '@alyle/ui/icon';
import { DOCUMENT } from '@angular/platform-browser';
import { LyDrawer } from '@alyle/ui/drawer';
import { CustomMinimaLight, CustomMinimaDark } from './app.module';

const styles = (theme: ThemeVariables & CustomMinimaLight & CustomMinimaDark) => {
const onLinkActive = {
color: theme.primary.default,
borderLeft: '3px solid'
};
return {
'@global': {
'body': {
backgroundColor: theme.background.default,
color: theme.text.default,
fontFamily: theme.typography.fontFamily,
margin: 0
},
const styles = (theme: ThemeVariables & CustomMinimaLight & CustomMinimaDark) => ({
'@global': {
'body': {
backgroundColor: theme.background.default,
color: theme.text.default,
fontFamily: theme.typography.fontFamily,
margin: 0
},
root: {
display: 'block',
'& a:not([ly-icon-button]):not([ly-button])': {
color: theme.accent.default,
textDecoration: 'inherit',
'&:hover': {
textDecoration: 'underline'
}
},
root: {
display: 'block',
'a:not([ly-icon-button]):not([ly-button])': {
color: theme.accent.default,
textDecoration: 'inherit',
'&:hover': {
textDecoration: 'underline'
}
},
// header: {
// position: 'fixed',
// zIndex: 11,
// width: '100%',
// // '@media print': {
// // color: 'blue'
// // },
// // '&:hover': {
// // '@media screen': {
// // color: 'red'
// // },
// // },
// button: { // => {root} {button}
// color: 'red'
// },
drawerContainer: {
height: 'calc(100% - 64px)'
},
// drawer: {
// width: '230px',
// height: 'calc(100% - 64px)',
// bottom: 0,
// padding: '1rem 0'
// },
drawerUl: {
overflow: 'hidden',
position: 'relative',
listStyle: 'none',
padding: '2rem 1.8rem',
margin: 0,
borderBottom: '1px solid rgba(0, 0, 0, 0.11)'
},
drawerButton: {
color: theme.drawerButton,
fontWeight: 400,
borderLeft: '3px solid transparent',
display: 'flex',
justifyContent: 'space-between',
'&:hover': onLinkActive
},
onLinkActive
// themePickerText: {
// paddingLeft: '8px'
// '& button:hover, & button:focus': { // => {root} button:hover, {root} button:focus
// color: 'blue'
// }
};
};
},
// header: {
// position: 'fixed',
// zIndex: 11,
// width: '100%',
// // '@media print': {
// // color: 'blue'
// // },
// // '&:hover': {
// // '@media screen': {
// // color: 'red'
// // },
// // },
// },
drawerContainer: {
height: 'calc(100% - 64px)'
},
drawerUl: {
overflow: 'hidden',
position: 'relative',
listStyle: 'none',
padding: '2rem 1.8rem',
margin: 0,
borderBottom: '1px solid rgba(0, 0, 0, 0.11)'
},
drawerButton: {
color: theme.drawerButton,
fontWeight: 400,
borderLeft: '3px solid transparent',
display: 'flex',
justifyContent: 'space-between',
'&:hover, &{onLinkActive}': {
color: theme.primary.default,
borderLeft: '3px solid'
}
},
onLinkActive: {}
});

@Component({
selector: 'aui-root',
Expand Down
8 changes: 5 additions & 3 deletions src/lib/src/theme/theme2.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,13 @@ function styleToString(key: string, ob: Object, currentKey: string, parentKey?:
let keyAndValue = '';
let newKey;
if (parentKey && currentKey.indexOf('&') !== -1) {
newKey = currentKey.replace('&', parentKey);
newKey = currentKey.replace(/&/g, parentKey);
} else if (key === '@global') {
newKey = key;
} else if (parentKey) {
newKey = `${parentKey} ${currentKey}`;
} else {
newKey = currentKey;
newKey = `.${currentKey}`;
}
for (const styleKey in ob) {
if (ob.hasOwnProperty(styleKey)) {
Expand All @@ -371,7 +373,7 @@ function styleToString(key: string, ob: Object, currentKey: string, parentKey?:
} else if (parentKey && parentKey === '@global') {
content += `${currentKey}`;
} else {
content += `.${newKey}`;
content += `${newKey}`;
}
content += `{${keyAndValue}}`;
}
Expand Down

0 comments on commit fc2cb75

Please sign in to comment.