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

Makes tailwind config settings easier. #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,17 @@ You can use `twrnc` right out of the box if you haven't customized your
tailwind customizations you'd like to use. For that reason, we expose the ability to
create a **custom configured version** of the `tw` function object.

### Initialize

```js
// main.js (When the program will be initialized)
import { configure } from 'twrnc';

configure(require(`./tailwind.config.js`));
```

### Create your own tw function

```js
// lib/tailwind.js
import { create } from 'twrnc';
Expand Down
11 changes: 11 additions & 0 deletions src/configure.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { TwConfig } from './tw-config';

let initialTwConfig: TwConfig | undefined;

export function getInitialTwConfig(): TwConfig | undefined {
return initialTwConfig;
}

export function configure(twConfig: TwConfig): void {
initialTwConfig = twConfig;
}
12 changes: 10 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import type { TailwindFn, RnColorScheme, ClassInput, Style } from './types';
import type { TwConfig } from './tw-config';
import plugin from './plugin';
import rawCreate from './create';
import { getInitialTwConfig } from './configure';

// Apply default config and inject RN Platform
const create = (twConfig: TwConfig = {}): TailwindFn => rawCreate(twConfig, Platform.OS);
const initialTwConfig = getInitialTwConfig();

/**
* Apply default config and inject RN Platform
* If no config is provided, use the initial config
*/
const create = (twConfig: TwConfig = initialTwConfig || {}): TailwindFn => {
return rawCreate(twConfig, Platform.OS);
};

export type { TailwindFn, TwConfig, RnColorScheme, ClassInput, Style };
export { useDeviceContext, useAppColorScheme } from './hooks';
Expand Down
Loading