Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: rework internals of makeStaticStyles (#398)
- Loading branch information
1 parent
2ee1ee7
commit 0c22d89
Showing
4 changed files
with
59 additions
and
55 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@griffel-core-05c2915c-0733-4518-995d-e78d3784bc5e.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "patch", | ||
"comment": "chore: rework internals of makeStaticStyles", | ||
"packageName": "@griffel/core", | ||
"email": "olfedias@microsoft.com", | ||
"dependentChangeType": "patch" | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
import type { GriffelStaticStyles } from '@griffel/style-types'; | ||
import type { CSSRulesByBucket } from '../types'; | ||
|
||
import type { CSSBucketEntry } from '../types'; | ||
import { compileCSSRules } from './compileCSSRules'; | ||
import { compileStaticCSS } from './compileStaticCSS'; | ||
|
||
export function resolveStaticStyleRules(styles: GriffelStaticStyles, result: CSSRulesByBucket = {}): CSSRulesByBucket { | ||
if (typeof styles === 'string') { | ||
const cssRules = compileCSSRules(styles, false); | ||
export function resolveStaticStyleRules(stylesSet: GriffelStaticStyles[]): CSSBucketEntry[] { | ||
return stylesSet.reduce((acc, styles) => { | ||
if (typeof styles === 'string') { | ||
const cssRules = compileCSSRules(styles, false); | ||
|
||
for (const rule of cssRules) { | ||
acc.push(rule); | ||
} | ||
|
||
for (const rule of cssRules) { | ||
addResolvedStyles(rule, result); | ||
return acc; | ||
} | ||
} else { | ||
|
||
// eslint-disable-next-line guard-for-in | ||
for (const property in styles) { | ||
const value = styles[property]; | ||
const staticCSS = compileStaticCSS(property, value); | ||
|
||
addResolvedStyles(staticCSS, result); | ||
acc.push(staticCSS); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function addResolvedStyles(cssRule: string, result: CSSRulesByBucket = {}): void { | ||
// 👇 static rules should be inserted into default bucket | ||
result.d = result.d || []; | ||
result.d.push(cssRule); | ||
return acc; | ||
}, [] as CSSBucketEntry[]); | ||
} |