npm package: @onbeam/business-styled-system
Description: ## Table of Contents
Latest version: 1.17.1

# @onbeam/business-styled-system

## Table of Contents

- [@onbeam/business-styled-system](#onbeambusiness-styled-system)
  - [Table of Contents](#table-of-contents)
  - [Installation](#installation)
  - [PandaCSS](#pandacss)
    - [Config](#config)
    - [PostCSS](#postcss)
    - [CSS](#css)
    - [Scripts](#scripts)
  - [Examples](#examples)
    - [Example 1: Basic usage of css and cx](#example-1-basic-usage-of-css-and-cx)
    - [Example 2: Basic usage of a pattern](#example-2-basic-usage-of-a-pattern)
    - [Example 3: Getting token values](#example-3-getting-token-values)

## Installation

Install the packages using your preferred package manager:

```bash
pnpm add @onbeam/business-styled-system@latest
pnpm add @pandacss/dev@latest --save-dev
```

To keep all `@onbeam` packages updated, you can use the CLI:

```bash
npx @onbeam/cli update -d [directory]
```

## PandaCSS

Due to the component styles building just-in-time, you need to install and configure PandaCSS. This means that only the styles for the components you use will be generated, nothing more. When you decide to utilize PandaCSS in your own project, you will be able to use all design tokens and PandaCSS will combine the UI styles with your project styles before compiling the output.

### Config

Create a `panda.config.ts` file in the root of your application and paste this snippet in there:

```ts
import { defineBeamUiConfig } from "@onbeam/business-styled-system/config";

export default defineBeamUiConfig({
  include: [
    "./node_modules/@onbeam/business-ui/dist/panda.buildinfo.json", // Only add this when you're using the @onbeam/business-ui package
    // TODO: Configure this line to target your own files that utilize the component library and PandaCSS
    "./src/**/*.{ts,tsx}",
  ],
});
```

### PostCSS

Run `npx panda init --postcss`. This will create a `postcss.config.cjs` file in the root of your application with the following code:

```ts
module.exports = {
  plugins: {
    "@pandacss/dev/postcss": {},
  },
};
```

### CSS

To enable the styles, create a global CSS file, for example named "`globals.css`" and paste the following snippet in there:

```css
/* When adding libraries that could overwrite our styles, make sure to use css layers: */
/* https://panda-css.com/docs/overview/faq#how-can-i-prevent-other-libraries-from-overriding-my-styles */
@layer reset, base, tokens, recipes, utilities;

body {
  font-family: var(--beam-business-fonts-main);
  color: var(--beam-business-colors-mono-primaryBg);
}

/* TODO: These are all fonts used in the @onbeam/business-ui components. Add all your used fonts here */
@font-face {
  font-family: "Beam Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 300;
  src: url("../node_modules/@onbeam/business-ui/dist/fonts/BeamSans-Book.ttf");
}

@font-face {
  font-family: "Beam Sans";
  font-style: normal;
  font-display: swap;
  font-weight: 700;
  src: url("../node_modules/@onbeam/business-ui/dist/fonts/BeamSans-Bold.ttf");
}
```

In the root of your project code, for example `layout.tsx` or `_app.tsx`, import your created css file:

```ts
import "./globals.css";
```

### Scripts

To build the PandaCSS code, add the `panda codegen` command to your `package.json`'s build script. For example:

```json
"scripts": {
  "build": "panda codegen && next build",
},
```

## Examples

### Example 1: Basic usage of css and cx

```tsx
import { cx, css } from "@onbeam/business-styled-system/css";

const Component = ({ className }) => (
  <div
    className={cx(
      css({ w: "full", mx: "4", background: "mono.1000" }),
      className
    )}
  >
    ...
  </div>
);
```

### Example 2: Basic usage of a pattern

```tsx
import { flex } from "@onbeam/business-styled-system/patterns";

const Component = ({ className }) => (
  <div className={flex({ align: "center" })}>...</div>
);
```

### Example 3: Getting token values

```tsx
import { token } from "@onbeam/business-styled-system/tokens";

const Component = ({ className }) => (
  <SomeIcon fill={token("colors.mono.300")} />
);
```

---

**That's it! Happy coding! 🌈**