step.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'prism-sentry/index.css';
  2. import {useState} from 'react';
  3. import styled from '@emotion/styled';
  4. import CheckboxFancy from 'sentry/components/checkboxFancy/checkboxFancy';
  5. import space from 'sentry/styles/space';
  6. import {Project} from 'sentry/types';
  7. import localStorage from 'sentry/utils/localStorage';
  8. type Props = {
  9. docContent: string | undefined;
  10. docKey: string;
  11. project: Project;
  12. };
  13. function OnBoardingStep(props: Props) {
  14. const {docKey, project, docContent} = props;
  15. const [increment, setIncrement] = useState<number>(0);
  16. if (!docContent) {
  17. return null;
  18. }
  19. const localStorageKey = `perf-onboarding-${project.id}-${docKey}`;
  20. function isChecked() {
  21. return localStorage.getItem(localStorageKey) === 'check';
  22. }
  23. return (
  24. <Wrapper>
  25. <TaskCheckBox>
  26. <CheckboxFancy
  27. size="22px"
  28. isChecked={isChecked()}
  29. onClick={event => {
  30. event.preventDefault();
  31. event.stopPropagation();
  32. if (isChecked()) {
  33. localStorage.removeItem(localStorageKey);
  34. } else {
  35. localStorage.setItem(localStorageKey, 'check');
  36. }
  37. setIncrement(increment + 1);
  38. return;
  39. }}
  40. />
  41. </TaskCheckBox>
  42. <DocumentationWrapper dangerouslySetInnerHTML={{__html: docContent}} />
  43. </Wrapper>
  44. );
  45. }
  46. const Wrapper = styled('div')`
  47. position: relative;
  48. `;
  49. const TaskCheckBox = styled('div')`
  50. float: left;
  51. margin-right: ${space(1.5)};
  52. height: 27px;
  53. display: flex;
  54. align-items: center;
  55. z-index: 2;
  56. position: relative;
  57. `;
  58. const DocumentationWrapper = styled('div')`
  59. line-height: 1.5;
  60. .gatsby-highlight {
  61. margin-bottom: ${space(3)};
  62. &:last-child {
  63. margin-bottom: 0;
  64. }
  65. }
  66. .alert {
  67. margin-bottom: ${space(3)};
  68. border-radius: ${p => p.theme.borderRadius};
  69. }
  70. pre {
  71. word-break: break-all;
  72. white-space: pre-wrap;
  73. }
  74. blockquote {
  75. padding: ${space(1)};
  76. margin-left: 0;
  77. background: ${p => p.theme.alert.info.backgroundLight};
  78. border-left: 2px solid ${p => p.theme.alert.info.border};
  79. }
  80. blockquote > *:last-child {
  81. margin-bottom: 0;
  82. }
  83. /* Ensures documentation content is placed behind the checkbox */
  84. z-index: 1;
  85. position: relative;
  86. `;
  87. export default OnBoardingStep;