@platformatic/ui-components 0.2.15 → 0.2.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@platformatic/ui-components",
3
3
  "description": "Platformatic UI Components",
4
- "version": "0.2.15",
4
+ "version": "0.2.16",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -32,14 +32,13 @@ function Select ({
32
32
  const [showOptions, setShowOptions] = useState(false)
33
33
  const [isSelected, setIsSelected] = useState(false)
34
34
  const [isOnFocus, setIsOnFocus] = useState(false)
35
+
35
36
  const showError = errorMessage.length > 0
36
37
  const containerClassName = `${styles.container} ${defaultContainerClassName} `
37
38
  let inputClassName = `${commonStyles.fullWidth} ${styles.select} ${inputTextClassName}`
38
39
  inputClassName += ' ' + styles[`select-${mainColor}`]
39
40
  inputClassName += ' ' + commonStyles[`text--${borderColor}`]
40
41
  let optionsClassName = `${styles.options} ${defaultOptionsClassName} `
41
- if (showError) inputClassName += ' ' + commonStyles['bordered--error-red']
42
- if (disabled) inputClassName += ' ' + commonStyles['apply-opacity-30']
43
42
  inputClassName += ' ' + commonStyles[`background-color-${backgroundColor}`]
44
43
  optionsClassName += commonStyles[`background-color-${backgroundColor}`]
45
44
 
@@ -55,12 +54,20 @@ function Select ({
55
54
  const optionSpanClassName = commonStyles[`text--${mainColor}`]
56
55
 
57
56
  const [wrapperClassName, setWrapperClassName] = useState(normalClassName())
57
+
58
58
  function onFocusClassName () {
59
59
  return inputClassName + ' ' + commonStyles[`bordered--${borderColor}-100`]
60
60
  }
61
61
 
62
62
  function normalClassName () {
63
- return inputClassName + ' ' + commonStyles[`bordered--${borderColor}-70`]
63
+ const baseClassName = inputClassName
64
+ if (showError) {
65
+ inputClassName += ' ' + commonStyles['bordered--error-red']
66
+ } else {
67
+ inputClassName += ' ' + commonStyles[`bordered--${borderColor}-70`]
68
+ }
69
+ if (disabled) inputClassName += ' ' + commonStyles['apply-opacity-30']
70
+ return baseClassName
64
71
  }
65
72
 
66
73
  const dataProps = {}
@@ -101,6 +108,15 @@ function Select ({
101
108
  }
102
109
  }, [optionSelected])
103
110
 
111
+ useEffect(() => {
112
+ if (disabled) {
113
+ const className = normalClassName() + ' ' + commonStyles['apply-opacity-30']
114
+ setWrapperClassName(className)
115
+ } else {
116
+ setWrapperClassName(normalClassName())
117
+ }
118
+ }, [disabled])
119
+
104
120
  function renderLi (option, index) {
105
121
  return (
106
122
  <li
@@ -173,8 +189,8 @@ function Select ({
173
189
  <div className={styles.selectContainer}>
174
190
  <input type='text' name={name} value={value} className={wrapperClassName} ref={inputRef} onChange={onChange} disabled={disabled} placeholder={placeholder} onFocus={() => handleFocus()} onBlur={(e) => handleBlur(e)} />
175
191
  <div className={styles.icons}>
176
- {value?.length > 0 && <PlatformaticIcon iconName='CircleCloseIcon' color={borderColor} onClick={() => clearValue()} size={SMALL} />}
177
- <PlatformaticIcon iconName={showOptions ? 'ArrowUpIcon' : 'ArrowDownIcon'} color={borderColor} onClick={() => disabled ? null : setShowOptions(!showOptions)} size={SMALL} />
192
+ {value?.length > 0 && !disabled && <PlatformaticIcon iconName='CircleCloseIcon' color={borderColor} onClick={() => clearValue()} size={SMALL} />}
193
+ <PlatformaticIcon iconName={showOptions ? 'ArrowUpIcon' : 'ArrowDownIcon'} color={borderColor} disabled={disabled} onClick={() => setShowOptions(!showOptions)} size={SMALL} />
178
194
  </div>
179
195
  </div>
180
196
  {showOptions && !showError && renderOptions()}