@utahdts/utah-design-system 0.0.1

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 (134) hide show
  1. package/README.md +54 -0
  2. package/css/1-settings/_class-vars.scss +11 -0
  3. package/css/1-settings/_color-swatches.scss +422 -0
  4. package/css/1-settings/_font-stuff.scss +48 -0
  5. package/css/1-settings/_grid.scss +39 -0
  6. package/css/1-settings/_icons.scss +6 -0
  7. package/css/1-settings/_settings-index.scss +116 -0
  8. package/css/1-settings/_spacing.scss +70 -0
  9. package/css/2-tools/_tools-index.scss +47 -0
  10. package/css/3-generic/_generic-index.scss +4 -0
  11. package/css/3-generic/normalize.css +349 -0
  12. package/css/4-elements/_elements-index.scss +89 -0
  13. package/css/5-objects/_objects-index.scss +9 -0
  14. package/css/6-components/_components-index.scss +31 -0
  15. package/css/6-components/base-components/buttons/_button.scss +401 -0
  16. package/css/6-components/base-components/buttons/_icon-button.scss +54 -0
  17. package/css/6-components/base-components/containers/_accordion.scss +31 -0
  18. package/css/6-components/base-components/containers/_tab-group.scss +57 -0
  19. package/css/6-components/base-components/forms/_checkbox.scss +67 -0
  20. package/css/6-components/base-components/forms/_info-box.scss +23 -0
  21. package/css/6-components/base-components/forms/_input-wrapper.scss +9 -0
  22. package/css/6-components/base-components/forms/_input.scss +10 -0
  23. package/css/6-components/base-components/forms/_radio-button.scss +60 -0
  24. package/css/6-components/base-components/forms/_select-input.scss +18 -0
  25. package/css/6-components/base-components/forms/_switch.scss +191 -0
  26. package/css/6-components/base-components/forms/_text-input.scss +15 -0
  27. package/css/6-components/base-components/navigation/_main-menu.scss +69 -0
  28. package/css/6-components/base-components/navigation/_menu-item.scss +44 -0
  29. package/css/6-components/base-components/navigation/_side-panel-navigation.scss +83 -0
  30. package/css/6-components/base-components/tablesAndLists/_table.scss +52 -0
  31. package/css/6-components/base-components/templates/_documenation-template.scss +50 -0
  32. package/css/6-components/base-components/templates/_landing-page-template.scss +8 -0
  33. package/css/6-components/base-components/templates/_on-this-page.scss +33 -0
  34. package/css/6-components/base-components/widgetsInicators/_spinner.scss +38 -0
  35. package/css/6-components/project-components/_popup.scss +22 -0
  36. package/css/6-components/project-components/_swatch-list.scss +41 -0
  37. package/css/7-utilities/_animation.scss +41 -0
  38. package/css/7-utilities/_utilities-index.scss +119 -0
  39. package/css/8-super/_print.scss +38 -0
  40. package/css/8-super/_super-index.scss +6 -0
  41. package/css/9-tip/_tip-index.scss +6 -0
  42. package/css/build/utah-design-system.css +2374 -0
  43. package/css/index.scss +52 -0
  44. package/index.js +117 -0
  45. package/package.json +55 -0
  46. package/react/components/buttons/Button.jsx +103 -0
  47. package/react/components/buttons/IconButton.jsx +36 -0
  48. package/react/components/buttons/SegmentedButton.jsx +1 -0
  49. package/react/components/containers/accordion/Accordion.jsx +67 -0
  50. package/react/components/containers/tabs/Tab.jsx +53 -0
  51. package/react/components/containers/tabs/TabGroup.jsx +66 -0
  52. package/react/components/containers/tabs/TabGroupContext.jsx +3 -0
  53. package/react/components/containers/tabs/TabGroupTitle.jsx +28 -0
  54. package/react/components/containers/tabs/TabList.jsx +31 -0
  55. package/react/components/containers/tabs/TabPanel.jsx +41 -0
  56. package/react/components/containers/tabs/TabPanels.jsx +20 -0
  57. package/react/components/forms/CheckBox.jsx +79 -0
  58. package/react/components/forms/ErrorMessage.jsx +25 -0
  59. package/react/components/forms/Form.jsx +68 -0
  60. package/react/components/forms/FormContext.jsx +3 -0
  61. package/react/components/forms/FormContextProvider.jsx +87 -0
  62. package/react/components/forms/PLACEHOLDER.md +1 -0
  63. package/react/components/forms/Select.jsx +85 -0
  64. package/react/components/forms/SelectOption.jsx +42 -0
  65. package/react/components/forms/Switch.jsx +122 -0
  66. package/react/components/forms/TextInput.jsx +80 -0
  67. package/react/components/icons/Icons.jsx +7 -0
  68. package/react/components/lists/PLACEHOLDER.md +1 -0
  69. package/react/components/map/PLACEHOLDER.md +1 -0
  70. package/react/components/navigation/HorizontalMenu.jsx +46 -0
  71. package/react/components/navigation/MainMenu.jsx +28 -0
  72. package/react/components/navigation/MenuItem.jsx +116 -0
  73. package/react/components/navigation/OnThisPage.jsx +34 -0
  74. package/react/components/navigation/OnThisPageHeadersLevel.jsx +35 -0
  75. package/react/components/navigation/SidePanelNavigation.jsx +41 -0
  76. package/react/components/navigation/util/findElementsByTagNameMatch.js +11 -0
  77. package/react/components/navigation/util/groupElementsByHeaderLevel.js +41 -0
  78. package/react/components/popups/PLACEHOLDER.md +1 -0
  79. package/react/components/table/Table.jsx +34 -0
  80. package/react/components/table/TableBody.jsx +35 -0
  81. package/react/components/table/TableBodyData.jsx +91 -0
  82. package/react/components/table/TableBodyDataCellTemplate.jsx +73 -0
  83. package/react/components/table/TableBodyDataRowContext.jsx +3 -0
  84. package/react/components/table/TableBodyDataRowTemplate.jsx +56 -0
  85. package/react/components/table/TableCell.jsx +50 -0
  86. package/react/components/table/TableContext.jsx +3 -0
  87. package/react/components/table/TableFilterCustom.jsx +34 -0
  88. package/react/components/table/TableFilterNone.jsx +34 -0
  89. package/react/components/table/TableFilterSelect.jsx +34 -0
  90. package/react/components/table/TableFilterSelectOption.jsx +34 -0
  91. package/react/components/table/TableFilterTextInput.jsx +64 -0
  92. package/react/components/table/TableFilters.jsx +88 -0
  93. package/react/components/table/TableFoot.jsx +34 -0
  94. package/react/components/table/TableFootCell.jsx +34 -0
  95. package/react/components/table/TableFootRow.jsx +34 -0
  96. package/react/components/table/TableHead.jsx +39 -0
  97. package/react/components/table/TableHeadCell.jsx +79 -0
  98. package/react/components/table/TableHeadRow.jsx +34 -0
  99. package/react/components/table/TableRow.jsx +49 -0
  100. package/react/components/table/TableSortingRule.jsx +55 -0
  101. package/react/components/table/TableSortingRules.jsx +64 -0
  102. package/react/components/table/TableWrapper.jsx +128 -0
  103. package/react/components/table/useCurrentValuesFromStateContext.js +73 -0
  104. package/react/components/templates/DocumentationTemplate.jsx +52 -0
  105. package/react/components/templates/LandingTemplate.jsx +29 -0
  106. package/react/components/utahHeader/UtahHeader.jsx +25 -0
  107. package/react/components/utahHeader/UtahUnbrand.jsx +50 -0
  108. package/react/components/widgetsIndicators/Spinner.jsx +71 -0
  109. package/react/enums/formElementSizesEnum.js +9 -0
  110. package/react/enums/tableSortingRuleFieldType.js +9 -0
  111. package/react/hooks/forms/useCurrentValuesFromForm.js +44 -0
  112. package/react/hooks/useBanner.js +6 -0
  113. package/react/hooks/useCurrentMenuItem.js +29 -0
  114. package/react/hooks/usePrepMenuItems.js +24 -0
  115. package/react/hooks/useRefAlways.js +8 -0
  116. package/react/hooks/useRefLazy.js +11 -0
  117. package/react/hooks/useScrollPosition.js +18 -0
  118. package/react/hooks/useStateEffect.js +43 -0
  119. package/react/propTypesShapes/MenuItemShape.js +20 -0
  120. package/react/propTypesShapes/MenuItemsShape.js +4 -0
  121. package/react/propTypesShapes/MenuShape.js +10 -0
  122. package/react/propTypesShapes/RefShape.js +9 -0
  123. package/react/util/arrayMatchRecursive.js +21 -0
  124. package/react/util/chainSorters.js +19 -0
  125. package/react/util/handleEvent.js +25 -0
  126. package/react/util/handleKeyPress.js +1 -0
  127. package/react/util/joinClassNames.js +23 -0
  128. package/react/util/menuItems/calculateMenuItemsParents.js +54 -0
  129. package/react/util/menuItems/findMenuItemInMenusByPathname.js +25 -0
  130. package/react/util/onKeyPress.js +12 -0
  131. package/react/util/rectContainsPoint.js +7 -0
  132. package/react/util/state/setValueAtPath.js +80 -0
  133. package/react/util/state/valueAtPath.js +5 -0
  134. package/react/util/stringToId.js +11 -0
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableFilter({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <th className={joinClassNames('some-TableFilter-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </th>
28
+ );
29
+ }
30
+
31
+ TableFilter.propTypes = propTypes;
32
+ TableFilter.defaultProps = defaultProps;
33
+
34
+ export default TableFilter;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableFilter({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <th className={joinClassNames('some-TableFilter-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </th>
28
+ );
29
+ }
30
+
31
+ TableFilter.propTypes = propTypes;
32
+ TableFilter.defaultProps = defaultProps;
33
+
34
+ export default TableFilter;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableFilter({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <th className={joinClassNames('some-TableFilter-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </th>
28
+ );
29
+ }
30
+
31
+ TableFilter.propTypes = propTypes;
32
+ TableFilter.defaultProps = defaultProps;
33
+
34
+ export default TableFilter;
@@ -0,0 +1,64 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+ import TextInput from '../forms/TextInput';
5
+ import TableContext from './TableContext';
6
+ import useCurrentValuesFromStateContext from './useCurrentValuesFromStateContext';
7
+
8
+ const propTypes = {
9
+ className: PropTypes.string,
10
+ defaultValue: PropTypes.string,
11
+ innerRef: RefShape,
12
+ id: PropTypes.string,
13
+ onChange: PropTypes.func,
14
+ recordFieldPath: PropTypes.string.isRequired,
15
+ value: PropTypes.string,
16
+ };
17
+ const defaultProps = {
18
+ className: null,
19
+ defaultValue: null,
20
+ innerRef: null,
21
+ id: null,
22
+ onChange: null,
23
+ value: null,
24
+ };
25
+
26
+ function TableFilter({
27
+ className,
28
+ defaultValue,
29
+ innerRef,
30
+ id,
31
+ onChange,
32
+ recordFieldPath,
33
+ value,
34
+ ...rest
35
+ }) {
36
+ const {
37
+ currentOnChange,
38
+ currentValue,
39
+ } = useCurrentValuesFromStateContext({
40
+ context: TableContext,
41
+ contextStatePath: recordFieldPath,
42
+ defaultOnChange: (e) => e.target.value,
43
+ defaultValue,
44
+ onChange,
45
+ value,
46
+ });
47
+ return (
48
+ <th className={joinClassNames('some-TableFilter-className', className)} id={id} ref={innerRef}>
49
+ <TextInput
50
+ id={`table-filter-text-input-${recordFieldPath}`}
51
+ label={`filter ${recordFieldPath}`}
52
+ onChange={currentOnChange}
53
+ value={currentValue}
54
+ // eslint-disable-next-line react/jsx-props-no-spreading
55
+ {...rest}
56
+ />
57
+ </th>
58
+ );
59
+ }
60
+
61
+ TableFilter.propTypes = propTypes;
62
+ TableFilter.defaultProps = defaultProps;
63
+
64
+ export default TableFilter;
@@ -0,0 +1,88 @@
1
+ import PropTypes from 'prop-types';
2
+ import { useContext, useEffect } from 'react';
3
+ import RefShape from '../../propTypesShapes/RefShape';
4
+ import joinClassNames from '../../util/joinClassNames';
5
+ import TableContext from './TableContext';
6
+
7
+ const propTypes = {
8
+ children: PropTypes.node.isRequired,
9
+ defaultValue: PropTypes.shape({}),
10
+ className: PropTypes.string,
11
+ innerRef: RefShape,
12
+ id: PropTypes.string,
13
+ // fires when any filter changes; ie ({ recordFieldPath, value }) => { ... do something ... }
14
+ onChange: PropTypes.func,
15
+ // make sure to useMemo() before passing value in here
16
+ value: PropTypes.shape({}),
17
+ };
18
+ const defaultProps = {
19
+ className: null,
20
+ defaultValue: null,
21
+ innerRef: null,
22
+ id: null,
23
+ onChange: null,
24
+ value: null,
25
+ };
26
+
27
+ function TableFilters({
28
+ children,
29
+ className,
30
+ defaultValue,
31
+ innerRef,
32
+ id,
33
+ onChange,
34
+ value,
35
+ ...rest
36
+ }) {
37
+ const { setState, state } = useContext(TableContext);
38
+
39
+ useEffect(
40
+ () => {
41
+ if (
42
+ state.filterValues.defaultValue
43
+ || state.filterValues.onChange
44
+ || state.filterValues.value
45
+ ) {
46
+ // if you want to do more than one Filters section, then you'll want to update the context's
47
+ // filterValues.onChange to be an array... and maybe some other changes... ymmv
48
+ console.warn('defaultValue, onChange, or value were already set for Filters. There should only be one <TableFilters/> section in a table.');
49
+ }
50
+
51
+ setState((draftState) => {
52
+ draftState.filterValues.defaultValue = defaultValue;
53
+ draftState.filterValues.onChange = onChange;
54
+ draftState.filterValues.value = value || draftState.filterValues.value;
55
+ });
56
+
57
+ return () => {
58
+ setState((draftState) => {
59
+ draftState.filterValues.defaultValue = null;
60
+ draftState.filterValues.onChange = null;
61
+ draftState.filterValues.value = null;
62
+ });
63
+ };
64
+ },
65
+ []
66
+ );
67
+
68
+ // when value changes, update state...
69
+ useEffect(
70
+ () => {
71
+ setState((draftState) => {
72
+ draftState.filterValues.value = value || draftState.filterValues.value;
73
+ });
74
+ },
75
+ [value]
76
+ );
77
+
78
+ return (
79
+ <tr className={joinClassNames('some-TableFilters-classname', className)} id={id} ref={innerRef} {...rest}>
80
+ {children}
81
+ </tr>
82
+ );
83
+ }
84
+
85
+ TableFilters.propTypes = propTypes;
86
+ TableFilters.defaultProps = defaultProps;
87
+
88
+ export default TableFilters;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableFoot({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <tfoot className={joinClassNames('some-TableFoot-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </tfoot>
28
+ );
29
+ }
30
+
31
+ TableFoot.propTypes = propTypes;
32
+ TableFoot.defaultProps = defaultProps;
33
+
34
+ export default TableFoot;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableFootCell({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <td className={joinClassNames('some-TableFootCell-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </td>
28
+ );
29
+ }
30
+
31
+ TableFootCell.propTypes = propTypes;
32
+ TableFootCell.defaultProps = defaultProps;
33
+
34
+ export default TableFootCell;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableFootRow({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <tr className={joinClassNames('some-TableFootRow-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </tr>
28
+ );
29
+ }
30
+
31
+ TableFootRow.propTypes = propTypes;
32
+ TableFootRow.defaultProps = defaultProps;
33
+
34
+ export default TableFootRow;
@@ -0,0 +1,39 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableHead({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <thead
26
+ className={joinClassNames('some-TableHead-classname', className)}
27
+ id={id}
28
+ ref={innerRef}
29
+ {...rest}
30
+ >
31
+ {children}
32
+ </thead>
33
+ );
34
+ }
35
+
36
+ TableHead.propTypes = propTypes;
37
+ TableHead.defaultProps = defaultProps;
38
+
39
+ export default TableHead;
@@ -0,0 +1,79 @@
1
+ import PropTypes from 'prop-types';
2
+ import { useContext } from 'react';
3
+ import RefShape from '../../propTypesShapes/RefShape';
4
+ import joinClassNames from '../../util/joinClassNames';
5
+ import TableContext from './TableContext';
6
+
7
+ const propTypes = {
8
+ children: PropTypes.node,
9
+ className: PropTypes.string,
10
+ // The field related to this column. CellTemplate and RowTemplate can define a field. This field is used for determining sorting and filtering.
11
+ recordFieldPath: PropTypes.string,
12
+ innerRef: RefShape,
13
+ id: PropTypes.string,
14
+ onClick: PropTypes.func,
15
+ tableSortingFieldPaths: PropTypes.arrayOf(PropTypes.string),
16
+ };
17
+ const defaultProps = {
18
+ children: null,
19
+ className: null,
20
+ recordFieldPath: null,
21
+ innerRef: null,
22
+ id: null,
23
+ onClick: null,
24
+ tableSortingFieldPaths: null,
25
+ };
26
+
27
+ function TableHeadCell({
28
+ children,
29
+ className,
30
+ recordFieldPath,
31
+ innerRef,
32
+ id,
33
+ onClick,
34
+ tableSortingFieldPaths,
35
+ ...rest
36
+ }) {
37
+ const { setState, state: { currentSortingOrderIsDefault, sortingRules, tableSortingFieldPath } } = useContext(TableContext);
38
+ return (
39
+ <th
40
+ className={joinClassNames(
41
+ 'some-TableHeadCell-classname',
42
+ className,
43
+ (sortingRules[recordFieldPath] || tableSortingFieldPaths) && 'this-td-is-sortable!-by-clicking-on-the-th!',
44
+ (tableSortingFieldPath === recordFieldPath) && 'i-am-a-bad-classname-denoting-that-this-th-is-currently-the-sorted-column',
45
+ (tableSortingFieldPath === recordFieldPath) && (
46
+ currentSortingOrderIsDefault
47
+ ? 'another-bad-classname-saying-that-this-column-is-sorting-by-default-order'
48
+ : 'another-bad-classname-saying-that-this-column-is-sorting-by-not-default-/-opposite-order'
49
+ )
50
+ )}
51
+ id={id}
52
+ onClick={(e) => {
53
+ if (onClick) {
54
+ onClick(e);
55
+ } else if (tableSortingFieldPath === recordFieldPath) {
56
+ setState((draftState) => {
57
+ draftState.currentSortingOrderIsDefault = !draftState.currentSortingOrderIsDefault;
58
+ });
59
+ } else if (sortingRules[recordFieldPath] || tableSortingFieldPaths) {
60
+ setState((draftState) => {
61
+ // still need fieldPath to identify which head cell this is, but tableSortingFieldPaths determines sorting
62
+ draftState.tableSortingFieldPath = recordFieldPath;
63
+ draftState.tableSortingFieldPaths = tableSortingFieldPaths;
64
+ draftState.currentSortingOrderIsDefault = true;
65
+ });
66
+ }
67
+ }}
68
+ ref={innerRef}
69
+ {...rest}
70
+ >
71
+ {children}
72
+ </th>
73
+ );
74
+ }
75
+
76
+ TableHeadCell.propTypes = propTypes;
77
+ TableHeadCell.defaultProps = defaultProps;
78
+
79
+ export default TableHeadCell;
@@ -0,0 +1,34 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ };
11
+ const defaultProps = {
12
+ className: null,
13
+ innerRef: null,
14
+ id: null,
15
+ };
16
+
17
+ function TableHeadRow({
18
+ children,
19
+ className,
20
+ innerRef,
21
+ id,
22
+ ...rest
23
+ }) {
24
+ return (
25
+ <tr className={joinClassNames('some-TableHeadRow-classname', className)} id={id} ref={innerRef} {...rest}>
26
+ {children}
27
+ </tr>
28
+ );
29
+ }
30
+
31
+ TableHeadRow.propTypes = propTypes;
32
+ TableHeadRow.defaultProps = defaultProps;
33
+
34
+ export default TableHeadRow;
@@ -0,0 +1,49 @@
1
+ import PropTypes from 'prop-types';
2
+ import RefShape from '../../propTypesShapes/RefShape';
3
+ import joinClassNames from '../../util/joinClassNames';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ className: PropTypes.string,
8
+ innerRef: RefShape,
9
+ id: PropTypes.string,
10
+ // (e) => { ... do something ... }
11
+ onClick: PropTypes.func,
12
+ // (e) => { ... do something ... }
13
+ onDoubleClick: PropTypes.func,
14
+ };
15
+ const defaultProps = {
16
+ className: null,
17
+ innerRef: null,
18
+ id: null,
19
+ onClick: null,
20
+ onDoubleClick: null,
21
+ };
22
+
23
+ function TableRow({
24
+ children,
25
+ className,
26
+ innerRef,
27
+ id,
28
+ onClick,
29
+ onDoubleClick,
30
+ ...rest
31
+ }) {
32
+ return (
33
+ <tr
34
+ className={joinClassNames('some-TableRow-classname', className)}
35
+ id={id}
36
+ ref={innerRef}
37
+ onClick={onClick}
38
+ onDoubleClick={onDoubleClick}
39
+ {...rest}
40
+ >
41
+ {children}
42
+ </tr>
43
+ );
44
+ }
45
+
46
+ TableRow.propTypes = propTypes;
47
+ TableRow.defaultProps = defaultProps;
48
+
49
+ export default TableRow;
@@ -0,0 +1,55 @@
1
+ import PropTypes from 'prop-types';
2
+ import { useContext, useEffect } from 'react';
3
+ import tableSortingRuleFieldType from '../../enums/tableSortingRuleFieldType';
4
+ import TableContext from './TableContext';
5
+
6
+ const propTypes = {
7
+ // should be a function that does sorting
8
+ // ({ fieldValueA, fieldValueB, recordA, recordB, records }) => (a < b ? -1 : a > b ? 1 : 0)
9
+ customSort: PropTypes.func,
10
+ // should the field sort ascending by default
11
+ defaultIsAscending: PropTypes.bool,
12
+ // what type of data is in this field so it knows how to sort it
13
+ fieldType: PropTypes.oneOf(Object.values(tableSortingRuleFieldType)),
14
+ // recordFieldPath should match with a recordFieldPath for a <TableHeadCell> in the table
15
+ // OR as one of the tableSortingFieldPaths in a<TableHeadCell>
16
+ // if your records need a calculated field, it is suggested to calculate the value and store it on the record and set this path to the
17
+ // calculated value's path. This way the value does not have to be recalculatd on every render.
18
+ recordFieldPath: PropTypes.string.isRequired,
19
+ };
20
+ const defaultProps = {
21
+ customSort: null,
22
+ defaultIsAscending: true,
23
+ fieldType: 'string',
24
+ };
25
+
26
+ function TableSortingRule({
27
+ customSort,
28
+ defaultIsAscending,
29
+ fieldType,
30
+ recordFieldPath,
31
+ }) {
32
+ const { registerSortingRule, unregisterSortingRule } = useContext(TableContext);
33
+
34
+ // register this sorting rule with the context
35
+ useEffect(
36
+ () => {
37
+ registerSortingRule({
38
+ customSort,
39
+ defaultIsAscending,
40
+ fieldType,
41
+ recordFieldPath,
42
+ });
43
+ return () => unregisterSortingRule(recordFieldPath);
44
+ },
45
+ []
46
+ );
47
+
48
+ // this component does not render anything
49
+ return null;
50
+ }
51
+
52
+ TableSortingRule.propTypes = propTypes;
53
+ TableSortingRule.defaultProps = defaultProps;
54
+
55
+ export default TableSortingRule;
@@ -0,0 +1,64 @@
1
+ import PropTypes from 'prop-types';
2
+ import { useContext, useEffect } from 'react';
3
+ import TableContext from './TableContext';
4
+
5
+ const propTypes = {
6
+ children: PropTypes.node.isRequired,
7
+ defaultValue: PropTypes.string,
8
+ // ({ recordFieldPath }) => { ... do something ... }
9
+ onChange: PropTypes.func,
10
+ value: PropTypes.string,
11
+ };
12
+ const defaultProps = {
13
+ defaultValue: null,
14
+ onChange: null,
15
+ value: undefined,
16
+ };
17
+
18
+ function TableSortingRules({
19
+ children,
20
+ defaultValue,
21
+ onChange,
22
+ value,
23
+ }) {
24
+ const { setState, state } = useContext(TableContext);
25
+ useEffect(
26
+ () => {
27
+ if ((onChange && state.tableSortingOnChange) || (defaultValue && state.tableSortingFieldPath)) {
28
+ console.error('A TableWrapper should only have one TableSortingRules section.');
29
+ } else {
30
+ if (onChange) {
31
+ setState((draftState) => { draftState.tableSortingOnChange = onChange; });
32
+ }
33
+ if (defaultValue) {
34
+ setState((draftState) => { draftState.tableSortingFieldPath = defaultValue; });
35
+ }
36
+ }
37
+
38
+ // unset the onChange if this component gets unmounted
39
+ return () => {
40
+ if (onChange === state.tableSortingOnChange) {
41
+ setState((draftState) => { draftState.tableSortingOnChange = null; });
42
+ }
43
+ };
44
+ },
45
+ []
46
+ );
47
+
48
+ // controlled by parent, so set value to current value
49
+ useEffect(
50
+ () => {
51
+ if (value !== undefined) {
52
+ setState((draftState) => { draftState.tableSortingFieldPath = value; });
53
+ }
54
+ },
55
+ [value]
56
+ );
57
+
58
+ return children;
59
+ }
60
+
61
+ TableSortingRules.propTypes = propTypes;
62
+ TableSortingRules.defaultProps = defaultProps;
63
+
64
+ export default TableSortingRules;