Created
May 27, 2022 22:02
-
-
Save jonshipman/80c6047b05a1a89056e36c4d8bea86f2 to your computer and use it in GitHub Desktop.
Gets all the styling hooks in use on SLDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default class Hooks { | |
constructor() { | |
console.log(this.styleHooks); | |
} | |
get stylesheets() { | |
return [...document.styleSheets, ...document.adoptedStyleSheets]; | |
} | |
get rules() { | |
return this.stylesheets.map((s) => [...s.rules]).flat(1); | |
} | |
get styles() { | |
return this.rules.map((r) => r.style).filter((s) => !!s); | |
} | |
get styleValues() { | |
return this.styles | |
.map((s) => { | |
return Object.values(s); | |
}) | |
.flat(1) | |
.filter((x) => !!x); | |
} | |
get sldsValues() { | |
return [...new Set(this.styleValues)].filter( | |
(x) => 0 === x.indexOf('--') || x.includes('var(') | |
); | |
} | |
get styleHooks() { | |
return [ | |
...new Set( | |
this.sldsValues | |
.map((h) => | |
0 === h.indexOf('--') ? h : h.match(/--sl?ds-(.*?),/g) | |
) | |
.flat(1) | |
), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment