bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/actions-bar/emoji-select/component.jsx

104 lines
3.4 KiB
React
Raw Normal View History

2017-11-24 01:20:27 +08:00
import React from 'react';
import PropTypes from 'prop-types';
import { defineMessages, intlShape, injectIntl } from 'react-intl';
import Button from '/imports/ui/components/button/component';
import Dropdown from '/imports/ui/components/dropdown/component';
import DropdownTrigger from '/imports/ui/components/dropdown/trigger/component';
import DropdownContent from '/imports/ui/components/dropdown/content/component';
import DropdownList from '/imports/ui/components/dropdown/list/component';
import DropdownListItem from '/imports/ui/components/dropdown/list/item/component';
import DropdownListSeparator from '/imports/ui/components/dropdown/list/separator/component';
2018-01-08 14:17:18 +08:00
import { styles } from '../styles';
2017-11-24 01:20:27 +08:00
const intlMessages = defineMessages({
statusTriggerLabel: {
id: 'app.actionsBar.emojiMenu.statusTriggerLabel',
description: 'Emoji status button label',
},
changeStatusLabel: {
2017-11-30 18:29:52 +08:00
id: 'app.actionsBar.changeStatusLabel',
2017-11-24 01:20:27 +08:00
description: 'Aria-label for emoji status button',
},
currentStatusDesc: {
2017-11-30 18:29:52 +08:00
id: 'app.actionsBar.currentStatusDesc',
2017-11-24 01:20:27 +08:00
description: 'Aria description for status button',
},
});
const propTypes = {
intl: intlShape.isRequired,
options: PropTypes.objectOf(PropTypes.string).isRequired,
selected: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
};
const EmojiSelect = ({
intl,
options,
selected,
onChange,
}) => {
const statuses = Object.keys(options);
const lastStatus = statuses.pop();
const statusLabel = intl.formatMessage(intlMessages.statusTriggerLabel);
2017-11-24 01:20:27 +08:00
return (
<Dropdown autoFocus>
<DropdownTrigger tabIndex={0}>
<Button
className={styles.button}
label={statusLabel}
aria-label={statusLabel}
2017-11-24 01:20:27 +08:00
aria-describedby="currentStatus"
icon={options[selected !== lastStatus ? selected : statuses[1]]}
ghost={false}
hideLabel
2017-11-24 01:20:27 +08:00
circle
size="lg"
color="primary"
onClick={() => null}
2018-03-23 23:42:56 +08:00
accessKey="s"
2017-11-24 01:20:27 +08:00
>
<div id="currentStatus" hidden>
{ intl.formatMessage(intlMessages.currentStatusDesc, { 0: selected }) }
</div>
</Button>
</DropdownTrigger>
<DropdownContent placement="top left">
<DropdownList>
{
statuses.map(status => (
<DropdownListItem
2017-12-01 21:11:17 +08:00
key={status}
2017-11-24 01:20:27 +08:00
className={status === selected ? styles.emojiSelected : null}
icon={options[status]}
label={intl.formatMessage({ id: `app.actionsBar.emojiMenu.${status}Label` })}
description={intl.formatMessage({ id: `app.actionsBar.emojiMenu.${status}Desc` })}
onClick={() => onChange(status)}
tabIndex={-1}
/>
))
2017-12-01 21:11:17 +08:00
.concat(
<DropdownListSeparator key={-1} />,
<DropdownListItem
key={lastStatus}
icon={options[lastStatus]}
label={intl.formatMessage({ id: `app.actionsBar.emojiMenu.${lastStatus}Label` })}
description={intl.formatMessage({ id: `app.actionsBar.emojiMenu.${lastStatus}Desc` })}
onClick={() => onChange(lastStatus)}
tabIndex={-1}
/>,
)
2017-11-24 01:20:27 +08:00
}
</DropdownList>
</DropdownContent>
</Dropdown>
);
};
EmojiSelect.propTypes = propTypes;
export default injectIntl(EmojiSelect);