SpoilerButton.jsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import React, { useState } from 'react'
  2. import { Button } from 'antd'
  3. export const SpoilerButton = ({ text, children, style }) => {
  4. const [opened, setOpened] = useState(false)
  5. return (
  6. <>
  7. <Button
  8. onClick={() => {
  9. setOpened(!opened)
  10. }}
  11. style={style}
  12. >
  13. {text}
  14. </Button>
  15. {opened && children}
  16. </>
  17. )
  18. }
  19. export const ReplyButton = ({ text, children, style }) => {
  20. const [opened, setOpened] = useState(false)
  21. return (
  22. <>
  23. <p
  24. strong
  25. className="ButtonComment"
  26. onClick={() => {
  27. setOpened(!opened)
  28. }}
  29. style={style}
  30. >
  31. {text}
  32. </p>
  33. {opened && children}
  34. </>
  35. )
  36. }
  37. export const ViewComment = ({ text, count, children, style, textClosed }) => {
  38. const [opened, setOpened] = useState(false)
  39. return (
  40. <>
  41. <p
  42. strong
  43. className="ButtonComment"
  44. onClick={() => {
  45. setOpened(!opened)
  46. }}
  47. >
  48. {!opened ? text + count + ' comments' : textClosed}
  49. </p>
  50. {
  51. <div className={opened && children ? 'ScrollForFeed' : 'WithOutScroll'}>
  52. {opened && children}
  53. </div>
  54. }
  55. </>
  56. )
  57. }