Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { isEmpty } from 'lodash';
  4. import { Label, InputDescription, InputErrors } from 'strapi-helper-plugin';
  5. import Editor from '../CKEditor';
  6.  
  7. const WysiwygWithErrors = ({
  8. inputDescription,
  9. errors,
  10. label,
  11. name,
  12. noErrorsDescription,
  13. onChange,
  14. value,
  15. }) => {
  16. let spacer = !isEmpty(inputDescription) ? (
  17. <div style={{ height: '.4rem' }} />
  18. ) : (
  19. <div />
  20. );
  21.  
  22. if (!noErrorsDescription && !isEmpty(errors)) {
  23. spacer = <div />;
  24. }
  25.  
  26. return (
  27. <div
  28. className="col-12"
  29. style={{
  30. marginBottom: '1.6rem',
  31. fontSize: '1.3rem',
  32. fontFamily: 'Lato',
  33. }}
  34. >
  35. <Label htmlFor={name} message={label} style={{ marginBottom: 10 }} />
  36. <Editor name={name} onChange={onChange} value={value} />
  37. <InputDescription
  38. message={inputDescription}
  39. style={!isEmpty(inputDescription) ? { marginTop: '1.4rem' } : {}}
  40. />
  41. <InputErrors
  42. errors={(!noErrorsDescription && errors) || []}
  43. name={name}
  44. />
  45. {spacer}
  46. </div>
  47. );
  48. };
  49.  
  50. WysiwygWithErrors.defaultProps = {
  51. errors: [],
  52. label: '',
  53. noErrorsDescription: false,
  54. };
  55.  
  56. WysiwygWithErrors.propTypes = {
  57. errors: PropTypes.array,
  58. inputDescription: PropTypes.oneOfType([
  59. PropTypes.string,
  60. PropTypes.func,
  61. PropTypes.shape({
  62. id: PropTypes.string,
  63. params: PropTypes.object,
  64. }),
  65. ]),
  66. label: PropTypes.oneOfType([
  67. PropTypes.string,
  68. PropTypes.func,
  69. PropTypes.shape({
  70. id: PropTypes.string,
  71. params: PropTypes.object,
  72. }),
  73. ]),
  74. name: PropTypes.string.isRequired,
  75. noErrorsDescription: PropTypes.bool,
  76. onChange: PropTypes.func.isRequired,
  77. value: PropTypes.string.isRequired,
  78. };
  79.  
  80. export default WysiwygWithErrors;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement