2017-08-23 00:09:08 +05:30
|
|
|
// @flow
|
2019-06-09 13:59:54 +05:30
|
|
|
import type { Node } from 'react';
|
2017-08-23 00:09:08 +05:30
|
|
|
import React, { Component } from 'react';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
|
|
|
import classNames from 'classnames';
|
2016-01-08 18:44:35 +05:30
|
|
|
|
2016-08-08 00:48:11 +05:30
|
|
|
import { omit } from 'functions';
|
|
|
|
|
2016-01-08 18:44:35 +05:30
|
|
|
import styles from './panel.scss';
|
2016-01-09 17:29:42 +05:30
|
|
|
import icons from './icons.scss';
|
2016-01-08 18:44:35 +05:30
|
|
|
|
2017-08-23 00:09:08 +05:30
|
|
|
export function Panel(props: {
|
2019-06-09 13:59:54 +05:30
|
|
|
title?: string,
|
|
|
|
icon?: string,
|
|
|
|
children: Node,
|
2017-08-23 00:09:08 +05:30
|
|
|
}) {
|
|
|
|
let { title, icon } = props;
|
2016-01-09 17:29:42 +05:30
|
|
|
|
|
|
|
if (icon) {
|
|
|
|
icon = (
|
|
|
|
<button className={styles.headerControl}>
|
|
|
|
<span className={icons[icon]} />
|
|
|
|
</button>
|
|
|
|
);
|
|
|
|
}
|
2016-01-08 18:44:35 +05:30
|
|
|
|
|
|
|
if (title) {
|
|
|
|
title = (
|
|
|
|
<PanelHeader>
|
2016-01-09 17:29:42 +05:30
|
|
|
{icon}
|
2016-01-08 18:44:35 +05:30
|
|
|
{title}
|
|
|
|
</PanelHeader>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.panel}>
|
|
|
|
{title}
|
|
|
|
|
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-23 00:09:08 +05:30
|
|
|
export function PanelHeader(props: {
|
|
|
|
children: *
|
|
|
|
}) {
|
2016-01-08 18:44:35 +05:30
|
|
|
return (
|
2016-01-10 05:34:44 +05:30
|
|
|
<div className={styles.header} {...props}>
|
2016-01-08 18:44:35 +05:30
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-23 00:09:08 +05:30
|
|
|
export function PanelBody(props: {
|
|
|
|
children: *
|
|
|
|
}) {
|
2016-01-08 18:44:35 +05:30
|
|
|
return (
|
2016-01-10 05:34:44 +05:30
|
|
|
<div className={styles.body} {...props}>
|
2016-01-08 18:44:35 +05:30
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-23 00:09:08 +05:30
|
|
|
export function PanelFooter(props: {
|
|
|
|
children: *
|
|
|
|
}) {
|
2016-01-08 18:44:35 +05:30
|
|
|
return (
|
2016-01-10 05:34:44 +05:30
|
|
|
<div className={styles.footer} {...props}>
|
2016-01-08 18:44:35 +05:30
|
|
|
{props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-01-09 19:21:55 +05:30
|
|
|
|
2017-08-23 02:01:41 +05:30
|
|
|
export class PanelBodyHeader extends Component<{
|
2017-09-09 20:34:26 +05:30
|
|
|
type: 'default' | 'error',
|
2017-08-23 02:01:41 +05:30
|
|
|
onClose: Function,
|
|
|
|
children: *
|
|
|
|
}, {
|
|
|
|
isClosed: bool
|
|
|
|
}> {
|
2017-08-23 00:09:08 +05:30
|
|
|
state: {
|
|
|
|
isClosed: bool
|
|
|
|
} = {
|
|
|
|
isClosed: false
|
2016-02-13 20:58:47 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {type = 'default', children} = this.props;
|
2016-01-09 19:21:55 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
let close;
|
|
|
|
if (type === 'error') {
|
|
|
|
close = (
|
|
|
|
<span className={styles.close} onClick={this.onClose} />
|
|
|
|
);
|
|
|
|
}
|
2016-01-09 21:17:21 +05:30
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
const className = classNames(styles[`${type}BodyHeader`], {
|
2017-08-23 00:09:08 +05:30
|
|
|
[styles.isClosed]: this.state.isClosed
|
2016-02-13 20:58:47 +05:30
|
|
|
});
|
|
|
|
|
2017-08-23 00:09:08 +05:30
|
|
|
const extraProps = omit(this.props, [
|
|
|
|
'type',
|
|
|
|
'onClose'
|
|
|
|
]);
|
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
return (
|
2017-08-23 00:09:08 +05:30
|
|
|
<div className={className} {...extraProps}>
|
2016-02-13 20:58:47 +05:30
|
|
|
{close}
|
|
|
|
{children}
|
|
|
|
</div>
|
2016-01-09 21:17:21 +05:30
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-08-23 00:09:08 +05:30
|
|
|
onClose = (event: MouseEvent) => {
|
2016-02-13 20:58:47 +05:30
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
this.setState({isClosed: true});
|
|
|
|
|
|
|
|
this.props.onClose();
|
|
|
|
};
|
2016-01-09 19:21:55 +05:30
|
|
|
}
|
2017-08-23 00:09:08 +05:30
|
|
|
|
|
|
|
export function PanelIcon({icon}: {icon: string}) {
|
|
|
|
return (
|
|
|
|
<div className={styles.panelIcon}>
|
|
|
|
<span className={icons[icon]} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|