# @brix-ui/theme

> Theme package providing light and dark modes as well as CSS/JS variables and helpers used in theming

Latest version **2.2.2** (published 2021-01-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install @brix-ui/theme
pnpm add @brix-ui/theme
yarn add @brix-ui/theme
bun add @brix-ui/theme
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.2 |
| Published | 2021-01-12 |
| First published | 2020-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=12 |
| Dependencies | 6 |
| Unpacked size | 57.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 57 |
| Author | uStudio Company |
| Maintainers | brix-ui |
| Keywords | react, typescript, theme, ui, light mode, dark mode, css, styled-components, css-in-js |

## Links

- npm: https://www.npmjs.com/package/@brix-ui/theme
- Repository: https://github.com/uStudioTeam/brix-ui
- Homepage: https://github.com/uStudioTeam/brix-ui/blob/master/README.md
- npm.io page: https://npm.io/package/@brix-ui/theme

## Dependencies (6)

- [polished](https://npm.io/package/polished.md) ^3.6.6
- [lodash.merge](https://npm.io/package/lodash.merge.md) ^4.6.2
- [@brix-ui/hooks](https://npm.io/package/@brix-ui/hooks.md) ^2.2.2
- [@brix-ui/types](https://npm.io/package/@brix-ui/types.md) ^2.2.2
- [@brix-ui/utils](https://npm.io/package/@brix-ui/utils.md) ^2.2.2
- [@brix-ui/prop-types](https://npm.io/package/@brix-ui/prop-types.md) ^2.2.2

## Alternatives

- [style-dictionary](https://npm.io/package/style-dictionary.md) — 2.0M weekly downloads
- [postcss-merge-idents](https://npm.io/package/postcss-merge-idents.md) — 1.7M weekly downloads
- [@fontsource/noto-sans](https://npm.io/package/@fontsource/noto-sans.md) — 93.0K weekly downloads
- [uglifycss](https://npm.io/package/uglifycss.md) — 71.6K weekly downloads
- [mat4-interpolate](https://npm.io/package/mat4-interpolate.md) — 23.3K weekly downloads

## Recent versions

- 2.2.2 (latest) — 2021-01-12
- 2.2.1 — 2021-01-11
- 2.2.0 — 2021-01-11
- 2.1.1 — 2021-01-08
- 2.1.0 — 2020-11-11
- 2.0.0 — 2020-11-05
- 2.0.0-rc.1 — 2020-10-28

## README

# @brix-ui/theme

Theme package providing light and dark modes as well as CSS/JS variables and helpers used in theming.

---

## Installation

```shell script
npm i @brix-ui/theme # styled-components react react-dom
```

```shell script
yarn add @brix-ui/theme # styled-components react react-dom
```

> Make sure to have `react`, `react-dom` and `styled-components` installed in your package as they are included in our peer dependencies.

## Usage

Along with `<ThemeProvider />` component, which has to be wrapper around you application, we export two important
hooks – `useTheme` and `useThemeMode`.
As mentioned in the description, Brix UI theme and design system support both light and dark modes, making it
easy to switch between the two.

First and foremost, setup the provider:

```typescript jsx
<ThemeProvider>
  <App />
</ThemeProvider>
```

Or as [render props](https://en.reactjs.org/docs/render-props.html):

```typescript jsx
<ThemeProvider>
  {({ mode }) => {
    return <App themeMode={mode ? 'Light' : 'Dark'} />;
  }}
</ThemeProvider>
```

Then, use all the features of our theme inside any part of your React application:

### CSS

```css
.class {
  color: var(--c-accent-strong);
}
```

### styled-components

```typescript
import { shadow } from '@brix-ui/theme/mixin';

const Button = styled.button(
  ({ theme }) => css`
    color: ${theme.palette['accent-strong']};

    box-shadow: ${shadow('base-strong', 0.1)};
  `
);
```

### React (switching theme mode)

```typescript jsx
import { useTheme } from '@brix-ui/theme/hooks';

import Flex from '@brix-ui/core/switch';
import Switch from '@brix-ui/core/switch';
import Text from '@brix-ui/core/switch';

const Component = () => {
  const { switchMode, mode } = useTheme();

  return (
    <Flex as="label" verticalAlign="center" gap={{ horizontal: '8px' }}>
      <Switch onChange={() => switchMode()} />

      <Text>{mode ? 'Light' : 'Dark'}</Text>
    </Flex>
  );
};
```

### Fonts

Out of the box we provide **no default fonts**.

To connect the fonts defined as default in our design system you have an option to create your own `@font-face`
rules.

To override predefined `font-family` names for each of the font variants (`body`, `article`, `code`),
you can either override custom properties for each of those variants (prefixed with `f-`)
or pass them into the `theme` prop of the `ThemeProvider` component:

```typescript jsx
<ThemeProvider
  theme={{
    typography: {
      font: {
        body: 'Roboto, sans-serif',
        article: 'Lora, serif',
        code: '"Fira Code", monospace',
      },
    },
  }}
/>
```

An example of the `@font-face` rules we expect to receive:

```css
@font-face {
  font-family: 'Source Sans Pro';
  font-weight: 900;
  src: url('') format('');
}

@font-face {
  font-family: 'Source Sans Pro';
  font-weight: 700;
  src: url('') format('');
}

@font-face {
  font-family: 'Source Sans Pro';
  font-weight: 600;
  src: url('') format('');
}

@font-face {
  font-family: 'Source Sans Pro';
  font-weight: 400;
  src: url('') format('');
}

@font-face {
  font-family: 'Source Sans Pro';
  font-weight: 300;
  src: url('') format('');
}

@font-face {
  font-family: Merriweather;
  font-weight: 900;
  src: url('') format('');
}

@font-face {
  font-family: Merriweather;
  font-weight: 400;
  src: url('') format('');
}

@font-face {
  font-family: Merriweather;
  font-weight: 300;
  src: url('') format('');
}

@font-face {
  font-family: Inconsolata;
  font-weight: 800;
  src: url('') format('');
}

@font-face {
  font-family: Inconsolata;
  font-weight: 400;
  src: url('') format('');
}

@font-face {
  font-family: Inconsolata;
  font-weight: 300;
  src: url('') format('');
}
```

---
_Source: https://npm.io/package/@brix-ui/theme · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
