Skip to content

Commit

Permalink
fix(field): fix theme variables
Browse files Browse the repository at this point in the history
ability to customize a component through themes
  • Loading branch information
Enlcxx committed Mar 31, 2019
1 parent 403bfa4 commit ff58123
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 159 deletions.
68 changes: 20 additions & 48 deletions src/lib/field/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
forwardRef,
DoCheck
} from '@angular/core';
import { LyTheme2, ThemeVariables, mergeDeep, ElementObserver, Platform, toBoolean, DirAlias } from '@alyle/ui';
import { LyTheme2, ThemeVariables, ElementObserver, Platform, toBoolean, DirAlias } from '@alyle/ui';
import { LyLabel } from './label';
import { LyPlaceholder } from './placeholder';
import { LyHint } from './hint';
Expand All @@ -40,44 +40,39 @@ const STYLE_PRIORITY = -2;
const DEFAULT_APPEARANCE = 'standard';
const DEFAULT_APPEARANCE_THEME = {
standard: {
root: {
'&:not({disabled}) {container}:hover:after': {
borderBottomColor: 'currentColor'
},
'&{disabled} {container}:after': {
borderBottomStyle: 'dotted',
borderColor: 'inherit'
},
'textarea{inputNative}': {
margin: '0.25em 0'
},
'{inputNative}:not(textarea)': {
padding: '0.25em 0'
}
'&:not({disabled}) {container}:hover:after': {
borderBottomColor: 'currentColor'
},
'&{disabled} {container}:after': {
borderBottomStyle: 'dotted',
borderColor: 'inherit'
},
'textarea{inputNative}': {
margin: '0.25em 0'
},
container: {
'{inputNative}:not(textarea)': {
padding: '0.25em 0'
},
'& {container}': {
padding: '1em 0 0',
'&:after': {
borderBottomStyle: 'solid',
borderBottomWidth: '1px'
}
},
containerFocused: {
'&{focused} {container}': {
'&:after': {
borderWidth: '2px',
borderColor: 'currentColor'
}
},
containerLabelHover: {
color: 'currentColor'
},
label: {
'& {label}': {
margin: '0.25em 0'
},
placeholder: {
'& {placeholder}': {
margin: '0.25em 0'
},
floatingLabel: {
'& {floatingLabel}': {
transform: 'translateY(-1.25em)'
}
}
Expand Down Expand Up @@ -214,31 +209,8 @@ export class LyField implements OnInit, AfterContentInit, AfterViewInit, OnDestr
throw new Error(`${val} not found in theme.field.appearance`);
}
this._appearanceClass = this._theme.addStyle(`ly-field.appearance:${val}`, (theme: ThemeVariables) => {
const appearance = mergeDeep({}, theme.field.appearance.base, theme.field.appearance[val] || DEFAULT_APPEARANCE_THEME[val]);
const classes = this.classes;
return {
'&': {...appearance.root},
[`& .${classes.container}`]: {...appearance.container},
[`& .${classes.prefix}`]: {...appearance.prefix},
[`& .${classes.infix}`]: {...appearance.infix},
[`& .${classes.suffix}`]: {...appearance.suffix},
[`& .${classes.inputNative}`]: {...appearance.input},
[`& .${classes.fieldset}`]: {...appearance.fieldset},
[`& .${classes.placeholder}`]: {
...appearance.placeholder
},
[`& .${classes.label}`]: {
...appearance.label
},
[`& .${classes.hintContainer}`]: {
...appearance.hint
},
[`& .${classes.floatingLabel}.${classes.label}`]: {...appearance.floatingLabel},

[`&.${classes.focused} .${classes.container}`]: {
...appearance.containerFocused
},
};
const appearance = theme.field.appearance[val] || DEFAULT_APPEARANCE_THEME[val];
return appearance;
}, this._el.nativeElement, this._appearanceClass, STYLE_PRIORITY, STYLES);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/lib/src/theme/variables/field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { StyleContainer } from '../style';

export interface FieldVariables {
root?: StyleContainer;
borderColor: string;
labelColor: string;
defaultConfig: {
appearance?: keyof FieldVariables['appearance']
};
appearance: {
outlined?: StyleContainer
filled?: StyleContainer
};
}
88 changes: 88 additions & 0 deletions src/lib/themes/minima/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,94 @@ export class MinimaBase extends LyStyleUtils {
}
}
};

field = {
appearance: {
outlined: {
'&:not({focused}):not({disabled}):hover {fieldset}': {
borderColor: 'currentColor'
},
'&{focused} {fieldset}': {
borderWidth: '2px',
borderColor: 'inherit'
},
'& textarea{inputNative}': {
margin: '1em 0'
},
'& {inputNative}:not(textarea)': {
padding: '1em 0'
},
'& {container}': {
padding: '0 0.75em'
},
'& {fieldset}': {
borderWidth: '1px',
borderRadius: '5px',
padding: '0 .5em'
},
'& {prefix}': {
'&:after': {
padding: '0.25em'
}
},
'& suffix': {
'&:after': {
padding: '0.25em'
}
},
'& {label}': {
margin: '1em 0'
},
'& {placeholder}': {
margin: '1em 0'
},
'& {floatingLabel}{label}': {
transform: 'translateY(-1.75em)'
},
'& {hintContainer}': {
padding: '0 0.75em'
}
},
filled: {
'&:not({focused}):not({disabled}) {container}:hover:after': {
borderBottomWidth: '1px'
},
'textarea{inputNative}': {
margin: '1.59375em 0 0.40625em'
},
'{inputNative}:not(textarea)': {
padding: '1.59375em 0 0.40625em'
},
'& {container}': {
borderRadius: '5px 5px 0 0',
padding: '0 0.75em',
'&:after': {
borderBottomStyle: 'solid',
borderBottomColor: 'currentColor',
borderBottomWidth: '0'
}
},
'&{focused} {container}': {
'&:after': {
borderBottomWidth: '2px'
}
},
'& {placeholder}': {
margin: '1.59375em 0 0.40625em'
},
'& {label}': {
margin: '1em 0'
},
'& {floatingLabel}{label}': {
transform: 'translateY(-.75em)'
},
'& {hintContainer}': {
padding: '0 0.75em'
}
}
}
};

constructor() {
super();
this.typography.lyTyp = {
Expand Down
5 changes: 2 additions & 3 deletions src/lib/themes/minima/dark.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { field } from './variables';
import { ThemeConfig, mergeDeep } from '@alyle/ui';
import { MinimaBase } from './base';

Expand Down Expand Up @@ -56,12 +55,12 @@ export class MinimaDark extends MinimaBase implements ThemeConfig {
divider = 'rgba(255, 255, 255, 0.12)';
colorShadow = shadow;
shadow = shadow;
field = mergeDeep({}, field, {
field = mergeDeep({}, this.field, {
borderColor: 'rgba(255, 255, 255, 0.12)',
labelColor: 'rgba(255, 255, 255, 0.4)',
appearance: {
filled: {
container: {
'& {container}': {
backgroundColor: 'rgba(255, 255, 255, 0.04)',
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/lib/themes/minima/light.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ThemeConfig, mergeDeep } from '@alyle/ui';
import { field } from './variables';
import { MinimaBase } from './base';

const contrast = '#fff';
Expand Down Expand Up @@ -56,12 +55,12 @@ export class MinimaLight extends MinimaBase implements ThemeConfig {
backdrop: 'rgba(0,0,0,.6)'
};
bar = '#f5f5f5';
field = mergeDeep({}, field, {
field = mergeDeep({}, this.field, {
borderColor: 'rgba(0, 0, 0, 0.23)',
labelColor: 'rgba(0, 0, 0, 0.6)',
appearance: {
filled: {
container: {
'{container}': {
backgroundColor: 'rgba(0, 0, 0, 0.04)',
}
}
Expand Down
105 changes: 0 additions & 105 deletions src/lib/themes/minima/variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,111 +5,6 @@ export const iconButton = {
export const icon = {
fontSize: '24px'
};
export const field = {
appearance: {
outlined: {
root: {
'&:not({focused}):not({disabled}):hover {fieldset}': {
borderColor: 'currentColor'
},
'&{focused} {fieldset}': {
borderWidth: '2px',
borderColor: 'inherit'
},
'textarea{inputNative}': {
margin: '1em 0'
},
'{inputNative}:not(textarea)': {
padding: '1em 0'
}
},
container: {
padding: '0 0.75em'
},
fieldset: {
borderWidth: '1px',
borderRadius: '5px',
padding: '0 .5em'
},
containerLabelFocused: {
color: 'currentColor',
'&:after': {
borderWidth: '2px',
borderColor: 'currentColor'
}
},
prefix: {
'&:after': {
padding: '0.25em'
}
},
suffix: {
'&:after': {
padding: '0.25em'
}
},
label: {
margin: '1em 0'
},
placeholder: {
margin: '1em 0'
},
floatingLabel: {
transform: 'translateY(-1.75em)'
},
hint: {
padding: '0 0.75em'
}
},
filled: {
root: {
'&:not({focused}):not({disabled}) {container}:hover:after': {
borderBottomWidth: '1px'
},
'textarea{inputNative}': {
margin: '1.59375em 0 0.40625em'
},
'{inputNative}:not(textarea)': {
padding: '1.59375em 0 0.40625em'
}
},
container: {
borderRadius: '5px 5px 0 0',
padding: '0 0.75em',
'&:after': {
borderBottomStyle: 'solid',
borderBottomColor: 'currentColor',
borderBottomWidth: '0'
}
},
containerFocused: {
'&:after': {
borderBottomWidth: '2px'
}
},
containerLabelFocused: {
color: 'currentColor',
borderWidth: '2px',
borderColor: 'currentColor'
},
containerLabelHover: {
color: 'currentColor'
},
placeholder: {
margin: '1.59375em 0 0.40625em'
},
label: {
margin: '1em 0'
},
floatingLabel: {
transform: 'translateY(-.75em)'
},
hint: {
padding: '0 0.75em'
}
}
}
};

export const zIndex = {
toolbar: 1000,
Expand Down

0 comments on commit ff58123

Please sign in to comment.