-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/import new components #52
Changes from all commits
d8eb971
08b816e
7552076
01b6aef
c889f4d
262165e
befce0a
fdededa
ff486ab
df67312
4737b02
488fb4d
6bec7d3
ef8d936
43c1286
5b63ae2
16c2811
a4e5ec7
f77fe9e
15c9a85
edba0f9
0513249
8c9ed6f
eab9831
4d1285e
6743e4b
883516c
ed31d1c
f5301cc
cbd44a9
78dd0b7
5569713
e10e441
d692945
a988733
6d9684f
f952583
0ad6002
c558fc4
a113349
2d97081
ed53cb4
b3498cc
e0ef0df
9a45366
749101b
51b732b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
ArrayObjectTable | ||
================ | ||
|
||
### Import | ||
```js | ||
import ArrayObjectTable from '@govuk-frederic/array-object-table'; | ||
``` | ||
<!-- STORY --> | ||
|
||
### Usage | ||
|
||
Simple | ||
```jsx | ||
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 | ||
```jsx | ||
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 | ||
```jsx | ||
const fields = [ | ||
{ key: 'one', heading: 'One' }, | ||
{ key: 'two', heading: 'Two' }, | ||
]; | ||
const array = [ | ||
{}, | ||
{}, | ||
]; | ||
const title = ['Heading']; | ||
|
||
<ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>; | ||
``` | ||
|
||
### Properties | ||
Prop | Required | Default | Type | Description | ||
:--- | :------- | :------ | :--- | :---------- | ||
`array` | | ```[]``` | arrayOf[object Object] | | ||
`fields` | | ```[]``` | arrayOf[object Object] | | ||
`hideWithNoValues` | | ```false``` | bool | | ||
`skipEmptyRows` | | ```false``` | bool | | ||
`title` | | `````` | node | | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"name": "@govuk-frederic/array-object-table", | ||
"version": "0.0.1", | ||
"dependencies": { | ||
"@govuk-frederic/table": "^0.0.3", | ||
"@govuk-frederic/utils": "^0.0.1" | ||
}, | ||
"devDependencies": { | ||
"@govuk-react/storybook-components": "^0.2.4", | ||
"@storybook/addon-knobs": "^3.4.2" | ||
}, | ||
"peerDependencies": { | ||
"emotion": ">=9", | ||
"prop-types": ">=15", | ||
"react": ">=16.2.0", | ||
"react-emotion": ">=9" | ||
}, | ||
"scripts": { | ||
"build": "npm run build:lib && npm run build:es", | ||
"build:lib": "rimraf lib && babel src -d lib --source-maps", | ||
"build:es": "rimraf es && cross-env BABEL_ENV=es babel src -d es --source-maps", | ||
"docs": "doc-component ./lib/index.js ./README.md" | ||
}, | ||
"main": "lib/index.js", | ||
"module": "es/index.js", | ||
"author": "Gavin Orland", | ||
"license": "MIT", | ||
"homepage": "https://github.com/stevesims/govuk-frederic#readme", | ||
"description": "govuk-frederic: Frederic project specific components.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the description for this package file not be about what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, ideally - this is something that needs doing for all Fred components (and |
||
"private": false, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, { Fragment } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Table } from 'govuk-frederic'; | ||
|
||
import { rowsFromArray, titlesFromFields } from '@govuk-frederic/utils'; | ||
|
||
/** | ||
* | ||
* ### Usage | ||
* | ||
* Simple | ||
* ```jsx | ||
* 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 | ||
* ```jsx | ||
* 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 | ||
* ```jsx | ||
* const fields = [ | ||
* { key: 'one', heading: 'One' }, | ||
* { key: 'two', heading: 'Two' }, | ||
* ]; | ||
* const array = [ | ||
* {}, | ||
* {}, | ||
* ]; | ||
* const title = ['Heading']; | ||
* | ||
* <ArrayObjectTable fields={fields} array={array} title={title} skipEmptyRows hideWithNoValues/>; | ||
* ``` | ||
* */ | ||
const ArrayObjectTable = ({ fields = [], array = [], hideWithNoValues = false, skipEmptyRows = false, title, ...props }) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be better/nicer to use |
||
let rows = rowsFromArray(array, fields, skipEmptyRows); | ||
if (!rows.length && !hideWithNoValues) { | ||
rows = rowsFromArray([{}], fields, false); | ||
} | ||
return rows.length ? | ||
<Fragment> | ||
{title ? title : null} | ||
<Table rows={rows} titles={titlesFromFields(fields)} {...props}/> | ||
</Fragment> | ||
: | ||
null; | ||
}; | ||
|
||
ArrayObjectTable.propTypes = { | ||
fields: PropTypes.arrayOf(PropTypes.shape({ | ||
key: PropTypes.string.isRequired, | ||
heading: PropTypes.string.isRequired, | ||
transform: PropTypes.func, | ||
})), | ||
array: PropTypes.arrayOf(PropTypes.object), | ||
hideWithNoValues: PropTypes.bool, | ||
skipEmptyRows: PropTypes.bool, | ||
title: PropTypes.node, | ||
}; | ||
|
||
export default ArrayObjectTable; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this really right?
i.e.
govuk-react
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if that is right, actually, but that's how it is for all the components in Frederic and that's where that package is. I'm not sure if there should be a duplicate of it in Frederic or if it should be elsewhere.