fonteva-design-guide
Version:
## Dev, Build and Test
105 lines (87 loc) • 3.12 kB
JavaScript
import { LightningElement, api, track } from 'lwc';
import PFM_Base from 'c/pfmBase';
export default class Text extends PFM_Base {
type; // heading, body, label
weight; // light, medium, bold
align; // left, center, right
transform; // lowercase, uppercase, capitalize
color; // danger, warning, success, default, detail, brand, link, white
size; // xx-small, x-small, small, medium, large, x-large
inline; // changes display to inline block
required; // only works when type is label
text;
classes;
isHeader;
isH1;
isH2;
isH3;
isH4;
isH5;
isH6;
isLabel;
get padding() {
return super.paddingStr;
}
set padding(value) {
super.paddingStr = value;
}
get margin() {
return super.marginStr;
}
set margin(value) {
super.marginStr = value;
}
refreshAttributes() {
this.connectedCallback();
}
connectedCallback() {
super.connectedCallback('pfm-text');
this.isHeader = this.type === 'heading';
this.isLabel = this.type === 'label';
const valWeight = this.weight,
valColor = this.color,
valAlign = this.align,
valSize = this.size,
valTransform = this.transform,
valInline = this.inline;
let align, transform, color, weight, size, inline, base;
if (this.isHeader) {
switch (valSize) {
case 'x-large':
this.isH1 = true;
break;
case 'large':
this.isH2 = true;
break;
case 'medium':
this.isH3 = true;
break;
case 'small':
this.isH4 = true;
break;
case 'x-small':
this.isH5 = true;
break;
case 'xx-small':
this.isH6 = true;
break;
default:
this.isH2 = true;
}
}
if (this.isHeader) {
weight = valWeight ? ' pfm-font-weight_' + valWeight : ' pfm-font-weight_bold';
size = valSize ? ' pfm-text-heading_' + valSize : ' pfm-text-heading_small';
} else {
weight = valWeight ? ' pfm-font-weight_' + valWeight : '';
size = valSize ? ' pfm-text-body_' + valSize : ' pfm-text-body_small';
}
transform = valTransform ? ' pfm-text-transform_' + valTransform : '';
color = valColor ? ' pfm-text-color_' + valColor : '';
align = valAlign ? ' slds-text-align_' + valAlign : '';
inline = valInline ? ' pfm-text_inline' : '';
this.classes = this.classStr + size + align + weight + color + transform + inline;
}
}