-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style(Search): several cleanups #1150
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,14 +24,6 @@ import SearchResults from './SearchResults' | |
|
||
const debug = makeDebugger('search') | ||
|
||
const _meta = { | ||
name: 'Search', | ||
type: META.TYPES.MODULE, | ||
props: { | ||
size: _.without(SUI.SIZES, 'medium'), | ||
}, | ||
} | ||
|
||
/** | ||
* A search module allows a user to query for results from a selection of data | ||
*/ | ||
|
@@ -44,12 +36,24 @@ export default class Search extends Component { | |
// Behavior | ||
// ------------------------------------ | ||
|
||
/** Initial value of open. */ | ||
defaultOpen: PropTypes.bool, | ||
|
||
/** Initial value. */ | ||
defaultValue: PropTypes.string, | ||
|
||
/** Shorthand for Icon. */ | ||
icon: PropTypes.oneOfType([ | ||
PropTypes.node, | ||
PropTypes.object, | ||
]), | ||
|
||
/** Controls whether or not the results menu is displayed. */ | ||
open: PropTypes.bool, | ||
|
||
/** Placeholder of the search input. */ | ||
placeholder: PropTypes.string, | ||
|
||
/** | ||
* One of: | ||
* - array of Search.Result props e.g. `{ title: '', description: '' }` or | ||
|
@@ -60,36 +64,24 @@ export default class Search extends Component { | |
PropTypes.object, | ||
]), | ||
|
||
/** Controls whether or not the results menu is displayed. */ | ||
open: PropTypes.bool, | ||
|
||
/** Initial value of open. */ | ||
defaultOpen: PropTypes.bool, | ||
|
||
/** Current value of the search input. Creates a controlled component. */ | ||
value: PropTypes.string, | ||
|
||
/** Initial value. */ | ||
defaultValue: PropTypes.string, | ||
|
||
/** Placeholder of the search input. */ | ||
placeholder: PropTypes.string, | ||
|
||
/** Minimum characters to query for results */ | ||
minCharacters: PropTypes.number, | ||
|
||
/** Message to display when there are no results. */ | ||
noResultsMessage: PropTypes.string, | ||
|
||
/** Additional text for "No Results" message with less emphasis. */ | ||
noResultsDescription: PropTypes.string, | ||
|
||
/** Message to display when there are no results. */ | ||
noResultsMessage: PropTypes.string, | ||
|
||
/** Whether the search should automatically select the first result after searching */ | ||
selectFirstResult: PropTypes.bool, | ||
|
||
/** Whether a "no results" message should be shown if no results are found. */ | ||
showNoResults: PropTypes.bool, | ||
|
||
/** Current value of the search input. Creates a controlled component. */ | ||
value: PropTypes.string, | ||
|
||
// ------------------------------------ | ||
// Rendering | ||
// ------------------------------------ | ||
|
@@ -119,36 +111,36 @@ export default class Search extends Component { | |
onBlur: PropTypes.func, | ||
|
||
/** | ||
* Called when a result is selected. | ||
* Called on focus. | ||
* | ||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {object} data - All props. | ||
*/ | ||
onResultSelect: PropTypes.func, | ||
onFocus: PropTypes.func, | ||
|
||
/** | ||
* Called on search input change. | ||
* Called on mousedown. | ||
* | ||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {string} value - Current value of search input. | ||
* @param {object} data - All props. | ||
*/ | ||
onSearchChange: PropTypes.func, | ||
onMouseDown: PropTypes.func, | ||
|
||
/** | ||
* Called on focus. | ||
* Called when a result is selected. | ||
* | ||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {object} data - All props. | ||
*/ | ||
onFocus: PropTypes.func, | ||
onResultSelect: PropTypes.func, | ||
|
||
/** | ||
* Called on mousedown. | ||
* Called on search input change. | ||
* | ||
* @param {SyntheticEvent} event - React's original SyntheticEvent. | ||
* @param {object} data - All props. | ||
* @param {string} value - Current value of search input. | ||
*/ | ||
onMouseDown: PropTypes.func, | ||
onSearchChange: PropTypes.func, | ||
|
||
// ------------------------------------ | ||
// Style | ||
|
@@ -169,28 +161,36 @@ export default class Search extends Component { | |
/** A search input can take up the width of its container. */ | ||
input: customPropTypes.itemShorthand, | ||
|
||
size: PropTypes.oneOf(_meta.props.size), | ||
|
||
/** A search can show a loading indicator. */ | ||
loading: PropTypes.bool, | ||
|
||
/** A search can have different sizes. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ 😄 |
||
size: PropTypes.oneOf(_.without(SUI.SIZES, 'medium')), | ||
} | ||
|
||
static defaultProps = { | ||
icon: 'search', | ||
input: 'text', | ||
minCharacters: 1, | ||
noResultsMessage: 'No results found.', | ||
showNoResults: true, | ||
input: 'text', | ||
} | ||
|
||
static autoControlledProps = [ | ||
'open', | ||
'value', | ||
] | ||
|
||
static _meta = _meta | ||
static _meta = { | ||
name: 'Search', | ||
type: META.TYPES.MODULE, | ||
} | ||
|
||
static Category = SearchCategory | ||
|
||
static Result = SearchResult | ||
|
||
static Results = SearchResults | ||
static Category = SearchCategory | ||
|
||
componentWillMount() { | ||
if (super.componentWillMount) super.componentWillMount() | ||
|
@@ -512,25 +512,23 @@ export default class Search extends Component { | |
// ---------------------------------------- | ||
|
||
renderSearchInput = () => { | ||
const { icon, placeholder, input } = this.props | ||
const { icon, input, placeholder } = this.props | ||
const { value } = this.state | ||
|
||
return ( | ||
Input.create(input, { | ||
value, | ||
placeholder, | ||
onBlur: this.handleBlur, | ||
onChange: this.handleSearchChange, | ||
onFocus: this.handleFocus, | ||
onClick: this.handleInputClick, | ||
input: { className: 'prompt', tabIndex: '0', autoComplete: 'off' }, | ||
icon, | ||
}) | ||
) | ||
return Input.create(input, { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't really need parens there. |
||
value, | ||
placeholder, | ||
onBlur: this.handleBlur, | ||
onChange: this.handleSearchChange, | ||
onFocus: this.handleFocus, | ||
onClick: this.handleInputClick, | ||
input: { className: 'prompt', tabIndex: '0', autoComplete: 'off' }, | ||
icon, | ||
}) | ||
} | ||
|
||
renderNoResults = () => { | ||
const { noResultsMessage, noResultsDescription } = this.props | ||
const { noResultsDescription, noResultsMessage } = this.props | ||
|
||
return ( | ||
<div className='message empty'> | ||
|
@@ -612,11 +610,7 @@ export default class Search extends Component { | |
|
||
if (!menuContent) return | ||
|
||
return ( | ||
<SearchResults className={resultsClasses}> | ||
{menuContent} | ||
</SearchResults> | ||
) | ||
return <SearchResults className={resultsClasses}>{menuContent}</SearchResults> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This expression is too simple to be multiline. |
||
} | ||
|
||
render() { | ||
|
@@ -640,15 +634,13 @@ export default class Search extends Component { | |
open && 'active visible', | ||
size, | ||
searchClasses, | ||
useKeyOnly(loading, 'loading'), | ||
|
||
useValueAndKey(aligned, 'aligned'), | ||
useKeyOnly(category, 'category'), | ||
useKeyOnly(focus, 'focus'), | ||
useKeyOnly(fluid, 'fluid'), | ||
|
||
className, | ||
useKeyOnly(loading, 'loading'), | ||
useValueAndKey(aligned, 'aligned'), | ||
'search', | ||
className, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
const rest = getUnhandledProps(Search, this.props) | ||
const ElementType = getElementType(Search, this.props) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ interface SearchProps extends ReactMouseEvents<HTMLInputElement>, ReactFocusEven | |
/** Shorthand for Icon. */ | ||
icon?: any; | ||
|
||
/** A search can show a loading indicator. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added inline comment to prop. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, we should also update the ts file comment as well. |
||
loading?: boolean; | ||
|
||
/** Minimum characters to query for results */ | ||
|
@@ -86,7 +87,7 @@ interface SearchProps extends ReactMouseEvents<HTMLInputElement>, ReactFocusEven | |
/** Whether a "no results" message should be shown if no results are found. */ | ||
showNoResults?: boolean; | ||
|
||
/** Search size */ | ||
/** A search can have different sizes. */ | ||
size?: SemanticSIZES; | ||
|
||
/** Current value of the search input. Creates a controlled component. */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inline comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's also update the ts file.