@pareto-engineering/design-system 2.0.0-alpha.15 → 2.0.0-alpha.16

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.
@@ -38,13 +38,18 @@ var SelectInput = _ref => {
38
38
  name,
39
39
  label,
40
40
  options,
41
+ validate,
42
+ description,
41
43
  disabled // ...otherProps
42
44
 
43
45
  } = _ref;
44
46
  (0, React.useLayoutEffect)(() => {
45
47
  Promise.resolve().then(() => _interopRequireWildcard(require("./styles.scss")));
46
48
  }, []);
47
- var [field, meta] = (0, _formik.useField)(name);
49
+ var [field, meta] = (0, _formik.useField)({
50
+ name,
51
+ validate
52
+ });
48
53
  return /*#__PURE__*/React.createElement("div", {
49
54
  id: id,
50
55
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
@@ -56,6 +61,7 @@ var SelectInput = _ref => {
56
61
  }, label), /*#__PURE__*/React.createElement("select", _extends({
57
62
  className: "input v25 pv-v"
58
63
  }, field, {
64
+ value: field.value || '',
59
65
  id: name,
60
66
  disabled: disabled
61
67
  }), options.map(option => {
@@ -66,11 +72,13 @@ var SelectInput = _ref => {
66
72
  } : option;
67
73
  return /*#__PURE__*/React.createElement("option", {
68
74
  key: newOption.value,
69
- value: newOption.value
75
+ value: newOption.value,
76
+ disabled: (newOption === null || newOption === void 0 ? void 0 : newOption.disabled) || false
70
77
  }, newOption.label);
71
- })), meta.error && meta.touched && /*#__PURE__*/React.createElement(_common.FormDescription, {
72
- error: true
73
- }, meta.error));
78
+ })), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(_common.FormDescription, {
79
+ isError: !!meta.error,
80
+ className: "v50 mt-v s-1"
81
+ }, meta.error || description));
74
82
  };
75
83
 
76
84
  SelectInput.propTypes = {
@@ -99,12 +107,23 @@ SelectInput.propTypes = {
99
107
  */
100
108
  label: _propTypes.default.string,
101
109
 
110
+ /**
111
+ * The input field validator function
112
+ */
113
+ validate: _propTypes.default.func,
114
+
115
+ /**
116
+ * The select input description
117
+ */
118
+ description: _propTypes.default.string,
119
+
102
120
  /**
103
121
  * The options of the select input
104
122
  */
105
123
  options: _propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.shape({
106
124
  value: _propTypes.default.string,
107
- label: _propTypes.default.string
125
+ label: _propTypes.default.string,
126
+ disabled: _propTypes.default.bool
108
127
  })])),
109
128
 
110
129
  /**
@@ -18,12 +18,12 @@ $default-padding: 0.75em 0.75em 0.55em;
18
18
  }
19
19
 
20
20
  .input {
21
- background: var(--light-background1);
22
- color: var(--on-background1);
21
+ background: var(--light-background2);
22
+ color: var(--on-background2);
23
23
  padding: $default-padding;
24
24
 
25
25
  &:focus {
26
- background: var(--dark-background1);
26
+ background: var(--dark-background2);
27
27
  }
28
28
  }
29
29
  }
@@ -41,7 +41,8 @@ var TextInput = _ref => {
41
41
  validate,
42
42
  oneInputLabel,
43
43
  description,
44
- disabled // ...otherProps
44
+ disabled,
45
+ placeholder // ...otherProps
45
46
 
46
47
  } = _ref;
47
48
  (0, React.useLayoutEffect)(() => {
@@ -63,7 +64,8 @@ var TextInput = _ref => {
63
64
  id: name,
64
65
  className: "input ".concat(meta.touched && meta.error ? 'input-border-error' : 'input-border'),
65
66
  type: type,
66
- disabled: disabled
67
+ disabled: disabled,
68
+ placeholder: placeholder
67
69
  }, field)), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(_common.FormDescription, {
68
70
  isError: !!meta.error,
69
71
  className: "v50 mt-v s-1"
@@ -119,7 +121,12 @@ TextInput.propTypes = {
119
121
  /**
120
122
  * Whether the text input should be disabled
121
123
  */
122
- disabled: _propTypes.default.bool
124
+ disabled: _propTypes.default.bool,
125
+
126
+ /**
127
+ * The placeholder text for the input
128
+ */
129
+ placeholder: _propTypes.default.string
123
130
  };
124
131
  TextInput.defaultProps = {
125
132
  type: 'text',
@@ -21,13 +21,18 @@ const SelectInput = ({
21
21
  name,
22
22
  label,
23
23
  options,
24
+ validate,
25
+ description,
24
26
  disabled // ...otherProps
25
27
 
26
28
  }) => {
27
29
  useLayoutEffect(() => {
28
30
  import("./styles.scss");
29
31
  }, []);
30
- const [field, meta] = useField(name);
32
+ const [field, meta] = useField({
33
+ name,
34
+ validate
35
+ });
31
36
  return /*#__PURE__*/React.createElement("div", {
32
37
  id: id,
33
38
  className: [baseClassName, componentClassName, userClassName].filter(e => e).join(' '),
@@ -39,6 +44,7 @@ const SelectInput = ({
39
44
  }, label), /*#__PURE__*/React.createElement("select", _extends({
40
45
  className: "input v25 pv-v"
41
46
  }, field, {
47
+ value: field.value || '',
42
48
  id: name,
43
49
  disabled: disabled
44
50
  }), options.map(option => {
@@ -49,11 +55,13 @@ const SelectInput = ({
49
55
  } : option;
50
56
  return /*#__PURE__*/React.createElement("option", {
51
57
  key: newOption.value,
52
- value: newOption.value
58
+ value: newOption.value,
59
+ disabled: (newOption === null || newOption === void 0 ? void 0 : newOption.disabled) || false
53
60
  }, newOption.label);
54
- })), meta.error && meta.touched && /*#__PURE__*/React.createElement(FormDescription, {
55
- error: true
56
- }, meta.error));
61
+ })), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(FormDescription, {
62
+ isError: !!meta.error,
63
+ className: "v50 mt-v s-1"
64
+ }, meta.error || description));
57
65
  };
58
66
 
59
67
  SelectInput.propTypes = {
@@ -82,12 +90,23 @@ SelectInput.propTypes = {
82
90
  */
83
91
  label: PropTypes.string,
84
92
 
93
+ /**
94
+ * The input field validator function
95
+ */
96
+ validate: PropTypes.func,
97
+
98
+ /**
99
+ * The select input description
100
+ */
101
+ description: PropTypes.string,
102
+
85
103
  /**
86
104
  * The options of the select input
87
105
  */
88
106
  options: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.shape({
89
107
  value: PropTypes.string,
90
- label: PropTypes.string
108
+ label: PropTypes.string,
109
+ disabled: PropTypes.bool
91
110
  })])),
92
111
 
93
112
  /**
@@ -18,12 +18,12 @@ $default-padding: 0.75em 0.75em 0.55em;
18
18
  }
19
19
 
20
20
  .input {
21
- background: var(--light-background1);
22
- color: var(--on-background1);
21
+ background: var(--light-background2);
22
+ color: var(--on-background2);
23
23
  padding: $default-padding;
24
24
 
25
25
  &:focus {
26
- background: var(--dark-background1);
26
+ background: var(--dark-background2);
27
27
  }
28
28
  }
29
29
  }
@@ -24,7 +24,8 @@ const TextInput = ({
24
24
  validate,
25
25
  oneInputLabel,
26
26
  description,
27
- disabled // ...otherProps
27
+ disabled,
28
+ placeholder // ...otherProps
28
29
 
29
30
  }) => {
30
31
  useLayoutEffect(() => {
@@ -46,7 +47,8 @@ const TextInput = ({
46
47
  id: name,
47
48
  className: `input ${meta.touched && meta.error ? 'input-border-error' : 'input-border'}`,
48
49
  type: type,
49
- disabled: disabled
50
+ disabled: disabled,
51
+ placeholder: placeholder
50
52
  }, field)), (description || meta.touched && meta.error) && /*#__PURE__*/React.createElement(FormDescription, {
51
53
  isError: !!meta.error,
52
54
  className: "v50 mt-v s-1"
@@ -102,7 +104,12 @@ TextInput.propTypes = {
102
104
  /**
103
105
  * Whether the text input should be disabled
104
106
  */
105
- disabled: PropTypes.bool
107
+ disabled: PropTypes.bool,
108
+
109
+ /**
110
+ * The placeholder text for the input
111
+ */
112
+ placeholder: PropTypes.string
106
113
  };
107
114
  TextInput.defaultProps = {
108
115
  type: 'text',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pareto-engineering/design-system",
3
- "version": "2.0.0-alpha.15",
3
+ "version": "2.0.0-alpha.16",
4
4
  "description": "",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/es/index.js",
@@ -9273,18 +9273,22 @@ exports[`Storyshots f/FormInput Base 1`] = `
9273
9273
  name="food"
9274
9274
  onBlur={[Function]}
9275
9275
  onChange={[Function]}
9276
+ value=""
9276
9277
  >
9277
9278
  <option
9279
+ disabled={false}
9278
9280
  value="italian"
9279
9281
  >
9280
9282
  A nice pizza
9281
9283
  </option>
9282
9284
  <option
9285
+ disabled={false}
9283
9286
  value="turkish"
9284
9287
  >
9285
9288
  A delicious kebab
9286
9289
  </option>
9287
9290
  <option
9291
+ disabled={false}
9288
9292
  value="french"
9289
9293
  >
9290
9294
  A three course delicate french meal
@@ -9458,18 +9462,22 @@ exports[`Storyshots f/FormInput Disabled Form Input 1`] = `
9458
9462
  name="food"
9459
9463
  onBlur={[Function]}
9460
9464
  onChange={[Function]}
9465
+ value=""
9461
9466
  >
9462
9467
  <option
9468
+ disabled={false}
9463
9469
  value="italian"
9464
9470
  >
9465
9471
  A nice pizza
9466
9472
  </option>
9467
9473
  <option
9474
+ disabled={false}
9468
9475
  value="turkish"
9469
9476
  >
9470
9477
  A delicious kebab
9471
9478
  </option>
9472
9479
  <option
9480
+ disabled={false}
9473
9481
  value="french"
9474
9482
  >
9475
9483
  A three course delicate french meal
@@ -11124,16 +11132,19 @@ exports[`Storyshots f/fields/SelectInput Base 1`] = `
11124
11132
  value="Work"
11125
11133
  >
11126
11134
  <option
11135
+ disabled={false}
11127
11136
  value="Work"
11128
11137
  >
11129
11138
  Work
11130
11139
  </option>
11131
11140
  <option
11141
+ disabled={false}
11132
11142
  value="Managing"
11133
11143
  >
11134
11144
  Managing
11135
11145
  </option>
11136
11146
  <option
11147
+ disabled={false}
11137
11148
  value="Training"
11138
11149
  >
11139
11150
  Training
@@ -11179,26 +11190,31 @@ exports[`Storyshots f/fields/SelectInput Disabled Select Input 1`] = `
11179
11190
  value="Work"
11180
11191
  >
11181
11192
  <option
11193
+ disabled={false}
11182
11194
  value="Work"
11183
11195
  >
11184
11196
  Work
11185
11197
  </option>
11186
11198
  <option
11199
+ disabled={false}
11187
11200
  value="Managing"
11188
11201
  >
11189
11202
  Managing
11190
11203
  </option>
11191
11204
  <option
11205
+ disabled={false}
11192
11206
  value="Training"
11193
11207
  >
11194
11208
  Training
11195
11209
  </option>
11196
11210
  <option
11211
+ disabled={false}
11197
11212
  value="20th Aug 2020 to 19th Sept, 2020"
11198
11213
  >
11199
11214
  20th Aug 2020 to 19th Sept, 2020
11200
11215
  </option>
11201
11216
  <option
11217
+ disabled={false}
11202
11218
  value="20th Sept 2020 to 19th Oct, 2020"
11203
11219
  >
11204
11220
  20th Sept 2020 to 19th Oct, 2020
@@ -11244,11 +11260,13 @@ exports[`Storyshots f/fields/SelectInput Objects 1`] = `
11244
11260
  value="Work"
11245
11261
  >
11246
11262
  <option
11263
+ disabled={false}
11247
11264
  value="20th Aug 2020 to 19th Sept, 2020"
11248
11265
  >
11249
11266
  20th Aug 2020 to 19th Sept, 2020
11250
11267
  </option>
11251
11268
  <option
11269
+ disabled={false}
11252
11270
  value="20th Sept 2020 to 19th Oct, 2020"
11253
11271
  >
11254
11272
  20th Sept 2020 to 19th Oct, 2020
@@ -11269,6 +11287,64 @@ exports[`Storyshots f/fields/SelectInput Objects 1`] = `
11269
11287
  </form>
11270
11288
  `;
11271
11289
 
11290
+ exports[`Storyshots f/fields/SelectInput Required Select 1`] = `
11291
+ <form
11292
+ action="#"
11293
+ onReset={[Function]}
11294
+ onSubmit={[Function]}
11295
+ >
11296
+ <div
11297
+ className="base select-input"
11298
+ >
11299
+ <label
11300
+ className="base label input-label x-main2"
11301
+ htmlFor="activity"
11302
+ >
11303
+ Activity Type
11304
+ </label>
11305
+ <select
11306
+ className="input v25 pv-v"
11307
+ disabled={false}
11308
+ id="activity"
11309
+ name="activity"
11310
+ onBlur={[Function]}
11311
+ onChange={[Function]}
11312
+ value=""
11313
+ >
11314
+ <option
11315
+ disabled={true}
11316
+ value=""
11317
+ >
11318
+ Select activity type
11319
+ </option>
11320
+ <option
11321
+ disabled={false}
11322
+ value="review"
11323
+ >
11324
+ Review
11325
+ </option>
11326
+ <option
11327
+ disabled={false}
11328
+ value="Approve"
11329
+ >
11330
+ Approve
11331
+ </option>
11332
+ </select>
11333
+ </div>
11334
+ <div
11335
+ className="debugger"
11336
+ >
11337
+ <button
11338
+ className="base button x-main2"
11339
+ onClick={[Function]}
11340
+ type="button"
11341
+ >
11342
+ Open FormDebugger
11343
+ </button>
11344
+ </div>
11345
+ </form>
11346
+ `;
11347
+
11272
11348
  exports[`Storyshots f/fields/SelectInput String And Objects 1`] = `
11273
11349
  <form
11274
11350
  action="#"
@@ -11294,26 +11370,31 @@ exports[`Storyshots f/fields/SelectInput String And Objects 1`] = `
11294
11370
  value="Work"
11295
11371
  >
11296
11372
  <option
11373
+ disabled={false}
11297
11374
  value="Work"
11298
11375
  >
11299
11376
  Work
11300
11377
  </option>
11301
11378
  <option
11379
+ disabled={false}
11302
11380
  value="Managing"
11303
11381
  >
11304
11382
  Managing
11305
11383
  </option>
11306
11384
  <option
11385
+ disabled={false}
11307
11386
  value="Training"
11308
11387
  >
11309
11388
  Training
11310
11389
  </option>
11311
11390
  <option
11391
+ disabled={false}
11312
11392
  value="20th Aug 2020 to 19th Sept, 2020"
11313
11393
  >
11314
11394
  20th Aug 2020 to 19th Sept, 2020
11315
11395
  </option>
11316
11396
  <option
11397
+ disabled={false}
11317
11398
  value="20th Sept 2020 to 19th Oct, 2020"
11318
11399
  >
11319
11400
  20th Sept 2020 to 19th Oct, 2020
@@ -11530,6 +11611,40 @@ exports[`Storyshots f/fields/TextInput Disabled Text Input 1`] = `
11530
11611
  </form>
11531
11612
  `;
11532
11613
 
11614
+ exports[`Storyshots f/fields/TextInput Text Input With Place Holder 1`] = `
11615
+ <form
11616
+ action="#"
11617
+ onReset={[Function]}
11618
+ onSubmit={[Function]}
11619
+ >
11620
+ <div
11621
+ className="y-background1 b-dark-y u2 pb-u"
11622
+ >
11623
+ <div
11624
+ className="base text-input"
11625
+ >
11626
+ <label
11627
+ className="base label input-label v50 mb-v x-main2"
11628
+ htmlFor="firstName"
11629
+ >
11630
+ What's your first name ?
11631
+ </label>
11632
+ <input
11633
+ className="input input-border"
11634
+ disabled={false}
11635
+ id="firstName"
11636
+ name="firstName"
11637
+ onBlur={[Function]}
11638
+ onChange={[Function]}
11639
+ placeholder="First Name"
11640
+ type="text"
11641
+ value=""
11642
+ />
11643
+ </div>
11644
+ </div>
11645
+ </form>
11646
+ `;
11647
+
11533
11648
  exports[`Storyshots f/fields/TextareaInput Base 1`] = `
11534
11649
  <form
11535
11650
  action="#"
@@ -38,6 +38,35 @@ export const Base = () => (
38
38
  </>
39
39
  )
40
40
 
41
+ export const RequiredSelect = () => {
42
+ const requiredInput = (inputValue) => {
43
+ let error = ''
44
+
45
+ if (!inputValue || !inputValue?.length === 0) {
46
+ error = 'This information is required'
47
+ }
48
+ return error
49
+ }
50
+
51
+ return (
52
+ <>
53
+ <SelectInput
54
+ validate={requiredInput}
55
+ name="activity"
56
+ label="Activity Type"
57
+ options={[
58
+ {
59
+ value:'', label:'Select activity type', disabled:true,
60
+ },
61
+ { value: 'review', label: 'Review' },
62
+ { value: 'Approve', label: 'Approve' },
63
+ ]}
64
+ />
65
+ <FormDebugger />
66
+ </>
67
+ )
68
+ }
69
+
41
70
  export const Objects = () => (
42
71
  <>
43
72
  <SelectInput
@@ -52,6 +52,16 @@ export const Base = () => {
52
52
  )
53
53
  }
54
54
 
55
+ export const TextInputWithPlaceHolder = () => (
56
+ <div className="y-background1 b-dark-y u2 pb-u">
57
+ <TextInput
58
+ name="firstName"
59
+ label="What's your first name ?"
60
+ placeholder="First Name"
61
+ />
62
+ </div>
63
+ )
64
+
55
65
  export const DisabledTextInput = () => (
56
66
  <div className="y-background1 b-dark-y u2 pb-u">
57
67
  <TextInput
@@ -27,6 +27,8 @@ const SelectInput = ({
27
27
  name,
28
28
  label,
29
29
  options,
30
+ validate,
31
+ description,
30
32
  disabled,
31
33
  // ...otherProps
32
34
  }) => {
@@ -34,7 +36,7 @@ const SelectInput = ({
34
36
  import('./styles.scss')
35
37
  }, [])
36
38
 
37
- const [field, meta] = useField(name)
39
+ const [field, meta] = useField({ name, validate })
38
40
 
39
41
  return (
40
42
  <div
@@ -52,18 +54,30 @@ const SelectInput = ({
52
54
  // {...otherProps}
53
55
  >
54
56
  <FormLabel className="input-label" name={name}>{label}</FormLabel>
55
- <select className="input v25 pv-v" {...field} id={name} disabled={disabled}>
57
+ <select className="input v25 pv-v" {...field} value={field.value || ''} id={name} disabled={disabled}>
56
58
  {
57
59
  options.map((option) => {
58
60
  // i.e if option is a string like "blah", return { value: "blah", label: "blah" }
59
61
  const newOption = typeof option === 'string' ? { value: option, label: option } : option
62
+
60
63
  return (
61
- <option key={newOption.value} value={newOption.value}>{newOption.label}</option>
64
+ <option
65
+ key={newOption.value}
66
+ value={newOption.value}
67
+ disabled={newOption?.disabled || false}
68
+ >
69
+ {newOption.label}
70
+ </option>
62
71
  )
63
72
  })
64
73
  }
65
74
  </select>
66
- {meta.error && meta.touched && <FormDescription error>{meta.error}</FormDescription>}
75
+ {(description || (meta.touched && meta.error))
76
+ && (
77
+ <FormDescription isError={!!meta.error} className="v50 mt-v s-1">
78
+ { meta.error || description }
79
+ </FormDescription>
80
+ )}
67
81
  </div>
68
82
  )
69
83
  }
@@ -93,12 +107,28 @@ SelectInput.propTypes = {
93
107
  */
94
108
  label:PropTypes.string,
95
109
 
110
+ /**
111
+ * The input field validator function
112
+ */
113
+ validate:PropTypes.func,
114
+
115
+ /**
116
+ * The select input description
117
+ */
118
+ description:PropTypes.string,
119
+
96
120
  /**
97
121
  * The options of the select input
98
122
  */
99
123
  options:PropTypes.arrayOf(
100
124
  PropTypes.oneOfType(
101
- [PropTypes.string, PropTypes.shape({ value: PropTypes.string, label: PropTypes.string })],
125
+ [
126
+ PropTypes.string,
127
+ PropTypes.shape({
128
+ value :PropTypes.string,
129
+ label :PropTypes.string,
130
+ disabled:PropTypes.bool,
131
+ })],
102
132
  ),
103
133
  ),
104
134
  /**
@@ -18,12 +18,12 @@ $default-padding: 0.75em 0.75em 0.55em;
18
18
  }
19
19
 
20
20
  .input {
21
- background: var(--light-background1);
22
- color: var(--on-background1);
21
+ background: var(--light-background2);
22
+ color: var(--on-background2);
23
23
  padding: $default-padding;
24
24
 
25
25
  &:focus {
26
- background: var(--dark-background1);
26
+ background: var(--dark-background2);
27
27
  }
28
28
  }
29
29
  }
@@ -31,6 +31,7 @@ const TextInput = ({
31
31
  oneInputLabel,
32
32
  description,
33
33
  disabled,
34
+ placeholder,
34
35
  // ...otherProps
35
36
  }) => {
36
37
  useLayoutEffect(() => {
@@ -66,6 +67,7 @@ const TextInput = ({
66
67
  className={`input ${meta.touched && meta.error ? 'input-border-error' : 'input-border'}`}
67
68
  type={type}
68
69
  disabled={disabled}
70
+ placeholder={placeholder}
69
71
  {...field}
70
72
  />
71
73
  {(description || (meta.touched && meta.error))
@@ -136,6 +138,11 @@ TextInput.propTypes = {
136
138
  * Whether the text input should be disabled
137
139
  */
138
140
  disabled :PropTypes.bool,
141
+
142
+ /**
143
+ * The placeholder text for the input
144
+ */
145
+ placeholder:PropTypes.string,
139
146
  }
140
147
 
141
148
  TextInput.defaultProps = {