@pareto-engineering/design-system 2.0.0-alpha.48 → 2.0.0-alpha.50

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 (30) hide show
  1. package/dist/cjs/f/FormInput/FormInput.js +7 -0
  2. package/dist/cjs/f/fields/QueryCombobox/QueryCombobox.js +14 -8
  3. package/dist/cjs/f/fields/QuerySelect/QuerySelect.js +201 -0
  4. package/dist/cjs/f/fields/QuerySelect/index.js +15 -0
  5. package/dist/cjs/f/fields/QuerySelect/styles.scss +21 -0
  6. package/dist/cjs/f/fields/SelectInput/SelectInput.js +15 -3
  7. package/dist/cjs/f/fields/SelectInput/styles.scss +27 -14
  8. package/dist/cjs/f/fields/index.js +9 -1
  9. package/dist/es/f/FormInput/FormInput.js +8 -1
  10. package/dist/es/f/fields/QueryCombobox/QueryCombobox.js +14 -8
  11. package/dist/es/f/fields/QuerySelect/QuerySelect.js +179 -0
  12. package/dist/es/f/fields/QuerySelect/index.js +2 -0
  13. package/dist/es/f/fields/QuerySelect/styles.scss +21 -0
  14. package/dist/es/f/fields/SelectInput/SelectInput.js +14 -3
  15. package/dist/es/f/fields/SelectInput/styles.scss +27 -14
  16. package/dist/es/f/fields/index.js +2 -1
  17. package/package.json +1 -1
  18. package/src/__snapshots__/Storyshots.test.js.snap +582 -246
  19. package/src/stories/f/FormInput.stories.jsx +124 -6
  20. package/src/stories/f/QueryCombobox.stories.jsx +6 -4
  21. package/src/stories/f/QuerySelect.stories.jsx +134 -0
  22. package/src/stories/f/__generated__/FormInputAllTaskStatusesQuery.graphql.js +122 -0
  23. package/src/stories/f/__generated__/QuerySelectAllTaskStatusesQuery.graphql.js +122 -0
  24. package/src/ui/f/FormInput/FormInput.jsx +10 -0
  25. package/src/ui/f/fields/QueryCombobox/QueryCombobox.jsx +17 -13
  26. package/src/ui/f/fields/QuerySelect/QuerySelect.jsx +200 -0
  27. package/src/ui/f/fields/QuerySelect/index.js +2 -0
  28. package/src/ui/f/fields/SelectInput/SelectInput.jsx +16 -3
  29. package/src/ui/f/fields/SelectInput/styles.scss +27 -14
  30. package/src/ui/f/fields/index.js +1 -0
@@ -0,0 +1,179 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ import * as React from 'react';
3
+ import { useState, useEffect } from 'react';
4
+ import { useRelayEnvironment, fetchQuery } from 'react-relay';
5
+ import { useField } from 'formik';
6
+ import PropTypes from 'prop-types'; // Local Definitions
7
+
8
+ import { SelectInput } from "../..";
9
+ /**
10
+ * This is the component description.
11
+ */
12
+
13
+ const QuerySelect = ({
14
+ id,
15
+ className: userClassName,
16
+ style,
17
+ name,
18
+ label,
19
+ query,
20
+ variables,
21
+ optionsKeyMap,
22
+ description,
23
+ disabled,
24
+ color,
25
+ loadingOption,
26
+ defaultOption // ...otherProps
27
+
28
+ }) => {
29
+ const [,, helpers] = useField(name);
30
+ const {
31
+ setError
32
+ } = helpers;
33
+ const environment = useRelayEnvironment();
34
+ const [isFetching, setIsFetching] = useState(false);
35
+ const [options, setOptions] = useState([]);
36
+ const {
37
+ graphql,
38
+ accessor
39
+ } = query;
40
+
41
+ const getOptions = () => {
42
+ if (isFetching) return;
43
+ fetchQuery(environment, graphql, variables).subscribe({
44
+ start: () => {
45
+ setIsFetching(true);
46
+ setOptions([loadingOption]);
47
+ },
48
+ complete: () => {
49
+ setIsFetching(false);
50
+ },
51
+ error: fetchError => {
52
+ setIsFetching(false);
53
+ if (setError) setError(fetchError.message);
54
+ },
55
+ next: data => {
56
+ setOptions([defaultOption, ...data[accessor].edges.map(({
57
+ node
58
+ }) => ({
59
+ value: node[optionsKeyMap.value],
60
+ label: optionsKeyMap.getLabel(node)
61
+ }))]);
62
+ }
63
+ });
64
+ };
65
+
66
+ useEffect(() => {
67
+ getOptions();
68
+ }, [variables]);
69
+ return /*#__PURE__*/React.createElement(SelectInput, {
70
+ id: id,
71
+ className: userClassName,
72
+ style: style,
73
+ name: name,
74
+ label: label,
75
+ color: color,
76
+ description: description,
77
+ disabled: isFetching || disabled,
78
+ options: options,
79
+ isLoading: isFetching
80
+ });
81
+ };
82
+
83
+ QuerySelect.propTypes = {
84
+ /**
85
+ * The HTML id for this element
86
+ */
87
+ id: PropTypes.string,
88
+
89
+ /**
90
+ * The HTML class names for this element
91
+ */
92
+ className: PropTypes.string,
93
+
94
+ /**
95
+ * The React-written, css properties for this element.
96
+ */
97
+ style: PropTypes.objectOf(PropTypes.string),
98
+
99
+ /**
100
+ * The name of the custom select input
101
+ */
102
+ name: PropTypes.string,
103
+
104
+ /**
105
+ * The label of the custom select input
106
+ */
107
+ label: PropTypes.string,
108
+
109
+ /**
110
+ * The custom select input description
111
+ */
112
+ description: PropTypes.string,
113
+
114
+ /**
115
+ * Whether the input should be disabled
116
+ */
117
+ disabled: PropTypes.bool,
118
+
119
+ /**
120
+ * The base color of the custom select input
121
+ */
122
+ color: PropTypes.string,
123
+
124
+ /**
125
+ * The graphql query to fetch the options and the accessor to destructure the results from
126
+ */
127
+ query: PropTypes.shape({
128
+ accessor: PropTypes.string,
129
+ graphql: PropTypes.oneOfType([PropTypes.string, PropTypes.object]).isRequired
130
+ }),
131
+
132
+ /**
133
+ * The variables that might be required to be used in the query to fetch
134
+ * select options.
135
+ */
136
+ variables: PropTypes.objectOf(PropTypes.string),
137
+
138
+ /**
139
+ * The select option keys to be used to map the data to the select options.
140
+ * i.e `{ value: 'id', label: 'name' }`
141
+ */
142
+ optionsKeyMap: PropTypes.shape({
143
+ value: PropTypes.string.isRequired,
144
+ getLabel: PropTypes.func.isRequired
145
+ }).isRequired,
146
+
147
+ /**
148
+ * The default select option for the query select
149
+ */
150
+ defaultOption: PropTypes.shape({
151
+ value: PropTypes.string.isRequired,
152
+ label: PropTypes.string.isRequired,
153
+ disabled: PropTypes.bool.isRequired
154
+ }),
155
+
156
+ /**
157
+ * The option to dipslayed when the select options are being fetched
158
+ */
159
+ loadingOption: PropTypes.shape({
160
+ value: PropTypes.string.isRequired,
161
+ label: PropTypes.string.isRequired,
162
+ disabled: PropTypes.bool.isRequired
163
+ })
164
+ };
165
+ QuerySelect.defaultProps = {
166
+ disabled: false,
167
+ color: 'background2',
168
+ defaultOption: {
169
+ value: '',
170
+ label: 'Select an option',
171
+ disabled: true
172
+ },
173
+ loadingOption: {
174
+ value: '',
175
+ label: 'Fetching Options',
176
+ disabled: true
177
+ }
178
+ };
179
+ export default QuerySelect;
@@ -0,0 +1,2 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ export { default as QuerySelect } from "./QuerySelect";
@@ -0,0 +1,21 @@
1
+ /* @pareto-engineering/generator-front 1.0.12 */
2
+ @use "@pareto-engineering/bem";
3
+
4
+ $default-loading-circle-displacement: .8em;
5
+
6
+ .#{bem.$base}.query-select {
7
+ position: relative;
8
+
9
+
10
+ >.#{bem.$base}.select-input {
11
+ select:disabled {
12
+ appearance: none;
13
+ }
14
+ }
15
+
16
+ >.#{bem.$base}.loading-circle {
17
+ position: absolute;
18
+ right: $default-loading-circle-displacement;
19
+ bottom: $default-loading-circle-displacement;
20
+ }
21
+ }
@@ -6,6 +6,7 @@ import { useLayoutEffect, memo } from 'react';
6
6
  import { useField } from 'formik';
7
7
  import PropTypes from 'prop-types';
8
8
  import styleNames from '@pareto-engineering/bem';
9
+ import { LoadingCircle } from "../../../a";
9
10
  import { FormLabel, FormDescription } from "../../common"; // Local Definitions
10
11
 
11
12
  const baseClassName = styleNames.base;
@@ -24,7 +25,8 @@ const SelectInput = ({
24
25
  options,
25
26
  validate,
26
27
  description,
27
- disabled // ...otherProps
28
+ disabled,
29
+ isLoading // ...otherProps
28
30
 
29
31
  }) => {
30
32
  useLayoutEffect(() => {
@@ -41,7 +43,9 @@ const SelectInput = ({
41
43
 
42
44
  }, /*#__PURE__*/React.createElement(FormLabel, {
43
45
  name: name
44
- }, label), /*#__PURE__*/React.createElement("select", _extends({
46
+ }, label), /*#__PURE__*/React.createElement("div", {
47
+ className: "select-wrapper"
48
+ }, /*#__PURE__*/React.createElement("select", _extends({
45
49
  className: "input"
46
50
  }, field, {
47
51
  value: field.value || '',
@@ -58,6 +62,8 @@ const SelectInput = ({
58
62
  value: newOption.value,
59
63
  disabled: (newOption === null || newOption === void 0 ? void 0 : newOption.disabled) || false
60
64
  }, newOption.label);
65
+ })), isLoading && /*#__PURE__*/React.createElement(LoadingCircle, {
66
+ className: "x-main2"
61
67
  })), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(FormDescription, {
62
68
  isError: !!meta.error,
63
69
  className: "v50 mt-v s-1"
@@ -117,7 +123,12 @@ SelectInput.propTypes = {
117
123
  /**
118
124
  * The color of the select input
119
125
  */
120
- color: PropTypes.string
126
+ color: PropTypes.string,
127
+
128
+ /*
129
+ * Whether the query that is fetching the select options is still in flight
130
+ */
131
+ isLoading: PropTypes.bool
121
132
  };
122
133
  SelectInput.defaultProps = {
123
134
  disabled: false,
@@ -16,22 +16,35 @@ $default-margin: 1em;
16
16
  margin-bottom: $default-margin
17
17
  }
18
18
 
19
- .input {
20
- border: var(--theme-border-style) var(--dark-y);
21
- background: var(--light-y);
22
- color: var(--on-y);
23
- padding: $default-padding;
24
-
25
- &:not(:disabled):hover {
26
- border: var(--theme-border-style) var(--light-background4);
19
+ .select-wrapper {
20
+ position: relative;
21
+
22
+ >.#{bem.$base}.loading-circle {
23
+ position: absolute;
24
+ right: 0;
25
+ top: 50%;
26
+ transform: translateY(-50%);
27
27
  }
28
28
 
29
- &:disabled {
30
- background-color: var(--dark-y);
31
- }
32
-
33
- &:focus {
34
- background: var(--y);
29
+ >.input {
30
+ width: 100%;
31
+ border: var(--theme-border-style) var(--dark-y);
32
+ background: var(--light-y);
33
+ color: var(--on-y);
34
+ padding: $default-padding;
35
+
36
+ &:not(:disabled):hover {
37
+ border: var(--theme-border-style) var(--light-background4);
38
+ }
39
+
40
+ &:disabled {
41
+ background-color: var(--dark-y);
42
+ appearance: none;
43
+ }
44
+
45
+ &:focus {
46
+ background: var(--y);
47
+ }
35
48
  }
36
49
  }
37
50
  }
@@ -3,4 +3,5 @@ export { SelectInput } from "./SelectInput";
3
3
  export { ChoicesInput } from "./ChoicesInput";
4
4
  export { TextareaInput } from "./TextareaInput";
5
5
  export { RatingsInput } from "./RatingsInput";
6
- export { QueryCombobox } from "./QueryCombobox";
6
+ export { QueryCombobox } from "./QueryCombobox";
7
+ export { QuerySelect } from "./QuerySelect";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pareto-engineering/design-system",
3
- "version": "2.0.0-alpha.48",
3
+ "version": "2.0.0-alpha.50",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",