placeholder wip
This commit is contained in:
parent
ea490c8b2e
commit
aa2f3dc419
|
@ -21,12 +21,13 @@ const SelectInput = ({
|
||||||
...rest
|
...rest
|
||||||
}: SelectFieldProps) => {
|
}: SelectFieldProps) => {
|
||||||
const showError = ((meta.submitError && !meta.dirtySinceLastSubmit) || meta.error) && meta.touched
|
const showError = ((meta.submitError && !meta.dirtySinceLastSubmit) || meta.error) && meta.touched
|
||||||
const inputProps = { ...restInput, name }
|
const inputProps = {
|
||||||
console.log(classes)
|
...restInput,
|
||||||
|
name,
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<FormControl {...formControlProps} error={showError} style={style}>
|
<FormControl {...formControlProps} error={showError} style={style}>
|
||||||
<InputLabel htmlFor={name}>{label}</InputLabel>
|
<InputLabel htmlFor={name}>{label}</InputLabel>
|
||||||
{/* eslint-disable-next-line */}
|
|
||||||
<Select
|
<Select
|
||||||
classes={classes}
|
classes={classes}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
import React, { useState } from 'react'
|
||||||
import React from 'react'
|
|
||||||
import { List } from 'immutable'
|
import { List } from 'immutable'
|
||||||
import { withStyles } from '@material-ui/core/styles'
|
import { withStyles } from '@material-ui/core/styles'
|
||||||
import MenuItem from '@material-ui/core/MenuItem'
|
import MenuItem from '@material-ui/core/MenuItem'
|
||||||
|
@ -20,38 +19,58 @@ type SelectFieldProps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SelectedTokenProps = {
|
type SelectedTokenProps = {
|
||||||
token: Token,
|
token?: Token,
|
||||||
classes: Object,
|
classes: Object,
|
||||||
}
|
}
|
||||||
|
|
||||||
const SelectedToken = ({ token, classes }: SelectedTokenProps) => (
|
const SelectedToken = ({ token, classes }: SelectedTokenProps) => (
|
||||||
<MenuItem className={classes.container} key={token.address} value={token.address}>
|
<MenuItem className={classes.container}>
|
||||||
<ListItemIcon className={classes.tokenImage}>
|
{token ? (
|
||||||
<Img src={token.logoUri} height={28} alt={token.name} onError={setImageToPlaceholder} />
|
<>
|
||||||
</ListItemIcon>
|
<ListItemIcon className={classes.tokenImage}>
|
||||||
<ListItemText className={classes.tokenData} primary={token.name} secondary={`${token.balance} ${token.symbol}`} />
|
<Img src={token.logoUri} height={28} alt={token.name} onError={setImageToPlaceholder} />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText
|
||||||
|
className={classes.tokenData}
|
||||||
|
primary={token.name}
|
||||||
|
secondary={`${token.balance} ${token.symbol}`}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'Select an asset'
|
||||||
|
)}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
)
|
)
|
||||||
|
|
||||||
const SelectedTokenStyled = withStyles(selectedTokenStyles)(SelectedToken)
|
const SelectedTokenStyled = withStyles(selectedTokenStyles)(SelectedToken)
|
||||||
|
|
||||||
const TokenSelectField = ({ tokens, classes }: SelectFieldProps) => (
|
const TokenSelectField = ({ tokens, classes }: SelectFieldProps) => {
|
||||||
<Field
|
const [selectedToken, setSelectedToken] = useState('')
|
||||||
name="token"
|
const onSelect = (event) => {
|
||||||
component={SelectField}
|
setSelectedToken(event.target.value)
|
||||||
classes={{ selectMenu: classes.selectMenu }}
|
}
|
||||||
validate={composeValidators(required)}
|
|
||||||
renderValue={token => <SelectedTokenStyled token={token} />}
|
return (
|
||||||
>
|
<Field
|
||||||
{tokens.map(token => (
|
name="token"
|
||||||
<MenuItem key={token.address} value={token}>
|
component={SelectField}
|
||||||
<ListItemIcon>
|
classes={{ selectMenu: classes.selectMenu }}
|
||||||
<Img src={token.logoUri} height={28} alt={token.name} onError={setImageToPlaceholder} />
|
validate={composeValidators(required)}
|
||||||
</ListItemIcon>
|
renderValue={token => <SelectedTokenStyled token={token} />}
|
||||||
<ListItemText primary={token.name} secondary={`${token.balance} ${token.symbol}`} />
|
value={selectedToken}
|
||||||
</MenuItem>
|
onChange={onSelect}
|
||||||
))}
|
displayEmpty
|
||||||
</Field>
|
>
|
||||||
)
|
{tokens.map(token => (
|
||||||
|
<MenuItem key={token.address} value={token}>
|
||||||
|
<ListItemIcon>
|
||||||
|
<Img src={token.logoUri} height={28} alt={token.name} onError={setImageToPlaceholder} />
|
||||||
|
</ListItemIcon>
|
||||||
|
<ListItemText primary={token.name} secondary={`${token.balance} ${token.symbol}`} />
|
||||||
|
</MenuItem>
|
||||||
|
))}
|
||||||
|
</Field>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default withStyles(selectStyles)(TokenSelectField)
|
export default withStyles(selectStyles)(TokenSelectField)
|
||||||
|
|
Loading…
Reference in New Issue