onboardingStep.tsx 2.2 KB

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