|
| 1 | +import React from 'react'; |
| 2 | +import { ActionType, dispatch, useTutorialStore } from '../core/store'; |
| 3 | +import { styled } from 'goober'; |
| 4 | + |
| 5 | +export const Content = React.forwardRef((_, ref?: React.ForwardedRef<HTMLInputElement>) => { |
| 6 | + const { |
| 7 | + index, |
| 8 | + tutorial: { steps }, |
| 9 | + } = useTutorialStore(); |
| 10 | + const currentStep = steps[index]; |
| 11 | + const { onPrevStep, onNextStep } = currentStep; |
| 12 | + |
| 13 | + const handlePrev = () => { |
| 14 | + onPrevStep?.(); |
| 15 | + dispatch({ type: ActionType.PREV }); |
| 16 | + }; |
| 17 | + |
| 18 | + const handleNext = () => { |
| 19 | + onNextStep?.(); |
| 20 | + dispatch({ type: ActionType.NEXT }); |
| 21 | + }; |
| 22 | + |
| 23 | + const handleClose = () => { |
| 24 | + dispatch({ type: ActionType.CLOSE }); |
| 25 | + }; |
| 26 | + |
| 27 | + return ( |
| 28 | + <Wrapper ref={ref}> |
| 29 | + <Heander> |
| 30 | + <InfoTitle> |
| 31 | + <p>{currentStep.title}</p> |
| 32 | + <button onClick={handleClose}>건너뛰기</button> |
| 33 | + </InfoTitle> |
| 34 | + <InfoContent dangerouslySetInnerHTML={{ __html: currentStep.content ?? '' }} /> |
| 35 | + </Heander> |
| 36 | + <Footer className="flex items-center justify-between"> |
| 37 | + <InfoSteps className="text-[.75rem] font-medium text-sub-2.5"> |
| 38 | + <span>{`${index + 1} / ${steps.length}`}</span> |
| 39 | + </InfoSteps> |
| 40 | + <ButtonWrapper className="flex gap-[.625rem]"> |
| 41 | + {index !== 0 && <button onClick={handlePrev}>이전</button>} |
| 42 | + <button onClick={handleNext}>{index === steps.length - 1 ? '완료' : '다음'}</button> |
| 43 | + </ButtonWrapper> |
| 44 | + </Footer> |
| 45 | + </Wrapper> |
| 46 | + ); |
| 47 | +}); |
| 48 | + |
| 49 | +const Wrapper = styled('div', React.forwardRef)` |
| 50 | + position: absolute; |
| 51 | + top: 6.25rem; |
| 52 | + z-index: 999; |
| 53 | + width: 20rem; |
| 54 | + min-height: 7.5rem; |
| 55 | + display: flex; |
| 56 | + flex-direction: column; |
| 57 | + border-radius: 0.625rem; |
| 58 | + background-color: white; |
| 59 | + padding: 1rem; |
| 60 | + box-shadow: 5px 5px 15px 0px rgba(142, 142, 142, 0.3); |
| 61 | +`; |
| 62 | + |
| 63 | +const Heander = styled('div')` |
| 64 | + display: flex; |
| 65 | + flex-direction: column; |
| 66 | + flex: 1; |
| 67 | +`; |
| 68 | + |
| 69 | +const InfoTitle = styled('div')` |
| 70 | + display: flex; |
| 71 | + align-items: center; |
| 72 | +
|
| 73 | + p { |
| 74 | + font-size: 1.25rem; |
| 75 | + font-weight: 600; |
| 76 | + color: #1f1f1f; |
| 77 | + } |
| 78 | +
|
| 79 | + button { |
| 80 | + font-size: 0.75rem; |
| 81 | + font-weight: 500; |
| 82 | + color: #1f1f1f; |
| 83 | + margin-left: auto; |
| 84 | + text-decoration: underline; |
| 85 | + text-underline-offset: 0.1rem; |
| 86 | + } |
| 87 | +`; |
| 88 | + |
| 89 | +const InfoContent = styled('div')` |
| 90 | + margin-top: 1rem; |
| 91 | + flex: 1; |
| 92 | + overflow-y: scroll; |
| 93 | +`; |
| 94 | + |
| 95 | +const Footer = styled('div')` |
| 96 | + display: flex; |
| 97 | + align-items: center; |
| 98 | + justify-content: space-between; |
| 99 | +`; |
| 100 | + |
| 101 | +const InfoSteps = styled('div')` |
| 102 | + display: flex; |
| 103 | + font-size: 0.75rem; |
| 104 | + font-weight: 500; |
| 105 | + color: #1f1f1f; |
| 106 | +`; |
| 107 | + |
| 108 | +const ButtonWrapper = styled('div')` |
| 109 | + display: flex; |
| 110 | + gap: 0.625rem; |
| 111 | +
|
| 112 | + button { |
| 113 | + display: flex; |
| 114 | + align-items: center; |
| 115 | + justify-content: center; |
| 116 | + height: 1.5rem; |
| 117 | + padding: 0 0.375rem; |
| 118 | + border-radius: 0.3125rem; |
| 119 | + border: 0.0625rem solid #1f1f1f; |
| 120 | + font-size: 0.875rem; |
| 121 | + font-weight: 500; |
| 122 | + color: #1f1f1f; |
| 123 | + transition: all 0.3s; |
| 124 | +
|
| 125 | + &:hover { |
| 126 | + background-color: #1f1f1f; |
| 127 | + color: white; |
| 128 | + } |
| 129 | +
|
| 130 | + &:disabled { |
| 131 | + border: 0.0625rem solid #1f1f1f; |
| 132 | + color: #1f1f1f; |
| 133 | + } |
| 134 | + } |
| 135 | +`; |
0 commit comments