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

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.
@@ -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
  }
@@ -27,10 +27,12 @@ const TextInput = ({
27
27
  type,
28
28
  name,
29
29
  label,
30
+ labelColor,
30
31
  validate,
31
32
  oneInputLabel,
32
33
  description,
33
34
  disabled,
35
+ placeholder,
34
36
  // ...otherProps
35
37
  }) => {
36
38
  useLayoutEffect(() => {
@@ -53,11 +55,11 @@ const TextInput = ({
53
55
  // {...otherProps}
54
56
  >
55
57
  <FormLabel
56
- className={[
57
- 'input-label', oneInputLabel ? 'md-s2 s0 v1 mb-v' : 'v50 mb-v']
58
+ className={[oneInputLabel ? 'md-s2 s0 v1 mb-v' : 'v50 mb-v']
58
59
  .filter((e) => e)
59
60
  .join(' ')}
60
61
  name={name}
62
+ color={labelColor}
61
63
  >
62
64
  { label }
63
65
  </FormLabel>
@@ -66,6 +68,7 @@ const TextInput = ({
66
68
  className={`input ${meta.touched && meta.error ? 'input-border-error' : 'input-border'}`}
67
69
  type={type}
68
70
  disabled={disabled}
71
+ placeholder={placeholder}
69
72
  {...field}
70
73
  />
71
74
  {(description || (meta.touched && meta.error))
@@ -104,6 +107,11 @@ TextInput.propTypes = {
104
107
  */
105
108
  label:PropTypes.string.isRequired,
106
109
 
110
+ /**
111
+ * The input label color
112
+ */
113
+ labelColor:PropTypes.string,
114
+
107
115
  /**
108
116
  * The type of the input (html)
109
117
  */
@@ -136,6 +144,11 @@ TextInput.propTypes = {
136
144
  * Whether the text input should be disabled
137
145
  */
138
146
  disabled :PropTypes.bool,
147
+
148
+ /**
149
+ * The placeholder text for the input
150
+ */
151
+ placeholder:PropTypes.string,
139
152
  }
140
153
 
141
154
  TextInput.defaultProps = {
@@ -9,10 +9,6 @@ $default-padding: 0.75em 0.75em 0.55em;
9
9
  display: flex;
10
10
  flex-direction: column;
11
11
 
12
- .input-label {
13
- color: var(--main2);
14
- }
15
-
16
12
  .input {
17
13
  background: var(--light-background2);
18
14
  color: var(--on-background2);
@@ -34,6 +34,7 @@ const TextareaInput = ({
34
34
  labelColor,
35
35
  description,
36
36
  disabled,
37
+ placeholder,
37
38
  // ...otherProps
38
39
  }) => {
39
40
  useLayoutEffect(() => {
@@ -52,7 +53,6 @@ const TextareaInput = ({
52
53
  componentClassName,
53
54
  userClassName,
54
55
  `x-${textAreaColor}`,
55
- `y-${labelColor}`,
56
56
  ]
57
57
  .filter((e) => e)
58
58
  .join(' ')}
@@ -60,11 +60,11 @@ const TextareaInput = ({
60
60
  // {...otherProps}
61
61
  >
62
62
  <FormLabel
63
- className={[
64
- 'c-y', labelAsDescription ? 'md-s2 s0 v1 mb-v' : 'v50 mb-v']
63
+ className={[labelAsDescription ? 'md-s2 s0 v1 mb-v' : 'v50 mb-v']
65
64
  .filter((e) => e)
66
65
  .join(' ')}
67
66
  name={name}
67
+ color={labelColor}
68
68
  >
69
69
  { label }
70
70
  </FormLabel>
@@ -72,6 +72,7 @@ const TextareaInput = ({
72
72
  id={textAreaId}
73
73
  className={`textarea v50 pv-v ${meta.touched && meta.error ? 'input-border-error' : 'input-border'}`}
74
74
  {...field}
75
+ placeholder={placeholder}
75
76
  rows={rows}
76
77
  disabled={disabled}
77
78
  >
@@ -123,36 +124,46 @@ TextareaInput.propTypes = {
123
124
  * If the text area depends on it's label's text as the default description
124
125
  */
125
126
  labelAsDescription:PropTypes.bool,
127
+
126
128
  /**
127
129
  * The textarea id
128
130
  */
129
- textAreaId :PropTypes.string,
131
+ textAreaId:PropTypes.string,
132
+
130
133
  /**
131
134
  * The number of rows int the text area
132
135
  */
133
- rows :PropTypes.number,
136
+ rows:PropTypes.number,
137
+
134
138
  /**
135
139
  * Text area base color
136
140
  */
137
- textAreaColor :PropTypes.string,
141
+ textAreaColor:PropTypes.string,
142
+
138
143
  /**
139
144
  * Label base color
140
145
  */
141
- labelColor :PropTypes.string,
146
+ labelColor:PropTypes.string,
147
+
142
148
  /**
143
149
  * Text area description
144
150
  */
145
- description :PropTypes.string,
151
+ description:PropTypes.string,
152
+
146
153
  /**
147
154
  * Whether the text area should be disabled
148
155
  */
149
- disabled :PropTypes.bool,
156
+ disabled:PropTypes.bool,
157
+
158
+ /**
159
+ * The textarea placeholder text
160
+ */
161
+ placeholder:PropTypes.string,
150
162
  }
151
163
 
152
164
  TextareaInput.defaultProps = {
153
165
  rows :3,
154
166
  textAreaColor:'background1',
155
- labelColor :'main2',
156
167
  disabled :false,
157
168
  }
158
169