The code powering m.abunchtell.com https://m.abunchtell.com
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

102 lignes
3.8 KiB

  1. import PureRenderMixin from 'react-addons-pure-render-mixin';
  2. import { injectIntl, defineMessages } from 'react-intl';
  3. import IconButton from '../../../components/icon_button';
  4. const messages = defineMessages({
  5. public_short: { id: 'privacy.public.short', defaultMessage: 'Public' },
  6. public_long: { id: 'privacy.public.long', defaultMessage: 'Post to public timelines' },
  7. unlisted_short: { id: 'privacy.unlisted.short', defaultMessage: 'Unlisted' },
  8. unlisted_long: { id: 'privacy.unlisted.long', defaultMessage: 'Do not show in public timelines' },
  9. private_short: { id: 'privacy.private.short', defaultMessage: 'Private' },
  10. private_long: { id: 'privacy.private.long', defaultMessage: 'Post to followers only' },
  11. direct_short: { id: 'privacy.direct.short', defaultMessage: 'Direct' },
  12. direct_long: { id: 'privacy.direct.long', defaultMessage: 'Post to mentioned users only' },
  13. change_privacy: { id: 'privacy.change', defaultMessage: 'Adjust status privacy' }
  14. });
  15. const iconStyle = {
  16. lineHeight: '27px',
  17. height: null
  18. };
  19. const PrivacyDropdown = React.createClass({
  20. propTypes: {
  21. value: React.PropTypes.string.isRequired,
  22. onChange: React.PropTypes.func.isRequired,
  23. intl: React.PropTypes.object.isRequired
  24. },
  25. getInitialState () {
  26. return {
  27. open: false
  28. };
  29. },
  30. mixins: [PureRenderMixin],
  31. handleToggle () {
  32. this.setState({ open: !this.state.open });
  33. },
  34. handleClick (value, e) {
  35. e.preventDefault();
  36. this.setState({ open: false });
  37. this.props.onChange(value);
  38. },
  39. onGlobalClick (e) {
  40. if (e.target !== this.node && !this.node.contains(e.target) && this.state.open) {
  41. this.setState({ open: false });
  42. }
  43. },
  44. componentDidMount () {
  45. window.addEventListener('click', this.onGlobalClick);
  46. window.addEventListener('touchstart', this.onGlobalClick);
  47. },
  48. componentWillUnmount () {
  49. window.removeEventListener('click', this.onGlobalClick);
  50. window.removeEventListener('touchstart', this.onGlobalClick);
  51. },
  52. setRef (c) {
  53. this.node = c;
  54. },
  55. render () {
  56. const { value, onChange, intl } = this.props;
  57. const { open } = this.state;
  58. const options = [
  59. { icon: 'globe', value: 'public', shortText: intl.formatMessage(messages.public_short), longText: intl.formatMessage(messages.public_long) },
  60. { icon: 'unlock-alt', value: 'unlisted', shortText: intl.formatMessage(messages.unlisted_short), longText: intl.formatMessage(messages.unlisted_long) },
  61. { icon: 'lock', value: 'private', shortText: intl.formatMessage(messages.private_short), longText: intl.formatMessage(messages.private_long) },
  62. { icon: 'envelope', value: 'direct', shortText: intl.formatMessage(messages.direct_short), longText: intl.formatMessage(messages.direct_long) }
  63. ];
  64. const valueOption = options.find(item => item.value === value);
  65. return (
  66. <div ref={this.setRef} className={`privacy-dropdown ${open ? 'active' : ''}`}>
  67. <div className='privacy-dropdown__value'><IconButton icon={valueOption.icon} title={intl.formatMessage(messages.change_privacy)} size={18} active={open} inverted onClick={this.handleToggle} style={iconStyle} /></div>
  68. <div className='privacy-dropdown__dropdown'>
  69. {options.map(item =>
  70. <div role='button' tabIndex='0' key={item.value} onClick={this.handleClick.bind(this, item.value)} className={`privacy-dropdown__option ${item.value === value ? 'active' : ''}`}>
  71. <div className='privacy-dropdown__option__icon'><i className={`fa fa-fw fa-${item.icon}`} /></div>
  72. <div className='privacy-dropdown__option__content'>
  73. <strong>{item.shortText}</strong>
  74. {item.longText}
  75. </div>
  76. </div>
  77. )}
  78. </div>
  79. </div>
  80. );
  81. }
  82. });
  83. export default injectIntl(PrivacyDropdown);