UNPKG

64.1 kBMarkdownView Raw
1# Rendition
2
3[![npm version](https://badge.fury.io/js/rendition.svg)](http://badge.fury.io/js/rendition)
4[![Dependency Status](https://img.shields.io/david/balena-io-modules/rendition.svg)](https://david-dm.org/balena-io-modules/rendition)
5[![style: styled-components](https://img.shields.io/badge/style-%F0%9F%92%85%20styled--components-orange.svg?colorB=daa357&colorA=db748e)](https://github.com/styled-components/styled-components)
6
7A library of UI components, built using [React][react], [recompose][recompose], [styled-components][styled-components] and [styled-system][styled-system].
8
9## Table of Contents
10
11* [Installation](#installation)
12* [Usage](#usage)
13* [Components](#components)
14* [Development](#development)
15* [Testing](#testing)
16* [Upgrading](#testing)
17
18## Installation
19
20```
21npm install --save rendition
22```
23
24## Usage
25
26Wrap your application in the `Provider` component and start using components!
27
28```jsx
29import React from 'react'
30import ReactDOM from 'react-dom'
31import { Button, Box, Provider } from 'rendition';
32
33ReactDOM.render(
34 <Provider>
35 <Box my={3} mx={['auto', 15]}>
36 <Button primary emphasized>Click me</Button>
37 </Box>
38 </Provider>,
39 document.getElementById('root')
40);
41```
42
43## Components
44
45For an interactive demo of all components, see https://balena-io-modules.github.io/rendition
46
47- [Accordion](#accordion)
48- [Alert](#alert)
49- [ArcSlider](#arcslider)
50- [Badge](#badge)
51- [Banner](#banner)
52- [Box](#box)
53- [Button](#button)
54- [ButtonGroup](#buttongroup)
55- [Card](#card)
56- [Checkbox](#checkbox)
57- [Container](#container)
58- [Copy](#copy)
59- [Divider](#divider)
60- [DropDownButton](#dropdownbutton)
61- [Filters](#filters)
62- [Fixed](#fixed)
63- [Flex](#flex)
64- [Heading](#heading)
65- [HighlightedName](#highlightedname)
66- [Img](#img)
67- [Input](#input)
68- [Link](#link)
69- [List](#list)
70- [Modal](#modal)
71- [Navbar](#navbar)
72- [Notifications](#notifications)
73- [Pager](#pager)
74- [ProgressBar](#progressbar)
75- [RadioButton](#radiobutton)
76- [RadioButtonGroup](#radiobuttongroup)
77- [Search](#search)
78- [Select](#select)
79- [Spinner](#spinner)
80- [Steps](#steps)
81- [Table](#table)
82- [Tabs](#tabs)
83- [Tag](#tag)
84- [Terminal](#terminal)
85- [TextWithCopy](#textwithcopy)
86- [Textarea](#textarea)
87- [Tooltips](#tooltips)
88- [Txt](#txt)
89- [Markdown](#markdown)
90- [MarkdownEditor](#markdowneditor)
91- [Mermaid](#mermaid)
92- [Form](#form)
93
94### Accordion
95
96[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Accordion/story.js)
97
98#### Props
99
100| Name | Type | Default | Required | Description |
101| ------ | ------ | --------- | ---------- | ------------- |
102| `items` | `[{label: string \| node; panel: string \| node }]` | - | true | renders label as title and panel as body of accordion |
103
104### Alert
105
106[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Alert/story.js)
107
108#### Props
109
110| Name | Type | Default | Required | Description |
111| ------ | ------ | --------- | ---------- | ------------- |
112| `primary` | `boolean` | - | - | If true, use the `primary` theme color |
113| `secondary` | `boolean` | - | - | If true, use the `secondary` theme color |
114| `tertiary` | `boolean` | - | - | If true, use the `tertiary` theme color |
115| `quarternary` | `boolean` | - | - | If true, use the `quarternary` theme color |
116| `danger` | `boolean` | - | - | If true, use the `danger` theme color |
117| `warning` | `boolean` | - | - | If true, use the `warning` theme color |
118| `success` | `boolean` | - | - | If true, use the `success` theme color |
119| `info` | `boolean` | - | - | If true, use the `info` theme color |
120| `emphasized` | `boolean` | - | - | If true, use the use bolder colors and a larger size |
121| `plaintext` | `boolean` | - | - | If true, the alert will be rendered without a border or a background |
122| `prefix` | <code>JSX.Element &#124; string &#124; false</code> | - | - | Set a prefix on the alert message, if this prop is set to false, the default prefix will not be shown |
123| `onDismiss` | `() => void` | - | - | A function that is called when dismissing an alert
124
125### ArcSlider
126
127A slider input that is displayed as an arc. This component will scale in size to
128fit it's container. A label can be added by placing a child element inside this
129component.
130
131[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/ArcSlider/story.js)
132
133#### Props
134
135| Name | Type | Default | Required | Description |
136| --------------|-----------|-----------|------------|-------------------------------------------------------------- |
137| `onValueChange` | `(value: number) => void` | - | - | A function that is called when the slider value changes, this will always be a value between 0 and 1 |
138| `value` | `number` | - | - | A number between 0 and 1 that represents the progress |
139| `fillColor` | `string` | - | - | A CSS color string to use for the color of the "filled" part of the arc |
140| `background` | `string` | - | - | A CSS color string to use for the color of the arc track |
141
142#### Inheritance
143
144The properties of the [`Box`](#box) component are also available.
145### Badge
146
147Badges should be used to present data that is not generated by the user (otherwise, tags should be used).
148The badge can use any of the pre-defined shades, from which the background and text color are generated.
149
150[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Badge/story.js)
151
152#### Props
153
154| Name | Type | Default | Required | Description |
155| ------ | ------ | --------- | ---------- | ------------- |
156| `shade` | `number` | - | - | The index for one of the pre-determined shades for the badge |
157| `children` | `string` | - | ✓ | The text to display inside the badge |
158
159### Banner
160
161[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Banner/story.js)
162
163#### Props
164
165| Name | Type | Default | Required | Description |
166| ------ | ------ | --------- | ---------- | ------------- |
167| `backgroundImage`| `string`| - | - | The path to an image that should be displayed in the background |
168| `minHeight`| `string`| - | - | The minimum height of the `Banner`, eg `180px` |
169
170
171### Box
172
173Displays a block level element.
174
175The basic building block of a rendition application.
176
177[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Grid/Box.js)
178
179#### Props
180
181| Name | Type | Default | Required | Description |
182| ------ | ------ | --------- | ---------- | ------------- |
183| `flex` | <code>string &#124; string[]</code> | - | - | Sets `flex`, if the value is an array, sets a responsive style corresponding to the theme's breakpoints
184| `order` | <code>number &#124; string &#124; Array&lt;number &#124; string&gt;</code> | - | - | Sets `order`, if the value is an array, sets a responsive style corresponding to the theme's breakpoints
185
186
187### Button
188
189[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Button/story.js)
190
191#### Props
192
193| Name | Type | Default | Required | Description |
194| ------ | ------ | --------- | ---------- | ------------- |
195| `primary` | `boolean` | - | - | If true, use the `primary` theme color |
196| `secondary` | `boolean` | - | - | If true, use the `secondary` theme color |
197| `tertiary` | `boolean` | - | - | If true, use the `tertiary` theme color |
198| `quarternary` | `boolean` | - | - | If true, use the `quarternary` theme color |
199| `danger` | `boolean` | - | - | If true, use the `danger` theme color |
200| `warning` | `boolean` | - | - | If true, use the `warning` theme color |
201| `success` | `boolean` | - | - | If true, use the `success` theme color |
202| `info` | `boolean` | - | - | If true, use the `info` theme color |
203| `light` | `boolean` | - | - | If true, use white background and default text color |
204| `disabled` | `boolean` | - | - | If true, disabled the button |
205| `outline` | `boolean` | - | - | If true, the button will have a transparent background, and the border and text color will match |
206| `plain` | `boolean` | - | - | If true, render the button without padding, background or border |
207| `underline` | `boolean` | - | - | Similar to the `plaintext` prop, but displays a line underneath the button text |
208| `icon` | `JSX.Element` | - | - | Optionally provide a JSX element that will be rendered before the text inside the button |
209| `compact` | `boolean[]` | [false] | - | Optionally renders the label according to the value inside the array for each breakpoint |
210
211### ButtonGroup
212
213Wrapper for buttons to make them stick together.
214
215[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/ButtonGroup/story.js)
216### Card
217
218Section containing content and actions on the same topic.
219
220[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Card/story.js)
221
222#### Props
223
224| Name | Type | Default | Required | Description |
225| -------|--------|-----------|------------|-------------- |
226| `title` | `string` | - | - | The title of the card |
227| `cta` | `JSX.Element` | - | - | React component added to the header |
228| `rows` | `JSX.Element[]` | - | - | Subsections separated by a horizontal separator |
229| `minHeight` | `string` | `auto` | - | CSS minHeight property |
230| `small` | `boolean` | - | - | If true, reduces the scale of the card |
231| `children` | `JSX.Element` | - | - | Any content that is internally wrapped in a Box |
232
233### Checkbox
234
235[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Checkbox/story.js)
236
237#### Props
238
239`Checkbox` implements all properties from [Grommet's CheckBox component](https://v2.grommet.io/checkbox)
240
241### Container
242
243A padded container with a responsive width.
244
245[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Container/story.js)
246
247
248### Copy
249
250Wrapper that adds a "copy to clipboard" button to any component and copies the passed content to the user's clipboard.
251
252[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Copy/story.js)
253
254#### Props
255
256| Name | Type | Default | Required | Description |
257| ------ | ------ | --------- | ---------- | ------------- |
258| `content` | `string` | - | ✓ | The value that should be copied to the clipboard
259| `show` | <code>'hover' &#124; 'always'</code> | - | - | Optionally show the copy button on hover or always show the button
260| `onClick` | `(content: string) => void` | - | - | onClick handler, useful if you wish to do other actions after content was copied
261| `children` | `React.ReactNode` | - | - | The content next to which the clipboard button should be shown
262
263### Divider
264
265A styled horizontal rule.
266
267[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Divider/story.js)
268
269#### Props
270
271| Name | Type | Default | Required | Description |
272| -------|--------|-----------|------------|-------------- |
273| `height` | `number` | `0.5` | - | The height of the divider |
274| `color` | `string` | `quartenary.main` | - | The color of the divider |
275| `type` | `'solid' | 'dashed'` | `'solid` | - | The type of divider |
276| `children` | `string` | - | - | Textual explanation to go in the middle of the divider |
277
278
279### DropDownButton
280
281Displays a button with an attached dropdown list, `children` of the component
282are rendered inside a dropdown list.
283
284[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/DropDownButton/story.js)
285
286#### Props
287
288| Name | Type | Default | Required | Description |
289| ------------- | ------ | --------- | ---------- | ------------- |
290| `primary` | `boolean` | - | - | If true, use the `primary` theme color |
291| `secondary` | `boolean` | - | - | If true, use the `secondary` theme color |
292| `tertiary` | `boolean` | - | - | If true, use the `tertiary` theme color |
293| `quarternary` | `boolean` | - | - | If true, use the `quarternary` theme color |
294| `danger` | `boolean` | - | - | If true, use the `danger` theme color |
295| `warning` | `boolean` | - | - | If true, use the `warning` theme color |
296| `success` | `boolean` | - | - | If true, use the `success` theme color |
297| `info` | `boolean` | - | - | If true, use the `info` theme color |
298| `emphasized` | `boolean` | - | - | If true, use a larger size |
299| `square` | `boolean` | - | - | If true, render the button with equal length width and height |
300| `disabled` | `boolean` | - | - | If true, disabled the button |
301| `label` | `JSX.Element` | - | - | Optionally provide a JSX element that will be displayed inside the main button |
302| `border` | `boolean` | - | - | If true, place a border between each item in the dropdown |
303| `joined` | `boolean` | - | - | If true, render the component as a single button instead of two |
304| `noListFormat` | `boolean` | - | - | If true, render children as a single JSX element instead of iterating over each of them |
305| `alignRight` | `boolean` | - | - | If true, put the dropdown list on the right |
306| `listMaxHeight` | `string \| number` | - | - | If setted, it defines the maximum height of the dropdown list |
307| `compact` | `boolean[]` | [false] | - | Optionally renders the label according to the value inside the array for each breakpoint |
308
309### Filters
310
311A component that can be used for generating filters in the form of [json schema](http://json-schema.org/) objects and saving sets of filters as "views".
312The filters created by this component can be used to filter a collection of
313objects using the `SchemaSieve` object.
314
315[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Filters/story.js)
316
317#### Schema
318
319The `Filters` component requires a `schema` property which should be a json
320schema that defines the shape of the objects you want to filter. For example if
321you want to filter on a collection that looks like this:
322
323```
324[
325 {
326 name: 'Bulbasaur',
327 caught: true,
328 },
329 {
330 name: 'Pikachu',
331 caught: true,
332 },
333 {
334 name: 'Dratini',
335 caught: false,
336 }
337]
338```
339
340You would define a schema that looks like this:
341
342```
343{
344 type: 'object',
345 properties: {
346 name: {
347 title: 'Name',
348 type: 'string'
349 },
350 caught: {
351 title: 'Has been caught',
352 type: 'boolean'
353 }
354 }
355}
356```
357
358If you provide a `title` property, it will be used to label the field when
359filtering, otherwise the field name will be used.
360
361##### Views
362
363Views represent a set of filters, along with an id and a name. This is a useful
364feature for storing a set filters and loading it again at a later point.
365A view can optionally have a `scope` property, which will correspond to the
366`slug` of a view scope, if you have provided one in the `Filters` property
367`viewScopes` property. Scopes allow you to easily add an extra layer of
368granularity/grouping to views that are generated. If you provide view scopes,
369the user can select a scope when creating a new view.
370
371A view scope has the following properties:
372
373| Name | Type | Description |
374| ------------- | --------- | ---------------------------------------------------- |
375| slug | `string` | A unique identifier for the scope |
376| name | `string` | A descriptive name for the scope |
377| label | `string` | An optional label to use for this scope when creating a view |
378
379A view has the following properties:
380
381| Name | Type | Description |
382| ------------- | --------- | ---------------------------------------------------- |
383| id | `string` | A unique identifier for the view |
384| name | `string` | A descriptive name for the view |
385| filters | `string` | An array of json schemas |
386| scope | <code>string &#124; null</code> | The slug of a view scope, or `null` if now scopes are provided |
387
388#### Props
389
390| Name | Type | Default | Required | Description |
391| ------ | ------ | --------- | ---------- | ------------- |
392| `schema` | `object` | - | ✓ | A json schema describing the shape of the objects you want to filter |
393| `disabled` | `boolean` | - | - | If true, disable the entire `Filters` interface
394| `filters` | `object[]` | - | - | An array of json schemas to be displayed as the currently selected filters, typically used when loading when loading filters from storage |
395| `views` | `object[]` | - | - | An array of views, as described above, typically used when loading when loading views from storage |
396| `viewScopes` | `object[]` | - | - | An array of view scopes, as described above |
397| `onFiltersUpdate` | `(filters: object[]) => void` | - | - | A function that is called when filters are updated |
398| `onViewsUpdate` | `(views: object[]) => void` | - | - | A function that is called when views are updated |
399| `addFilterButtonProps` | `object` | - | - | Properties that are passed to the "Add filter" button, these are the same props used for the [`Button`](#button) component |
400| `viewsMenuButtonProps` | `object` | - | - | Properties that are passed to the "Views" button, these are the same props used for the [`DropDownButton`](#dropdownbutton) component |
401| `renderMode` | <code>string &#124; string[]</code> | - | - | Controls which parts of the `Filters` interface are displayed. One of `all`, `add`, `search`, `views`, `summary`, or an array containing any of these values |
402| `dark` | `boolean` | - | - | If true, Set the `Filters` component against a dark background |
403| `compact` | `boolean[]` | - | - | Accept a boolean for each rendition breakpoint. If true remove `Filters` labels |
404### Fixed
405
406Displays an element with a [`fixed`](https://developer.mozilla.org/en-US/docs/Web/CSS/position#fixed) position.
407
408[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Fixed/story.js)
409
410#### Props
411
412| Name | Type | Default | Required | Description |
413| ------ | ------ | --------- | ---------- | ------------- |
414| `top` | <code>boolean &#124; ResponsiveStyle</code> | - | - | Sets the distance to the top of the containing block. If true, sets the value to zero
415| `right` | <code>boolean &#124; ResponsiveStyle</code> | - | - | Sets the distance to the right of the containing block. If true, sets the value to zero
416| `bottom` | <code>boolean &#124; ResponsiveStyle</code> | - | - | Sets the distance to the bottom of the containing block. If true, sets the value to zero
417| `left` | <code>boolean &#124; ResponsiveStyle</code> | - | - | Sets the distance to the left of the containing block. If true, sets the value to zero
418| `z` | `ResponsiveStyle` | - | - | Sets the z-index of the component |
419### Flex
420
421Displays an element using [flexbox](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Flexible_Box_Layout/Basic_Concepts_of_Flexbox).
422
423[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Grid/Flex.js)
424
425#### Props
426
427| Name | Type | Default | Required | Description |
428| ------ | ------ | --------- | ---------- | ------------- |
429| `alignItems` | <code>string &#124; string[]</code> | - | - | Sets `align-items`, if the value is an array, sets a responsive style corresponding to the theme's breakpoints
430| `justifyContent` | <code>string &#124; string[]</code> | - | - | Sets `justify-content`, if the value is an array, sets a responsive style corresponding to the theme's breakpoints
431| `flexDirection` | <code>string &#124; string[]</code> | - | - | Sets `flex-direction`, if the value is an array, sets a responsive style corresponding to the theme's breakpoints
432| `flexWrap` | <code>string &#124; string[]</code> | - | - | Sets `flex-wrap` css property
433### Heading
434
435A component that displays a heading. By default an `<h3>` tag is used. The exact
436heading type can be specifed by appending the element name to the component, for
437example `<Heading.h1>`, `<Heading.h2>`, `<Heading.h3>` etc.
438
439[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Heading/story.js)
440
441### HighlightedName
442
443By default, the background color of a `HighlightedName` component is generated
444automatically from its `children` (which must be a string), though this can be overridden.
445
446[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/HighlightedName/story.js)
447
448#### Props
449
450| Name | Type | Default | Required | Description |
451|------------|----------|-------------------------------------|----------|-----------------------------------------------------|
452| `children` | `string` | - | ✓ | The text to display inside the highlighted name |
453| `bg` | `string` | autogenerated from `children` | - | If passed, it will be used as the background color of the component |
454| `color` | `string` | `theme.colors.text.main` or `white` | - | If passed, it will be used as the text color of the component |
455
456### Img
457
458Displays an image.
459
460[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Img/story.js)
461
462#### Inheritance
463
464The attributes of an [`<img>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/img) element are also available.
465
466### Input
467
468[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Input/story.js)
469
470#### Props
471
472| Name | Type | Default | Required | Description |
473| ------ | ------ | --------- | ---------- | ------------- |
474| `emphasized` | `boolean` | - | - | If true, use a larger size |
475| `monospace` | `boolean` | - | - | If true, render text in a monospace font |
476| `onChange` | `(e: Event) => void` | - | - | A function that is called when the input value changes |
477
478#### Inheritance
479
480The attributes of an [`<input>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input) element are also available.
481
482
483
484### Link
485
486Displays an anchor link.
487
488[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Link/story.js)
489
490#### Props
491
492| Name | Type | Default | Required | Description |
493| ------ | ------ | --------- | ---------- | ------------- |
494| `blank` | `boolean` | - | - | If true, open the link in a new tab |
495| `disabled` | `boolean` | - | - | If true, disable the link |
496
497#### Inheritance
498
499The attributes of an [`<a>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a) element are also available.
500
501
502### List
503
504[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/List/story.js)
505
506#### Props
507
508| Name | Type | Default | Required | Description |
509| ------ | ------ | --------- | ---------- | ------------- |
510| `children` | `ReactNode` | - | - | Each child represents a list item |
511| `ordered` | `boolean` | - | - | If true, render an ordered (numbered) list, otherwise render a bullet list |
512
513
514
515
516### Modal
517
518Displays a centrally position modal overlay. Children passed to this component
519are rendered inside the modal.
520
521[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Modal/story.js)
522
523#### Props
524
525| Name | Type | Default | Required | Description |
526| --------------|-----------|-----------|------------|----------------------------------------------------- |
527| `title` | `string`
528 | - | - | A title to display at the top of the Modal, only displayed if the `titleElement` property is not used |
529| `titleElement` | <code>string &#124; JSX.Element</code> | - | - | A string or JSX element to display at the top of the modal |
530| `titleDetails` | <code>string &#124; JSX.Element</code> | - | - | A string or JSX element to display underneath the modal's `title`, only displayed if the `titleElement` property is not used and a `title` property is provided |
531| `action` | <code>string &#124; JSX.Element</code> | - | - | A string or JSX element to display in the primary modal button, defaults to 'OK' |
532| `cancel` | `() => any` | - | - | A function that is called if the modal is dismissed |
533| `done` | `() => any` | - | ✓ | A function that is called if the primary modal button is clicked |
534| `primaryButtonProps` | `object` | - | - | Properties that are passed to the primary button, these are the same props used for the [`Button`](#button) component |
535| `secondaryButtonProps` | `object` | - | - | If provided, will cause a secondary button to appear on the modal. These properties that are passed to that button, these are the same props used for the [`Button`](#button) component |
536| `cancelButtonProps` | `object` | - | - | Properties that are passed to the cancel button, these are the same props used for the [`Button`](#button) component |
537| style | `object` | - | - | Apply custom styles to Modal, the object is applied as a [`style` attribute](https://reactjs.org/docs/dom-elements.html#style) |
538### Navbar
539
540A component used to render a navigation bar.
541
542[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Navbar/story.js)
543
544#### Props
545
546| Name | Type | Default | Required | Description |
547| ------ | ------ | --------- | ---------- | ------------- |
548| `brand` | `JSX.Element` | - | ✓ | A JSX element used as the main branding in the navbar |
549
550### Notifications
551
552To use this component, you first need to add the `NotificationsContainer` component at the root of your React application.
553You can then programatically add or remove notifications using the `notifications` module. For example:
554
555```
556import {notifications} from 'rendition';
557
558const notificationId = notifications.addNotification("Hi there");
559notifications.removeNotification(notificationId);
560```
561
562[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Notifications/story.js)
563
564#### Props
565
566The `NotificationsContainer` component doesn't take any props. You do all customizations on a per-notification basis.
567The `addNotification` function can take either a valid React node component, or the following options:
568
569| Name | Type | Default | Required | Description |
570| ------ | ------ | --------- | ---------- | ------------- |
571| `content` | `React.ReactNode` | - | ✓ | The content you wish to display in the notification |
572| `duration`| `number` | 6000 | - | The duration this notification will be shown for in `ms`. `0` means it will never close automatically |
573| `id` | `number` | (random) | - | A custom id for the notification |
574| `baselineHeight` | `number` | Normal text line height | - | The base height of the content, used to align the dismiss button correctly |
575| `onDismiss` | `() => void` | | - | A callback function that is triggered when the "dismiss" button is clicked |
576### Pager
577
578Displays a pager widget.
579
580[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Pager/story.js)
581
582#### Props
583
584| Name | Type | Default | Required | Description |
585| ------ | ------ | --------- | ---------- | ------------- |
586| `totalItems` | `number` | - | - | The total number of items to split into pages |
587| `itemsPerPage`| `number` | - | - | The number of items on each page |
588| `page` | `number` | - | - | The current page (zero-indexed) |
589| `nextPage` | `() => void` | - | - | Callback invoked when the "next page" button is clicked
590| `prevPage` | `() => void` | - | - | Callback invoked when the "previous page" button is clicked
591
592### ProgressBar
593
594Displays a progress bar using a value representing a percentage.
595
596[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/ProgressBar/story.js)
597
598#### Props
599
600| Name | Type | Default | Required | Description |
601| --------------|-----------|-----------|------------|-------------------------------------------------------------- |
602| `primary` | `boolean` | `true` | - | If true, use the `primary` theme color |
603| `secondary` | `boolean` | - | - | If true, use the `secondary` theme color |
604| `tertiary` | `boolean` | - | - | If true, use the `tertiary` theme color |
605| `quarternary` | `boolean` | - | - | If true, use the `quarternary` theme color |
606| `danger` | `boolean` | - | - | If true, use the `danger` theme color |
607| `warning` | `boolean` | - | - | If true, use the `warning` theme color |
608| `success` | `boolean` | - | - | If true, use the `success` theme color |
609| `info` | `boolean` | - | - | If true, use the `info` theme color |
610| `emphasized` | `boolean` | - | - | If true, use a larger size |
611| `value` | `number` | - | ✓ | A value between 1 and 100 that represents the progress |
612| background | `string` | - | - | A CSS color string to use for the progress bar |
613| color | `string` | - | - | A CSS color string to use for the content of the progress bar |
614
615### RadioButton
616
617[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/RadioButton/story.js)
618
619#### Props
620
621| Name | Type | Default | Required | Description |
622| ------ | ------ | --------- | ---------- | ------------- |
623| `checked` | `boolean` | - | - | If true, render the radio button as checked |
624| `disabled` | `boolean` | - | - | If true, set the radio button as disabled |
625| `label` | `string` | - | - | The label to render next to the radio button |
626| `onChange` | `(event: Event) => void` | - | - | Function called when the value of the radio button changes |
627
628
629### RadioButtonGroup
630
631[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Search/story.js)
632
633#### Props
634
635| Name | Type | Default | Required | Description |
636| ------ | ------ | --------- | ---------- | ------------- |
637| `value` | `string` | - | - | Currently selected option value |
638| `options` | `["string"] | [{"disabled": boolean, "id": string, "label": string, "name": string, "value": string}]` | - | - | Settings for each radio button |
639| `onChange` | `(event: Event) => void` | - | - | Function called when the value of the radio button changes |
640
641
642### Search
643
644Displays an input styled as a search bar.
645
646[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Search/story.js)
647
648#### Props
649
650| Name | Type | Default | Required | Description |
651| ------ | ------ | --------- | ---------- | ------------- |
652| `dark` | `boolean` | - | - | If true, uses a light colorscheme for use on a dark background |
653| `disabled` | `boolean` | - | - | If true, disable the input |
654| `placeholder` | `string` | - | - | A placeholder to use in the input |
655| `value` | `string` | - | ✓ | The value of the input |
656| `onChange` | `(event: Event) => void` | - | ✓ | A function that is called when the input changes |
657
658### Select
659
660[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Select/story.js)
661
662#### Props
663
664You can refer to the [grommet select page](https://v2.grommet.io/select) for all possible props.
665
666##### Excluded props are:
667
668`'size' | 'selected' | 'focusIndicator' | 'margin'`
669
670
671##### Additional props are:
672
673| Name | Type | Default | Required | Description |
674| ------ | ------ | --------- | ---------- | ------------- |
675| `emphasized` | `boolean` | - | - | If true, use a larger size |
676
677
678
679### Spinner
680
681[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Spinner/story.js)
682
683#### Props
684
685| Name | Type | Default | Required | Description |
686| ------ | ------ | --------- | ---------- | ------------- |
687| `children` | `React.ReactNode` | | - | If the spinner has children, it will show an opaque overlay over the children when it is spinning |
688| `show` | `boolean` | true | - | If passed, it will control whether the spinner is shown or not |
689| `emphasized` | `boolean` | false | - | If true, it will render a large spinner |
690| `label` | `string` \| `React.ReactNode`| | - | A label that will be rendered next to the spinner. Renders on right-hand side for standard spinner, and below spinner for emphasized |
691### Steps
692
693A visual guide showing a number of steps to be performed by the user. The `Steps` component takes one or more `Step` components as children.
694
695If the `ordered` prop is `true`, the steps will be considered as an ordered (numbered) list. In this case, the `activeStepIndex` must be set and the `onClick` callback prop of the child `Step` components used to update the `activeStepIndex`.
696
697[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Steps/story.js)
698
699#### Props
700
701| Name | Type | Default | Required | Description |
702| ------------- | ------------- | --------- | ---------- | ----------- |
703| `children` | `Array<Step>` | - | - | The step components that form this sequence of steps |
704| `titleText` | `string` | - | - | If passed, the steps will have a title at the beginning |
705| `titleIcon` | `ReactNode` | - | - | If passed, an icon will be shown next to the title text, or on its own if there is no title text passed |
706| `onClose` | `() => void` | - | - | Function that is called when a user clicks on the close button, if not passed, no close button will be rendered |
707| `bordered` | `boolean` | `true` | - | If true (default), the steps container will have a visible border |
708| `ordered` | `boolean` | `false` | - | If true, the steps will be treated as an ordered list. Instead of the check icon, pending ordered steps will be displayed with a grey step number and active ordered steps with a blue step number.
709| `activeStepIndex` | `number` | - | - | If passed, specifies the step that is currently active. Only use with the `ordered` prop |
710
711##### Step Props
712
713| Name | Type | Default | Required | Description |
714| ---------- | ---------------------------------- | ------- | ---------- | ----------- |
715| `children` | `string` | - | ✓ | The text of the step |
716| `status` | `'pending' | 'completed' | 'none'` | - | ✓ | Whether the step has been completed or is still pending |
717| `onClick` | () => void | - | - | If passed, the step will be clickable. _Note: If the steps are ordered, this callback should be used to update the `activeStepIndex` prop passed to the `Steps` component._ |
718
719### Table
720
721A component used to generate a styled table.
722
723[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Table/story.js)
724
725#### Columns
726
727The `columns` property defines what columns the table should display, how they
728are rendered and whether or not the column is sortable.
729
730The `columns` property should be an array of objects with the following properties:
731
732| Name | Type | Required | Description |
733| ------------- | --------- | -------- | ---------------------------------------------------- |
734| field | `keyof T` | ✓ | The name of the field this column should render, this should correspond to a key on the objects passed to the `data` property of the `Table` component |
735| cellAttributes | <code>object &#124; (value: any, row: T) => object</code> | - | Attributes that are passed to each cell in this column. This can also be a function, which will be called with the value of the `field` provided and the row data (`T`) |
736| label | <code>string &#124; JSX.Element</code> | - | A string or JSX element that will be used to display the name of the column. If this property is not provided, the `field` property will be used instead |
737| render | <code>(value: any, row: T) => string &#124; number &#124; number &#124; JSX.Element &#124; null</code> | - | Use a custom render function to display the value in each column cell. This function will be called with the value of the `field` provided and the row data (`T`) |
738| sortable | <code>boolean &#124; (a: T, b: T) => number</code> | - | If true, the column will be sortable using an alphanumeric sort, alternatively a function can be provided allowing finer grained control over sorting |
739
740#### Notes
741
742For performance reasons table rows are only re-rendered if the row properties
743have changed. For this reason, rows **will not** re-render if their properties
744are mutated: you should clone the item instead, for example:
745
746```js
747update (index) {
748 const newData = this.state.data
749 const element = newData[index]
750 newData[index] = Object.assign({}, element, { active: !element.active })
751 this.setState({ data: newData })
752}
753```
754
755See the **Updating data in a table** story for an example of how this can be
756done using a high order component.
757
758Additionally, because of this rendering behaviour the `render()` functions in
759the `Table` component's `columns` property should only use values provided to
760the render function.
761When `render()` functions are provided, they must act like pure functions with
762respect to their props. They should only rely on their arguments to generate
763their output and not use any context variables. If you are using a context
764variable in your `render()` function, then changes to that variable will not
765cause a re-render of the component and will not be reflected on the table.
766
767#### Props
768
769| Name | Type | Default | Required | Description |
770| ------------- | --------- | --------- | ---------- | ---------------------------------------------------- |
771| `columns` | `object[]` | - | ✓ | An array of column objects, as described above |
772| `data` | `T[]` | - | ✓ | An array of objects that will be displayed in the table |
773| `getRowHref` | `(row: T) => string` | - | - | If provided, each row in the table will be a clickable link, this function is used to create the link href |
774| `onCheck` | `(checkedItems: T[]) => string` | - | - | If provided, each row will begin with a checkbox. This function is called with every checked row every time a checkbox is toggled on or off. This property requires that you have provided a `rowKey` property |
775| `onRowClick` | `(row: T, event: Event) => void` | - | - | A function that is called when a row is clicked. This property requires that you have provided a `rowKey` property |
776| `onSort` | `(sort: TableSortOptions<T>) => void` | - | - | A function that is called when a column is sorted |
777| `onPageChange` | `(page: number) => void` | - | - | A function that is called when the page is incremented, decremented and reset |
778| `sort` | `TableSortOptions<T>` | - | - | sort options to be used both as a default sort, and on subsequent renders if the passed sort changes |
779| `rowAnchorAttributes` | `object` | - | - | Attributes to pass to the anchor element used in a row |
780| `rowCheckboxAttributes` | `object` | - | - | Attributes to pass to the checkbox element used in a row |
781| `rowKey` | `key of T` | - | - | A field on a row that contains a unique identifier, can help speed up render performance and is required for the `onCheck` property |
782| `toBodyPrefix` | <code>JSX.element &#124; JSX.Element</code> | - | - | JSX element(s) to display at the top of the table body |
783| `highlightedRows` | <code>&ast;[]</code> | - | - | Highlights one or more rows. This property requires that you have provided a `rowKey` property: the row with a `rowKey` property that matches one of these values is highlighted.
784| `usePager` | `boolean` | - | - | If true, a pager will be used when displaying items.
785| `itemsPerPage` | `number` | `50` | - | The number of items to be shown per page. Only used if `usePager` is true. Defaults to `50`.
786| `pagerPosition` | <code>'top' &#124; 'bottom' &#124; 'both'</code> | `top` | - | Sets wether the pager is displayed at the top of the table, the bottom of the table or in both positions. Only used if `usePager` is true. Defaults to `top`.
787
788#### Programmatically selecting rows
789
790The component has a `setRowSelection` method that can be accesssed via <a href='https://reactjs.org/docs/refs-and-the-dom.html' target='_blank' rel='noopener'>ref</a>.
791
792It will accept an array of rows `T[]`, or an empty array in order to clear the selection.
793
794This method requires that you have provided a `rowKey` property.
795
796### Tabs
797
798A component used to render tabbed children components.
799
800[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Tabs/story.js)
801
802### Tag
803
804Represents a name-value pair with an optional operator between.
805
806[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Tag/story.js)
807
808#### Props
809
810| Name | Type | Default | Required | Description |
811| ------ | ------ | --------- | ---------- | ------------- |
812| `value` | `string` | - | - | The value part of the tag |
813| `operator` | `boolean` | `':'` | - | The operator that goes between the name and value of the tag |
814| `name` | `boolean` | - | - | The name part of the tag, if not provided, only the value will be shown |
815| `multiple` | `Array<{name?: string, value?: string, operator?: string, prefix?: string}>` | - | - | An array of name-value pairs, with an optional delimiter to be used between the previous and current tag entry |
816| `onClose` | `() => void` | - | - | Callback method, that if passed, a "close" button will be added to the right-hand side of the tag|
817| `onClick` | `() => void` | - | - | Callback method, that if passed, the tag will become clickable |
818
819### Terminal
820
821An xterm emulator built on top of [xterm.js](https://xtermjs.org/).
822
823[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Terminal/story.js)
824
825#### API
826
827The `Terminal` component exposes a simple api, typically accessed via a `ref`.
828
829Here is a simple example that writes a number every second:
830
831```
832import * as React from 'react'
833import { Terminal } from 'rendition'
834
835export class Logger extends React.Component {
836 constructor (props) {
837 super(props)
838
839 this.count = 0
840 }
841
842 componentDidMount () {
843 this.interval = setInterval(() => {
844 this.term.writeln(++this.count)
845 }
846 }, 1000)
847 }
848
849 render () {
850 return (
851 <Terminal
852 ref={term => (this.term = term)}
853 />
854 )
855 }
856}
857```
858
859##### `resize()`
860
861Resize the `Terminal` component to fill its container.
862
863##### `clear()`
864
865Clear all output from the terminal.
866
867##### `writeln(text)`
868
869Write text to the terminal, followed by a line break.
870
871##### `write(text)`
872
873Write text to the terminal.
874
875##### `destroy(text)`
876
877Tear down the terminal instance.
878
879#### Remounting old instances
880
881If you'd like to preserve a terminal session and remount it to the DOM at
882a later point, you will need to set the `persistent` property to `true` and then access the readonly property `tty` and store it in memory.
883The `persistent` flag prevents the `Terminal` component form destroying the
884`tty` instance when it unmounts.
885When you want to remount the session, instantiate a new `Terminal`
886component and provide the `tty` value as the `ttyInstance` property. When
887a `ttyInstance` property is provided, the `Terminal` component will use that
888instance instead of creating a new one.
889
890#### Props
891
892| Name | Type | Default | Required | Description |
893| ------ | ------ | --------- | ---------- | ------------- |
894| `ttyInstance` | `object` | - | - | An existing `Terminal.tty` instance to use instead of creating a new one |
895| `persistent` | `boolean` | - | - | If true, don't destroy the `Terminal.tty` instance when the component unmounts |
896| `nonInteractive` | `boolean` | - | - | If true, the component will go into a "read-only" state, useful for displaying logs |
897| `color` | `string` | - | - | A CSS color string that sets the background color of the terminal |
898| `config` | `object` | - | - | Startup options to pass to the tty instance, see the [xterm.js options](https://github.com/xtermjs/xterm.js/blob/master/typings/xterm.d.ts#L24) for more detail |
899### TextWithCopy
900
901Displays text that can be copied to the clipboard.
902
903[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/TextWithCopy/story.js)
904
905#### Props
906
907| Name | Type | Default | Required | Description |
908| ------ | ------ | --------- | ---------- | ------------- |
909| `copy` | `string` | - | ✓ | The value that should be copied to the clipboard
910| `showCopyButton` | <code>'hover' &#124; 'always'</code> | - | - | Optionally show the copy button on hover or always show the button
911
912### Textarea
913
914[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Textarea/story.js)
915
916#### Props
917
918| Name | Type | Default | Required | Description |
919| ------ | ------ | --------- | ---------- | ------------- |
920| `monospace` | `boolean` | `false` | - | If true, render text in a monospace font |
921| `autoRows` | `boolean` | `false` | - | If true, the textarea `rows` property will be changed automatically based on the content of the textarea, this behaviour will only work with a [controlled input](https://reactjs.org/docs/forms.html#controlled-components) (i.e. you have used the `onChange` property |
922| `minRows` | `number` | - | - | Set the minimum number of rows |
923| `maxRows` | `number` | - | - | Set the maximum number of rows |
924| `onChange` | `(e: Event) => void` | - | - | A function that is called when the textarea value changes |
925
926#### Inheritance
927
928The attributes of a [`<textarea>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) element are also available.
929
930
931### Tooltips
932
933Tooltips are somewhat special in how they are used.
934Instead of using them as a typical React component, they can be added to a supported component using the `tooltip` attribute.
935For example, to add a tooltip to a `Button` component you would do the
936following:
937
938```
939<Button
940 tooltip='I am a tooltip'
941>
942 Click me
943</Button>
944```
945
946If the `tooltip` attribute is a string then a tooltip containing the strings
947content will be displayed above the component.
948
949If you need more control over the tooltip, you can set the attribute to an
950object with the following properties:
951
952| Name | Type | Required | Description |
953| ------------- | --------- | -------- | ---------------------------------------------------- |
954| text | `string` | ✓ | The text to display in the tooltip |
955| trigger | <code>'click' &#124; 'hover'</code> | - | Controls whether the tooltip is displayed on hover or click, defaults to `'hover'`
956| placement | <code>'top' &#124; 'right' &#124; 'bottom' &#124; 'left'</code> | - | Controls the position of the tooltip related to the component, defaults to `'top'` |
957| containerStyle | `object` | - | Apply custom styles to the tooltip outer container, the object is applied as a [`style` attribute](https://reactjs.org/docs/dom-elements.html#style) |
958| innerStyle | `object` | - | Apply custom styles to the tooltip inner container, the object is applied as a [`style` attribute](https://reactjs.org/docs/dom-elements.html#style) |
959| arrowStyle | `object` | - | Apply custom styles to the tooltip arrow, the object is applied as a [`style` attribute](https://reactjs.org/docs/dom-elements.html#style) |
960
961The following rendition components support the `tooltip` attribute:
962
963- `Alert`
964- `Badge`
965- `Box`
966- `Button`
967- `CodeWithCopy`
968- `DropDownButton`
969- `Fixed`
970- `Flex`
971- `Heading`
972- `Txt`
973- `Link`
974
975[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Tooltip/story.js)
976
977### Txt
978
979Displays a text block. A `<span>` tag can be used with `<Txt.span>` and a `<p>`
980tag can be used with `<Txt.p>`.
981
982[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/components/Txt/story.js)
983
984#### Props
985
986| Name | Type | Default | Required | Description |
987| ------ | ------ | --------- | ---------- | ------------- |
988| `monospace` | `boolean` | - | - | If true, render text in a monospace font |
989| `bold` | `boolean` | - | - | If true, render text in a bold font |
990| `italic` | `boolean` | - | - | If true, render text in an italic font style |
991| `caps` | `boolean` | - | - | If true, render text in uppercase |
992| `align` | `string` | - | - | Align text inside the component, one of 'left', 'right', 'center', 'justify', 'justify-all', 'start', 'end', 'match-parent', 'inherit', 'initial', 'unset' |
993| `whitespace` | `string` | - | - | Equivalent to the CSS `white-space` property, one of 'normal', 'nowrap', 'pre', 'pre-line', 'pre-wrap', 'initial', 'inherit' |
994
995
996### Markdown
997
998A simple component for rendering [GitHub flavored markdown](https://github.github.com/gfm/). This component
999sanitizes input.
1000This component is not loaded by default as it relies on a markdown parsing package
1001that you may not want to include in your application.
1002You can load this component using:
1003
1004```
1005import { Markdown } from 'rendition/dist/extra/Markdown';
1006```
1007
1008If you need to customize the conversion of markdown to HTML you can supply the `sanitizerOptions` prop. In this case, use the defaults as a starting point for your options:
1009
1010```
1011import { Markdown, defaultSanitizerOptions } from 'rendition/dist/extra/Markdown';
1012```
1013
1014
1015[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/extra/Markdown/story.js)
1016
1017#### Props
1018
1019| Name | Type | Default | Required | Description |
1020| ------ | ------ | --------- | ---------- | ------------- |
1021| `children` | `string` | - | ✓ | The markdown source that should be rendered |
1022| `sanitizerOptions` | [`sanitizeHtml.IOptions`](https://github.com/apostrophecms/sanitize-html#how-to-use) | (See `extra/utils/defaultSanitizerOptions`) | - | Specifies the options used when sanitizing the generated HTML. |
1023
1024Any other properties supplied are spread to the root element ([`Txt`](#txt)).
1025
1026#### Inheritance
1027
1028The properties of the [`Txt`](#txt) component are also available.
1029
1030### MarkdownEditor
1031
1032A markdown editor based on [simple MDE editor](https://github.com/RIP21/react-simplemde-editor)
1033
1034```
1035import { MarkdownEditor } from 'rendition/dist/extra/MarkdownEditor';
1036```
1037
1038[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/extra/MarkdownEditor/story.js)
1039
1040#### Props
1041
1042| Name | Type | Default | Required | Description |
1043| ------ | ------ | --------- | ---------- | ------------- |
1044| `value` | `string` | - | ✓ | The markdown-flavored text |
1045| `onChange` | `(text: string) => void` | - | ✓ | Callback called on every content change |
1046
1047### Mermaid
1048
1049Generate charts from text using [mermaidjs](https://mermaidjs.github.io/).
1050This component is not loaded by default as it relies on the mermaidjs library
1051that you may not want to include in your application.
1052You can load this component using:
1053
1054```
1055import { Mermaid } from 'rendition/dist/extra/Mermaid';
1056```
1057
1058[View story source](https://github.com/balena-io-modules/rendition/blob/master/src/extra/Mermaid/story.js)
1059
1060#### Props
1061
1062| Name | Type | Default | Required | Description |
1063| ------ | ------ | --------- | ---------- | ------------- |
1064| `value` | `string` | - | ✓ | The mermaid source that should be rendered |
1065
1066
1067### Form
1068
1069A component that can be used for generating a form from a [json schema](http://json-schema.org/) object.
1070The standard json schema types are supported, as well as the `date-time` format.
1071
1072Under the hood, this component uses [`react-jsonschema-form`](https://github.com/mozilla-services/react-jsonschema-form) and support
1073all [`uiSchema`](https://github.com/mozilla-services/react-jsonschema-form#the-uischema-object) options from that project.
1074
1075Additional formats are supported, but require supporting widgets to be loaded.
1076For example if you would like to support the [mermaid](https://mermaidjs.github.io/) format, you'll need to
1077import the widget using `import 'renditon/dist/extra/Form/mermaid'`.
1078
1079This import only needs to happen once, so it is recommended that its done at the
1080root level of your application.
1081
1082This component is experimental and still under development, if you would like to
1083use it, it can be imported using `import { Form } from 'rendition/dist/unstable'`.
1084
1085#### Custom uiSchema properties
1086
1087Some templates and widgets support additional uiSchema options, defined using `ui:options` object in the `uiSchema` definition. Those are:
1088
1089##### PasswordWidget
1090
1091| Name | Type | Default | Required | Description |
1092| ------ | ------ | --------- | ---------- | ------------- |
1093| `showPasswordStrengthMeter` | `boolean` | false | - | A boolean denoting whether a password strenth meter will be shown. `zxcvbn` should be loaded beforehand and set to the window object as `window.zxcvbn` |
1094
1095##### ObjectField
1096
1097| Name | Type | Default | Required | Description |
1098| ------ | ------ | --------- | ---------- | ------------- |
1099| `responsive` | `boolean` | false | - | A boolean denoting whether the object fields should be wrapped in a row-directed flex container and wrap once their size is larger than the minimum|
1100| `flex` | `Array<number | string>` | - | - | Works together with `responsive`. It passes the `flex` value to the same-indexed field in the object. This allows you to have more control over the layout of the fields |
1101
1102
1103#### Captcha
1104
1105If you wish to use a captcha (google recaptcha v2) in your form, you need to load the `captcha` widget using `import { CaptchaWidget } from 'rendition/dist/extra/Form/captcha'` and register it using `registerWidget` (see [story source](https://github.com/balena-io-modules/rendition/blob/master/src/unstable/components/Form/story.js)).
1106
1107In order for the captcha to work, you also need to set a valid recaptcha API key to the `window.RECAPTCHA_V2_API_KEY` variable.
1108A gotcha with the captcha widget is, upon submitting, you need to reset the captcha form value where you manage its state. Google only allows a captcha value (generated by clicking the captcha widget) to be verified only once against their API, after which it will be invalid so it needs to be reset.
1109
1110#### API
1111
1112##### `registerWidget(format, widget)`
1113
1114Register a widget that will be used to render fields of the specified format.
1115
1116#### Props
1117
1118| Name | Type | Default | Required | Description |
1119| ------ | ------ | --------- | ---------- | ------------- |
1120| `schema` | `object` | - | ✓ | A json schema describing the shape of the data you would like to gather |
1121| `submitButtonText` | <code>string &#124; JSX.Element</code> | - | - | A string or JSX element to replace the text in the form submit button |
1122| `hideSubmitButton` | `boolean` | - | - | If true, do not display the form submit button |
1123| `submitButtonProps` | `object` | - | - | Properties that are passed to the submit button, these are the same props used for the [`Button`](#button) component |
1124| `value` | `*` | - | - | The data that should be displayed in the form |
1125| `onFormChange` | `(result: object) => void` | - | - | A function that is called when form data changes |
1126| `onFormSubmit` | `(result: object) => void` | - | - | A function that is called when the form is submitted |
1127| `uiSchema` | `object` | - | - | A configuration object used to change the styling and layout of the form. See the [`react-jsonschema-form`](https://github.com/mozilla-services/react-jsonschema-form) docs for more details |
1128
1129
1130### Provider
1131
1132Wrap your application in the `<Provider>` component so that child components can correctly inherit the default theme. You can optionally provide your own theme.
1133
1134### Accessing the theme object
1135
1136You can access the theme object in `<Provider>`'s descendant components using the `useTheme` hook:
1137
1138```jsx
1139import React from 'react'
1140import { useTheme } from 'rendition';
1141
1142const MyComponent = () => {
1143 const theme = useTheme()
1144
1145 // ...
1146}
1147```
1148
1149### Styled system
1150
1151All components support [styled-system][styled-system] attributes, allowing you to use a shorthand properties for styling components. The properties can have the properties in the form of `string | number | Array<string | number>`. If an array is provided, then a property is chosen based on the width of the screen. The screen width corresponds to a breakpoint set in the `theme` property of the `Provider` component, by default this is set to `[32, 48, 64, 80]` where each number is the screen width in ems.
1152
1153| Name | Type | Description |
1154| --------------|-------------------|--------------------------------------------- |
1155| width | `ResponsiveStyle` | sets the width
1156| minWidth | `ResponsiveStyle` | sets the min-width
1157| maxWidth | `ResponsiveStyle` | sets the max-width
1158| height | `ResponsiveStyle` | sets the height
1159| minHeight | `ResponsiveStyle` | sets the min-height
1160| maxHeight | `ResponsiveStyle` | sets the max-height
1161| fontSize | `ResponsiveStyle` | sets the font size
1162| display | `ResponsiveStyle` | sets the `display` css property
1163| color | `ResponsiveStyle` | sets the `color` css property
1164| bg | `ResponsiveStyle` | sets the `background` css property
1165| m | `ResponsiveStyle` | sets the `margin` css property
1166| mt | `ResponsiveStyle` | sets the `margin-top` css property
1167| mr | `ResponsiveStyle` | sets the `margin-right` css property
1168| mb | `ResponsiveStyle` | sets the `margin-bottom` css property
1169| ml | `ResponsiveStyle` | sets the `margin-bottom` css property
1170| mx | `ResponsiveStyle` | sets both the `margin-right` and `margin-left` css properties
1171| my | `ResponsiveStyle` | sets both the `margin-top` and `margin-bottom` css properties
1172| p | `ResponsiveStyle` | sets the `padding` css property
1173| pt | `ResponsiveStyle` | sets the `padding-top` css property
1174| pr | `ResponsiveStyle` | sets the `padding-right` css property
1175| pb | `ResponsiveStyle` | sets the `padding-bottom` css property
1176| pl | `ResponsiveStyle` | sets the `padding-left` css property
1177| px | `ResponsiveStyle` | sets both the `padding-right` and `padding-left` css properties
1178| py | `ResponsiveStyle` | sets both the `padding-top` and `padding-bottom` css properties
1179
1180&ast;*`ResponsiveStyle` corresponds to a type of `string | number | Array<string | number>`*
1181
1182## Extra components
1183
1184Some components in the [storybook](https://balena-io-modules.github.io/rendition)
1185are grouped separately under the `Extra` label. These components are not loaded by default
1186as they rely on other large packages that you may not want to include in your
1187application.
1188If you would like to use them they can be loaded using by prefixing the
1189component name with `rendition/dist/extra/`. For example to load the `Markdown`
1190components you can use:
1191
1192```
1193import { Markdown } from 'rendition/dist/extra/Markdown';
1194```
1195
1196## Unstable/Beta components
1197
1198Some components in the [storybook](https://balena-io-modules.github.io/rendition)
1199are grouped seperately under the `Beta` label. These components are experimental and still
1200under development, as such their API may change without notice. They should not
1201be used in a production application.
1202If you would like to try them out they can be loaded using
1203`import * from 'rendition/dist/unstable'`.
1204
1205## Upgrading
1206
1207[Upgrading from 3.x to 4.x](docs/migrating_3x-4x.md)
1208
1209[Upgrading from 4.x to 5.x](docs/migrating_4x-5x.md)
1210
1211[Upgrading from 6.x to 7.x](docs/migrating_6x-7x.md)
1212
1213## Contributing
1214
1215Please read our [contribution guidelines](docs/CONTRIBUTING.md)
1216
1217[react]:https://reactjs.org/
1218[recompose]:https://github.com/acdlite/recompose
1219[styled-components]:https://www.styled-components.com/
1220[styled-system]:http://jxnblk.com/styled-system/
1221[husky]:https://github.com/typicode/husky