]>
cat aescling's git repositories - mastodon.git/blob - app/javascript/mastodon/features/compose/components/privacy_dropdown.js
1 import React
from 'react';
2 import PropTypes
from 'prop-types';
3 import { injectIntl
, defineMessages
} from 'react-intl';
4 import IconButton
from '../../../components/icon_button';
6 const messages
= defineMessages({
7 public_short: { id: 'privacy.public.short', defaultMessage: 'Public' },
8 public_long: { id: 'privacy.public.long', defaultMessage: 'Post to public timelines' },
9 unlisted_short: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
10 unlisted_long: { id: 'privacy.unlisted.long', defaultMessage: 'Do not show in public timelines' },
11 private_short: { id: 'privacy.private.short', defaultMessage: 'Followers-only' },
12 private_long: { id: 'privacy.private.long', defaultMessage: 'Post to followers only' },
13 direct_short: { id: 'privacy.direct.short', defaultMessage: 'Direct' },
14 direct_long: { id: 'privacy.direct.long', defaultMessage: 'Post to mentioned users only' },
15 change_privacy: { id: 'privacy.change', defaultMessage: 'Adjust status privacy' }
23 class PrivacyDropdown
extends React
.PureComponent
{
26 value: PropTypes
.string
.isRequired
,
27 onChange: PropTypes
.func
.isRequired
,
28 intl: PropTypes
.object
.isRequired
35 handleToggle
= () => {
36 this.setState({ open: !this.state
.open
});
39 handleClick
= (e
) => {
40 const value
= e
.currentTarget
.getAttribute('data-index');
42 this.setState({ open: false });
43 this.props
.onChange(value
);
46 onGlobalClick
= (e
) => {
47 if (e
.target
!== this.node
&& !this.node
.contains(e
.target
) && this.state
.open
) {
48 this.setState({ open: false });
52 componentDidMount () {
53 window
.addEventListener('click', this.onGlobalClick
);
54 window
.addEventListener('touchstart', this.onGlobalClick
);
57 componentWillUnmount () {
58 window
.removeEventListener('click', this.onGlobalClick
);
59 window
.removeEventListener('touchstart', this.onGlobalClick
);
67 const { value
, onChange
, intl
} = this.props
;
68 const { open
} = this.state
;
71 { icon: 'globe', value: 'public', shortText: intl
.formatMessage(messages
.public_short
), longText: intl
.formatMessage(messages
.public_long
) },
72 { icon: 'unlock-alt', value: 'unlisted', shortText: intl
.formatMessage(messages
.unlisted_short
), longText: intl
.formatMessage(messages
.unlisted_long
) },
73 { icon: 'lock', value: 'private', shortText: intl
.formatMessage(messages
.private_short
), longText: intl
.formatMessage(messages
.private_long
) },
74 { icon: 'envelope', value: 'direct', shortText: intl
.formatMessage(messages
.direct_short
), longText: intl
.formatMessage(messages
.direct_long
) }
77 const valueOption
= options
.find(item
=> item
.value
=== value
);
80 <div ref
={this.setRef
} className
={`privacy-dropdown ${open ? 'active' : ''}`}>
81 <div className
='privacy-dropdown__value'><IconButton className
='privacy-dropdown__value-icon' icon
={valueOption
.icon
} title
={intl
.formatMessage(messages
.change_privacy
)} size
={18} active
={open
} inverted onClick
={this.handleToggle
} style
={iconStyle
}/></div>
82 <div className
='privacy-dropdown__dropdown'>
83 {open
&& options
.map(item
=>
84 <div role
='button' tabIndex
='0' key
={item
.value
} data
-index
={item
.value
} onClick
={this.handleClick
} className
={`privacy-dropdown__option ${item.value === value ? 'active' : ''}`}>
85 <div className
='privacy-dropdown__option__icon'><i className
={`fa fa-fw fa-${item.icon}`} /></div>
86 <div className
='privacy-dropdown__option__content'>
87 <strong
>{item
.shortText
}</strong
>
99 export default injectIntl(PrivacyDropdown
);
This page took 0.118924 seconds and 4 git commands to generate.