• Stars
    star
    3,991
  • Rank 10,917 (Top 0.3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🦎 Use Tailwind CSS in React Native projects


tailwind-rn Status

Use Tailwind in React Native projects

All styles are generated directly from Tailwind's output, so they're always up-to-date.

  • JIT mode
  • Responsive breakpoints (e.g. sm, md, lg)
  • Dark mode
  • Custom configuration

Migrating from v3.x?


Install

$ npm install tailwind-rn

Getting Started

Run the following command to automatically add tailwind-rn to your React Native project:

$ npx setup-tailwind-rn

It will do most of the setup for you, but you'll have to follow a few more instructions from setup-tailwind-rn to finish the process.

Manual setup
  1. Install tailwind-rn.
$ npm install tailwind-rn
  1. Install Tailwind and concurrently.
$ npm install --save-dev tailwindcss postcss concurrently
  1. Create Tailwind config and necessary files.
$ npx tailwindcss init
$ echo '@tailwind utilities;' > input.css

These commands will create the following files:

  • tailwind.config.js - Tailwind configuration file.
  • input.css - Entrypoint for Tailwind compiler. It's required to override the output of Tailwind, so that it doesn't generate CSS for resetting browser styles, which will cause tailwind-rn to fail.

Disable unsupported utilities by adding this line to your tailwind.config.js:

module.exports = {
+	corePlugins: require('tailwind-rn/unsupported-core-plugins')
};

Make sure to configure content part of the config in tailwind.config.js to point to your JavaScript files to speed up compilation.

  1. Add scripts to build Tailwind styles in package.json.
{
	"scripts": {
+		"build:tailwind": "tailwindcss --input input.css --output tailwind.css --no-autoprefixer && tailwind-rn",
+		"dev:tailwind": "concurrently \"tailwindcss --input input.css --output tailwind.css --no-autoprefixer --watch\" \"tailwind-rn --watch\""
	}
}
  1. Build Tailwind styles in watch mode.
$ npm run dev:tailwind

After styles are built, you'll see two more files:

  • tailwind.css - CSS generated by Tailwind.
  • tailwind.json - The same CSS, but converted into JSON, so that tailwind-rn can understand it.
  1. Import TailwindProvider and tailwind.json in the root of your app and wrap the root of your app with it:
import {TailwindProvider} from 'tailwind-rn';
import utilities from './tailwind.json';

const App = () => (
	<TailwindProvider utilities={utilities}>
		<MyComponent />
	</TailwindProvider>
);

export default App;
  1. Use Tailwind in React Native!
import {useTailwind} from 'tailwind-rn';

const MyComponent = () => {
	const tailwind = useTailwind();

	return <Text style={tailwind('text-blue-600')}>Hello world</Text>;
};

Usage

Use useTailwind React hook and apply any of the supported utilities from Tailwind in your React Native views.

import React from 'react';
import {SafeAreaView, View, Text} from 'react-native';
import {useTailwind} from 'tailwind-rn';

const Hello = () => {
	const tailwind = useTailwind();

	return (
		<SafeAreaView style={tailwind('h-full')}>
			<View style={tailwind('pt-12 items-center')}>
				<View style={tailwind('bg-blue-200 px-3 py-1 rounded-full')}>
					<Text style={tailwind('text-blue-800 font-semibold')}>
						Hello Tailwind
					</Text>
				</View>
			</View>
		</SafeAreaView>
	);
};

export default Hello;

tailwind function returns a simple object with styles, which can be used in any React Native view, such as <View>, <Text> and others.

tailwind('pt-12 items-center');
//=> {
//     paddingTop: 48,
//     alignItems: 'center'
//   }

CLI

$ tailwind-rn --help

  Use Tailwind CSS in React Native projects

  Usage
    $ tailwind-rn [options]

  Options
    -i, --input    Path to CSS file that Tailwind generates (default: tailwind.css)
    -o, --output   Output file (default: tailwind.json)
    -w, --watch    Watch for changes and rebuild as needed

Run tailwind-rn CLI to transform the CSS generated by Tailwind into a JSON file that can be consumed by TailwindProvider. Add --watch flag to watch for changes and build styles continuously, which is useful for development.

API

TailwindProvider

utilities

Type: object

Parsed JSON object of styles generated by tailwind-rn CLI stored in tailwind.json by default.

import {TailwindProvider} from 'tailwind-rn';
import utilities from './tailwind.json';

const App = () => (
	<TailwindProvider utilities={utilities}>
		<MyComponent />
	</TailwindProvider>
);

colorScheme

Type: string

Override the default color scheme. Possible values are light or dark.

import {TailwindProvider} from 'tailwind-rn';
import utilities from './tailwind.json';

const App = () => (
	<TailwindProvider utilities={utilities} colorScheme="dark">
		<MyComponent />
	</TailwindProvider>
);

useTailwind

React hook, which returns a tailwind function, that accepts a string with class names. This function returns an object of styles, which can be applied to a React Native view via style property.

Note: Add TailwindProvider above the component where you're using this hook.

import {useTailwind} from 'tailwind-rn';

const MyComponent = () => {
	const tailwind = useTailwind();

	return <Text style={tailwind('text-blue-600')}>Hello world</Text>;
};

Supported Utilities

Modifiers

Layout

Flexbox

Spacing

Sizing

Typography

Backgrounds

Borders

Effects

Interactivity

More Repositories

1

ink

🌈 React for interactive command-line apps
TypeScript
22,325
star
2

pastel

🎨 Next.js-like framework for CLIs made with Ink
TypeScript
2,167
star
3

trevor

🚦 Your own mini Travis CI to run tests locally
JavaScript
2,125
star
4

mongorito

🍹 MongoDB ODM for Node.js apps based on Redux
JavaScript
1,393
star
5

gifi

watch GIFs while running npm install
JavaScript
1,025
star
6

draqula

🧛 GraphQL client for minimalistic React apps
JavaScript
777
star
7

pronto

⚡ The now.sh experience for databases
JavaScript
703
star
8

cancan

🔑 Pleasant authorization library for Node.js
JavaScript
621
star
9

ink-ui

💄 Ink-redible command-line interfaces made easy
TypeScript
573
star
10

dom-chef

🍔 Build DOM elements using JSX automatically
TypeScript
488
star
11

lanterns

⛩Write Markdown and get a GraphQL API for querying them for free
JavaScript
355
star
12

google-images

Search for images using Google Images
JavaScript
300
star
13

ronin

Toolkit for killer CLI applications
JavaScript
299
star
14

reconciled

⚛️ Simple way to create a custom React renderer
JavaScript
219
star
15

import-jsx

Import and transpile JSX on the fly
JavaScript
176
star
16

excalidraw-ui

Collection of reusable UI elements for Excalidraw
157
star
17

create-ink-app

Generate a starter Ink app
JavaScript
153
star
18

ink-spinner

Spinner component for Ink
TypeScript
144
star
19

generator-micro-service

🛫 Yeoman generator to kick-start your microservice with `micro` and `ava`!
JavaScript
144
star
20

thememirror

🦚 Beautiful themes for CodeMirror
TypeScript
132
star
21

ink-text-input

Text input component for Ink
TypeScript
131
star
22

ink-select-input

Select input component for Ink
TypeScript
128
star
23

thumbbot

Create thumbnails from images, video, audio and web pages.
JavaScript
124
star
24

ink-testing-library

Utilities for testing Ink apps
TypeScript
100
star
25

npm-search

Electron app to search npm via node-modules.com
JavaScript
95
star
26

mailman

Send emails in a comfortable way via models.
JavaScript
89
star
27

crown

Roll out features gradually
JavaScript
83
star
28

sushi

Koa-like framework for CLI tools.
JavaScript
83
star
29

create-pastel-app

Generate a starter Pastel app
JavaScript
71
star
30

ohcrash-app

Front-end web app of OhCrash
JavaScript
70
star
31

switch-branch-cli

Switch git branches by their pull request title
JavaScript
68
star
32

cat-facts

Interesting cat facts
JavaScript
57
star
33

minimist-options

Clean and beautiful options for minimist
JavaScript
54
star
34

node-video-thumb

Extract thumbnails from a video. Requires ffmpeg.
JavaScript
52
star
35

ohcrash-client

💣 Node.js client to report errors to OhCrash microservice
JavaScript
49
star
36

yoga-layout-prebuilt

Prebuilt yoga-layout package
JavaScript
47
star
37

slack-voice-messages

Record voice messages inside Slack
JavaScript
44
star
38

ink-redux

Redux bindings for Ink
JavaScript
43
star
39

interactor

Organize logic into interactors
JavaScript
36
star
40

restie

JavaScript ORM that talks to RESTful interface, rather than database. For Node.js and browsers.
JavaScript
31
star
41

supertap

Generate TAP output
JavaScript
30
star
42

mocha-generators

Enable support for ES6 generators in Mocha tests
JavaScript
29
star
43

generator-ink-cli

Scaffold out a CLI based on Ink
JavaScript
25
star
44

refined-overcast

Browser extension that improves Overcast user interface
CSS
18
star
45

templato

One interface to many template engines for Node.js and browsers.
JavaScript
17
star
46

ohcrash

💣 Microservice to report errors directly to your repo's GitHub Issues
JavaScript
17
star
47

ink-password-input

Password input component for Ink
JavaScript
16
star
48

interaptor

Intercept HTTP requests for testing purposes.
JavaScript
15
star
49

memcacher

Adding tags functionality to memcached, without modifying it. For Node.js.
CoffeeScript
15
star
50

buble-register

Bublé require hook
JavaScript
14
star
51

AnsiEscapes

ANSI escape codes for manipulating the terminal
Swift
14
star
52

udp-balancer

Load balancer for UDP
JavaScript
14
star
53

route66

Rails-inspired router for Koa and Express
JavaScript
14
star
54

setup-tailwind-rn

Set up Tailwind CSS in React Native apps
JavaScript
13
star
55

awesome-print

Beautifully print your JavaScript objects
JavaScript
12
star
56

patch-console

Patch console methods to intercept output
TypeScript
12
star
57

bucket-app

Interactive readme for your projects
JavaScript
11
star
58

detect-gender

Detect gender from name using genderize.io API
JavaScript
10
star
59

leeroy-jenkins-cli

Let Leeroy Jenkins make your boring CLI life more fun
JavaScript
9
star
60

syslog-parse

Parse syslog-formatted messages
JavaScript
9
star
61

net-socket

Node.js' net.Socket that automatically reconnects, 100% same API
JavaScript
8
star
62

code-excerpt

Extract excerpts from a source code
JavaScript
8
star
63

env-name

Get environment description (node + browser)
JavaScript
8
star
64

object-to-map

Convert object to ES6 Map
JavaScript
7
star
65

tempdir

Create a temporary directory
JavaScript
7
star
66

env-info

Get environment info (node + browser)
JavaScript
7
star
67

co-bind

Function#bind for generator functions.
JavaScript
7
star
68

generator-ink-component

Scaffold out an Ink component
JavaScript
7
star
69

ghost-api

Unofficial API client for Ghost blogs
JavaScript
6
star
70

ip-hash

ip-hash balancing algorithm (based on round-robin)
JavaScript
6
star
71

object-to-array

Convert object to an array of arrays of keys and values
JavaScript
6
star
72

leeroy-jenkins

Let Leeroy Jenkins make your boring developer life more fun.
JavaScript
5
star
73

asking

Tiny utility for getting user input in CLI programs
JavaScript
5
star
74

mongorito-timestamps

Plugin to add "created" and "updated" timestamps to Mongorito models
JavaScript
5
star
75

goodness-squad

4
star
76

react-floating-label-input

Floating-label input component for React
HTML
4
star
77

search-issues

Search GitHub issues
JavaScript
4
star
78

tailwindcss-custom-variant

Tailwind plugin to add custom variants
JavaScript
4
star
79

install-script-cli

Generate bash scripts to install your CLI programs from npm
JavaScript
4
star
80

install-script

Generate install scripts for your CLIs
Shell
4
star
81

wait-for-enter

Wait until user presses Enter in Terminal
JavaScript
3
star
82

list-dir

List directory contents recursively
JavaScript
3
star
83

crown-redis-store

Redis store for Crown
JavaScript
3
star
84

git-to-github-url

Get GitHub URL for a git repository
JavaScript
3
star
85

darkmatter-sdk

Enhance Darkmatter integration with your Astro website
TypeScript
3
star
86

express-errors

Express middleware for displaying Rails-inspired error pages
JavaScript
3
star
87

convert-to-spaces

Convert tabs to spaces in a string
JavaScript
3
star
88

koa-errors

Koa middleware for displaying Rails-inspired error pages
JavaScript
2
star
89

ama

Ask Me Anything!
2
star
90

mustached

CLI tool to render Mustache templates with JSON as data input
Crystal
2
star
91

format-object

util.format with object instead of argument list
JavaScript
2
star
92

is-public-repo

Check if GitHub repository is public
JavaScript
2
star
93

astro-selfie

Astro integration to generate page screenshots to show as Open Graph images
TypeScript
2
star
94

test

Dockerfile
2
star
95

crown-memory-store

Memory store for Crown
JavaScript
2
star
96

convert-to-tabs

Convert spaces to tabs in a string
JavaScript
2
star
97

fake-exec

Fake child_process#exec output for testing
JavaScript
1
star
98

koa-log-requests

Customizable Koa middleware for logging requests in console
JavaScript
1
star
99

sushi-help

Help message middleware for Sushi
JavaScript
1
star
100

array-generators

Common array functions with support for generators (forEach, filter, map)
JavaScript
1
star