|
| 1 | +import { useState } from "react"; |
| 2 | +import { MaterialSymbol } from "../MaterialSymbol"; |
| 3 | +import { getMagnitudeFromRange } from "./get-magnitude-from-range"; |
| 4 | +import { SlideViewerDashboardNavigation } from "./SlideViewerDashboardNavigation"; |
| 5 | +import { SlideViewerDashboardQiitaLogo } from "./SlideViewerDashboardQiitaLogo"; |
| 6 | +import { SlideViewerDashboardTooltip } from "./SlideViewerDashboardTooltip"; |
| 7 | + |
| 8 | +export const SlideViewerDashboard = ({ |
| 9 | + currentPage, |
| 10 | + totalPage, |
| 11 | + isFullScreen, |
| 12 | + onPrevious, |
| 13 | + onNext, |
| 14 | + onSwitchFullScreen, |
| 15 | + onSetPage, |
| 16 | +}: { |
| 17 | + currentPage: number; |
| 18 | + totalPage: number; |
| 19 | + isFullScreen: boolean; |
| 20 | + onPrevious: () => void; |
| 21 | + onNext: () => void; |
| 22 | + onSwitchFullScreen: () => void; |
| 23 | + onSetPage: (page: number) => void; |
| 24 | +}) => { |
| 25 | + const [isTooltipVisible, setIsTooltipVisible] = useState(false); |
| 26 | + const [destinationPage, setDestinationPage] = useState(currentPage); |
| 27 | + const [tooltipLeftDistance, setTooltipLeftDistance] = useState(0); |
| 28 | + |
| 29 | + return ( |
| 30 | + <div className="slideMode-Dashboard"> |
| 31 | + {isTooltipVisible && ( |
| 32 | + <SlideViewerDashboardTooltip leftDistance={tooltipLeftDistance}> |
| 33 | + {destinationPage}/{totalPage} |
| 34 | + </SlideViewerDashboardTooltip> |
| 35 | + )} |
| 36 | + |
| 37 | + <SlideViewerDashboardNavigation |
| 38 | + currentPage={currentPage} |
| 39 | + totalPage={totalPage} |
| 40 | + onPrevious={onPrevious} |
| 41 | + onNext={onNext} |
| 42 | + /> |
| 43 | + |
| 44 | + <span className="slideMode-Dashboard_pageCount"> |
| 45 | + {currentPage} / {totalPage} |
| 46 | + </span> |
| 47 | + |
| 48 | + <div |
| 49 | + className="slideMode-Dashboard_progress" |
| 50 | + onMouseMove={(event) => { |
| 51 | + setIsTooltipVisible(true); |
| 52 | + setTooltipLeftDistance( |
| 53 | + event.clientX - event.currentTarget.getBoundingClientRect().left |
| 54 | + ); |
| 55 | + setDestinationPage( |
| 56 | + getMagnitudeFromRange(event.currentTarget, event.clientX, totalPage) |
| 57 | + ); |
| 58 | + }} |
| 59 | + onMouseLeave={() => { |
| 60 | + setIsTooltipVisible(false); |
| 61 | + }} |
| 62 | + onClick={() => { |
| 63 | + onSetPage(destinationPage); |
| 64 | + }} |
| 65 | + > |
| 66 | + <div |
| 67 | + className="slideMode-Dashboard_progressFill" |
| 68 | + style={{ |
| 69 | + width: `${(currentPage / totalPage) * 100}%`, |
| 70 | + }} |
| 71 | + /> |
| 72 | + </div> |
| 73 | + |
| 74 | + <button |
| 75 | + aria-label={"スライドショー"} |
| 76 | + className="slideMode-Dashboard_button slideMode-Dashboard_button--fullscreen slideMode-Dashboard_button--clickable" |
| 77 | + onClick={onSwitchFullScreen} |
| 78 | + > |
| 79 | + <MaterialSymbol fill={true} size={20}> |
| 80 | + {isFullScreen ? "close_fullscreen" : "live_tv"} |
| 81 | + </MaterialSymbol> |
| 82 | + </button> |
| 83 | + |
| 84 | + <SlideViewerDashboardQiitaLogo /> |
| 85 | + </div> |
| 86 | + ); |
| 87 | +}; |
0 commit comments