MyCrypto/common/components/ui/SwapDropdown.tsx
James Prado 9cac0298a2 Improve accessibility (a11y) (#1267)
* Manage modal focus

* Add isOpen prop to CustomNodeModal

* Remove outline overrides

* Update outline style for inputs

* Fix modal focus management & Cleanup CustomNodeModal

* Add aria-label on modal close button

* Fix modal scroll to top

* Add aria-live property for notifications

* Add aria-busy to Spinner component

* Fix border styles for generatewallet password inputs

* Update token balances inputs

* Remove multiple h1's & Update styles

* Add alt text to all img elements

* Update swap link from bity to shapeshift

* Update aria-labels and alt text

* Only show keystore password input when required

* Revert "Only show keystore password input when required"

This reverts commit 7ec5de52da0982cd3131f365b142f6915638d831.

* address changes requested
2018-03-08 13:28:43 -06:00

80 lines
2.1 KiB
TypeScript

import React, { PureComponent } from 'react';
import './SwapDropdown.scss';
import { DropDown } from 'components/ui';
export interface SingleCoin {
id: string;
name: string;
image: string;
status: string;
}
interface Props<T> {
options: SingleCoin[];
value: string;
onChange(value: T): void;
}
const ValueComp: React.SFC = (props: any) => {
return (
<div className={`${props.className} swap-option-wrapper`}>
<img src={props.value.img} className="swap-option-img" alt={props.value.label + ' logo'} />
<span className="swap-option-label">{props.value.label}</span>
</div>
);
};
const OptionComp: React.SFC = (props: any) => {
const handleMouseDown = (event: React.MouseEvent<any>) => {
event.preventDefault();
event.stopPropagation();
props.onSelect(props.option, event);
};
const handleMouseEnter = (event: React.MouseEvent<any>) => {
props.onFocus(props.option, event);
};
const handleMouseMove = (event: React.MouseEvent<any>) => {
if (props.isFocused) {
return;
}
props.onFocus(props.option, event);
};
return (
<div
className={`${props.className} swap-option-wrapper`}
onMouseDown={handleMouseDown}
onMouseEnter={handleMouseEnter}
onMouseMove={handleMouseMove}
>
<img src={props.option.img} className="swap-option-img" alt={props.option.label + ' logo'} />
<span className="swap-option-label">{props.option.label}</span>
</div>
);
};
class SwapDropdown<T> extends PureComponent<Props<T>> {
public render() {
const { options, value, onChange } = this.props;
const mappedOptions = options.map(opt => {
return { label: opt.id, value: opt.name, img: opt.image, status: opt.status };
});
return (
<DropDown
className="Swap-dropdown"
options={mappedOptions}
optionComponent={(props: any) => {
return <OptionComp {...props} />;
}}
value={value}
clearable={false}
onChange={onChange}
valueComponent={(props: any) => {
return <ValueComp {...props} />;
}}
/>
);
}
}
export default SwapDropdown;