@platformatic/ui-components 0.1.139 → 0.1.141

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.1.139",
4
+ "version": "0.1.141",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "repository": {
@@ -14,7 +14,8 @@
14
14
  }
15
15
  .afterInputIcon,
16
16
  .beforeInputIcon {
17
- @apply absolute top-[50%] translate-y-[-50%] z-20;
17
+ @apply absolute top-[50%] z-20;
18
+ transform: translateY(-50%);
18
19
  }
19
20
  .beforeInputIcon {
20
21
  @apply left-0 ml-2
@@ -4,7 +4,7 @@ import PropTypes from 'prop-types'
4
4
  import inputStyles from './Input.module.css'
5
5
  import styles from './InputWithSeparator.module.css'
6
6
  import commonStyles from '../Common.module.css'
7
- import { BACKGROUND_COLOR_OPAQUE, MAIN_DARK_BLUE, MAIN_GREEN, MEDIUM, OPACITY_30, RICH_BLACK, SMALL, TRANSPARENT, WHITE } from '../constants'
7
+ import { BACKGROUND_COLOR_OPAQUE, ERROR_RED, MAIN_DARK_BLUE, MAIN_GREEN, MEDIUM, OPACITY_30, RICH_BLACK, SMALL, TRANSPARENT, WHITE } from '../constants'
8
8
  import BorderedBox from '../BorderedBox'
9
9
  import ButtonFullRounded from '../ButtonFullRounded'
10
10
 
@@ -17,19 +17,26 @@ function InputWithSeparator ({
17
17
  onChange,
18
18
  disabled,
19
19
  afterIcon,
20
+ defaultValue,
20
21
  value,
21
22
  separator,
22
23
  inputTextClassName
23
24
  }) {
25
+ const showError = errorMessage.length > 0
26
+ const [focus, setFocus] = useState(false)
24
27
  const baseClassName = `${styles.input} ${styles.flexNone} ${styles.smallMargin} ${inputTextClassName} ` + commonStyles[`background-color-${backgroundColor}`]
25
28
  const buttonClassName = commonStyles[`background-color-${borderColor}`] + ' ' + commonStyles['background-color-opaque-30']
26
29
  const [chunks, setChunks] = useState([])
27
30
  const [inputClassName, setInputClassName] = useState(normalClassName())
31
+ const [inputContainerClassName, setInputContainerClassName] = useState(unFocusedClassName())
28
32
  const chunkClasses = styles.chunkClasses
29
- let className = styles.inputContainer + ' ' + commonStyles[`bordered--${borderColor}-30`] + ' ' + commonStyles[`text--${borderColor}`]
30
- const showError = errorMessage.length > 0
31
- if (showError) className += ' ' + commonStyles['bordered--error-red']
32
- if (disabled) className += ' ' + commonStyles['apply-opacity-30']
33
+
34
+ useEffect(() => {
35
+ if (defaultValue.length > 0) {
36
+ const elements = defaultValue.split(separator).filter(e => e !== '')
37
+ setChunks(prevChunks => [...prevChunks, ...elements])
38
+ }
39
+ }, [])
33
40
 
34
41
  useEffect(() => {
35
42
  if (chunks.length > 0) {
@@ -39,6 +46,18 @@ function InputWithSeparator ({
39
46
  }
40
47
  }, [chunks.length])
41
48
 
49
+ useEffect(() => {
50
+ if (disabled) {
51
+ setInputContainerClassName(unFocusedClassName() + ' ' + commonStyles['apply-opacity-30'])
52
+ } else {
53
+ if (focus) {
54
+ setInputContainerClassName(focusedClassName())
55
+ } else {
56
+ setInputContainerClassName(unFocusedClassName())
57
+ }
58
+ }
59
+ }, [focus, disabled])
60
+
42
61
  function handleRemove (chunk) {
43
62
  const index = chunks.findIndex(c => c === chunk)
44
63
  if (index > -1) {
@@ -69,6 +88,16 @@ function InputWithSeparator ({
69
88
  return baseClassName
70
89
  }
71
90
 
91
+ function focusedClassName () {
92
+ const useEffectColor = showError ? ERROR_RED : borderColor
93
+ return styles.inputContainer + ' ' + commonStyles[`bordered--${useEffectColor}-100`]
94
+ }
95
+
96
+ function unFocusedClassName () {
97
+ const useEffectColor = showError ? ERROR_RED : borderColor
98
+ return styles.inputContainer + ' ' + commonStyles[`bordered--${useEffectColor}-70`]
99
+ }
100
+
72
101
  function renderChunk (chunk, index) {
73
102
  return (
74
103
  <BorderedBox color={TRANSPARENT} backgroundColor={borderColor} backgroundColorOpacity={OPACITY_30} classes={chunkClasses} key={index} bor>
@@ -87,12 +116,33 @@ function InputWithSeparator ({
87
116
  </BorderedBox>
88
117
  )
89
118
  }
119
+
120
+ function handleFocus () {
121
+ if (!disabled) {
122
+ setFocus(true)
123
+ }
124
+ }
125
+
126
+ function handleBlur () {
127
+ if (!disabled) setFocus(false)
128
+ }
129
+
90
130
  return (
91
131
  <div className={inputStyles.container}>
92
132
  <div className={styles.container}>
93
- <div className={className}>
133
+ <div className={inputContainerClassName}>
94
134
  {chunks.map((value, index) => renderChunk(value, index))}
95
- <input type='text' name={name} value={value} placeholder={placeholder} className={inputClassName} onChange={handleChange} disabled={disabled} />
135
+ <input
136
+ type='text'
137
+ name={name}
138
+ value={value}
139
+ placeholder={chunks.length > 0 ? '' : placeholder}
140
+ className={inputClassName}
141
+ onChange={handleChange}
142
+ disabled={disabled}
143
+ onFocus={() => handleFocus()}
144
+ onBlur={() => handleBlur()}
145
+ />
96
146
  </div>
97
147
  {afterIcon &&
98
148
  (
@@ -126,6 +176,10 @@ InputWithSeparator.propTypes = {
126
176
  * value
127
177
  */
128
178
  value: PropTypes.string,
179
+ /**
180
+ * defaultValue
181
+ */
182
+ defaultValue: PropTypes.string,
129
183
  /**
130
184
  * separator
131
185
  */
@@ -164,6 +218,7 @@ InputWithSeparator.propTypes = {
164
218
  InputWithSeparator.defaultProps = {
165
219
  placeholder: '',
166
220
  value: '',
221
+ defaultValue: '',
167
222
  name: '',
168
223
  borderColor: MAIN_GREEN,
169
224
  backgroundColor: WHITE,
@@ -8,7 +8,8 @@
8
8
  @apply border border-solid box-border rounded-md px-2 py-2.5;
9
9
  }
10
10
  .afterInputIcon {
11
- @apply absolute top-[50%] translate-y-[-50%] z-10 ;
11
+ @apply absolute top-[50%] z-10 ;
12
+ transform: translateY(-50%);
12
13
  }
13
14
  .afterInputIcon {
14
15
  @apply right-0 mr-2
@@ -112,7 +112,7 @@ function Select ({
112
112
  }}
113
113
  >
114
114
  <div className={styles.liContent}>
115
- {option.iconName && <PlatformaticIcon iconName={option.iconName} color={mainColor} size={SMALL} onClick={null} />}
115
+ {option.iconName && <PlatformaticIcon iconName={option.iconName} color={option.iconColor || mainColor} size={option.iconSize ?? SMALL} onClick={null} />}
116
116
  <span className={optionSpanClassName}>{option.label}</span>
117
117
  </div>
118
118
  {option.descriptionValue && <span className={`${optionSpanClassName} ${styles.descriptionValue}`}>{option.descriptionValue}</span>}
@@ -212,7 +212,9 @@ Select.propTypes = {
212
212
  PropTypes.string,
213
213
  PropTypes.number
214
214
  ]),
215
- icon: PropTypes.string,
215
+ iconName: PropTypes.string,
216
+ iconSize: PropTypes.string,
217
+ iconColor: PropTypes.string,
216
218
  notSelectable: PropTypes.bool,
217
219
  notFilterable: PropTypes.bool,
218
220
  onClick: PropTypes.func,
@@ -56,3 +56,40 @@ Default.args = {
56
56
  handleClick: () => alert('I\'m an AddIcon')
57
57
  }
58
58
  }
59
+
60
+ const TemplateDefaultWithValues = (args) => {
61
+ const [value, setValue] = useState(args.value)
62
+ const [chunks, setChunks] = useState('')
63
+ const [errorMessage, setErrorMessage] = useState('')
64
+ // errorMessage: 'error message displayed just for to be see',
65
+
66
+ function handleChange ({ value, chunks }) {
67
+ setValue(value)
68
+ setChunks(chunks)
69
+ }
70
+
71
+ return (
72
+ <>
73
+ <p>Chunks: {chunks.toString()} </p>
74
+ <p>Value inserted: {value} </p>
75
+ <label>Add Error message: <input type='checkbox' onChange={() => setErrorMessage(errorMessage === '' ? 'custom message' : '')} /></label>
76
+ <InputWithSeparator {...args} value={value} onChange={handleChange} errorMessage={errorMessage} />
77
+ </>
78
+ )
79
+ }
80
+
81
+ export const PredefinedValues = TemplateDefaultWithValues.bind({})
82
+
83
+ PredefinedValues.args = {
84
+ name: 'test',
85
+ placeholder: 'Initial value',
86
+ borderColor: 'main-dark-blue',
87
+ separator: ',',
88
+ defaultValue: 'test,test-1,test-2',
89
+ afterIcon: {
90
+ iconName: 'AddIcon',
91
+ color: ERROR_RED,
92
+ handleClick: () => alert('I\'m an AddIcon')
93
+ }
94
+
95
+ }