MCPcopy Create free account
hub / github.com/dailydotdev/apps / buttonThemeStyles

Function buttonThemeStyles

packages/shared/tailwind/buttonTheme.ts:49–124  ·  view source on GitHub ↗
({
  varPrefix,
  sourcePrefix,
  classes,
}: ButtonThemeOptions)

Source from the content-addressed store, hash-verified

47 * the `.auto` media queries), so every theme resolves as before.
48 */
49export const buttonThemeStyles = ({
50 varPrefix,
51 sourcePrefix,
52 classes,
53}: ButtonThemeOptions): [
54 Record<string, StyleMap>,
55 Record<string, NestedRule>,
56] => {
57 const values: Record<string, StyleMap> = {};
58 const groups: Array<{
59 signature: string;
60 classes: string[];
61 dark: string[];
62 light: string[];
63 }> = [];
64
65 classes.forEach(([className, style]) => {
66 const dark = stateEntries(style.darkStates);
67 const light = stateEntries(style.lightStates);
68 if (!dark.length && !light.length) {
69 return;
70 }
71 values[`.${className}`] = Object.fromEntries([
72 ...dark.map(([key, value]) => [`${sourcePrefix}-d-${key}`, value]),
73 ...light.map(([key, value]) => [`${sourcePrefix}-l-${key}`, value]),
74 ]);
75 const darkKeys = dark.map(([key]) => key);
76 const lightKeys = light.map(([key]) => key);
77 const signature = `${darkKeys.join()}|${lightKeys.join()}`;
78 // Only consecutive classes share rules, so an element carrying two
79 // button classes still resolves in the original cascade order.
80 const last = groups[groups.length - 1];
81 if (last?.signature === signature) {
82 last.classes.push(className);
83 return;
84 }
85 groups.push({
86 signature,
87 classes: [className],
88 dark: darkKeys,
89 light: lightKeys,
90 });
91 });
92
93 const themeMap = (keys: string[], theme: 'd' | 'l'): StyleMap =>
94 Object.fromEntries(
95 keys.map((key) => [
96 `${varPrefix}-${key}`,
97 `var(${sourcePrefix}-${theme}-${key})`,
98 ]),
99 );
100
101 const themes: Record<string, NestedRule> = {};
102 groups.forEach((group) => {
103 const selector =
104 group.classes.length === 1
105 ? `.${group.classes[0]}`
106 : `:is(${group.classes.map((name) => `.${name}`).join(', ')})`;

Callers 2

buttons-v2.tsFile · 0.90
buttons.tsFile · 0.90

Calls 3

stateEntriesFunction · 0.85
themeMapFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected