@oliasoft-open-source/react-ui-library 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (317) hide show
  1. package/.eslintignore +2 -0
  2. package/.eslintrc.js +125 -0
  3. package/.gitlab-ci.yml +45 -0
  4. package/.husky/pre-commit +4 -0
  5. package/.prettierignore +3 -0
  6. package/.prettierrc +4 -0
  7. package/.storybook/main.js +36 -0
  8. package/.storybook/preview.js +40 -0
  9. package/.storybook/storybook.less +8 -0
  10. package/LICENSE +21 -0
  11. package/README.md +5 -0
  12. package/babel.config.js +31 -0
  13. package/index.js +76 -0
  14. package/jest.config.js +9 -0
  15. package/package.json +136 -0
  16. package/src/components/accordion/accordion.jsx +132 -0
  17. package/src/components/accordion/accordion.module.less +66 -0
  18. package/src/components/accordion/accordion.stories.jsx +171 -0
  19. package/src/components/accordion/chevron/chevron.jsx +12 -0
  20. package/src/components/accordion/chevron/chevron.module.less +12 -0
  21. package/src/components/accordion/helpers/accordion-with-default-toggle.jsx +106 -0
  22. package/src/components/accordion/helpers/accordion-with-default-toggle.module.less +24 -0
  23. package/src/components/actions/actions.jsx +129 -0
  24. package/src/components/actions/actions.module.less +44 -0
  25. package/src/components/actions/actions.shape.js +32 -0
  26. package/src/components/actions/actions.stories.jsx +79 -0
  27. package/src/components/badge/badge.jsx +58 -0
  28. package/src/components/badge/badge.module.less +55 -0
  29. package/src/components/badge/badge.stories.jsx +31 -0
  30. package/src/components/breadcrumb/breadcrumb.jsx +49 -0
  31. package/src/components/breadcrumb/breadcrumb.module.less +39 -0
  32. package/src/components/breadcrumb/breadcrumb.stories.jsx +45 -0
  33. package/src/components/breadcrumb/link.jsx +31 -0
  34. package/src/components/button/button.jsx +156 -0
  35. package/src/components/button/button.module.less +300 -0
  36. package/src/components/button/button.stories.jsx +74 -0
  37. package/src/components/button-group/button-group.jsx +140 -0
  38. package/src/components/button-group/button-group.module.less +24 -0
  39. package/src/components/button-group/button-group.stories-data.jsx +67 -0
  40. package/src/components/button-group/button-group.stories.jsx +63 -0
  41. package/src/components/buttons-and-links.stories.mdx +55 -0
  42. package/src/components/card/card.jsx +51 -0
  43. package/src/components/card/card.module.less +48 -0
  44. package/src/components/card/card.stories.jsx +39 -0
  45. package/src/components/check-box/check-box.jsx +92 -0
  46. package/src/components/check-box/check-box.module.less +101 -0
  47. package/src/components/check-box/check-box.stories.jsx +27 -0
  48. package/src/components/color/color.stories-data.jsx +71 -0
  49. package/src/components/color/color.stories.mdx +37 -0
  50. package/src/components/dialog/dialog.jsx +64 -0
  51. package/src/components/dialog/dialog.module.less +76 -0
  52. package/src/components/divider/divider.jsx +40 -0
  53. package/src/components/divider/divider.module.less +28 -0
  54. package/src/components/divider/divider.stories.jsx +50 -0
  55. package/src/components/drawer/drawer-tabs.jsx +43 -0
  56. package/src/components/drawer/drawer.jsx +150 -0
  57. package/src/components/drawer/drawer.module.less +167 -0
  58. package/src/components/drawer/drawer.stories.jsx +156 -0
  59. package/src/components/empty/empty.jsx +52 -0
  60. package/src/components/empty/empty.module.less +17 -0
  61. package/src/components/empty/empty.stories.jsx +26 -0
  62. package/src/components/file-input/file-input.jsx +101 -0
  63. package/src/components/file-input/file-input.module.less +3 -0
  64. package/src/components/file-input/file-input.stories.jsx +109 -0
  65. package/src/components/form/field.jsx +96 -0
  66. package/src/components/form/field.stories.jsx +101 -0
  67. package/src/components/form/form.module.less +30 -0
  68. package/src/components/form/form.stories.jsx +191 -0
  69. package/src/components/heading/heading.jsx +105 -0
  70. package/src/components/heading/heading.module.less +59 -0
  71. package/src/components/heading/heading.stories.jsx +60 -0
  72. package/src/components/icon/deprecated-icon.jsx +97 -0
  73. package/src/components/icon/icon.jsx +71 -0
  74. package/src/components/icon/icon.module.less +33 -0
  75. package/src/components/icon/icon.stories.jsx +37 -0
  76. package/src/components/icon/icons.example.module.less +4 -0
  77. package/src/components/input/input.jsx +167 -0
  78. package/src/components/input/input.module.less +94 -0
  79. package/src/components/input/input.stories.jsx +28 -0
  80. package/src/components/input-group/input-group-addon/input-group-addon.jsx +36 -0
  81. package/src/components/input-group/input-group-addon/input-group-addon.module.less +31 -0
  82. package/src/components/input-group/input-group.jsx +51 -0
  83. package/src/components/input-group/input-group.module.less +10 -0
  84. package/src/components/input-group/input-group.stories.jsx +77 -0
  85. package/src/components/input-validation.stories.mdx +61 -0
  86. package/src/components/inputs.stories.mdx +201 -0
  87. package/src/components/label/label.jsx +115 -0
  88. package/src/components/label/label.module.less +43 -0
  89. package/src/components/label/label.stories.jsx +60 -0
  90. package/src/components/layout/column/column.jsx +85 -0
  91. package/src/components/layout/column/styles.js +45 -0
  92. package/src/components/layout/column.stories.jsx +60 -0
  93. package/src/components/layout/examples/afe.stories.jsx +180 -0
  94. package/src/components/layout/examples/blowout.stories.jsx +68 -0
  95. package/src/components/layout/examples/casing-loads.stories.jsx +297 -0
  96. package/src/components/layout/examples/formation.stories.jsx +110 -0
  97. package/src/components/layout/examples/projects.stories.jsx +108 -0
  98. package/src/components/layout/examples/reservoirs.stories.jsx +211 -0
  99. package/src/components/layout/examples/site.stories.jsx +263 -0
  100. package/src/components/layout/flex/flex.jsx +48 -0
  101. package/src/components/layout/flex/flex.stories.jsx +54 -0
  102. package/src/components/layout/form-row/form-row.jsx +15 -0
  103. package/src/components/layout/form-row/form-row.module.less +11 -0
  104. package/src/components/layout/grid/grid.jsx +62 -0
  105. package/src/components/layout/grid/grid.stories.jsx +65 -0
  106. package/src/components/layout/page/page.jsx +42 -0
  107. package/src/components/layout/page/page.module.less +27 -0
  108. package/src/components/layout/page.stories.jsx +93 -0
  109. package/src/components/layout/placeholder.jsx +2 -0
  110. package/src/components/layout/print-header/print-header.jsx +22 -0
  111. package/src/components/layout/print-header/print-header.module.less +9 -0
  112. package/src/components/layout/row/row.jsx +75 -0
  113. package/src/components/layout/row/row.module.less +7 -0
  114. package/src/components/layout/spacer/spacer.jsx +26 -0
  115. package/src/components/layout/spacer/spacer.stories.jsx +50 -0
  116. package/src/components/layout-forms.stories.mdx +104 -0
  117. package/src/components/layout-general.stories.mdx +215 -0
  118. package/src/components/list/list-row/item-content.jsx +15 -0
  119. package/src/components/list/list-row/label.jsx +11 -0
  120. package/src/components/list/list-row/list-heading.jsx +52 -0
  121. package/src/components/list/list-row/list-row.jsx +128 -0
  122. package/src/components/list/list-row/list-subheading.jsx +72 -0
  123. package/src/components/list/list-row/meta-content.jsx +24 -0
  124. package/src/components/list/list-row/meta-count.jsx +10 -0
  125. package/src/components/list/list-row/name.jsx +45 -0
  126. package/src/components/list/list.jsx +276 -0
  127. package/src/components/list/list.module.less +256 -0
  128. package/src/components/list/list.stories-data.jsx +287 -0
  129. package/src/components/list/list.stories.jsx +458 -0
  130. package/src/components/list/toggle-narrow.jsx +13 -0
  131. package/src/components/loader/loader.jsx +63 -0
  132. package/src/components/loader/loader.module.less +63 -0
  133. package/src/components/loader/loader.stories.jsx +155 -0
  134. package/src/components/menu/index.js +7 -0
  135. package/src/components/menu/layer/divider.jsx +4 -0
  136. package/src/components/menu/layer/heading.jsx +15 -0
  137. package/src/components/menu/layer/layer.jsx +82 -0
  138. package/src/components/menu/layer/option.jsx +77 -0
  139. package/src/components/menu/layer/path.js +44 -0
  140. package/src/components/menu/layer/placementOptions.js +6 -0
  141. package/src/components/menu/layer/section.jsx +66 -0
  142. package/src/components/menu/menu.jsx +359 -0
  143. package/src/components/menu/menu.module.less +241 -0
  144. package/src/components/menu/menu.stories-data.jsx +168 -0
  145. package/src/components/menu/menu.stories.jsx +126 -0
  146. package/src/components/menu/menu.test.js +58 -0
  147. package/src/components/menu/trigger/button.jsx +50 -0
  148. package/src/components/menu/trigger/component.jsx +14 -0
  149. package/src/components/menu/trigger/text.jsx +25 -0
  150. package/src/components/menu/trigger/trigger.jsx +86 -0
  151. package/src/components/message/dismiss.jsx +26 -0
  152. package/src/components/message/message.jsx +137 -0
  153. package/src/components/message/message.module.less +114 -0
  154. package/src/components/message/message.stories.jsx +84 -0
  155. package/src/components/modal/modal.jsx +50 -0
  156. package/src/components/modal/modal.module.less +35 -0
  157. package/src/components/modal/modal.stories.jsx +159 -0
  158. package/src/components/option-dropdown/heading.jsx +6 -0
  159. package/src/components/option-dropdown/layer.jsx +81 -0
  160. package/src/components/option-dropdown/option-dropdown.jsx +53 -0
  161. package/src/components/option-dropdown/option-dropdown.module.less +50 -0
  162. package/src/components/option-dropdown/option-dropdown.stories.jsx +35 -0
  163. package/src/components/option-dropdown/option.jsx +13 -0
  164. package/src/components/pagination/pagination.jsx +139 -0
  165. package/src/components/pagination/pagination.module.less +11 -0
  166. package/src/components/pagination/pagination.stories.jsx +78 -0
  167. package/src/components/pagination/pagination.test.js +92 -0
  168. package/src/components/pagination/pagination.viewdata.js +66 -0
  169. package/src/components/pop-confirm/content.jsx +25 -0
  170. package/src/components/pop-confirm/pop-confirm.jsx +61 -0
  171. package/src/components/pop-confirm/pop-confirm.module.less +18 -0
  172. package/src/components/pop-confirm/pop-confirm.stories.jsx +53 -0
  173. package/src/components/popover/popover.jsx +112 -0
  174. package/src/components/popover/popover.module.less +22 -0
  175. package/src/components/popover/popover.stories.jsx +59 -0
  176. package/src/components/portal/portal.jsx +16 -0
  177. package/src/components/portal/portal.stories.jsx +69 -0
  178. package/src/components/progress-bar/progress-bar.jsx +64 -0
  179. package/src/components/progress-bar/progress-bar.module.less +64 -0
  180. package/src/components/progress-bar/progress-bar.stories.jsx +23 -0
  181. package/src/components/radio-button/radio-button.jsx +139 -0
  182. package/src/components/radio-button/radio-button.module.less +135 -0
  183. package/src/components/radio-button/radio-button.stories.jsx +37 -0
  184. package/src/components/radio-button/radio-input.jsx +52 -0
  185. package/src/components/select/custom-select/custom-select.jsx +440 -0
  186. package/src/components/select/custom-select/custom-select.module.less +123 -0
  187. package/src/components/select/custom-select/custom-select.reducer.js +157 -0
  188. package/src/components/select/custom-select/layer/heading.jsx +13 -0
  189. package/src/components/select/custom-select/layer/layer.jsx +73 -0
  190. package/src/components/select/custom-select/layer/option.jsx +54 -0
  191. package/src/components/select/custom-select/layer/placementOptions.js +7 -0
  192. package/src/components/select/custom-select/layer/section.jsx +35 -0
  193. package/src/components/select/custom-select/trigger/input.jsx +100 -0
  194. package/src/components/select/custom-select/trigger/trigger.jsx +155 -0
  195. package/src/components/select/custom-select/trigger/trigger.module.less +289 -0
  196. package/src/components/select/native-select/native-select.jsx +198 -0
  197. package/src/components/select/native-select/native-select.module.less +107 -0
  198. package/src/components/select/select.input.js +146 -0
  199. package/src/components/select/select.jsx +207 -0
  200. package/src/components/select/select.stories-data.jsx +92 -0
  201. package/src/components/select/select.stories.jsx +135 -0
  202. package/src/components/select/select.test.js +519 -0
  203. package/src/components/side-bar/container.module.less +29 -0
  204. package/src/components/side-bar/link.jsx +83 -0
  205. package/src/components/side-bar/sections.jsx +23 -0
  206. package/src/components/side-bar/side-bar.jsx +102 -0
  207. package/src/components/side-bar/side-bar.module.less +137 -0
  208. package/src/components/side-bar/side-bar.stories.jsx +101 -0
  209. package/src/components/slider/rc-slider.less +47 -0
  210. package/src/components/slider/slider-tooltip.jsx +20 -0
  211. package/src/components/slider/slider.jsx +233 -0
  212. package/src/components/slider/slider.module.less +40 -0
  213. package/src/components/slider/slider.stories.jsx +110 -0
  214. package/src/components/spinner/spinner.jsx +37 -0
  215. package/src/components/spinner/spinner.module.less +115 -0
  216. package/src/components/spinner/spinner.stories.jsx +24 -0
  217. package/src/components/table/cell/cell.jsx +614 -0
  218. package/src/components/table/cell/cell.module.less +152 -0
  219. package/src/components/table/footer/footer.jsx +66 -0
  220. package/src/components/table/footer/footer.module.less +14 -0
  221. package/src/components/table/helper.js +64 -0
  222. package/src/components/table/helper.test.js +166 -0
  223. package/src/components/table/icon/icon.module.less +31 -0
  224. package/src/components/table/row/expanded-content-row.jsx +16 -0
  225. package/src/components/table/row/row.jsx +253 -0
  226. package/src/components/table/row/row.module.less +62 -0
  227. package/src/components/table/table-scroll-wrapper.jsx +48 -0
  228. package/src/components/table/table.jsx +232 -0
  229. package/src/components/table/table.module.less +145 -0
  230. package/src/components/table/table.stories-data.jsx +752 -0
  231. package/src/components/table/table.stories.jsx +814 -0
  232. package/src/components/table/table.test.js +30 -0
  233. package/src/components/table/table.variables.less +19 -0
  234. package/src/components/table/table.viewdata.js +26 -0
  235. package/src/components/table/title/title.jsx +30 -0
  236. package/src/components/table/title/title.module.less +9 -0
  237. package/src/components/tabs/content.jsx +14 -0
  238. package/src/components/tabs/label.jsx +50 -0
  239. package/src/components/tabs/tabs.jsx +191 -0
  240. package/src/components/tabs/tabs.module.less +73 -0
  241. package/src/components/tabs/tabs.stories.jsx +110 -0
  242. package/src/components/text/text.jsx +64 -0
  243. package/src/components/text/text.module.less +45 -0
  244. package/src/components/text/text.stories.jsx +31 -0
  245. package/src/components/text-link/text-link.jsx +23 -0
  246. package/src/components/text-link/text-link.stories.jsx +20 -0
  247. package/src/components/textarea/textarea.jsx +126 -0
  248. package/src/components/textarea/textarea.module.less +55 -0
  249. package/src/components/textarea/textarea.stories.jsx +26 -0
  250. package/src/components/toaster/toaster.jsx +39 -0
  251. package/src/components/toaster/toaster.less +17 -0
  252. package/src/components/toaster/toaster.stories.jsx +116 -0
  253. package/src/components/toggle/toggle.jsx +65 -0
  254. package/src/components/toggle/toggle.module.less +139 -0
  255. package/src/components/toggle/toggle.stories.jsx +26 -0
  256. package/src/components/tooltip/tooltip-layer.jsx +72 -0
  257. package/src/components/tooltip/tooltip.jsx +108 -0
  258. package/src/components/tooltip/tooltip.module.less +28 -0
  259. package/src/components/tooltip/tooltip.stories.jsx +71 -0
  260. package/src/components/top-bar/element/element.jsx +72 -0
  261. package/src/components/top-bar/element/link.jsx +29 -0
  262. package/src/components/top-bar/title.jsx +24 -0
  263. package/src/components/top-bar/top-bar.jsx +79 -0
  264. package/src/components/top-bar/top-bar.module.less +191 -0
  265. package/src/components/top-bar/top-bar.stories.jsx +137 -0
  266. package/src/components/top-bar/warning.jsx +6 -0
  267. package/src/components/tree/tree-item.jsx +79 -0
  268. package/src/components/tree/tree-placeholder.jsx +6 -0
  269. package/src/components/tree/tree.jsx +129 -0
  270. package/src/components/tree/tree.module.less +33 -0
  271. package/src/components/tree/tree.stories-data.jsx +89 -0
  272. package/src/components/tree/tree.stories.jsx +106 -0
  273. package/src/docs/components/page/page.jsx +16 -0
  274. package/src/docs/config/config.js +1 -0
  275. package/src/docs/html/favicon.png +0 -0
  276. package/src/docs/html/index.html +11 -0
  277. package/src/docs/navigation/footer/footer.jsx +48 -0
  278. package/src/docs/navigation/header/header.jsx +39 -0
  279. package/src/docs/navigation/header/header.module.less +32 -0
  280. package/src/docs/navigation/routes/routes.jsx +16 -0
  281. package/src/docs/start.jsx +12 -0
  282. package/src/docs/views/main/main.jsx +209 -0
  283. package/src/docs/views/main/main.module.less +14 -0
  284. package/src/docs/views/not-found/not-found.jsx +5 -0
  285. package/src/helpers/disabled-context.js +8 -0
  286. package/src/helpers/styles.js +68 -0
  287. package/src/helpers/text.js +6 -0
  288. package/src/helpers/types.js +5 -0
  289. package/src/hooks/index.js +3 -0
  290. package/src/hooks/use-focus.js +11 -0
  291. package/src/hooks/use-keyboard-event.js +16 -0
  292. package/src/hooks/use-window-width.js +20 -0
  293. package/src/images/icons/icon-drop.png +0 -0
  294. package/src/images/icons/icon-share.png +0 -0
  295. package/src/images/icons/icons8-junction.svg +4 -0
  296. package/src/images/logo.png +0 -0
  297. package/src/images/logo.svg +13 -0
  298. package/src/images/oliasoft-logo.svg +1 -0
  299. package/src/style/colors.less +26 -0
  300. package/src/style/external.less +10 -0
  301. package/src/style/fonts/lato/Lato-Bold.woff2 +0 -0
  302. package/src/style/fonts/lato/Lato-BoldItalic.woff2 +0 -0
  303. package/src/style/fonts/lato/Lato-Italic.woff2 +0 -0
  304. package/src/style/fonts/lato/Lato-Regular.woff2 +0 -0
  305. package/src/style/fonts.less +27 -0
  306. package/src/style/global.less +51 -0
  307. package/src/style/mixins.less +67 -0
  308. package/src/style/reset/reset.less +34 -0
  309. package/src/style/shared.less +25 -0
  310. package/src/style/theme.dark.less +37 -0
  311. package/src/style/theme.default.less +74 -0
  312. package/src/style/variables.less +49 -0
  313. package/webpack/webpack.common.js +39 -0
  314. package/webpack/webpack.common.rules.js +102 -0
  315. package/webpack/webpack.dev.js +22 -0
  316. package/webpack/webpack.prod.js +23 -0
  317. package/webpack/webpack.resolve.js +22 -0
@@ -0,0 +1,101 @@
1
+ import React, { useContext, useRef } from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { InputGroup } from '../input-group/input-group';
4
+ import { Input } from '../input/input';
5
+ import { Button } from '../button/button';
6
+ import styles from './file-input.module.less';
7
+ import { DisabledContext } from '../../helpers/disabled-context';
8
+
9
+ // https://stackoverflow.com/a/65140891/942635
10
+ export const readFile = (file = {}, method = 'readAsText') => {
11
+ const reader = new FileReader();
12
+ return new Promise((resolve, reject) => {
13
+ reader[method](file);
14
+ reader.onload = () => {
15
+ resolve(reader.result);
16
+ };
17
+ reader.onerror = (error) => reject(error);
18
+ });
19
+ };
20
+
21
+ export const FileInput = ({
22
+ label,
23
+ loading,
24
+ placeholder,
25
+ disabled,
26
+ file,
27
+ accept,
28
+ multi,
29
+ name,
30
+ width,
31
+ onChange,
32
+ testId,
33
+ }) => {
34
+ const disabledContext = useContext(DisabledContext);
35
+
36
+ const inputRef = useRef(null);
37
+ const fileName = file?.name || null;
38
+
39
+ const handleClick = () => {
40
+ if (!(disabled || disabledContext)) inputRef.current.click();
41
+ };
42
+
43
+ return (
44
+ <div onClick={() => handleClick()} style={{ width }}>
45
+ <InputGroup>
46
+ <Input value={fileName || ''} placeholder={placeholder} disabled />
47
+ <Button
48
+ label={label}
49
+ loading={loading}
50
+ disabled={loading || disabled || disabledContext}
51
+ groupOrder="last"
52
+ />
53
+ </InputGroup>
54
+ <input
55
+ name={name}
56
+ ref={inputRef}
57
+ className={styles.fileInput}
58
+ type="file"
59
+ accept={accept}
60
+ onChange={(evt) => {
61
+ onChange({
62
+ ...evt,
63
+ target: {
64
+ ...evt.target,
65
+ value: multi ? evt.target.files : evt.target.files[0],
66
+ },
67
+ });
68
+ }}
69
+ data-testid={testId}
70
+ />
71
+ </div>
72
+ );
73
+ };
74
+
75
+ FileInput.defaultProps = {
76
+ label: 'Select',
77
+ loading: false,
78
+ placeholder: 'No file selected',
79
+ disabled: false,
80
+ file: null,
81
+ accept: undefined,
82
+ name: null,
83
+ width: null,
84
+ onChange: () => {},
85
+ testId: undefined,
86
+ };
87
+
88
+ FileInput.propTypes = {
89
+ /** Custom button label */
90
+ label: PropTypes.string,
91
+ loading: PropTypes.bool,
92
+ placeholder: PropTypes.string,
93
+ disabled: PropTypes.bool,
94
+ file: PropTypes.object,
95
+ /** See [accept attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) to restrict file type */
96
+ accept: PropTypes.string,
97
+ name: PropTypes.string,
98
+ width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
99
+ onChange: PropTypes.func,
100
+ testId: PropTypes.string,
101
+ };
@@ -0,0 +1,3 @@
1
+ .fileInput {
2
+ display: none !important;
3
+ }
@@ -0,0 +1,109 @@
1
+ import React, { useState } from 'react';
2
+ import { useArgs } from '@storybook/addons';
3
+ import { FileInput, readFile, Spacer, Message, TextArea } from '../../..';
4
+
5
+ export default {
6
+ title: 'Forms/FileInput',
7
+ component: FileInput,
8
+ args: {
9
+ file: null,
10
+ },
11
+ };
12
+
13
+ const Template = (args) => {
14
+ const [_, updateArgs] = useArgs();
15
+ const handleChange = (evt) => {
16
+ updateArgs({ file: evt.target.value });
17
+ };
18
+
19
+ return (
20
+ <FileInput
21
+ // eslint-disable-next-line react/jsx-props-no-spreading
22
+ {...args}
23
+ onChange={handleChange}
24
+ />
25
+ );
26
+ };
27
+ export const Default = Template.bind({});
28
+
29
+ export const RestrictFiletype = Template.bind({});
30
+ RestrictFiletype.args = { accept: '.json' };
31
+ RestrictFiletype.parameters = {
32
+ docs: {
33
+ description: {
34
+ story:
35
+ 'See [accept attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) to restrict file type',
36
+ },
37
+ },
38
+ };
39
+
40
+ export const ReadJSONFile = () => {
41
+ const [file, setFile] = useState(null);
42
+ const [json, setJson] = useState({});
43
+
44
+ return (
45
+ <>
46
+ <FileInput
47
+ file={file}
48
+ onChange={async (evt) => {
49
+ const file = evt.target.value;
50
+ try {
51
+ const text = await readFile(file);
52
+ const json = JSON.parse(text);
53
+ setJson(json);
54
+ } catch (error) {
55
+ console.log(error);
56
+ }
57
+ setFile(file);
58
+ }}
59
+ accept=".json"
60
+ />
61
+ <Spacer />
62
+ {file ? (
63
+ <TextArea monospace value={JSON.stringify(json, null, 2)} rows={20} />
64
+ ) : (
65
+ <Message
66
+ message={{
67
+ visible: true,
68
+ content: 'Upload a JSON file to see preview',
69
+ type: 'Info',
70
+ }}
71
+ />
72
+ )}
73
+ </>
74
+ );
75
+ };
76
+
77
+ export const Image = () => {
78
+ const [file, setFile] = useState(null);
79
+ return (
80
+ <>
81
+ <FileInput
82
+ file={file}
83
+ onChange={(evt) => {
84
+ setFile(evt.target.value);
85
+ }}
86
+ accept="image/*"
87
+ />
88
+ <Spacer />
89
+ {file ? (
90
+ <img
91
+ src={file ? URL.createObjectURL(file) : ''}
92
+ alt="Preview"
93
+ style={{
94
+ maxHeight: '400px',
95
+ maxWidth: '400px',
96
+ }}
97
+ />
98
+ ) : (
99
+ <Message
100
+ message={{
101
+ visible: true,
102
+ content: 'Upload an image file to see preview',
103
+ type: 'Info',
104
+ }}
105
+ />
106
+ )}
107
+ </>
108
+ );
109
+ };
@@ -0,0 +1,96 @@
1
+ import React from 'react';
2
+ import cx from 'classnames';
3
+ import PropTypes from 'prop-types';
4
+ import { Label } from '../label/label';
5
+ import styles from './form.module.less';
6
+
7
+ export const Field = ({
8
+ label,
9
+ labelLeft,
10
+ labelWidth,
11
+ children,
12
+ helpText,
13
+ helpTextMaxWidth,
14
+ onClickHelp,
15
+ lock,
16
+ info,
17
+ libraryIcon,
18
+ testId,
19
+ }) => {
20
+ return (
21
+ <div
22
+ className={cx(styles.field, labelLeft ? styles.labelLeft : '')}
23
+ data-testid={testId}
24
+ >
25
+ {(label || labelLeft) && (
26
+ <Label
27
+ label={label}
28
+ width={labelWidth}
29
+ helpText={helpText}
30
+ helpTextMaxWidth={helpTextMaxWidth}
31
+ onClickHelp={onClickHelp}
32
+ lock={lock}
33
+ info={info}
34
+ libraryIcon={libraryIcon}
35
+ labelLeft={labelLeft}
36
+ />
37
+ )}
38
+ <div className={styles.fieldInput}>{children}</div>
39
+ </div>
40
+ );
41
+ };
42
+
43
+ Field.defaultProps = {
44
+ label: null,
45
+ helpText: null,
46
+ helpTextMaxWidth: '300px',
47
+ labelLeft: false,
48
+ labelWidth: 'auto',
49
+ info: null,
50
+ onClickHelp: null,
51
+ lock: {
52
+ visible: false,
53
+ active: false,
54
+ onClick: () => {},
55
+ tooltip: '',
56
+ testId: undefined,
57
+ },
58
+ libraryIcon: null,
59
+ testId: undefined,
60
+ };
61
+
62
+ Field.propTypes = {
63
+ label: PropTypes.oneOfType([
64
+ PropTypes.string,
65
+ PropTypes.number,
66
+ PropTypes.node,
67
+ ]),
68
+ /** Adds a help icon with a tooltip */
69
+ helpText: PropTypes.oneOfType([
70
+ PropTypes.string,
71
+ PropTypes.number,
72
+ PropTypes.node,
73
+ ]),
74
+ helpTextMaxWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), //'none' to disable
75
+ /** Moves the label to the left of the input */
76
+ labelLeft: PropTypes.bool,
77
+ labelWidth: PropTypes.string,
78
+ children: PropTypes.node.isRequired,
79
+ /** Adds an info icon with an optional tooltip and onClick event */
80
+ info: PropTypes.string,
81
+ onClickHelp: PropTypes.func,
82
+ /** Adds a lock icon with a tooltip */
83
+ lock: PropTypes.shape({
84
+ visible: PropTypes.bool,
85
+ active: PropTypes.bool,
86
+ onClick: PropTypes.func,
87
+ tooltip: PropTypes.string,
88
+ testId: PropTypes.string,
89
+ }),
90
+ /** Adds a library icon with a tooltip and onClick event */
91
+ libraryIcon: PropTypes.shape({
92
+ onClick: PropTypes.func,
93
+ tooltip: PropTypes.string,
94
+ }),
95
+ testId: PropTypes.string,
96
+ };
@@ -0,0 +1,101 @@
1
+ import React, { useState } from 'react';
2
+ import { Field, Input, Text } from '../../..';
3
+
4
+ export default {
5
+ title: 'Forms/Field',
6
+ component: Field,
7
+ args: {
8
+ label: 'Label',
9
+ labelLeft: false,
10
+ },
11
+ };
12
+
13
+ const Template = (args) => (
14
+ <Field
15
+ // eslint-disable-next-line react/jsx-props-no-spreading
16
+ {...args}
17
+ >
18
+ <Input />
19
+ </Field>
20
+ );
21
+ export const Default = Template.bind({});
22
+
23
+ export const LabelOnLeft = Template.bind({});
24
+ LabelOnLeft.args = {
25
+ labelLeft: true,
26
+ labelWidth: '80px',
27
+ };
28
+
29
+ export const HelpIconTooltip = Template.bind({});
30
+ HelpIconTooltip.args = {
31
+ helpText: 'Tooltip goes here',
32
+ };
33
+
34
+ export const HelpIconClickable = Template.bind({});
35
+ HelpIconClickable.args = {
36
+ onClickHelp: () => {},
37
+ };
38
+
39
+ export const HelpTextBelow = (args) => (
40
+ <>
41
+ <Field
42
+ // eslint-disable-next-line react/jsx-props-no-spreading
43
+ {...args}
44
+ >
45
+ <Input />
46
+ <Text small faint>
47
+ Help text goes here
48
+ </Text>
49
+ </Field>
50
+ <Field
51
+ // eslint-disable-next-line react/jsx-props-no-spreading
52
+ {...args}
53
+ >
54
+ <Input error="Error text goes here" />
55
+ <Text small error>
56
+ Error text goes here
57
+ </Text>
58
+ </Field>
59
+ <Field
60
+ // eslint-disable-next-line react/jsx-props-no-spreading
61
+ {...args}
62
+ >
63
+ <Input warning="Error text goes here" />
64
+ <Text small warning>
65
+ Warning text goes here
66
+ </Text>
67
+ </Field>
68
+ </>
69
+ );
70
+
71
+ export const InfoIcon = Template.bind({});
72
+ InfoIcon.args = {
73
+ info: 'Info goes here',
74
+ };
75
+
76
+ export const LockIcon = () => {
77
+ const [locked, setLocked] = useState(false);
78
+ const handleToggleLock = () => setLocked(!locked);
79
+ return (
80
+ <Field
81
+ label="Label"
82
+ lock={{
83
+ visible: true,
84
+ active: locked,
85
+ onClick: handleToggleLock,
86
+ tooltip: locked ? 'Unlock' : 'Lock',
87
+ testId: 'testId',
88
+ }}
89
+ >
90
+ <Input disabled={locked} />
91
+ </Field>
92
+ );
93
+ };
94
+
95
+ export const LibraryIcon = Template.bind({});
96
+ LibraryIcon.args = {
97
+ libraryIcon: {
98
+ onClick: () => {},
99
+ tooltip: 'View in library',
100
+ },
101
+ };
@@ -0,0 +1,30 @@
1
+ @import '../../style/variables.less';
2
+
3
+ .field {
4
+ margin-bottom: 14px;
5
+ color: var(--color-text);
6
+
7
+ &.labelLeft {
8
+ display: flex;
9
+ align-items: center;
10
+
11
+ .fieldInput {
12
+ flex-grow: 1;
13
+ }
14
+ }
15
+ }
16
+
17
+ .formRow,
18
+ .form-row /* hyphens are awkward (deprecate) */ {
19
+ display: flex;
20
+ flex-wrap: wrap;
21
+ align-items: flex-end;
22
+
23
+ > *:not(:last-child) {
24
+ margin-right: 20px;
25
+ }
26
+
27
+ .button {
28
+ margin-bottom: 14px;
29
+ }
30
+ }
@@ -0,0 +1,191 @@
1
+ import React from 'react';
2
+ import { DisabledContext } from '../../helpers/disabled-context';
3
+ import {
4
+ Field,
5
+ Input,
6
+ Select,
7
+ CheckBox,
8
+ ButtonGroup,
9
+ Button,
10
+ Toggle,
11
+ InputGroup,
12
+ InputGroupAddon,
13
+ Slider,
14
+ TextArea,
15
+ RadioButton,
16
+ Menu,
17
+ FormRow,
18
+ } from '../../..';
19
+
20
+ export default {
21
+ title: 'Forms/Layout',
22
+ argTypes: {
23
+ labelWidth: 'text',
24
+ },
25
+ args: {
26
+ small: false,
27
+ row: false,
28
+ labelLeft: false,
29
+ labelWidth: undefined,
30
+ disabled: false,
31
+ },
32
+ };
33
+
34
+ const renderFields = (args) => {
35
+ const { small, labelLeft, labelWidth } = args;
36
+ return (
37
+ <>
38
+ <Field
39
+ label="Input"
40
+ helpText="Some help text"
41
+ labelLeft={labelLeft}
42
+ labelWidth={labelWidth}
43
+ >
44
+ <Input value="Value" small={small} />
45
+ </Field>
46
+ <Field
47
+ label="TextArea"
48
+ helpText="Some very long help text that needs to have its width constrained so it doesn't look silly"
49
+ helpTextMaxWidth={200}
50
+ labelLeft={labelLeft}
51
+ labelWidth={labelWidth}
52
+ >
53
+ <TextArea value="Value" small={small} />
54
+ </Field>
55
+ <Field
56
+ label="Select (native)"
57
+ labelLeft={labelLeft}
58
+ labelWidth={labelWidth}
59
+ >
60
+ <Select
61
+ options={[
62
+ { label: 'Option 1', value: '1' },
63
+ { label: 'Option 2', value: '2' },
64
+ ]}
65
+ value={{ label: 'Option 2', value: '2' }}
66
+ native
67
+ small={small}
68
+ width="auto"
69
+ />
70
+ </Field>
71
+ <Field
72
+ label="Select (custom)"
73
+ labelLeft={labelLeft}
74
+ labelWidth={labelWidth}
75
+ >
76
+ <Select
77
+ options={[
78
+ { label: 'Option 1', value: '1' },
79
+ { label: 'Option 2', value: '2' },
80
+ ]}
81
+ value={{ label: 'Option 2', value: '2' }}
82
+ small={small}
83
+ width="auto"
84
+ />
85
+ </Field>
86
+ <Field
87
+ label="Select (multi)"
88
+ labelLeft={labelLeft}
89
+ labelWidth={labelWidth}
90
+ >
91
+ <Select
92
+ options={[
93
+ { label: 'Option 1', value: '1' },
94
+ { label: 'Option 2', value: '2' },
95
+ ]}
96
+ value={[
97
+ { label: 'Option 1', value: '1' },
98
+ { label: 'Option 2', value: '2' },
99
+ ]}
100
+ small={small}
101
+ />
102
+ </Field>
103
+ <Field label="Slider" labelLeft={labelLeft} labelWidth={labelWidth}>
104
+ <Slider
105
+ name="example"
106
+ label="Number of aardvarks"
107
+ value={35}
108
+ min={0}
109
+ max={100}
110
+ step={1}
111
+ onChange={() => {}}
112
+ showArrows
113
+ showTooltip
114
+ small={small}
115
+ />
116
+ </Field>
117
+ <Field label="ButtonGroup" labelLeft={labelLeft} labelWidth={labelWidth}>
118
+ <ButtonGroup
119
+ items={[
120
+ { key: 0, label: 'Option 1', value: '1' },
121
+ { key: 1, label: 'Option 2', value: '2' },
122
+ ]}
123
+ value={0}
124
+ small={small}
125
+ />
126
+ </Field>
127
+ <Field label="InputGroup" labelLeft={labelLeft} labelWidth={labelWidth}>
128
+ <InputGroup small={small}>
129
+ <InputGroupAddon>$</InputGroupAddon>
130
+ <Input name="example" value="123" onChange={() => {}} />
131
+ <InputGroupAddon>each</InputGroupAddon>
132
+ </InputGroup>
133
+ </Field>
134
+ <Field label="Menu" labelLeft={labelLeft} labelWidth={labelWidth}>
135
+ <Menu
136
+ menu={{
137
+ label: 'Menu',
138
+ trigger: 'DropDownButton',
139
+ sections: [
140
+ { type: 'Option', label: 'Lorem' },
141
+ { type: 'Option', label: 'Ipsum' },
142
+ ],
143
+ small,
144
+ }}
145
+ />
146
+ </Field>
147
+ <Field label="CheckBox" labelLeft={labelLeft} labelWidth={labelWidth}>
148
+ <CheckBox label="CheckBox" checked small={small} />
149
+ </Field>
150
+ <Field label="RadioButton" labelLeft={labelLeft} labelWidth={labelWidth}>
151
+ <RadioButton
152
+ options={[
153
+ { label: 'Aardvarks', value: 'termites' },
154
+ { label: 'Monkeys', value: 'bananas' },
155
+ ]}
156
+ value={{ label: 'Monkeys', value: 'bananas' }}
157
+ inline
158
+ small={small}
159
+ />
160
+ </Field>
161
+ <Field label="Toggle" labelLeft={labelLeft} labelWidth={labelWidth}>
162
+ <Toggle label="Toggle" checked onChange={() => {}} small={small} />
163
+ </Field>
164
+ <Field labelLeft={labelLeft} labelWidth={labelWidth}>
165
+ <Button colored label="Button" onClick={() => {}} small={small} />
166
+ </Field>
167
+ </>
168
+ );
169
+ };
170
+
171
+ const Template = (args) => {
172
+ const { row, disabled } = args;
173
+ return (
174
+ <DisabledContext.Provider value={disabled}>
175
+ {row ? <FormRow>{renderFields(args)}</FormRow> : renderFields(args)}
176
+ </DisabledContext.Provider>
177
+ );
178
+ };
179
+ export const Default = Template.bind({});
180
+
181
+ export const Small = Template.bind({});
182
+ Small.args = { small: true };
183
+
184
+ export const Row = Template.bind({});
185
+ Row.args = { row: true };
186
+
187
+ export const SmallRow = Template.bind({});
188
+ SmallRow.args = { row: true, small: true };
189
+
190
+ export const DisabledWithContext = Template.bind({});
191
+ DisabledWithContext.args = { disabled: true };