@indico-data/design-system 1.0.30 → 1.0.31
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
|
@@ -15,3 +15,19 @@ export default meta;
|
|
|
15
15
|
type Story = StoryObj<typeof SearchInput>;
|
|
16
16
|
|
|
17
17
|
export const Base: Story = {};
|
|
18
|
+
|
|
19
|
+
export const Border: Story = {
|
|
20
|
+
args: { border: true },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const SearchIcon: Story = {
|
|
24
|
+
args: { showSearchIcon: true },
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export const ClearInputIcon: Story = {
|
|
28
|
+
args: { showClearInputIcon: true },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const ClearInputIconWithBorder: Story = {
|
|
32
|
+
args: { showClearInputIcon: true, border: true },
|
|
33
|
+
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import styled from 'styled-components';
|
|
1
|
+
import styled, { css } from 'styled-components';
|
|
2
2
|
|
|
3
3
|
import { TYPOGRAPHY } from '@/tokens';
|
|
4
4
|
|
|
5
5
|
import { inputCommon } from '../inputsCommon.styles';
|
|
6
6
|
|
|
7
|
-
export const StyledSearchField = styled.div
|
|
7
|
+
export const StyledSearchField = styled.div<{
|
|
8
|
+
border?: boolean;
|
|
9
|
+
showSearchIcon?: boolean;
|
|
10
|
+
showClearInputIcon?: boolean;
|
|
11
|
+
}>`
|
|
8
12
|
position: relative;
|
|
9
13
|
background: transparent;
|
|
10
14
|
|
|
@@ -18,8 +22,36 @@ export const StyledSearchField = styled.div`
|
|
|
18
22
|
input {
|
|
19
23
|
${inputCommon};
|
|
20
24
|
|
|
21
|
-
padding: 5px
|
|
25
|
+
padding: 5px;
|
|
22
26
|
font-size: ${TYPOGRAPHY.fontSize.base};
|
|
23
27
|
margin-bottom: 0;
|
|
28
|
+
${(props) =>
|
|
29
|
+
props.border &&
|
|
30
|
+
css`
|
|
31
|
+
border: 1px solid currentColor;
|
|
32
|
+
border-radius: 4px;
|
|
33
|
+
`}
|
|
34
|
+
${(props) =>
|
|
35
|
+
props.showSearchIcon &&
|
|
36
|
+
css`
|
|
37
|
+
padding: 5px 5px 5px 25px;
|
|
38
|
+
`}
|
|
24
39
|
}
|
|
40
|
+
|
|
41
|
+
${(props) =>
|
|
42
|
+
props.showClearInputIcon &&
|
|
43
|
+
css`
|
|
44
|
+
.clear-input {
|
|
45
|
+
cursor: pointer;
|
|
46
|
+
height: 10px;
|
|
47
|
+
width: 10px;
|
|
48
|
+
position: absolute;
|
|
49
|
+
right: 10px;
|
|
50
|
+
top: 50%;
|
|
51
|
+
transform: translateY(-50%);
|
|
52
|
+
&:hover {
|
|
53
|
+
opacity: 0.5;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
`}
|
|
25
57
|
`;
|
|
@@ -9,23 +9,47 @@ import { PermafrostComponent } from '@/types';
|
|
|
9
9
|
import { StyledSearchField } from './SearchInput.styles';
|
|
10
10
|
|
|
11
11
|
type Props = PermafrostComponent & {
|
|
12
|
+
border?: boolean;
|
|
13
|
+
showClearInputIcon?: boolean;
|
|
14
|
+
showSearchIcon?: boolean;
|
|
12
15
|
inputProps?: { [key: string]: string };
|
|
13
16
|
onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
17
|
+
onClear?(): void;
|
|
14
18
|
onKeyUp?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
15
19
|
placeholder?: string;
|
|
16
20
|
value?: string;
|
|
17
21
|
};
|
|
18
22
|
|
|
19
23
|
export const SearchInput = (props: Props) => {
|
|
20
|
-
const {
|
|
24
|
+
const {
|
|
25
|
+
border,
|
|
26
|
+
showSearchIcon,
|
|
27
|
+
showClearInputIcon,
|
|
28
|
+
className,
|
|
29
|
+
inputProps,
|
|
30
|
+
onChange,
|
|
31
|
+
onClear,
|
|
32
|
+
onKeyUp,
|
|
33
|
+
placeholder,
|
|
34
|
+
value,
|
|
35
|
+
} = props;
|
|
21
36
|
|
|
22
37
|
const id = uuid();
|
|
23
38
|
|
|
24
39
|
return (
|
|
25
|
-
<StyledSearchField
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
40
|
+
<StyledSearchField
|
|
41
|
+
className={className}
|
|
42
|
+
border={border}
|
|
43
|
+
showSearchIcon={showSearchIcon}
|
|
44
|
+
showClearInputIcon={showClearInputIcon}
|
|
45
|
+
data-cy={props['data-cy']}
|
|
46
|
+
id={props.id}
|
|
47
|
+
>
|
|
48
|
+
{showSearchIcon && (
|
|
49
|
+
<label htmlFor={id}>
|
|
50
|
+
<Icon name="fa-search" ariaLabel="search" />
|
|
51
|
+
</label>
|
|
52
|
+
)}
|
|
29
53
|
|
|
30
54
|
<input
|
|
31
55
|
type="search"
|
|
@@ -36,6 +60,9 @@ export const SearchInput = (props: Props) => {
|
|
|
36
60
|
onKeyUp={onKeyUp}
|
|
37
61
|
{...inputProps}
|
|
38
62
|
/>
|
|
63
|
+
{showClearInputIcon && (
|
|
64
|
+
<Icon name="x-close" ariaLabel="clear input" className="clear-input" onClick={onClear} />
|
|
65
|
+
)}
|
|
39
66
|
</StyledSearchField>
|
|
40
67
|
);
|
|
41
68
|
};
|