mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-02-21 09:38:40 +05:30
#111: Draft dropdown events
This commit is contained in:
parent
8b8a6e1a64
commit
42993e1d1d
@ -11,6 +11,8 @@ import popupStyles from 'components/ui/popup/popup.scss';
|
|||||||
import styles from './contactForm.scss';
|
import styles from './contactForm.scss';
|
||||||
import messages from './contactForm.intl.json';
|
import messages from './contactForm.intl.json';
|
||||||
|
|
||||||
|
const CONTACT_CATEGORIES = ['Foo', 'Bar', 'Baz'];
|
||||||
|
|
||||||
export default class ContactForm extends Component {
|
export default class ContactForm extends Component {
|
||||||
static displayName = 'ContactForm';
|
static displayName = 'ContactForm';
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ export default class ContactForm extends Component {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={styles.formMargin}>
|
<div className={styles.formMargin}>
|
||||||
<Dropdown label={messages.whichQuestion} block />
|
<Dropdown label={messages.whichQuestion} items={CONTACT_CATEGORIES} block />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<TextArea
|
<TextArea
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import styles from 'components/ui/dropdown.scss';
|
import styles from './dropdown.scss';
|
||||||
|
|
||||||
import FormComponent from './FormComponent';
|
import FormComponent from './FormComponent';
|
||||||
|
|
||||||
export default class Dropdown extends FormComponent {
|
export default class Dropdown extends FormComponent {
|
||||||
@ -16,26 +16,81 @@ export default class Dropdown extends FormComponent {
|
|||||||
}),
|
}),
|
||||||
PropTypes.string
|
PropTypes.string
|
||||||
]).isRequired,
|
]).isRequired,
|
||||||
|
items: PropTypes.arrayOf(PropTypes.string).isRequired,
|
||||||
block: PropTypes.bool,
|
block: PropTypes.bool,
|
||||||
color: PropTypes.oneOf(['green', 'blue', 'red', 'lightViolet', 'darkBlue', 'violet'])
|
color: PropTypes.oneOf(['green', 'blue', 'red', 'lightViolet', 'darkBlue', 'violet'])
|
||||||
};
|
};
|
||||||
|
|
||||||
|
state = {
|
||||||
|
isActive: false,
|
||||||
|
activeItem: this.props.label
|
||||||
|
};
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
document.addEventListener('click', this.onBodyClick);
|
||||||
|
}
|
||||||
|
|
||||||
|
componentWillUnmount() {
|
||||||
|
document.removeEventListener('click', this.onBodyClick);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { color = 'green', block } = this.props;
|
const { color = 'green', block, items } = this.props;
|
||||||
|
const {isActive, activeItem} = this.state;
|
||||||
|
|
||||||
const props = {
|
const label = this.formatMessage(activeItem);
|
||||||
...this.props
|
|
||||||
};
|
|
||||||
|
|
||||||
props.label = this.formatMessage(props.label);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(styles[color], {
|
<div className={classNames(styles[color], {
|
||||||
[styles.block]: block
|
[styles.block]: block
|
||||||
})} {...props}>
|
})} {...this.props} onClick={this.onToggle}>
|
||||||
{props.label}
|
{label}
|
||||||
<span className={styles.toggleIcon} />
|
<span className={styles.toggleIcon} />
|
||||||
|
|
||||||
|
<div className={classNames(styles.menu, {
|
||||||
|
[styles.menuActive]: isActive
|
||||||
|
})}>
|
||||||
|
{items.map((item, key) => (
|
||||||
|
<div className={styles.menuItem} key={key} onClick={this.onSelectItem(item)}>
|
||||||
|
{item}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
toggle() {
|
||||||
|
this.setState({
|
||||||
|
isActive: !this.state.isActive
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onSelectItem(item) {
|
||||||
|
return (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
this.setState({
|
||||||
|
activeItem: item
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
onToggle = (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
this.toggle();
|
||||||
|
};
|
||||||
|
|
||||||
|
onBodyClick = (event) => {
|
||||||
|
if (this.state.isActive) {
|
||||||
|
const el = ReactDOM.findDOMNode(this);
|
||||||
|
|
||||||
|
if (!el.contains(event.target) && el !== event.taget) {
|
||||||
|
event.preventDefault();
|
||||||
|
|
||||||
|
this.toggle();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ $dropdownPadding: 15px;
|
|||||||
|
|
||||||
background-color: $backgroundColor;
|
background-color: $backgroundColor;
|
||||||
|
|
||||||
|
.menuItem:hover,
|
||||||
&:hover {
|
&:hover {
|
||||||
background-color: lighter($backgroundColor);
|
background-color: lighter($backgroundColor);
|
||||||
}
|
}
|
||||||
@ -42,7 +43,7 @@ $dropdownPadding: 15px;
|
|||||||
}
|
}
|
||||||
|
|
||||||
.toggleIcon {
|
.toggleIcon {
|
||||||
composes: selecter from './icons.scss';
|
composes: selecter from 'components/ui/icons.scss';
|
||||||
|
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: $dropdownPadding;
|
right: $dropdownPadding;
|
||||||
@ -62,6 +63,53 @@ $dropdownPadding: 15px;
|
|||||||
.block {
|
.block {
|
||||||
display: block;
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|
||||||
|
.menu {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu {
|
||||||
|
position: absolute;
|
||||||
|
top: 60px;
|
||||||
|
left: 0;
|
||||||
|
z-index: 10;
|
||||||
|
|
||||||
|
width: 120%;
|
||||||
|
|
||||||
|
background: #fff;
|
||||||
|
border: 1px solid #ddd;
|
||||||
|
|
||||||
|
transition: 0.5s ease;
|
||||||
|
transition-property: opacity, visibility;
|
||||||
|
opacity: 0;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menuActive {
|
||||||
|
opacity: 1;
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menuItem {
|
||||||
|
height: 50px;
|
||||||
|
padding: 0 13px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
|
||||||
|
color: #444;
|
||||||
|
line-height: 50px;
|
||||||
|
font-size: 18px;
|
||||||
|
font-family: $font-family-title;
|
||||||
|
|
||||||
|
border-bottom: 1px solid #ebe8df;
|
||||||
|
cursor: pointer;
|
||||||
|
|
||||||
|
transition: .25s;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@include dropdown-theme('green', $green);
|
@include dropdown-theme('green', $green);
|
Loading…
x
Reference in New Issue
Block a user