# react-native-theo

> Theo handler for React Native

Latest version **0.2.3** (published 2020-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-theo
pnpm add react-native-theo
yarn add react-native-theo
bun add react-native-theo
```

Provides the command `theo-native`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2020-11-13 |
| First published | 2020-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 20.9 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| Author | Levi Pires |
| Maintainers | levi-pires |
| Keywords | theo, react, react-native, desing, tokens |

## Links

- npm: https://www.npmjs.com/package/react-native-theo
- Repository: https://github.com/Meiuca/react-native-theo
- npm.io page: https://npm.io/package/react-native-theo

## Dependencies (8)

- [css](https://npm.io/package/css.md) ^3.0.0
- [theo](https://npm.io/package/theo.md) ^8.1.5
- [axios](https://npm.io/package/axios.md) ^0.21.0
- [chalk](https://npm.io/package/chalk.md) ^4.1.0
- [figlet](https://npm.io/package/figlet.md) ^1.5.0
- [inquirer](https://npm.io/package/inquirer.md) ^7.3.3
- [prettier](https://npm.io/package/prettier.md) ^2.1.2
- [commander](https://npm.io/package/commander.md) ^6.2.0

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.3 (latest) — 2020-11-13
- 0.2.2 — 2020-11-13
- 0.2.1 — 2020-11-13
- 0.2.0 — 2020-11-13
- 0.1.3 — 2020-11-10
- 0.1.2 — 2020-11-10
- 0.1.1 — 2020-11-10
- 0.1.0 — 2020-11-10

## README

# <img src="https://raw.githubusercontent.com/levi-pires/react-native-theo/master/assets/react-icon.webp" alt="RN logo" width="35" height="27" /> React Native + Theo <img src="https://raw.githubusercontent.com/salesforce-ux/theo/master/assets/theo.png" alt="Theo logo" width="28" height="28" />

[![NPM version][npm-image]][npm-url]

React Native Theo is an implementation of [Theo](https://github.com/salesforce-ux/theo) for React Native. Due to the use of tools that RN doesn't provide during runtime (like **fs** and **path**) I decided to create a CLI to handle Design Tokens before packaging.

## Installation

`yarn add react-native-theo`

## Basic Help

`yarn theo-native --help`

## CLI

First of all, start the project with `yarn theo-native init`. This command generates a default [config file](#default-configuration-file). If you want to create your own config file, try `yarn theo-native init --create`. You can also use the `--force` flag to change configurations.

### Link Fonts

Before linking, you will have to set up the [react-native.config.js](#react-native-configuration) to link fonts properly. If you already have it set up you can skip this step.

To link the fonts, run `yarn theo-native link-fonts|link`.

> Note: I highly recommend you to use Google Fonts links

### Convert Tokens

This part is pretty straightforward. Just run `yarn theo-native convert-tokens|convert`

> Example:
>
> > input: ./tokens/tokens.yml
> >
> > output: ./src/tokens.ts -->
> >
> > > ```typescript
> > > export const borderStyleDefault = "solid";
> > > export const borderWidthNone = 0;
> > > export const borderWidthHairline = 1;
> > > export const borderWidthThin = 2;
> > > export const borderWidthThick = 4;
> > > export const borderWidthHeavy = 8;
> > > export const opacityLevelSemiopaque = 0.8;
> > > export const opacityLevelIntense = 0.64;
> > > export const opacityLevelMedium = 0.32;
> > > export const opacityLevelLight = 0.16;
> > > export const opacityLevelSemitransparent = 0.08;
> > > export const borderRadiusNone = 0;
> > > /* ... */
> > > ```

## API Usage

Since React Native has a limited support to external fonts, I created this simple function.

> Note: Mainly on Android, the output of the function has to be the same as the file name

```javascript
const { renderNativeFont } = require('react-native-theo')

const styles = {
  foo: {
    ...renderNativeFont({
      fontFamily: 'Roboto';
      fontWeight: '600';
      italic: true;
    }) /*
        output: {
          fontFamily: Roboto-SemiBold-Italic,
          fontWeight: '600'
        }
        */
  }
}
```

<!-- ## Font Token

```yaml
# archivo.yml
global:
  type: object
  category: typography

props:
  - name: archivo-regular
    value:
      src: "https://fonts.gstatic.com/s/archivo/v7/k3kQo8UDI-1M0wlSTd4.ttf"
      local: "Archivo-Regular"
      format: ttf
    type: object
    category: font

  - name: archivo-medium
    value:
      src: "https://fonts.gstatic.com/s/archivo/v7/k3kVo8UDI-1M0wlSdSrLC0E.ttf"
      local: "Archivo-Medium"
      format: ttf
    type: object
    category: font
``` -->

## Default Configuration File

```javascript
// react-native-theo.config.js
module.exports = {
  // All required if you are going to use 'theo-native convert-tokens'
  styles: {
    files: ["./tokens/tokens.yml"],
    output: {
      dir: "./src/tokens/",
      // .js | .ts
      extension: ".js",
      // module.js | common.js
      format: "module.js",
    },
  },

  // You can declare both files and urls, but you cannot declare
  // 'fonts: {}' if you are going to use 'theo-native link-fonts'
  fonts: {
    files: ["./tokens/brand-01/typography/index.yml"],
    urls: [
      "https://fonts.googleapis.com/css2?family=Roboto",
      "https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,900;1,700",
    ],
  },
};
```

## React Native Configuration

```javascript
// react-native.config.js
module.exports = {
  assets: ["./assets/fonts/"] /* you will need to add this line */,
};
```

[npm-url]: https://npmjs.org/package/react-native-theo
[npm-image]: http://img.shields.io/npm/v/react-native-theo.svg
[travis-url]: https://travis-ci.org/salesforce-ux/theo
[travis-image]: http://img.shields.io/travis/salesforce-ux/theo.svg

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