2017-05-24 03:06:01 +04:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
interface Props<T> {
|
|
|
|
value: T;
|
|
|
|
options: T[];
|
|
|
|
ariaLabel: string;
|
|
|
|
extra?: any;
|
|
|
|
formatTitle(option: T): any;
|
|
|
|
onChange(value: T): void;
|
|
|
|
}
|
2017-07-04 05:25:01 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
interface State {
|
|
|
|
expanded: boolean;
|
|
|
|
}
|
2017-05-24 03:06:01 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
export default class DropdownComponent<T> extends Component<Props<T>, State> {
|
|
|
|
public state = {
|
2017-07-02 00:49:06 -05:00
|
|
|
expanded: false
|
|
|
|
};
|
2017-05-24 03:06:01 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public render() {
|
2017-07-02 00:49:06 -05:00
|
|
|
const { options, value, ariaLabel, extra } = this.props;
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
const { expanded } = this.state;
|
2017-05-24 03:06:01 +04:00
|
|
|
|
2017-07-02 00:49:06 -05:00
|
|
|
return (
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
<span className={`dropdown ${expanded ? 'open' : ''}`}>
|
2017-07-02 00:49:06 -05:00
|
|
|
<a
|
2017-09-24 19:06:28 -07:00
|
|
|
tabIndex={0}
|
2017-07-02 00:49:06 -05:00
|
|
|
aria-haspopup="true"
|
|
|
|
aria-expanded="false"
|
|
|
|
aria-label={ariaLabel}
|
|
|
|
className="dropdown-toggle"
|
|
|
|
onClick={this.toggleExpanded}
|
|
|
|
>
|
|
|
|
{this.formatTitle(value)}
|
|
|
|
<i className="caret" />
|
|
|
|
</a>
|
v3 Style Import (#151)
* Convert bootstrap to sass instead of checked in and less
* Darken body, adjust header.
* First pass at tab styles, each tab will need a lot of individual love tho.
* Update footer to main site content, improve responsiveness.
* Missing key added.
* Fix dropdowns.
* Convert GenerateWallet HTML over, still needs styling.
* Send form.
* Current rates styled.
* CurrencySwap form styles.
* SwapInfoHeader styled.
* Finish up swap restyling, minor usability improvements for mobile.
* Fix up notifications / alert customizations
* Import v3 variables.
* Fix notification spacing.
* Align input height base with buttons.
* Revert height base, add additional bootstrap overrides.
* Grid overrides.
* Move overrides to their own folder. Adjust naming.
* Fix inconsistencies.
* Style generate wallet pt 1.
* Style generate wallet pt 2
* Style generate wallet pt 3
* Fix swap
* Added some missing overries, fixed the fallout.
* Remove header text, indicate alpha version.
* Fix radio / checkbox weights.
* Bind => arrow
* Convert simpledropdown to proper form select, instead of weirdly implemented nonfuncitoning dropdown.
* Fix token balances buttons, footr icons.
2017-09-05 15:52:01 -04:00
|
|
|
{expanded &&
|
2017-07-02 00:49:06 -05:00
|
|
|
<ul className="dropdown-menu">
|
|
|
|
{options.map((option, i) => {
|
|
|
|
return (
|
|
|
|
<li key={i}>
|
|
|
|
<a
|
|
|
|
className={option === value ? 'active' : ''}
|
|
|
|
onClick={this.onChange.bind(null, option)}
|
|
|
|
>
|
|
|
|
{this.formatTitle(option)}
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
{extra}
|
|
|
|
</ul>}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
2017-05-24 03:06:01 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public formatTitle(option: any) {
|
2017-07-02 00:49:06 -05:00
|
|
|
return this.props.formatTitle(option);
|
|
|
|
}
|
2017-05-24 03:06:01 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public toggleExpanded = () => {
|
2017-07-02 00:49:06 -05:00
|
|
|
this.setState(state => {
|
|
|
|
return {
|
|
|
|
expanded: !state.expanded
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
2017-05-24 03:06:01 +04:00
|
|
|
|
2017-09-24 19:06:28 -07:00
|
|
|
public onChange = (value: any) => {
|
2017-07-02 00:49:06 -05:00
|
|
|
this.props.onChange(value);
|
|
|
|
this.setState({ expanded: false });
|
|
|
|
};
|
2017-05-24 03:06:01 +04:00
|
|
|
}
|