-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
414 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
x-pack/plugins/apm/public/components/shared/Typeahead/Suggestion.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
import { EuiIcon } from '@elastic/eui'; | ||
import { colors } from '../../../style/variables'; | ||
|
||
function getIconColor(type) { | ||
switch (type) { | ||
case 'field': | ||
return colors.apmOrange; | ||
|
||
case 'value': | ||
return colors.teal; | ||
|
||
case 'operator': | ||
return colors.apmBlue; | ||
|
||
case 'conjunction': | ||
return colors.apmPurple; | ||
|
||
case 'recentSearch': | ||
return colors.gray3; | ||
} | ||
} | ||
|
||
function getIconBgColor(type) { | ||
switch (type) { | ||
case 'field': | ||
return '#fccd9f'; | ||
|
||
case 'value': | ||
return '#99dbd7'; | ||
|
||
case 'operator': | ||
return '#accefd'; | ||
|
||
case 'conjunction': | ||
return '#b699d3'; | ||
|
||
case 'recentSearch': | ||
return colors.gray5; | ||
} | ||
} | ||
|
||
const Description = styled.div` | ||
color: #666; | ||
p { | ||
display: inline; | ||
span { | ||
font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, | ||
monospace; | ||
color: #000; | ||
padding: 0 4px; | ||
display: inline-block; | ||
} | ||
} | ||
`; | ||
|
||
const ListItem = styled.li` | ||
font-size: 13px; | ||
height: 32px; | ||
align-items: center; | ||
display: flex; | ||
background: ${props => (props.selected ? '#eee' : 'initial')}; | ||
cursor: pointer; | ||
border-radius: 5px; | ||
${Description} { | ||
p span { | ||
background: ${props => (props.selected ? '#fff' : '#eee')}; | ||
} | ||
} | ||
`; | ||
|
||
const Icon = styled.div` | ||
flex: 0 0 32px; | ||
background: ${props => getIconBgColor(props.type)}; | ||
color: ${props => getIconColor(props.type)}; | ||
width: 100%; | ||
height: 100%; | ||
text-align: center; | ||
line-height: 32px; | ||
`; | ||
|
||
const TextValue = styled.div` | ||
flex: 0 0 250px; | ||
color: #111; | ||
padding: 0 8px; | ||
`; | ||
|
||
function getEuiIconType(type) { | ||
switch (type) { | ||
case 'field': | ||
return 'kqlField'; | ||
case 'value': | ||
return 'kqlValue'; | ||
case 'recentSearch': | ||
return 'search'; | ||
case 'conjunction': | ||
return 'kqlSelector'; | ||
case 'operator': | ||
return 'kqlOperand'; | ||
default: | ||
throw new Error('Unknown type', type); | ||
} | ||
} | ||
|
||
function Suggestion(props) { | ||
return ( | ||
<ListItem | ||
selected={props.selected} | ||
onClick={() => props.onClick(props.suggestion)} | ||
onMouseOver={props.onMouseOver} | ||
> | ||
<Icon type={props.suggestion.type}> | ||
<EuiIcon type={getEuiIconType(props.suggestion.type)} /> | ||
</Icon> | ||
<TextValue>{props.suggestion.text}</TextValue> | ||
<Description | ||
dangerouslySetInnerHTML={{ __html: props.suggestion.description }} | ||
/> | ||
</ListItem> | ||
); | ||
} | ||
|
||
Suggestion.propTypes = { | ||
onClick: PropTypes.func.isRequired, | ||
onMouseOver: PropTypes.func.isRequired, | ||
selected: PropTypes.bool, | ||
suggestion: PropTypes.object.isRequired | ||
}; | ||
|
||
export default Suggestion; |
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/apm/public/components/shared/Typeahead/Suggestions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styled from 'styled-components'; | ||
import Suggestion from './Suggestion'; | ||
|
||
const List = styled.ul` | ||
width: 100%; | ||
list-style: none; | ||
padding: 0; | ||
margin-top: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.1); | ||
`; | ||
|
||
function Suggestions(props) { | ||
if (!props.show) { | ||
return null; | ||
} | ||
|
||
const suggestions = props.suggestions.map((suggestion, index) => { | ||
const key = suggestion + '_' + index; | ||
return ( | ||
<Suggestion | ||
selected={index === props.index} | ||
suggestion={suggestion} | ||
onClick={props.onClick} | ||
onMouseOver={() => props.onMouseOver(index)} | ||
key={key} | ||
/> | ||
); | ||
}); | ||
|
||
return <List>{suggestions}</List>; | ||
} | ||
|
||
Suggestions.propTypes = { | ||
index: PropTypes.number, | ||
onClick: PropTypes.func.isRequired, | ||
onMouseOver: PropTypes.func.isRequired, | ||
show: PropTypes.bool, | ||
suggestions: PropTypes.array.isRequired | ||
}; | ||
|
||
export default Suggestions; |
Oops, something went wrong.