@govuk-frederic/array-object-table

0.2.0 • Public • Published

ArrayObjectTable

Import

  import ArrayObjectTable from '@govuk-frederic/array-object-table';

Usage

Simple

const fields = [
  { key: 'one', heading: 'One' },
  { key: 'two', heading: 'Two' },
];
const array = [
  { one: 'test', two: 'test' },
  { one: 'test' },
  {},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title}/>;

With skipEmptyRows

const fields = [
  { key: 'one', heading: 'One' },
  { key: 'two', heading: 'Two' },
];
const array = [
  {},
  {},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows/>

With skipEmptyRows and hideWithNoValues

const fields = [
  { key: 'one', heading: 'One' },
  { key: 'two', heading: 'Two' },
];
const array = [
  {},
  {},
];
const title = ['Heading'];

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>;

With object transform and default transform

const fields = [
  { key: 'one', heading: 'One' },
  { key: 'two', heading: 'Two', transform: value => value ? value.toLowerCase() : '' },
  { key: 'three', heading: 'Three' },
  { key: 'three', heading: 'Four', transform: value => value ? value.toLowerCase() : '*' },
];
const array = [
  {one: 'One', two: 'Two'},
];
const title = ['Heading'];
const defaultTransform = value => (value || '-');

<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues defaultTransform={defaultTransform}/>

Properties

Prop Required Default Type Description
array true `````` arrayOf[object Object]
defaultTransform (value = '-') => value func
fields true `````` arrayOf[object Object]
hideWithNoValues false bool
skipEmptyRows false bool
title null node

Readme

Keywords

none

Package Sidebar

Install

npm i @govuk-frederic/array-object-table

Weekly Downloads

10

Version

0.2.0

License

MIT

Unpacked Size

81.9 kB

Total Files

18

Last publish

Collaborators

  • loque-
  • penx
  • petelockey
  • steve_sims