2023-02-23 23:50:38 +01:00
|
|
|
import { coerceBooleanProperty } from "@angular/cdk/coercion";
|
2023-02-03 10:32:29 +01:00
|
|
|
import { Directive, HostBinding, Input } from "@angular/core";
|
|
|
|
|
|
|
|
type TypographyType = "h1" | "h2" | "h3" | "h4" | "h5" | "h6" | "body1" | "body2" | "helper";
|
|
|
|
|
|
|
|
const styles: Record<TypographyType, string[]> = {
|
2023-02-23 23:50:38 +01:00
|
|
|
h1: ["tw-text-3xl", "tw-font-semibold"],
|
|
|
|
h2: ["tw-text-2xl", "tw-font-semibold"],
|
|
|
|
h3: ["tw-text-xl", "tw-font-semibold"],
|
|
|
|
h4: ["tw-text-lg", "tw-font-semibold"],
|
|
|
|
h5: ["tw-text-base", "tw-font-semibold"],
|
|
|
|
h6: ["tw-text-sm", "tw-font-semibold"],
|
2023-02-03 10:32:29 +01:00
|
|
|
body1: ["tw-text-base"],
|
|
|
|
body2: ["tw-text-sm"],
|
|
|
|
helper: ["tw-text-xs"],
|
|
|
|
};
|
|
|
|
|
2023-02-23 23:50:38 +01:00
|
|
|
const margins: Record<TypographyType, string[]> = {
|
|
|
|
h1: ["tw-mb-2"],
|
|
|
|
h2: ["tw-mb-2"],
|
|
|
|
h3: ["tw-mb-2"],
|
|
|
|
h4: ["tw-mb-2"],
|
|
|
|
h5: ["tw-mb-2"],
|
|
|
|
h6: ["tw-mb-2"],
|
|
|
|
body1: [],
|
|
|
|
body2: [],
|
|
|
|
helper: [],
|
|
|
|
};
|
|
|
|
|
2023-02-03 10:32:29 +01:00
|
|
|
@Directive({
|
|
|
|
selector: "[bitTypography]",
|
|
|
|
})
|
|
|
|
export class TypographyDirective {
|
|
|
|
@Input("bitTypography") bitTypography: TypographyType;
|
|
|
|
|
2023-02-23 23:50:38 +01:00
|
|
|
private _margin = true;
|
|
|
|
@Input()
|
|
|
|
set noMargin(value: boolean | "") {
|
|
|
|
this._margin = !coerceBooleanProperty(value);
|
|
|
|
}
|
|
|
|
|
2023-02-03 10:32:29 +01:00
|
|
|
@HostBinding("class") get classList() {
|
2023-02-23 23:50:38 +01:00
|
|
|
return styles[this.bitTypography].concat(this._margin ? margins[this.bitTypography] : []);
|
2023-02-03 10:32:29 +01:00
|
|
|
}
|
|
|
|
}
|