Improve macro handling

This commit is contained in:
Eric Bailey
2023-12-18 17:30:11 -06:00
parent f427862bbf
commit 2ee4528ee9
4 changed files with 19 additions and 3 deletions
+14
View File
@@ -20,6 +20,9 @@ const theme = createTheme({
}, },
macros: { macros: {
caps: (_: boolean) => ({textTransform: 'uppercase'}), caps: (_: boolean) => ({textTransform: 'uppercase'}),
column: (span: boolean | number) => ({
flex: typeof span === 'number' ? span : 1,
}),
}, },
breakpoints: { breakpoints: {
gtPhone: 640, gtPhone: 640,
@@ -139,6 +142,17 @@ describe('macros', () => {
expect(styles).toEqual({}) expect(styles).toEqual({})
}) })
test('custom', () => {
const {styles} = theme.style(
{
column: 2,
},
[],
)
expect(styles).toEqual({flex: 2})
})
}) })
describe('breakpoints', () => { describe('breakpoints', () => {
+1 -1
View File
@@ -344,7 +344,7 @@ export const createTheme = <
styles = { styles = {
...styles, ...styles,
// @ts-ignore no index sig, it's fine // @ts-ignore no index sig, it's fine
...(rawProps[prop] === true ? macros[prop](value, tokens) : {}), ...(rawProps[prop] !== false ? macros[prop](value, tokens) : {}),
} }
} else if (breakpoints[prop]) { } else if (breakpoints[prop]) {
for (const b of Object.keys(breakpoints)) { for (const b of Object.keys(breakpoints)) {
+3 -1
View File
@@ -132,7 +132,9 @@ export const light = createTheme({
* </Box> * </Box>
* </Box> * </Box>
*/ */
column: (_: boolean) => ({flex: 1}), column: (span: boolean | number) => ({
flex: typeof span === 'number' ? span : 1,
}),
/** Shorthand for `position: 'absolute'` */ /** Shorthand for `position: 'absolute'` */
abs: (_: boolean) => ({position: 'absolute'}), abs: (_: boolean) => ({position: 'absolute'}),
/** Shorthand for `StyleSheet.absoluteFillObject` */ /** Shorthand for `StyleSheet.absoluteFillObject` */
+1 -1
View File
@@ -139,7 +139,7 @@ export function DebugScreen() {
<Box row gap="s"> <Box row gap="s">
<Box column pa="s" bg="l6" debug /> <Box column pa="s" bg="l6" debug />
<Box column pa="s" bg="l6" debug flex={2} /> <Box column={2} pa="s" bg="l6" debug />
<Box column pa="s" bg="l6" /> <Box column pa="s" bg="l6" />
</Box> </Box>
</Box> </Box>