@platformatic/ui-components 0.1.128 → 0.1.130
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
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
@apply inline-flex items-center;
|
|
49
49
|
}
|
|
50
50
|
.modal--small {
|
|
51
|
-
@apply min-w-[480px] max-w-[480px];
|
|
51
|
+
@apply w-auto lg:min-w-[480px] lg:max-w-[480px];
|
|
52
52
|
}
|
|
53
53
|
.modal--medium {
|
|
54
|
-
@apply min-w-[880px] max-w-[880px];
|
|
54
|
+
@apply w-auto lg:min-w-[880px] lg:max-w-[880px];
|
|
55
55
|
}
|
|
56
56
|
.modal--full-width {
|
|
57
57
|
@apply w-screen min-w-full;
|
|
@@ -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: ''
|
|
@@ -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
|
+
}
|