-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): add page name tag to indicator and fix some small bugs (#841
- Loading branch information
Showing
15 changed files
with
193 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { Placement, OffsetOptions } from "@floating-ui/react"; | ||
import { Placement, OffsetOptions, ShiftOptions } from "@floating-ui/react"; | ||
|
||
export type PopoverOptions = { | ||
initialOpen?: boolean; | ||
placement?: Placement; | ||
modal?: boolean; // @see https://floating-ui.com/docs/floatingfocusmanager#modal | ||
open?: boolean; | ||
offset?: OffsetOptions; // @see https://floating-ui.com/docs/offset | ||
shift?: ShiftOptions; | ||
onOpenChange?: (open: boolean) => void; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
web/src/beta/lib/core/StoryPanel/PageIndicator/IndicatorSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { useCallback, useMemo, useState } from "react"; | ||
|
||
import * as Popover from "@reearth/beta/components/Popover"; | ||
import Text from "@reearth/beta/components/Text"; | ||
import { styled } from "@reearth/services/theme"; | ||
|
||
type Props = { | ||
title?: string; | ||
pageNumber: number; | ||
currentPageNumber: number; | ||
onPageChange: (page: number) => void; | ||
}; | ||
|
||
const IndicatorSection: React.FC<Props> = ({ | ||
pageNumber, | ||
currentPageNumber, | ||
title, | ||
onPageChange, | ||
}) => { | ||
const [isHovered, setIsHovered] = useState(false); | ||
|
||
const handleMouseEnter = useCallback(() => setIsHovered(true), []); | ||
const handleMouseOut = useCallback(() => setIsHovered(false), []); | ||
|
||
const handleClick = useCallback(() => { | ||
onPageChange(pageNumber); | ||
setIsHovered(false); | ||
}, [pageNumber, onPageChange]); | ||
|
||
const isHighlighted = useMemo( | ||
() => pageNumber <= currentPageNumber, | ||
[currentPageNumber, pageNumber], | ||
); | ||
|
||
// const isLast = useMemo(() => pageNumber === totalPages, [pageNumber, totalPages]); | ||
|
||
return ( | ||
<Wrapper onClick={handleClick} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseOut}> | ||
<Popover.Provider open={isHovered} placement="bottom" offset={0} shift={{ padding: 0 }}> | ||
<Popover.Trigger asChild> | ||
<Indicator highlighted={isHighlighted} /> | ||
</Popover.Trigger> | ||
<Popover.Content attachToRoot> | ||
<PageNameWrapper isHighlighted={isHighlighted}> | ||
<StyledText size="footnote" customColor> | ||
{title} | ||
</StyledText> | ||
</PageNameWrapper> | ||
</Popover.Content> | ||
</Popover.Provider> | ||
</Wrapper> | ||
); | ||
}; | ||
|
||
export default IndicatorSection; | ||
|
||
const Wrapper = styled.div` | ||
flex: 1; | ||
cursor: pointer; | ||
color: ${({ theme }) => theme.content.strong}; | ||
:not(:first-of-type) { | ||
border-left: 1px solid #ffffff; | ||
} | ||
`; | ||
|
||
const Indicator = styled.div<{ highlighted: boolean }>` | ||
height: 100%; | ||
${({ highlighted }) => | ||
highlighted && | ||
` | ||
background-color: #4589ff; | ||
width: 100%; | ||
`} | ||
`; | ||
|
||
const PageNameWrapper = styled.div<{ isHighlighted: boolean }>` | ||
background-color: #78a9ff; | ||
padding: 4px 8px; | ||
${({ isHighlighted }) => isHighlighted && "background-color: #4589ff;"} | ||
max-width: 255px; | ||
`; | ||
|
||
const StyledText = styled(Text)` | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
white-space: nowrap; | ||
`; |
Oops, something went wrong.