@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 +1 -1
- package/src/components/forms/Input.module.css +2 -1
- package/src/components/forms/InputWithSeparator.jsx +62 -7
- package/src/components/forms/Password.module.css +2 -1
- package/src/components/forms/Select.jsx +4 -2
- package/src/stories/forms/InputWithSeparator.stories.jsx +37 -0
package/package.json
CHANGED
|
@@ -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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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={
|
|
133
|
+
<div className={inputContainerClassName}>
|
|
94
134
|
{chunks.map((value, index) => renderChunk(value, index))}
|
|
95
|
-
<input
|
|
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,
|
|
@@ -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
|
-
|
|
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
|
+
}
|