make session dropdown use hooks

pull/1381/head
Audric Ackermann 4 years ago
parent e5ef061fbe
commit d2ada105ed
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -63,9 +63,6 @@ const {
SessionConfirm, SessionConfirm,
} = require('../../ts/components/session/SessionConfirm'); } = require('../../ts/components/session/SessionConfirm');
const {
SessionDropdown,
} = require('../../ts/components/session/SessionDropdown');
const { const {
SessionRegistrationView, SessionRegistrationView,
} = require('../../ts/components/session/SessionRegistrationView'); } = require('../../ts/components/session/SessionRegistrationView');
@ -267,7 +264,6 @@ exports.setup = (options = {}) => {
SessionSeedModal, SessionSeedModal,
SessionPasswordModal, SessionPasswordModal,
SessionPasswordPrompt, SessionPasswordPrompt,
SessionDropdown,
MediaGallery, MediaGallery,
Message, Message,
MessageBody, MessageBody,

@ -1,4 +1,4 @@
import React from 'react'; import React, { useState } from 'react';
import { SessionIcon, SessionIconSize, SessionIconType } from './icon/'; import { SessionIcon, SessionIconSize, SessionIconType } from './icon/';
import { import {
@ -8,11 +8,7 @@ import {
// THIS IS DROPDOWN ACCORDIAN STYLE OPTIONS SELECTOR ELEMENT, NOT A CONTEXTMENU // THIS IS DROPDOWN ACCORDIAN STYLE OPTIONS SELECTOR ELEMENT, NOT A CONTEXTMENU
interface State { type Props = {
expanded: boolean;
}
interface Props {
label: string; label: string;
onClick?: any; onClick?: any;
expanded?: boolean; expanded?: boolean;
@ -24,33 +20,20 @@ interface Props {
active?: boolean; active?: boolean;
onClick?: any; onClick?: any;
}>; }>;
}
export class SessionDropdown extends React.Component<Props, State> {
public static defaultProps = {
expanded: false,
};
constructor(props: any) {
super(props);
this.state = {
expanded: !!this.props.expanded,
}; };
this.toggleDropdown = this.toggleDropdown.bind(this); export const SessionDropdown = (props: Props) => {
} const { label, options } = props;
const [expanded, setExpanded] = useState(!!props.expanded);
public render() {
const { label, options } = this.props;
const { expanded } = this.state;
const chevronOrientation = expanded ? 180 : 0; const chevronOrientation = expanded ? 180 : 0;
return ( return (
<div className="session-dropdown"> <div className="session-dropdown">
<div <div
className="session-dropdown__label" className="session-dropdown__label"
onClick={this.toggleDropdown} onClick={() => {
setExpanded(!expanded);
}}
role="button" role="button"
> >
{label} {label}
@ -72,7 +55,8 @@ export class SessionDropdown extends React.Component<Props, State> {
type={item.type} type={item.type}
active={item.active} active={item.active}
onClick={() => { onClick={() => {
this.handleItemClick(item.onClick); setExpanded(false);
item.onClick();
}} }}
/> />
); );
@ -81,15 +65,4 @@ export class SessionDropdown extends React.Component<Props, State> {
)} )}
</div> </div>
); );
} };
public toggleDropdown() {
this.setState({
expanded: !this.state.expanded,
});
}
public handleItemClick(itemOnClickFn: any) {
this.setState({ expanded: false }, itemOnClickFn());
}
}

@ -8,39 +8,33 @@ export enum SessionDropDownItemType {
Danger = 'danger', Danger = 'danger',
} }
interface Props { type Props = {
content: string; content: string;
type: SessionDropDownItemType; type: SessionDropDownItemType;
icon: SessionIconType | null; icon: SessionIconType | null;
active: boolean; active: boolean;
onClick: any; onClick: any;
}
export class SessionDropdownItem extends React.PureComponent<Props> {
public static defaultProps = {
type: SessionDropDownItemType.Default,
icon: null,
active: false,
onClick: () => null,
}; };
constructor(props: any) { export const SessionDropdownItem = (props: Props) => {
super(props); const clickHandler = (e: any) => {
this.clickHandler = this.clickHandler.bind(this); if (props.onClick) {
e.stopPropagation();
props.onClick();
} }
};
public render() { const { content, type, icon, active } = props;
const { content, type, icon, active } = this.props;
return ( return (
<div <div
className={classNames( className={classNames(
'session-dropdown__item', 'session-dropdown__item',
active ? 'active' : '', active ? 'active' : '',
type || '' type || SessionDropDownItemType.Default
)} )}
role="button" role="button"
onClick={this.clickHandler} onClick={clickHandler}
> >
{icon ? ( {icon ? (
<SessionIcon iconType={icon} iconSize={SessionIconSize.Small} /> <SessionIcon iconType={icon} iconSize={SessionIconSize.Small} />
@ -50,12 +44,4 @@ export class SessionDropdownItem extends React.PureComponent<Props> {
<div className="item-content">{content}</div> <div className="item-content">{content}</div>
</div> </div>
); );
} };
private clickHandler(e: any) {
if (this.props.onClick) {
e.stopPropagation();
this.props.onClick();
}
}
}

Loading…
Cancel
Save