# react-native-easy-theming

> DX friendly theming library for React-Native

Latest version **0.0.4** (published 2023-12-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-native-easy-theming
pnpm add react-native-easy-theming
yarn add react-native-easy-theming
bun add react-native-easy-theming
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2023-12-07 |
| First published | 2023-12-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | leerman |

## Links

- npm: https://www.npmjs.com/package/react-native-easy-theming
- npm.io page: https://npm.io/package/react-native-easy-theming

## Dependencies (1)

- [validate-color](https://npm.io/package/validate-color.md) ^2.2.4

## Recent versions

- 0.0.4 (latest) — 2023-12-07
- 0.0.3 — 2023-12-06
- 0.0.2 — 2023-12-06
- 0.0.1 — 2023-12-06

## README

## react-native-easy-theming

DX friendly theming library for React-Native

## Geting started

1. install package

```cmd
yarn add react-native-easy-theming
```

2. add babel plugin in babel config

```
module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: [['react-native-easy-theming/plugin']], //<- add this
};
```

3. create your theme type

```ts
// themes.ts
const light = { name: "light", color: { background: "white" } };
const dark = { name: "dark", color: { background: "black" } };
export const themes = {
  light,
  dark,
};

export type TMyTheme = typeof light;
```

4. connect your theme type to package

```ts
// types/react-native-easy-theming.d.ts
import { TMyTheme } from "../themes";
export * from "react-native-easy-theming";
declare module "react-native-easy-theming" {
  interface TTheme extends TMyTheme {}
}
```

5. connect theme provider to your app

```ts
// App.tsx
import React from "react";
import {
  ThemeProvider,
  useTheme,
  useThemeChange,
} from "react-native-easy-theming";
import { themes } from "./themes";

export const App = () => {
  const [theme, setTheme] = React.useState("light");
  return (
    <ThemeProvider themes={themes} activeTheme={theme} onChange={setTheme}>
      {
        // Application
      }
    </ThemeProvider>
  );
};
```

6. use in your component

```ts
import React from "react";
import { View, ViewStyle } from "react-native";

const Component = (props: { style: ViewStyle }) => {
  return (
    <View
      s-background-color="color.background"
      s-opacity={(theme) => (theme.name === "dark" ? 0.5 : 0.7)}
      style={props.style}
      s-padding={20}
    >
      {
        //
      }
    </View>
  );
};
```

Code above will transform by babel to something like:

```
import { useTheme as _useTheme } from "react-native-easy-theming";
import React from "react";
import { View, ViewStyle } from "react-native";
const Component = ({ style }) => {
  const _theme = _useTheme();
  return /*#__PURE__*/ React.createElement(View, {
    style: [
      {
        backgroundColor: _theme.color.background,
        opacity: (() => (_theme.name === "dark" ? 0.5 : 0.7))(),
      },
      style,
      {
        padding: 20,
      },
    ],
  });
};
```

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