Skip to content

Commit dd37e09

Browse files
committed
style: code formatted
1 parent 3ecc459 commit dd37e09

File tree

11 files changed

+67
-55
lines changed

11 files changed

+67
-55
lines changed

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
![GitHub Issues](https://img.shields.io/github/issues/coderdiaz/jacaranda?style=flat)
77
![GitHub Stars](https://img.shields.io/github/stars/coderdiaz/jacaranda?style=flat)
88

9-
109
> ⚠️ **BETA SOFTWARE**: This library is in active development and not yet recommended for production use. APIs may change without notice. Feel free to try it out and provide feedback!
1110
1211
Provides a way to styling components in React Native with better experience and composability. The key feature is the ability to create multi-variants styles with a type-safe definition inspired by [Stitches](https://stitches.dev/docs/variants) and [CVA](https://cva.style/docs/getting-started/variants) (for React apps).
@@ -26,6 +25,7 @@ Provides a way to styling components in React Native with better experience and
2625
- [ ] Default design tokens.
2726

2827
### Create your config file
28+
2929
To configure `Jacaranda`, create a `jacaranda.config.ts` file (`.js` works too) to define your reusable design tokens and import the `defineTokens` function.
3030

3131
```tsx
@@ -34,6 +34,7 @@ import { defineTokens } from 'jacaranda';
3434
```
3535

3636
This function receives an object with the design tokens.
37+
3738
- `colors`: Define your colors design tokens.
3839
- `space`: Define your spacing.
3940
- `fonts`: Define your fonts.
@@ -42,7 +43,7 @@ This function receives an object with the design tokens.
4243

4344
And returns a `styles` function that you can use to style your components.
4445

45-
```tsx
46+
```tsx
4647
// jacaranda.config.ts
4748
import { defineTokens } from 'jacaranda';
4849

@@ -73,8 +74,9 @@ export const { styles } = defineTokens({
7374
xl: 32,
7475
xxl: 40,
7576
},
76-
})
77+
});
7778
```
79+
7880
### Import and use it
7981

8082
After the tokens are defined, you can use the design tokens in your components. You'll be importing the `styles` function from the `jacaranda.config.ts` file.
@@ -124,6 +126,7 @@ const buttonStyles = styles({
124126
```
125127

126128
### TypeScript
129+
127130
#### Extract variants from a component
128131

129132
You can use the `VariantProps` type to extract the variants from a component.

packages/app-typescript/App.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ const sty = StyleSheet.create({
2323
backgroundColor: '#fff',
2424
alignItems: 'center',
2525
justifyContent: 'center',
26-
gap: 12
26+
gap: 12,
2727
},
2828
});
+11-10
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { TouchableOpacity } from 'react-native';
2-
import { type VariantProps } from 'jacaranda'
2+
import { type VariantProps } from 'jacaranda';
33
import { Typography } from './Typography';
44
import { styles } from '../jacaranda.config';
55

6-
76
type ButtonProps = VariantProps<typeof buttonStyles> & {
87
children?: React.ReactNode;
98
};
109

1110
export const Button = (props: ButtonProps) => {
12-
return <TouchableOpacity style={buttonStyles(props)}>
13-
<Typography>{props.children}</Typography>
14-
</TouchableOpacity>
15-
}
11+
return (
12+
<TouchableOpacity style={buttonStyles(props)}>
13+
<Typography>{props.children}</Typography>
14+
</TouchableOpacity>
15+
);
16+
};
1617

1718
const buttonStyles = styles({
1819
base: {
@@ -28,9 +29,9 @@ const buttonStyles = styles({
2829
secondary: {
2930
backgroundColor: '$colors.secondary500',
3031
},
31-
}
32+
},
3233
},
3334
defaultVariants: {
34-
color: 'primary'
35-
}
36-
})
35+
color: 'primary',
36+
},
37+
});

packages/app-typescript/components/Typography.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ type TypographyProps = VariantProps<typeof typographyStyles> & {
77
};
88

99
export const Typography = (props: TypographyProps) => {
10-
return <Text style={typographyStyles(props)}>{props.children}</Text>
11-
}
10+
return <Text style={typographyStyles(props)}>{props.children}</Text>;
11+
};
1212

1313
const typographyStyles = styles({
1414
base: {},
@@ -34,12 +34,12 @@ const typographyStyles = styles({
3434
left: { textAlign: 'left' },
3535
center: { textAlign: 'center' },
3636
right: { textAlign: 'right' },
37-
}
37+
},
3838
},
3939
defaultVariants: {
4040
level: 3,
4141
color: 'white',
4242
weight: 'medium',
43-
align: 'left'
44-
}
45-
})
43+
align: 'left',
44+
},
45+
});

packages/app-typescript/jacaranda.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ export const { styles } = createTokens({
3131
6: 24,
3232
7: 28,
3333
8: 32,
34-
}
34+
},
3535
});

packages/app/App.js

+12-10
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
22
import { styles } from './jacaranda.config';
33

44
export const Button = (props) => {
5-
return (<TouchableOpacity style={buttonStyles({ intent: props.intent, size: props.size })}>
6-
<Text>Button</Text>
7-
</TouchableOpacity>)
8-
}
5+
return (
6+
<TouchableOpacity style={buttonStyles({ intent: props.intent, size: props.size })}>
7+
<Text>Button</Text>
8+
</TouchableOpacity>
9+
);
10+
};
911

1012
const buttonStyles = styles({
1113
base: { borderRadius: '$spacing.md' },
@@ -16,20 +18,20 @@ const buttonStyles = styles({
1618
},
1719
secondary: {
1820
backgroundColor: '$colors.secondary50',
19-
}
21+
},
2022
},
2123
size: {
2224
md: {
2325
paddingHorizontal: '$spacing.md',
2426
paddingVertical: '$spacing.sm',
25-
}
26-
}
27+
},
28+
},
2729
},
2830
defaultVariants: {
2931
intent: 'primary',
30-
size: 'md'
31-
}
32-
})
32+
size: 'md',
33+
},
34+
});
3335

3436
export default function App() {
3537
return (

packages/app/jacaranda.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineTokens } from "jacaranda";
1+
import { defineTokens } from 'jacaranda';
22

33
export const { styles } = defineTokens({
44
colors: {
@@ -28,4 +28,4 @@ export const { styles } = defineTokens({
2828
xl: 32,
2929
xxl: 40,
3030
},
31-
})
31+
});

packages/jacaranda/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@
7878
"stylsheets",
7979
"design-system"
8080
]
81-
}
81+
}

packages/jacaranda/src/index.test.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,15 @@ describe('defineTokens', () => {
200200
size: { small: {} },
201201
type: { primary: {} },
202202
},
203-
compoundVariants: [{
204-
variants: { size: 'small' as const, type: 'primary' as const },
205-
style: {
206-
backgroundColor: '$colors.primary',
207-
padding: '$space.sm',
203+
compoundVariants: [
204+
{
205+
variants: { size: 'small' as const, type: 'primary' as const },
206+
style: {
207+
backgroundColor: '$colors.primary',
208+
padding: '$space.sm',
209+
},
208210
},
209-
}],
211+
],
210212
});
211213

212214
expect(result({ size: 'small', type: 'primary' })).toEqual({
@@ -263,4 +265,4 @@ describe('defineTokens', () => {
263265
lineHeight: 1.5,
264266
});
265267
});
266-
});
268+
});

packages/jacaranda/src/index.ts

+17-13
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ type ResolvedStyle = ViewStyle & TextStyle & ImageStyle;
4848
// StyleObject now extends ResolvedStyle
4949
type StyleObject = {
5050
[K in keyof ResolvedStyle]?:
51-
| ResolvedStyle[K]
52-
| (string extends ResolvedStyle[K] ? `$${string}` : never)
53-
| (number extends ResolvedStyle[K] ? `$${string}` : never);
51+
| ResolvedStyle[K]
52+
| (string extends ResolvedStyle[K] ? `$${string}` : never)
53+
| (number extends ResolvedStyle[K] ? `$${string}` : never);
5454
};
5555

5656
// Define the VariantOptions type to ensure type safety in variant definitions
@@ -147,7 +147,6 @@ export function styles<V extends VariantOptions<V>>(config: VariantStyleConfig<V
147147
};
148148
}
149149

150-
151150
/**** Tokens definition */
152151

153152
// Define allowed token categories and their value types
@@ -206,15 +205,20 @@ export function defineTokens<T extends TokenConfig>(tokenConfig: T): CreateToken
206205
const resolvedBase = config.base ? resolveTokens(config.base, tokens) : config.base;
207206

208207
// Resolve tokens in variants
209-
const resolvedVariants = config.variants ? Object.entries(config.variants).reduce((acc, [key, variantGroup]: [string, any]) => {
210-
const resolvedGroup = Object.entries(variantGroup).reduce((groupAcc, [variantKey, styles]: [string, any]) => {
211-
return {
212-
...groupAcc,
213-
[variantKey]: resolveTokens(styles, tokens),
214-
};
215-
}, {});
216-
return { ...acc, [key]: resolvedGroup };
217-
}, {}) : {};
208+
const resolvedVariants = config.variants
209+
? Object.entries(config.variants).reduce((acc, [key, variantGroup]: [string, any]) => {
210+
const resolvedGroup = Object.entries(variantGroup).reduce(
211+
(groupAcc, [variantKey, styles]: [string, any]) => {
212+
return {
213+
...groupAcc,
214+
[variantKey]: resolveTokens(styles, tokens),
215+
};
216+
},
217+
{},
218+
);
219+
return { ...acc, [key]: resolvedGroup };
220+
}, {})
221+
: {};
218222

219223
// Resolve tokens in compound variants
220224
const resolvedCompoundVariants = config.compoundVariants?.map((compound: any) => ({

pnpm-workspace.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
packages:
2-
- 'packages/*'
2+
- 'packages/*'

0 commit comments

Comments
 (0)