Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🔖]: v2.0.0-rc.1 #9

Merged
merged 2 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ pnpm add react-design-tokens

The library exposes two APIs, `create` and `defaultCSSVariableGenerator`:

### 1. `create(variants, config?): { useTokens, VariantSelector, generateCSSVariablesAsInlineStyle }`
### 1. `create`

```ts
declare const create: (variants, config?) => {
VariantSelector,
useTokens,
generateCSSVariablesAsInlineStyle,
}
```

This is the main API exposed by the library. It will take your variants map and an optional config options to create your theming client.

Expand Down Expand Up @@ -57,15 +65,25 @@ A React hook to use in a component that is descendant of `<VariantSelector>` wra

A helper function to generate CSS variables in valid CSS syntax (`--variable=value`). It is helpful when you want to manually control the population of the CSS variables (e.g. Put initial tokens on html tag with `<html style={generateCSSVariablesAsInlineStyle('dark')} />`)

### 2. `defaultCSSVariableGenerator(context): { variableName: string; variableValue: string } | null`
### 2. `defaultCSSVariableGenerator`

```ts
declare const defaultCSSVariableGenerator: (context: {
tokenFamilyKey: string;
tokenKey: string;
tokenPath: string;
tokenValue: unknown;
}) => {
variableName: string;
variableValue: string;
} | null;
```

The default CSS variable generate function. The generated variables obey the following rules:
- Values that are not of type `string` or `number` will be omitted (returns `null`).
- Values of type `number` will be converted into `{tokenValue}px`.
- The generated variable format: `{ variableName: 'PATH-TO-TOKEN', variableValue: 'tokenValue' }`

The `context` consists of:

#### `context.tokenFamilyKey`:

The key of a root token family.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-design-tokens",
"version": "2.0.0-rc.0",
"version": "2.0.0-rc.1",
"description": "An optimized and creative theming solution that generates CSS variables based on the tokens provided.",
"license": "MIT",
"type": "module",
Expand Down
Loading