forked from Semantic-Org/Semantic-UI-React
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(Search): remove imports of other examples (Semantic-Org#3494)
* docs(Search): Implement own standard custom. * docs(Search): Implement own category custom example. * docs(Search): Implement own example for fluid search. * docs(Search): Implement own example for aligned search. * docs(Search): Implement own example for input search and fix typo.
- Loading branch information
Showing
6 changed files
with
376 additions
and
28 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
74 changes: 70 additions & 4 deletions
74
docs/src/examples/modules/Search/Variations/SearchExampleAligned.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 |
---|---|---|
@@ -1,6 +1,72 @@ | ||
import React from 'react' | ||
import SearchExampleStandard from '../Types/SearchExampleStandard' | ||
import _ from 'lodash' | ||
import faker from 'faker' | ||
import React, { Component } from 'react' | ||
import { Search, Grid, Header, Segment } from 'semantic-ui-react' | ||
|
||
const SearchExampleAligned = () => <SearchExampleStandard aligned='right' /> | ||
const source = _.times(5, () => ({ | ||
title: faker.company.companyName(), | ||
description: faker.company.catchPhrase(), | ||
image: faker.internet.avatar(), | ||
price: faker.finance.amount(0, 100, 2, '$'), | ||
})) | ||
|
||
export default SearchExampleAligned | ||
export default class SearchExampleStandard extends Component { | ||
componentWillMount() { | ||
this.resetComponent() | ||
} | ||
|
||
resetComponent = () => | ||
this.setState({ isLoading: false, results: [], value: '' }) | ||
|
||
handleResultSelect = (e, { result }) => this.setState({ value: result.title }) | ||
|
||
handleSearchChange = (e, { value }) => { | ||
this.setState({ isLoading: true, value }) | ||
|
||
setTimeout(() => { | ||
if (this.state.value.length < 1) return this.resetComponent() | ||
|
||
const re = new RegExp(_.escapeRegExp(this.state.value), 'i') | ||
const isMatch = result => re.test(result.title) | ||
|
||
this.setState({ | ||
isLoading: false, | ||
results: _.filter(source, isMatch), | ||
}) | ||
}, 300) | ||
} | ||
|
||
render() { | ||
const { isLoading, value, results } = this.state | ||
|
||
return ( | ||
<Grid> | ||
<Grid.Column width={6}> | ||
<Search | ||
aligned='right' | ||
loading={isLoading} | ||
onResultSelect={this.handleResultSelect} | ||
onSearchChange={_.debounce(this.handleSearchChange, 500, { | ||
leading: true, | ||
})} | ||
results={results} | ||
value={value} | ||
{...this.props} | ||
/> | ||
</Grid.Column> | ||
<Grid.Column width={10}> | ||
<Segment> | ||
<Header>State</Header> | ||
<pre style={{ overflowX: 'auto' }}> | ||
{JSON.stringify(this.state, null, 2)} | ||
</pre> | ||
<Header>Options</Header> | ||
<pre style={{ overflowX: 'auto' }}> | ||
{JSON.stringify(source, null, 2)} | ||
</pre> | ||
</Segment> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} |
74 changes: 70 additions & 4 deletions
74
docs/src/examples/modules/Search/Variations/SearchExampleFluid.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 |
---|---|---|
@@ -1,6 +1,72 @@ | ||
import React from 'react' | ||
import SearchExampleStandard from '../Types/SearchExampleStandard' | ||
import _ from 'lodash' | ||
import faker from 'faker' | ||
import React, { Component } from 'react' | ||
import { Search, Grid, Header, Segment } from 'semantic-ui-react' | ||
|
||
const SearchExampleFluid = () => <SearchExampleStandard fluid /> | ||
const source = _.times(5, () => ({ | ||
title: faker.company.companyName(), | ||
description: faker.company.catchPhrase(), | ||
image: faker.internet.avatar(), | ||
price: faker.finance.amount(0, 100, 2, '$'), | ||
})) | ||
|
||
export default SearchExampleFluid | ||
export default class SearchExampleStandard extends Component { | ||
componentWillMount() { | ||
this.resetComponent() | ||
} | ||
|
||
resetComponent = () => | ||
this.setState({ isLoading: false, results: [], value: '' }) | ||
|
||
handleResultSelect = (e, { result }) => this.setState({ value: result.title }) | ||
|
||
handleSearchChange = (e, { value }) => { | ||
this.setState({ isLoading: true, value }) | ||
|
||
setTimeout(() => { | ||
if (this.state.value.length < 1) return this.resetComponent() | ||
|
||
const re = new RegExp(_.escapeRegExp(this.state.value), 'i') | ||
const isMatch = result => re.test(result.title) | ||
|
||
this.setState({ | ||
isLoading: false, | ||
results: _.filter(source, isMatch), | ||
}) | ||
}, 300) | ||
} | ||
|
||
render() { | ||
const { isLoading, value, results } = this.state | ||
|
||
return ( | ||
<Grid> | ||
<Grid.Column width={6}> | ||
<Search | ||
fluid | ||
loading={isLoading} | ||
onResultSelect={this.handleResultSelect} | ||
onSearchChange={_.debounce(this.handleSearchChange, 500, { | ||
leading: true, | ||
})} | ||
results={results} | ||
value={value} | ||
{...this.props} | ||
/> | ||
</Grid.Column> | ||
<Grid.Column width={10}> | ||
<Segment> | ||
<Header>State</Header> | ||
<pre style={{ overflowX: 'auto' }}> | ||
{JSON.stringify(this.state, null, 2)} | ||
</pre> | ||
<Header>Options</Header> | ||
<pre style={{ overflowX: 'auto' }}> | ||
{JSON.stringify(source, null, 2)} | ||
</pre> | ||
</Segment> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} |
Oops, something went wrong.