2.0.1 • Published 1 month ago

@feds01/mozaika v2.0.1

Weekly downloads
19
License
MIT
Repository
github
Last release
1 month ago

mozaika

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

NPM JavaScript Style Guide

Install

npm install --save @feds01/mozaika

Usage

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:

NameDescriptionProp typeDefault ValueRequired
adjustScrollAdjust the Y-scroll position when container/window gets resizedbooltruefalse
backgroundColourThe background colour of the gallerystring#0f0f10false
childrenAny content or React Sub-tree that is loaded after the all the content is loaded.anyN/Afalse
streamThe data that is used to populate the items that are loaded into the gallery.[object]N/Atrue
ElementThe Component/Function Component that is used as an item in the gallery.func\|objectN/Atrue
ElementPropsAny props that should be passed to element objects when appending them into the view.objectN/Afalse
idThe 'id' attribute of the gallery container.stringN/Atrue
loadBatchSizeThe number of items that is attempted to be added when the gallery attempts to append more elements into the view.number15false
loaderStrokeColourColour of the provided loaderstringhsl(0, 100%, 100%)false
maxColumnsThe maximum number of columns the gallery can use to display items.number8false
onNextBatchFunction that is invoked to load the next batch of data. This function is onlyused in stream mode. The function should return a boolean vallue denoting whetherthere is more data to come after the present batch or not. Mozaika will attemptto load more data the next batch if the function true, and will assume the end ofstream was reached otherwise.funcN/Atrue when streamMode
onLayoutFunction callback that is invoked when a layout cycle is complete. The width, height, and computed styles of elements are piped into callback.funcN/Afalse
resetStreamKeyThis key is used to reset a stream flow, if it changes at any point; Mozaika will assume that we beguna new stream orderanynullfalse
streamModeFlag to determine if we're expecting data to come in as a stream instead of a singular chunkboolfalsefalse
strictOrderForces layout of items to be in the exact order given by the caller. No height optimisations will becarried out if 'strict' order is specified.boolfalsefalse

License

MIT © feds01

2.0.1

1 month ago

2.0.0

1 month ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.9

4 years ago

1.2.8

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.6-1

4 years ago

1.2.5

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.2.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago