# tailwind-react-native-classnames

> simple, expressive API for tailwindcss + react-native

Latest version **1.5.1** (published 2021-09-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install tailwind-react-native-classnames
pnpm add tailwind-react-native-classnames
yarn add tailwind-react-native-classnames
bun add tailwind-react-native-classnames
```

Provides the command `trnc-create-styles`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.5.1 |
| Published | 2021-09-19 |
| First published | 2020-12-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 190 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2377 |
| Author | Jared Henderson |
| Maintainers | jaredhenderson |
| Keywords | tailwind, tailwindcss, react-native, classnames |

## Links

- npm: https://www.npmjs.com/package/tailwind-react-native-classnames
- Repository: https://github.com/jaredh159/tailwind-react-native-classnames
- Issues: https://github.com/jaredh159/tailwind-react-native-classnames/issues
- npm.io page: https://npm.io/package/tailwind-react-native-classnames

## Dependencies (5)

- [css](https://npm.io/package/css.md) ^3.0.0
- [postcss](https://npm.io/package/postcss.md) ^8.2.1
- [x-chalk](https://npm.io/package/x-chalk.md) ^1.0.1
- [tailwindcss](https://npm.io/package/tailwindcss.md) ^2.0.0
- [css-to-react-native](https://npm.io/package/css-to-react-native.md) ^3.0.0

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 1.5.1 (latest) — 2021-09-19
- 3.0.1 — 2021-09-16
- 3.0.0-alpha.1 — 2021-09-16
- 2.0.1 — 2021-09-16
- 2.0.0 — 2021-09-16
- 1.5.0 — 2021-09-15
- 1.4.3 — 2021-08-24
- 1.4.2 — 2021-08-04
- 1.4.1 — 2021-07-17
- 1.4.0 — 2021-07-12
- 1.3.0 — 2021-06-16
- 1.3.0-beta.1 — 2021-06-15
- 1.2.1 — 2021-06-02
- 1.2.0 — 2020-12-23
- 1.1.1 — 2020-12-23
- … 8 more at https://npm.io/package/tailwind-react-native-classnames/versions

## README

# Tailwind React Native Classnames 🏄‍♂️

> A simple, expressive API for TailwindCSS + React Native, written in TypeScript

```jsx
import { View, Text } from 'react-native';
import tw from 'tailwind-react-native-classnames';

const MyComponent = () => (
  <View style={tw`p-4 android:pt-2 bg-red-300 flex-row`}>
    <Text style={tw`text-md tracking-wide`}>Hello World</Text>
  </View>
);
```

#### 🚀 &nbsp;_V2 Now in Beta_ 🚀

_Help us beta-test the new V2 re-write, including dark-mode, breakpoints, JIT-mode, and
more. Docs and migration guide
[over here](https://github.com/jaredh159/tailwind-react-native-classnames/tree/v2#readme)._

---

## API

The default export is an ES6 _Tagged template function_ which is nice and terse for the
most common use case -- passing a bunch of space-separated Tailwind classes and getting
back a react-native style object:

```js
import tw from 'tailwind-react-native-classnames';

tw`pt-6 bg-blue-100`;
// -> { paddingTop: 24, backgroundColor: 'rgba(219, 234, 254, 1)' }
```

In the spirit of Tailwindcss's intuitive responsive prefix syntax,
`tailwind-react-native-classnames` adds support for **platform prefixes** to conditionally
apply styles based on the current platform:

```js
// 😎 styles only added if platform matches
tw`ios:pt-4 android:pt-2`;
```

You can also use `tw.style()` for handling more complex class name declarations. The api
for this function is directly taken from the excellent
[classnames](https://github.com/JedWatson/classnames#readme) package.

```js
// pass multiple args
tw.style('text-sm', 'bg-blue-100', 'flex-row mb-2');

// arrays of classnames work too
tw.style(['text-sm', 'bg-blue-100']);

// falsy stuff is ignored, so you can do conditionals like this
tw.style(isOpen && 'bg-blue-100');

// { [className]: boolean } style - key class only added if value is `true`
tw.style({
  'bg-blue-100': isActive,
  'text-red-500': invalid,
});

// or, combine tailwind classes with plain react-native style object:
tw.style('bg-blue-100', { elevation: 3, lineHeight: 13.5 });

// mix and match input styles as much as you want
tw.style('bg-blue-100', ['flex-row'], { 'text-xs': true }, { fontSize: 9 });
```

The `tw` function also has a method `color` that can be used to get back a string value of
a tailwind color. Especially useful if you're using a customized color pallette.

```js
tw.color('blue-100');
// -> "rgba(219, 234, 254, 1)"
```

You can import the main `tw` function and reach for `tw.style` only when you need it:

```jsx
import tw from 'tailwind-react-native-classnames';

const MyComponent = () => (
  <View style={tw`bg-blue-100`}>
    <Text style={tw.style('text-md', invalid && 'text-red-500')}>Hello</Text>
  </View>
);
```

...or if the tagged template function isn't your jam, just import `tw.style` as `tw`:

```jsx
import { style as tw } from 'tailwind-react-native-classnames';

const MyComponent = () => (
  <View style={tw('bg-blue-100', invalid && 'text-red-500')}></View>
);
```

## Installation

```bash
npm install tailwind-react-native-classnames
```

## Customization

You can use `tailwind-react-native-classnames` right out of the box if you haven't
customized your `tailwind.config.js` file at all. But more likely you've got some
important app-specific tailwind customizations you'd like to use. In that case, this
package exposes a cli command to generate a style-map which can then be used to create
your own custom-scoped `tw` function, like so:

```bash
npx trnc-create-styles
```

This command will create a `tw-rn-styles.json` file in the root of your project dir. This
file contains the info the package needs to generate customized react-native styles. It
should be checked in to source control, and regenerated whenever you change your
`tailwind.config.js` file. Then, somewhere in your app, you just do this:

```js
// lib/tailwind.js
import { create } from 'tailwind-react-native-classnames';
import styles from '../../tw-rn-styles.json'; // <-- your path may differ

// this function works just like the default package export
// except it is customized according to your `tailwind.config.js`
const tw = create(styles);

export default tw;
```

...and in your component files import your own customized version of the function instead:

```jsx
// SomeComponent.js
import tw from './lib/tailwind';
```

## Prior Art

- Though not a fork, this package was based heavily on the excellent
  [vadimdemedes/tailwind-rn](https://github.com/vadimdemedes/tailwind-rn).
- The flexible `tw.style()` api was taken outright from
  [classnames](https://github.com/JedWatson/classnames#readme)
- [TailwindCSS](https://tailwindcss.com)
- [React Native](https://reactnative.dev)

---
_Source: https://npm.io/package/tailwind-react-native-classnames · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
