Skip to content

Commit db331f8

Browse files
committed
chore: updated readme.md
1 parent 46a0320 commit db331f8

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

README.md

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,24 @@ Provides a way to styling components in React Native with better experience and
1818
- [x] Support to define theme tokens.
1919
- [ ] Styles based on conditions.
2020

21-
### Example of usage
21+
### Create your config file
22+
To configure `Jacaranda`, create a `jacaranda.config.ts` file (`.js` works too) to define your reusable design tokens and import the `createTokens` function.
23+
```tsx
24+
// jacaranda.config.ts
25+
import { createTokens } from 'jacaranda';
26+
```
27+
28+
This function receives an object with the design tokens and returns a `styles` object that you can use to style your components.
29+
- `colors`: Define your colors.
30+
- `fontSize`: Define your font sizes.
31+
- `spacing`: Define your spacing.
32+
- `fonts`: Define your fonts.
33+
- `lineHeight`: Define your line heights.
2234

23-
```tsx jacaranda.ts
35+
And returns a `styles` function that you can use to style your components.
36+
37+
```tsx
38+
// jacaranda.config.ts
2439
import { createTokens } from 'jacaranda';
2540

2641
export const { styles } = createTokens({
@@ -33,7 +48,6 @@ export const { styles } = createTokens({
3348
primary500: '#06b6d4',
3449
primary600: '#0e93d1',
3550
primary700: '#1570ad',
36-
// Secondary
3751
secondary50: '#ecfdf5',
3852
secondary100: '#d9f9eb',
3953
secondary200: '#bbfde8',
@@ -53,14 +67,23 @@ export const { styles } = createTokens({
5367
},
5468
})
5569
```
70+
### Import and use it
71+
72+
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.
5673

5774
```tsx
58-
import { styles } from './jacaranda';
75+
// Button.tsx
76+
import { TouchableOpacity } from 'react-native';
77+
import { type VariantProps } from 'jacaranda';
78+
import { styles } from './jacaranda.config';
79+
80+
type ButtonProps = VariantProps<typeof buttonStyles> & {
81+
children?: React.ReactNode;
82+
};
5983

60-
// Button primitive
61-
export const Button = () => {
84+
export const Button = (props: ButtonProps) => {
6285
return (
63-
<TouchableOpacity style={buttonStyles()}>
86+
<TouchableOpacity style={buttonStyles(props)}>
6487
<Text>Click me</Text>
6588
</TouchableOpacity>
6689
);
@@ -92,4 +115,15 @@ const buttonStyles = styles({
92115
});
93116
```
94117

118+
### TypeScript
119+
#### Extract variants from a component
120+
121+
You can use the `VariantProps` type to extract the variants from a component.
122+
123+
```tsx
124+
import { type VariantProps } from 'jacaranda';
125+
126+
type ButtonProps = VariantProps<typeof buttonStyles>;
127+
```
128+
95129
Copyright @ 2025 by Javier Diaz

0 commit comments

Comments
 (0)