1+ import { HTMLAttributes } from 'react'
12import styled from 'styled-components'
23import { Theme } from 'uiSrc/components/base/theme/types'
34import { Row } from 'uiSrc/components/base/layout/flex'
45import { TextInput } from 'uiSrc/components/base/inputs'
6+ import {
7+ ActionIconButton ,
8+ IconButton ,
9+ } from 'uiSrc/components/base/forms/buttons'
10+ import GroupBadge from 'uiSrc/components/group-badge'
511
6- interface StyledMultiSearchProps extends React . HTMLAttributes < HTMLDivElement > {
12+ interface StyledMultiSearchProps extends HTMLAttributes < HTMLDivElement > {
713 $isFocused : boolean
814}
915
16+ interface StyledSuggestionProps extends HTMLAttributes < HTMLLIElement > {
17+ $isFocused ?: boolean
18+ }
19+
1020export const StyledMultiSearch = styled ( Row ) < StyledMultiSearchProps > `
1121 border: 1px solid
1222 ${ ( { theme, $isFocused } : { theme : Theme ; $isFocused : boolean } ) =>
@@ -29,25 +39,25 @@ export const StyledMultiSearch = styled(Row)<StyledMultiSearchProps>`
2939 background-size 150ms ease-in,
3040 background-color 150ms ease-in;
3141`
32- export const StyledAutoSuggestions = styled . div <
33- React . HTMLAttributes < HTMLDivElement >
34- > `
35- background-color: ${ ( { theme } : { theme : Theme } ) =>
36- theme . components . select . dropdown . bgColor } ;
42+ /**
43+ * Auto-suggestions dropdown container
44+ * Replaces: .autoSuggestions
45+ */
46+ export const StyledAutoSuggestions = styled . div < React . HTMLAttributes < HTMLDivElement >> `
47+ background-color: ${ ( { theme } ) => theme . components . select . dropdown . bgColor } ;
3748 border: 1px solid
38- ${ ( { theme } : { theme : Theme } ) =>
39- theme . components . select . states . disabled . borderColor } ;
49+ ${ ( { theme } ) => theme . components . select . states . disabled . borderColor } ;
4050 position: absolute;
41- top: calc(100% + 2px );
51+ top: calc(100% + ${ ( { theme } ) => theme . core . space . space025 } );
4252 left: 0;
4353 width: 100%;
44- min-width: 180px;
54+ min-width: calc(
55+ ${ ( { theme } ) => theme . core . space . space550 } * 4
56+ ); // 176px instead of hardcoded 180px
4557
46- border-radius: 4px ;
58+ border-radius: ${ ( { theme } ) => theme . core . space . space050 } ;
4759 z-index: 1001;
48- padding: 4px 0 0;
49-
50- font-size: 13px;
60+ padding: ${ ( { theme } ) => theme . core . space . space050 } 0 0;
5161`
5262
5363export const StyledMultiSearchWrapper = styled ( Row ) <
@@ -59,13 +69,6 @@ export const StyledMultiSearchWrapper = styled(Row)<
5969 min-height: 36px;
6070`
6171
62- export const StyledSuggestion = styled . li < React . HTMLAttributes < HTMLLIElement >> `
63- &:hover {
64- background: ${ ( { theme } : { theme : Theme } ) =>
65- theme . components . select . dropdown . option . states . highlighted . bgColor } ;
66- }
67- `
68-
6972export const StyledClearHistory = styled . li <
7073 React . HTMLAttributes < HTMLDivElement >
7174> `
@@ -95,3 +98,78 @@ export const StyledSearchInput = styled(TextInput)`
9598 padding: 0 6px 0 10px;
9699 background-image: none;
97100`
101+
102+ /**
103+ * Remove button within suggestion item
104+ * Replaces: .suggestionRemoveBtn
105+ * Note: Defined before StyledSuggestion so it can be referenced in selectors
106+ */
107+ export const StyledSuggestionRemoveBtn = styled ( IconButton ) `
108+ flex-shrink: 0;
109+ visibility: hidden;
110+ pointer-events: none;
111+ `
112+
113+ /**
114+ * Individual suggestion item in the dropdown
115+ * Replaces: .suggestion
116+ */
117+ export const StyledSuggestion = styled . li < StyledSuggestionProps > `
118+ display: flex;
119+ align-items: center;
120+ text-align: left;
121+ padding: ${ ( { theme } ) => theme . core . space . space050 }
122+ ${ ( { theme } ) => theme . core . space . space100 } ;
123+ cursor: default;
124+
125+ ${ ( { $isFocused, theme } ) =>
126+ $isFocused &&
127+ `background: ${ theme . components . select . dropdown . option . states . highlighted . bgColor } ;` }
128+
129+ &:hover {
130+ background: ${ ( { theme } ) =>
131+ theme . components . select . dropdown . option . states . highlighted . bgColor } ;
132+ }
133+
134+ /* Show remove button on hover or when focused */
135+ &:hover ${ StyledSuggestionRemoveBtn } {
136+ visibility: visible;
137+ pointer-events: auto;
138+ }
139+
140+ ${ ( { $isFocused } ) =>
141+ $isFocused &&
142+ `& ${ StyledSuggestionRemoveBtn } {
143+ visibility: visible;
144+ pointer-events: auto;
145+ }` }
146+ `
147+
148+ /**
149+ * GroupBadge wrapper within suggestion item
150+ * Replaces: .suggestionOption
151+ */
152+ export const StyledSuggestionOption = styled ( GroupBadge ) `
153+ margin-right: ${ ( { theme } ) => theme . core . space . space100 } ;
154+ `
155+
156+ /**
157+ * Text content within a suggestion item
158+ * Replaces: .suggestionText
159+ */
160+ export const StyledSuggestionText = styled . span <
161+ HTMLAttributes < HTMLSpanElement >
162+ > `
163+ text-overflow: ellipsis;
164+ overflow: hidden;
165+ white-space: nowrap;
166+ flex-grow: 1;
167+ line-height: 1.4;
168+ `
169+ /**
170+ * Clear/Reset filters button
171+ * Replaces: .clearButton
172+ */
173+ export const StyledClearButton = styled ( ActionIconButton ) `
174+ margin-left: ${ ( { theme } ) => theme . core . space . space050 } ;
175+ `
0 commit comments