-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
53 deletions.
There are no files selected for viewing
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,14 @@ | ||
--- | ||
"@design-blocks/primitives": patch | ||
"@design-blocks/system": patch | ||
"@design-blocks/colors": patch | ||
"@design-blocks/theme": patch | ||
"@design-blocks/types": patch | ||
"@design-blocks/unstyled": patch | ||
"@design-blocks/utils": patch | ||
"@design-blocks/block": patch | ||
"@design-blocks/native": patch | ||
"tsconfig": patch | ||
--- | ||
|
||
Fixed stacks |
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,3 +1,5 @@ | ||
export * from './getValuesTokens'; | ||
export * from './styleFunction'; | ||
export * from './validateProperties'; | ||
export * from './styleFunctionProps'; | ||
export * from './styleFunctionSx'; |
49 changes: 49 additions & 0 deletions
49
packages/@blocks-system/src/styleFunction/styleFunctionProps.ts
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,49 @@ | ||
import { componentsKeys } from '@design-blocks/theme'; | ||
|
||
import { getValuesTokens } from './getValuesTokens'; | ||
import validateProperties from './validateProperties'; | ||
|
||
import type { IComponentsKeysProps, Theme } from '@design-blocks/theme'; | ||
import type { StylesObjectProps } from '@design-blocks/types'; | ||
|
||
type PropertyStyle<TokensProperty> = TokensProperty; | ||
|
||
export const styleFunctionProps = ( | ||
nameTokenComp: IComponentsKeysProps, | ||
theme: Theme, | ||
stylesObjectProps: StylesObjectProps, | ||
) => { | ||
const tokensBase = componentsKeys[nameTokenComp]; | ||
|
||
const styles = Object.entries(stylesObjectProps ?? {}).reduce( | ||
(objStyles: Record<string, unknown>, [propertyStyle, valueStyle]) => { | ||
let propertyStyleValue = tokensBase[propertyStyle as PropertyStyle<keyof typeof tokensBase>] as string; | ||
let finalValueStyle = valueStyle; | ||
|
||
const valueToken = getValuesTokens(theme, valueStyle?.toString()); | ||
|
||
if (!valueToken) { | ||
finalValueStyle = validateProperties(valueStyle, propertyStyle, theme); | ||
} | ||
|
||
if (propertyStyle === 'fontWeight') { | ||
propertyStyleValue = propertyStyle as PropertyStyle<keyof typeof tokensBase>; | ||
finalValueStyle = theme.fontWeights[valueStyle as keyof Theme['fontWeights']] ?? valueStyle; | ||
} | ||
|
||
if (propertyStyle === 'fontSize') { | ||
propertyStyleValue = propertyStyle as PropertyStyle<keyof typeof tokensBase>; | ||
finalValueStyle = theme.fontSizes[valueStyle as keyof Theme['fontSizes']] ?? valueStyle; | ||
} | ||
|
||
if (propertyStyleValue) { | ||
objStyles[propertyStyleValue] = valueToken ?? finalValueStyle; | ||
} | ||
|
||
return objStyles; | ||
}, | ||
{}, | ||
); | ||
|
||
return styles; | ||
}; |
42 changes: 42 additions & 0 deletions
42
packages/@blocks-system/src/styleFunction/styleFunctionSx.ts
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,42 @@ | ||
import { componentsKeys } from '@design-blocks/theme'; | ||
|
||
import { getValuesTokens } from './getValuesTokens'; | ||
import validateProperties from './validateProperties'; | ||
|
||
import type { IComponentsKeysProps, Theme } from '@design-blocks/theme'; | ||
import type { StylesObjectProps } from '@design-blocks/types'; | ||
|
||
type PropertyStyle<TokensProperty> = TokensProperty; | ||
|
||
export const styleFunctionSx = ( | ||
nameTokenComponent: IComponentsKeysProps, | ||
theme: Theme, | ||
sxStyles: StylesObjectProps = {}, | ||
) => { | ||
const tokensBase = componentsKeys[nameTokenComponent]; | ||
|
||
const styles = Object.entries(sxStyles).reduce((objStyles: Record<string, unknown>, [propertyStyle, valueStyle]) => { | ||
const propertyStyleValue = tokensBase[propertyStyle as PropertyStyle<keyof typeof tokensBase>]; | ||
let finalValueStyle = valueStyle; | ||
|
||
const valueToken = getValuesTokens(theme, valueStyle?.toString()); | ||
|
||
if (!valueToken) { | ||
finalValueStyle = validateProperties(valueStyle, propertyStyle, theme); | ||
} | ||
|
||
if (propertyStyle === 'fontWeight') { | ||
finalValueStyle = theme.fontWeights[valueStyle as keyof Theme['fontWeights']] ?? valueStyle; | ||
} | ||
|
||
if (propertyStyle === 'fontSize') { | ||
finalValueStyle = theme.fontSizes[valueStyle as keyof Theme['fontSizes']] ?? valueStyle; | ||
} | ||
|
||
objStyles[propertyStyleValue || propertyStyle] = valueToken ?? finalValueStyle; | ||
|
||
return objStyles; | ||
}, {}); | ||
|
||
return styles; | ||
}; |