Skip to content

Commit

Permalink
Add isolated examples of size prop
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Jun 19, 2020
1 parent d5d320e commit 97c7b8f
Showing 1 changed file with 174 additions and 3 deletions.
177 changes: 174 additions & 3 deletions react/components/AutocompleteInput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ const UsersAutocomplete = () => {
? user.toLowerCase().includes(term.toLowerCase())
: user.label.toLowerCase().includes(term.toLowerCase())
),
size: 'small',
}

const input = {
Expand Down Expand Up @@ -107,7 +106,6 @@ const UsersAutocomplete = () => {
onChange: option =>
option && setLastSearched(uniq([...lastSearched, option])),
},
size: 'regular',
}

const input = {
Expand Down Expand Up @@ -226,7 +224,6 @@ const UsersAutocomplete = () => {
},
// --- This is what makes the custom option work!
renderOption: props => <CustomOption {...props} />,
size: 'large',
}

const input = {
Expand Down Expand Up @@ -255,3 +252,177 @@ const UsersAutocomplete = () => {

;<UsersAutocomplete />
```

#### Size

### small size bar
```jsx
import { uniq } from 'lodash'
import { useState, useRef } from 'react'

const allUsers = [
'Ana Clara',
'Ana Luiza',
{ value: 1, label: 'Bruno' },
'Carlos',
'Daniela',
]

const UsersAutocomplete = () => {
const [term, setTerm] = useState('')
const [loading, setLoading] = useState(false)
const timeoutRef = useRef(null)

const options = {
onSelect: (...args) => console.log('onSelect: ', ...args),
loading,
value: !term.length
? []
: allUsers.filter(user =>
typeof user === 'string'
? user.toLowerCase().includes(term.toLowerCase())
: user.label.toLowerCase().includes(term.toLowerCase())
),
size: 'small',
}

const input = {
onChange: term => {
if (term) {
setLoading(true)
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}
timeoutRef.current = setTimeout(() => {
setLoading(false)
setTerm(term)
timeoutRef.current = null
}, 1000)
} else {
setTerm(term)
}
},
onSearch: (...args) => console.log('onSearch:', ...args),
onClear: () => setTerm(''),
placeholder: 'Search user... (e.g.: Ana)',
value: term,
}
return <AutocompleteInput input={input} options={options} />
}

;<UsersAutocomplete />
```
### regular size bar
```jsx
import { uniq } from 'lodash'
import { useState, useRef } from 'react'

const allUsers = [
'Ana Clara',
'Ana Luiza',
{ value: 1, label: 'Bruno' },
'Carlos',
'Daniela',
]

const UsersAutocomplete = () => {
const [term, setTerm] = useState('')
const [loading, setLoading] = useState(false)
const timeoutRef = useRef(null)

const options = {
onSelect: (...args) => console.log('onSelect: ', ...args),
loading,
value: !term.length
? []
: allUsers.filter(user =>
typeof user === 'string'
? user.toLowerCase().includes(term.toLowerCase())
: user.label.toLowerCase().includes(term.toLowerCase())
),
size: 'regular',
}

const input = {
onChange: term => {
if (term) {
setLoading(true)
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}
timeoutRef.current = setTimeout(() => {
setLoading(false)
setTerm(term)
timeoutRef.current = null
}, 1000)
} else {
setTerm(term)
}
},
onSearch: (...args) => console.log('onSearch:', ...args),
onClear: () => setTerm(''),
placeholder: 'Search user... (e.g.: Ana)',
value: term,
}
return <AutocompleteInput input={input} options={options} />
}

;<UsersAutocomplete />
```
### large size bar
```jsx
import { uniq } from 'lodash'
import { useState, useRef } from 'react'

const allUsers = [
'Ana Clara',
'Ana Luiza',
{ value: 1, label: 'Bruno' },
'Carlos',
'Daniela',
]

const UsersAutocomplete = () => {
const [term, setTerm] = useState('')
const [loading, setLoading] = useState(false)
const timeoutRef = useRef(null)

const options = {
onSelect: (...args) => console.log('onSelect: ', ...args),
loading,
value: !term.length
? []
: allUsers.filter(user =>
typeof user === 'string'
? user.toLowerCase().includes(term.toLowerCase())
: user.label.toLowerCase().includes(term.toLowerCase())
),
size: 'large',
}

const input = {
onChange: term => {
if (term) {
setLoading(true)
if (timeoutRef.current) {
clearTimeout(timeoutRef.current)
}
timeoutRef.current = setTimeout(() => {
setLoading(false)
setTerm(term)
timeoutRef.current = null
}, 1000)
} else {
setTerm(term)
}
},
onSearch: (...args) => console.log('onSearch:', ...args),
onClear: () => setTerm(''),
placeholder: 'Search user... (e.g.: Ana)',
value: term,
}
return <AutocompleteInput input={input} options={options} />
}

;<UsersAutocomplete />
```

0 comments on commit 97c7b8f

Please sign in to comment.