Generate the inline style string from the given parameters. The first parameter is the query selector, and the second parameter is the style array.
Usage:
const ret1 = genStyleString(".a", [ "color:red" ]);const ret2 = genStyleString("#b", [ "color:red", "font-size:12px" ]);console.log(ret1);console.log(ret2); Copy
const ret1 = genStyleString(".a", [ "color:red" ]);const ret2 = genStyleString("#b", [ "color:red", "font-size:12px" ]);console.log(ret1);console.log(ret2);
Output:
.a{color:red;} #b{color:red;font-size:12px;} Copy
.a{color:red;} #b{color:red;font-size:12px;}
Example: Combine genStyleString and addStyle to add multiple styles at once.
genStyleString
addStyle
import { genStyleString, addStyle } from "mazey";const xStyle = genStyleString( ".footer>.x-wish>a:first-child" + ",div.wish-flex>a[href^='https://github.com/chengchuu']" + ",.m-hide", [ "display: none" ]);const yStyle = genStyleString( ".footer>.y-wish:before", [ `content: 'Copyright (c) chengchuu'`, "color: inherit", "padding-inline-start: var(--y-wish-1_5)", "padding-inline-end: var(--y-wish-1_5)", "padding-top: var(--y-wish-1)", "padding-bottom: var(--y-wish-1)", ]);addStyle(xStyle + yStyle, { id: "z-style" }); Copy
import { genStyleString, addStyle } from "mazey";const xStyle = genStyleString( ".footer>.x-wish>a:first-child" + ",div.wish-flex>a[href^='https://github.com/chengchuu']" + ",.m-hide", [ "display: none" ]);const yStyle = genStyleString( ".footer>.y-wish:before", [ `content: 'Copyright (c) chengchuu'`, "color: inherit", "padding-inline-start: var(--y-wish-1_5)", "padding-inline-end: var(--y-wish-1_5)", "padding-top: var(--y-wish-1)", "padding-bottom: var(--y-wish-1)", ]);addStyle(xStyle + yStyle, { id: "z-style" });
<style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style> Copy
<style id="z-style">.footer>.x-wish>a:first-child,div.wish-flex>a[href^='https://github.com/chengchuu'],.m-hide{display: none;}.footer>.y-wish:before{content: 'Copyright (c) chengchuu';color: inherit;padding-inline-start: var(--y-wish-1_5);padding-inline-end: var(--y-wish-1_5);padding-top: var(--y-wish-1);padding-bottom: var(--y-wish-1);}</style>
The inline style string.
Generate the inline style string from the given parameters. The first parameter is the query selector, and the second parameter is the style array.
Usage:
Output:
Example: Combine
genStyleStringandaddStyleto add multiple styles at once.Output: