# components/Breakdown (zidane-ui)

Import: `import { … } from 'zidane-ui'`. Source: [ui/src/components/Breakdown.tsx](https://github.com/Tahul/zidane/blob/main/ui/src/components/Breakdown.tsx).

## Components

### `Breakdown`

Component.

Renders parts of a whole as sorted bars, or as one split bar and a list.

```ts
function Breakdown(props: BreakdownProps): Element
```

**Parameters**

- `props` (`BreakdownProps`): [`BreakdownProps`](https://zidane.si/docs/reference/ui-components-breakdown.md#BreakdownProps).

**Returns** `Element`

**Props**

- `className?` (`string`): Extra classes on the root element.
- `format?` (`(value: number) => string`): Formats a value. Default: the number in full, up to two decimals.
- `highlight?` (`string`): The label of the part to emphasize: the others dim.
- `mode?` (`'bars' | 'stacked'`, default `'bars'`): `bars`: one bar per part. `stacked`: one split bar and a list.
- `parts` (`readonly BreakdownPart[]`): The parts, in any order. Negative values count as 0.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `title?` (`ReactNode`): A title above the bar.
- `top?` (`number`): Bars: how many of the largest parts take the accent. Default: those that make half the whole, at most 3.
- `total?` (`number`): The whole. Default: the sum of the parts. Shares are of this.
- `unit?` (`string`): The values' unit, for example `tokens` (see `withUnit`).

Source: [ui/src/components/Breakdown.tsx:143](https://github.com/Tahul/zidane/blob/main/ui/src/components/Breakdown.tsx#L143)

## Functions

### `breakdownSlices`

Function.

The parts as drawn: largest first, the parts under 3% merged into one
(past `BREAKDOWN_SHOW_ALL` parts, when there are two or more of them), each with its share of `total`
(default: the sum).

```ts
function breakdownSlices(
  parts: readonly BreakdownPart[],
  total: number | undefined,
  otherLabel: string,
): { slices: BreakdownSlice[]; total: number }
```

**Parameters**

- `parts` (`readonly BreakdownPart[]`): The parts.
- `total` (`number | undefined`): The whole.
- `otherLabel` (`string`): The merged part's label.

**Returns** `{ slices: BreakdownSlice[]; total: number }`

Source: [ui/src/components/Breakdown.tsx:75](https://github.com/Tahul/zidane/blob/main/ui/src/components/Breakdown.tsx#L75)

## Interfaces

### `BreakdownProps`

Interface.

Props for [`Breakdown`](https://zidane.si/docs/reference/ui-components-breakdown.md#Breakdown).

```ts
interface BreakdownProps
```

**Properties**

- `className?` (`string`): Extra classes on the root element.
- `format?` (`(value: number) => string`): Formats a value. Default: the number in full, up to two decimals.
- `highlight?` (`string`): The label of the part to emphasize: the others dim.
- `mode?` (`'bars' | 'stacked'`, default `'bars'`): `bars`: one bar per part. `stacked`: one split bar and a list.
- `parts` (`readonly BreakdownPart[]`): The parts, in any order. Negative values count as 0.
- `style?` (`CSSProperties`): Inline styles on the root element.
- `title?` (`ReactNode`): A title above the bar.
- `top?` (`number`): Bars: how many of the largest parts take the accent. Default: those that make half the whole, at most 3.
- `total?` (`number`): The whole. Default: the sum of the parts. Shares are of this.
- `unit?` (`string`): The values' unit, for example `tokens` (see `withUnit`).

Source: [ui/src/components/Breakdown.tsx:22](https://github.com/Tahul/zidane/blob/main/ui/src/components/Breakdown.tsx#L22)

## Types

### `BreakdownPart`

Type.

One part: its label and its value.

```ts
type BreakdownPart = readonly [label: string, value: number]
```

Source: [ui/src/components/Breakdown.tsx:19](https://github.com/Tahul/zidane/blob/main/ui/src/components/Breakdown.tsx#L19)
