Skip to content
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

Merged
merged 1 commit into from
Jan 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 57 additions & 65 deletions src/modules/Search/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
Expand All @@ -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
// ------------------------------------
Expand Down Expand Up @@ -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
Expand All @@ -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. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comment.

Copy link
Member

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.

loading: PropTypes.bool,

/** A search can have different sizes. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

Copy link
Member

Choose a reason for hiding this comment

The 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()
Expand Down Expand Up @@ -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, {
Copy link
Member Author

Choose a reason for hiding this comment

The 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'>
Expand Down Expand Up @@ -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>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This expression is too simple to be multiline.

}

render() {
Expand All @@ -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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

className is always last in our pattern.

)
const rest = getUnhandledProps(Search, this.props)
const ElementType = getElementType(Search, this.props)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Search/SearchCategory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import {
customPropTypes,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Search/SearchResult.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component, PropTypes } from 'react'
import cx from 'classnames'
import React, { Component, PropTypes } from 'react'

import {
createHTMLImage,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Search/SearchResults.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { PropTypes } from 'react'
import cx from 'classnames'
import React, { PropTypes } from 'react'

import {
customPropTypes,
Expand Down
3 changes: 2 additions & 1 deletion src/modules/Search/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface SearchProps extends ReactMouseEvents<HTMLInputElement>, ReactFocusEven
/** Shorthand for Icon. */
icon?: any;

/** A search can show a loading indicator. */
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added inline comment to prop.

Copy link
Member

Choose a reason for hiding this comment

The 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 */
Expand Down Expand Up @@ -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. */
Expand Down