WhiteListInput.jsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* eslint-disable max-len */
  2. import React from 'react';
  3. import PropTypes from 'prop-types';
  4. import { withTranslation } from 'react-i18next';
  5. import { createSubscribedElement } from '../../UnstatedUtils';
  6. import AppContainer from '../../../services/AppContainer';
  7. class WhiteListInput extends React.Component {
  8. renderRecommendBtn() {
  9. const { t } = this.props;
  10. return (
  11. <p id="btn-import-tags" className="btn btn-xs btn-primary">
  12. { t('markdown_setting.import_recommended', 'tags') }
  13. </p>
  14. );
  15. }
  16. render() {
  17. const { t, customizable } = this.props;
  18. const { onChangeTagWhiteList, onChangeAttrWhiteList } = this.props;
  19. return (
  20. <>
  21. <div className="m-t-15">
  22. <div className="d-flex justify-content-between">
  23. { t('markdown_setting.Tag names') }
  24. {customizable && this.renderRecommendBtn()}
  25. </div>
  26. {/* TODO GW-304 fetch correct defaultValue */}
  27. <textarea className="form-control xss-list" name="recommendedTags" rows="6" cols="40" readOnly={!customizable} defaultValue="recommendedWhitelist.tags" onChange={(e) => { onChangeTagWhiteList(e.target.value) }} />
  28. </div>
  29. <div className="m-t-15">
  30. <div className="d-flex justify-content-between">
  31. { t('markdown_setting.Tag attributes') }
  32. {customizable && this.renderRecommendBtn()}
  33. </div>
  34. {/* TODO GW-304 fetch correct defaultValue */}
  35. <textarea className="form-control xss-list" name="recommendedAttrs" rows="6" cols="40" readOnly={!customizable} defaultValue="recommendedWhitelist.attrs" onChange={(e) => { onChangeAttrWhiteList(e.target.value) }} />
  36. </div>
  37. </>
  38. );
  39. }
  40. }
  41. const WhiteListWrapper = (props) => {
  42. return createSubscribedElement(WhiteListInput, props, [AppContainer]);
  43. };
  44. WhiteListInput.propTypes = {
  45. t: PropTypes.func.isRequired, // i18next
  46. appContainer: PropTypes.instanceOf(AppContainer).isRequired,
  47. customizable: PropTypes.bool.isRequired,
  48. onChangeTagWhiteList: PropTypes.func,
  49. onChangeAttrWhiteList: PropTypes.func,
  50. };
  51. export default withTranslation()(WhiteListWrapper);