Skip to content

Instantly share code, notes, and snippets.

@jonshipman
Created May 27, 2022 22:02
Show Gist options
  • Save jonshipman/80c6047b05a1a89056e36c4d8bea86f2 to your computer and use it in GitHub Desktop.
Save jonshipman/80c6047b05a1a89056e36c4d8bea86f2 to your computer and use it in GitHub Desktop.
Gets all the styling hooks in use on SLDS
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