@platformatic/ui-components 0.1.127 → 0.1.129
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,22 +1,25 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
import React, { useRef, useState } from 'react'
|
|
3
3
|
import PropTypes from 'prop-types'
|
|
4
|
+
import commonStyles from './Common.module.css'
|
|
4
5
|
import styles from './SearchBarV2.module.css'
|
|
5
6
|
import PlatformaticIcon from './PlatformaticIcon'
|
|
6
|
-
import { MEDIUM, WHITE } from './constants'
|
|
7
|
+
import { MEDIUM, RICH_BLACK, TRANSPARENT, WHITE } from './constants'
|
|
7
8
|
function SearchBarV2 ({
|
|
8
9
|
onSubmit,
|
|
9
10
|
onChange,
|
|
10
11
|
onClear,
|
|
11
12
|
color,
|
|
12
|
-
|
|
13
|
+
backgroundColor,
|
|
13
14
|
placeholder,
|
|
14
15
|
dataAttrName,
|
|
15
16
|
dataAttrValue
|
|
16
17
|
}) {
|
|
17
18
|
const inputRef = useRef()
|
|
19
|
+
const baseClassName = `${styles.container} ${styles.wrapperPadding} ` + commonStyles[`background-color-${backgroundColor}`]
|
|
18
20
|
const [wrapperClassName, setWrapperClassName] = useState(normalClassName())
|
|
19
21
|
const [isOnFocus, setIsOnFocus] = useState(false)
|
|
22
|
+
const [showClear, setShowClear] = useState(false)
|
|
20
23
|
const dataProps = {}
|
|
21
24
|
if (dataAttrName && dataAttrValue) {
|
|
22
25
|
dataProps[`data-${dataAttrName}`] = dataAttrValue
|
|
@@ -31,12 +34,14 @@ function SearchBarV2 ({
|
|
|
31
34
|
function handleChange () {
|
|
32
35
|
if (onChange) {
|
|
33
36
|
const value = inputRef.current.value
|
|
37
|
+
setShowClear(!!value)
|
|
34
38
|
return onChange(value)
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
|
|
38
42
|
function handleClear () {
|
|
39
43
|
inputRef.current.value = ''
|
|
44
|
+
setShowClear(false)
|
|
40
45
|
return onClear()
|
|
41
46
|
}
|
|
42
47
|
|
|
@@ -53,20 +58,22 @@ function SearchBarV2 ({
|
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
function onFocusClassName () {
|
|
56
|
-
return `${
|
|
61
|
+
return `${baseClassName} ${styles.onFocus}`
|
|
57
62
|
}
|
|
58
63
|
|
|
59
64
|
function normalClassName () {
|
|
60
|
-
return `${
|
|
65
|
+
return `${baseClassName} ${styles.onBlur}`
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
return (
|
|
64
69
|
<div className={wrapperClassName} {...dataProps}>
|
|
65
|
-
<PlatformaticIcon iconName='LensIcon' color={
|
|
70
|
+
<PlatformaticIcon iconName='LensIcon' color={color} disabled={!isOnFocus} size={MEDIUM} onClick={handleSearch} />
|
|
66
71
|
<input type='text' placeholder={placeholder} className={styles.input} ref={inputRef} onChange={handleChange} onFocus={onFocus} onBlur={onBlur} />
|
|
67
|
-
|
|
68
|
-
<
|
|
69
|
-
|
|
72
|
+
{showClear && (
|
|
73
|
+
<div className={styles.clearContainer}>
|
|
74
|
+
<PlatformaticIcon iconName='CircleCloseIcon' color={color} size={MEDIUM} onClick={handleClear} />
|
|
75
|
+
</div>
|
|
76
|
+
)}
|
|
70
77
|
</div>
|
|
71
78
|
)
|
|
72
79
|
}
|
|
@@ -87,11 +94,11 @@ SearchBarV2.propTypes = {
|
|
|
87
94
|
/**
|
|
88
95
|
* color
|
|
89
96
|
*/
|
|
90
|
-
color: PropTypes.
|
|
97
|
+
color: PropTypes.oneOf([WHITE, RICH_BLACK]),
|
|
91
98
|
/**
|
|
92
|
-
*
|
|
99
|
+
* backgroundColor
|
|
93
100
|
*/
|
|
94
|
-
|
|
101
|
+
backgroundColor: PropTypes.oneOf([WHITE, RICH_BLACK, TRANSPARENT]),
|
|
95
102
|
/**
|
|
96
103
|
* placeholder
|
|
97
104
|
*/
|
|
@@ -108,10 +115,10 @@ SearchBarV2.propTypes = {
|
|
|
108
115
|
|
|
109
116
|
SearchBarV2.defaultProps = {
|
|
110
117
|
color: WHITE,
|
|
111
|
-
|
|
112
|
-
onSubmit: () => {},
|
|
113
|
-
onChange: () => {},
|
|
114
|
-
onClear: () => {},
|
|
118
|
+
backgroundColor: RICH_BLACK,
|
|
119
|
+
onSubmit: () => { },
|
|
120
|
+
onChange: () => { },
|
|
121
|
+
onClear: () => { },
|
|
115
122
|
placeholder: 'Search',
|
|
116
123
|
dataAttrName: '',
|
|
117
124
|
dataAttrValue: ''
|
|
@@ -52,6 +52,8 @@ function Select ({
|
|
|
52
52
|
singleOptionClassName += ` ${styles['bordered-bottom']}`
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
+
const optionSpanClassName = commonStyles[`text--${mainColor}`]
|
|
56
|
+
|
|
55
57
|
const [wrapperClassName, setWrapperClassName] = useState(normalClassName())
|
|
56
58
|
function onFocusClassName () {
|
|
57
59
|
return inputClassName + ' ' + commonStyles[`bordered--${borderColor}-100`]
|
|
@@ -111,8 +113,9 @@ function Select ({
|
|
|
111
113
|
>
|
|
112
114
|
<div className={styles.liContent}>
|
|
113
115
|
{option.iconName && <PlatformaticIcon iconName={option.iconName} color={mainColor} size={SMALL} onClick={null} />}
|
|
114
|
-
<span className={
|
|
116
|
+
<span className={optionSpanClassName}>{option.label}</span>
|
|
115
117
|
</div>
|
|
118
|
+
{option.descriptionValue && <span className={`${optionSpanClassName} ${styles.descriptionValue}`}>{option.descriptionValue}</span>}
|
|
116
119
|
</li>
|
|
117
120
|
)
|
|
118
121
|
}
|
|
@@ -212,7 +215,8 @@ Select.propTypes = {
|
|
|
212
215
|
icon: PropTypes.string,
|
|
213
216
|
notSelectable: PropTypes.bool,
|
|
214
217
|
notFilterable: PropTypes.bool,
|
|
215
|
-
onClick: PropTypes.func
|
|
218
|
+
onClick: PropTypes.func,
|
|
219
|
+
descriptionValue: PropTypes.string
|
|
216
220
|
})),
|
|
217
221
|
/**
|
|
218
222
|
* defaultOptionsClassName
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
@apply border border-solid rounded-md
|
|
24
24
|
}
|
|
25
25
|
.option {
|
|
26
|
-
@apply
|
|
26
|
+
@apply font-light cursor-pointer z-10 flex flex-row justify-between items-center px-4;
|
|
27
27
|
}
|
|
28
28
|
.bordered-bottom {
|
|
29
29
|
@apply border-b
|
|
@@ -33,5 +33,8 @@
|
|
|
33
33
|
transform: translateY(-50%);
|
|
34
34
|
}
|
|
35
35
|
.liContent {
|
|
36
|
-
@apply
|
|
36
|
+
@apply py-2 flex items-center gap-x-1 relative z-[-1] w-auto basis-2/3;
|
|
37
|
+
}
|
|
38
|
+
.descriptionValue {
|
|
39
|
+
@apply opacity-70
|
|
37
40
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
import SearchBarV2 from '../components/SearchBarV2'
|
|
3
|
+
export default {
|
|
4
|
+
title: 'Platformatic/SearchBarV2',
|
|
5
|
+
component: SearchBarV2
|
|
6
|
+
}
|
|
7
|
+
const Template = (args) => {
|
|
8
|
+
return (
|
|
9
|
+
<>
|
|
10
|
+
<SearchBarV2 {...args} />
|
|
11
|
+
</>
|
|
12
|
+
|
|
13
|
+
)
|
|
14
|
+
}
|
|
15
|
+
export const Standard = Template.bind({})
|
|
16
|
+
|
|
17
|
+
Standard.args = {
|
|
18
|
+
onChange: (value) => {
|
|
19
|
+
console.log('Current search: ' + value)
|
|
20
|
+
},
|
|
21
|
+
onSubmit: (value) => {
|
|
22
|
+
alert('Query value: ' + value)
|
|
23
|
+
}
|
|
24
|
+
}
|