# @microsoft/arbutus.style-utilities

> Collection of utilities for styling with Griffel.

Latest version **1.0.4** (published 2023-11-29) · 0 weekly downloads

## Install

```sh
npm install @microsoft/arbutus.style-utilities
pnpm add @microsoft/arbutus.style-utilities
yarn add @microsoft/arbutus.style-utilities
bun add @microsoft/arbutus.style-utilities
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-11-29 |
| First published | 2022-09-22 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jinjun-ms, riacarmin |

## Links

- npm: https://www.npmjs.com/package/@microsoft/arbutus.style-utilities
- npm.io page: https://npm.io/package/@microsoft/arbutus.style-utilities

## Dependencies (1)

- [@griffel/react](https://npm.io/package/@griffel/react.md) ^1.5.18

## Recent versions

- 1.0.4 (latest) — 2023-11-29
- 1.0.3 — 2023-11-09
- 1.0.2 — 2023-06-05
- 1.0.1 — 2023-05-25
- 1.0.0 — 2023-03-16
- 0.0.2 — 2023-01-16
- 0.0.1 — 2022-09-22

## README

# Style: Utilities

**Collection of utilities for styling with Griffel.**

## Get Started

```sh
npm i @microsoft/arbutus.style-utilities
```

## Usage

### mapToStyles

**mapToStyles is designed to help generating styles variants. It generates Griffel classes from a map of values.**

```tsx
import { mapToStyles } from '@microsoft/arbutus.style-utilities';
```

#### Parameters

- `map` An object, where the key will become a class name, and the value will be passed to the `styleFunction`.
- `styleFunction` A function that takes the value from the `map` and returns a `GriffelStyle`.

#### Returns

An object with keys from the map and values as GriffelStyle returned by the `styleFunction`.

#### Example

##### Step 1: Create a map of variants for your component.

```tsx
type ColorValue = string;
const textColors = { primary: 'red', secondary: 'blue' };
const textStyleFunction = (color: ColorValue) => ({
  color,
  '&:visited': { color },
});
const textColorClasses = mapToStyles<ColorValue, typeof textColors>(
  textColors,
  textStyleFunction,
);
// Output
// {
//   primary: {
//     color: 'red',
//     '&:visited: { color: 'red'}}
//   },
//   secondary: {
//     color: 'blue',
//     '&:visited: { color: 'blue'}}
//   },
// }
```

##### Step 2: Pass to the `makeStyles()` function.

---
_Source: https://npm.io/package/@microsoft/arbutus.style-utilities · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
