HelpOverlay.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2017-2020 @polkadot/react-components authors & contributors
  2. // This software may be modified and distributed under the terms
  3. // of the Apache-2.0 license. See the LICENSE file for details.
  4. import React from 'react';
  5. import ReactMd from 'react-markdown';
  6. import styled from 'styled-components';
  7. import { useToggle } from '@polkadot/react-hooks';
  8. import Icon from './Icon';
  9. interface Props {
  10. className?: string;
  11. md: string;
  12. }
  13. function HelpOverlay ({ className = '', md }: Props): React.ReactElement<Props> {
  14. const [isVisible, toggleVisible] = useToggle();
  15. return (
  16. <div className={className}>
  17. <div className='help-button'>
  18. <Icon
  19. icon='question-circle'
  20. onClick={toggleVisible}
  21. />
  22. </div>
  23. <div className={`help-slideout ${isVisible ? 'open' : 'closed'}`}>
  24. <div className='help-button'>
  25. <Icon
  26. icon='times'
  27. onClick={toggleVisible}
  28. />
  29. </div>
  30. <ReactMd
  31. className='help-content'
  32. escapeHtml={false}
  33. source={md}
  34. />
  35. </div>
  36. </div>
  37. );
  38. }
  39. export default React.memo(styled(HelpOverlay)`
  40. .help-button {
  41. cursor: pointer;
  42. font-size: 2rem;
  43. padding: 1.25rem 1.5rem 0 0;
  44. }
  45. > .help-button {
  46. position: absolute;
  47. right: 0rem;
  48. top: 0rem;
  49. }
  50. .help-slideout {
  51. background: #eee;
  52. border-left: 0.25rem solid #ddd;
  53. bottom: 0;
  54. max-width: 50rem;
  55. overflow-y: scroll;
  56. position: fixed;
  57. right: -50rem;
  58. top: 0;
  59. transition-duration: .5s;
  60. transition-property: all;
  61. z-index: 10;
  62. .help-button {
  63. text-align: right;
  64. }
  65. .help-content {
  66. padding: 1rem 1.5rem 5rem;
  67. }
  68. &.open {
  69. right: 0;
  70. }
  71. }
  72. `);