# @feds01/mozaika

> A React component which organises an arbitrary number of elements into a neat grid.

Latest version **2.0.1** (published 2024-03-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @feds01/mozaika
pnpm add @feds01/mozaika
yarn add @feds01/mozaika
bun add @feds01/mozaika
```

## Health

**Score 35/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2024-03-30 |
| First published | 2020-04-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16 |
| Dependencies | 4 |
| Unpacked size | 7.6 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | feds01 |
| Maintainers | feds01 |

## Links

- npm: https://www.npmjs.com/package/@feds01/mozaika
- Repository: https://github.com/Maria-Mirage/mozaika
- Homepage: https://github.com/Maria-Mirage/mozaika#readme
- Issues: https://github.com/Maria-Mirage/mozaika/issues
- npm.io page: https://npm.io/package/@feds01/mozaika

## Dependencies (4)

- [deep-equal](https://npm.io/package/deep-equal.md) ^2.2.2
- [lodash.debounce](https://npm.io/package/lodash.debounce.md) 4.0.8
- [intersection-observer](https://npm.io/package/intersection-observer.md) 0.12.0
- [@juggle/resize-observer](https://npm.io/package/@juggle/resize-observer.md) ^3.3.1

## Recent versions

- 2.0.1 (latest) — 2024-03-30
- 1.3.7 — 2022-03-15
- 1.3.3 — 2021-05-19
- 1.3.0 — 2021-05-06
- 1.2.9 — 2020-10-02
- 1.2.8 — 2020-08-21
- 1.2.7 — 2020-08-11
- 1.2.6-1 — 2020-08-10
- 1.2.6 — 2020-08-10
- 1.2.5 — 2020-08-09
- 1.2.4 — 2020-08-09
- 1.2.3 — 2020-07-03
- 1.2.2 — 2020-06-30
- 1.2.1 — 2020-06-30
- 1.2.0 — 2020-06-30
- … 10 more at https://npm.io/package/@feds01/mozaika/versions

## README

# mozaika

> A React component which organises an arbitrary number of elements into a neat grid.

[![NPM](https://img.shields.io/npm/v/@feds01/mozaika.svg)](https://www.npmjs.com/package/@feds01/mozaika) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save @feds01/mozaika
```

## Usage

```jsx
import React, { Component } from 'react';

import Mozaika, { MozaikaElementProps, MozaikaStream } from 'mozaika';

type ExampleItem = {
    id: string;
    title: string;
    description: string;
};

const ChildContainer = ({ data, updateCallback, style }: MozaikaElementProps<ExampleItem>) => {
  useEffect(() => {
    updateCallback();
  }, []);

  return (
    <div style={style}>
      <h1>{data.title}</h1>
      <p>{data.description}</p>
    </div>
  );
};



export type ExampleProps = {
  data: ExampleItem[];
};

const Example = ({ data }: ExampleProps) => {
    const [stream, setStream] = useState<MozaikaStream<ExampleItem, string>>({ data, key: '' });

    return <Mozaika
      stream={stream}
      getUniqueIdFromElement={(element: ExampleItem) => element.id}
      ExplorerElement={ChildContainer}
    />;
  }
}
```

## Customise

Mozaika can be customised to a high level of degree via the component props:

| Name                 | Description                                                                                                                                                                                                                                                                                                                                                                  | Prop type      | Default Value        | Required                 |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------------- | ------------------------ |
| `adjustScroll`       | Adjust the Y-scroll position when container/window gets resized                                                                                                                                                                                                                                                                                                              | `bool`         | `true`               | `false`                  |
| `backgroundColour`   | The background colour of the gallery                                                                                                                                                                                                                                                                                                                                         | `string`       | `#0f0f10`            | `false`                  |
| `children`           | Any content or React Sub-tree that is loaded after the all the content is loaded.                                                                                                                                                                                                                                                                                            | `any`          | N/A                  | `false`                  |
| `stream`             | The data that is used to populate the items that are loaded into the gallery.                                                                                                                                                                                                                                                                                                | `[object]`     | N/A                  | `true`                   |
| `Element`            | The Component/Function Component that is used as an item in the gallery.                                                                                                                                                                                                                                                                                                     | `func\|object` | N/A                  | `true`                   |
| `ElementProps`       | Any props that should be passed to element objects when appending them into the view.                                                                                                                                                                                                                                                                                        | `object`       | N/A                  | `false`                  |
| `id`                 | The 'id' attribute of the gallery container.                                                                                                                                                                                                                                                                                                                                 | `string`       | N/A                  | `true`                   |
| `loadBatchSize`      | The number of items that is attempted to be added when the gallery attempts to append more elements<br> into the view.                                                                                                                                                                                                                                                       | `number`       | `15`                 | `false`                  |
| `loaderStrokeColour` | Colour of the provided loader                                                                                                                                                                                                                                                                                                                                                | `string`       | `hsl(0, 100%, 100%)` | `false`                  |
| `maxColumns`         | The maximum number of columns the gallery can use to display items.                                                                                                                                                                                                                                                                                                          | `number`       | `8`                  | `false`                  |
| `onNextBatch`        | Function that is invoked to load the next batch of data. This function is only<br>used in stream mode. The function should return a boolean vallue denoting whether<br>there is more data to come after the present batch or not. Mozaika will attempt<br>to load more data the next batch if the function true, and will assume the end of<br>stream was reached otherwise. | `func`         | N/A                  | `true` when `streamMode` |
| `onLayout`           | Function callback that is invoked when a layout cycle is complete. The width, height, and computed<br> styles of elements are piped into callback.                                                                                                                                                                                                                           | `func`         | N/A                  | `false`                  |
| `resetStreamKey`     | This key is used to reset a stream flow, if it changes at any point; Mozaika will assume that we begun<br>a new stream order                                                                                                                                                                                                                                                 | `any`          | `null`               | `false`                  |
| `streamMode`         | Flag to determine if we're expecting data to come in as a stream instead of a singular chunk                                                                                                                                                                                                                                                                                 | `bool`         | `false`              | `false`                  |
| `strictOrder`        | Forces layout of items to be in the exact order given by the caller. No height optimisations will be<br>carried out if 'strict' order is specified.                                                                                                                                                                                                                          | `bool`         | `false`              | `false`                  |

## License

MIT © [feds01](https://github.com/feds01)

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