feat(md-font): Add color prop support
This commit is contained in:
parent
f337acd142
commit
fa57727abb
|
|
@ -8,6 +8,8 @@ export interface FontProps {
|
||||||
source?: "google" | "emfont" | "local";
|
source?: "google" | "emfont" | "local";
|
||||||
/** Font weight (for google and emfont sources) */
|
/** Font weight (for google and emfont sources) */
|
||||||
weight?: string;
|
weight?: string;
|
||||||
|
/** Font color (CSS color value, e.g. #ff00dd, rgb(255,0,0)) */
|
||||||
|
color?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildLinkHref(
|
function buildLinkHref(
|
||||||
|
|
@ -27,7 +29,7 @@ function buildLinkHref(
|
||||||
|
|
||||||
customElement(
|
customElement(
|
||||||
"md-font",
|
"md-font",
|
||||||
{ source: "local", weight: "400" },
|
{ source: "local", weight: "400", color: undefined },
|
||||||
(props, { element }) => {
|
(props, { element }) => {
|
||||||
noShadowDOM();
|
noShadowDOM();
|
||||||
|
|
||||||
|
|
@ -49,10 +51,18 @@ customElement(
|
||||||
? [{ href, dataset: { mdFontSource: source, mdFontName: font } }]
|
? [{ href, dataset: { mdFontSource: source, mdFontName: font } }]
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const styles: Partial<CSSStyleDeclaration> = {
|
||||||
|
fontFamily: `"${font}", sans-serif`,
|
||||||
|
} as any;
|
||||||
|
|
||||||
|
if (props.color) {
|
||||||
|
(styles as any).color = props.color;
|
||||||
|
}
|
||||||
|
|
||||||
const handle = registerStyle({
|
const handle = registerStyle({
|
||||||
key: "fontFamily",
|
key: "fontFamily",
|
||||||
article: articleEl,
|
article: articleEl,
|
||||||
styles: { fontFamily: `"${font}", sans-serif` },
|
styles,
|
||||||
links,
|
links,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue