-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add timestamp zone toggle to Explorer (#22616)
* Add timestamp zone toggle to Explorer * style: code formatting
- Loading branch information
1 parent
d6011ba
commit 88bf3c7
Showing
2 changed files
with
51 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { useState } from "react"; | ||
import { displayTimestampUtc, displayTimestamp } from "utils/date"; | ||
|
||
type State = "hide" | "show"; | ||
|
||
function Tooltip({ state }: { state: State }) { | ||
const tooltip = { | ||
maxWidth: "20rem", | ||
}; | ||
|
||
if (state === "hide") return null; | ||
return ( | ||
<div className="popover bs-popover-bottom show" style={tooltip}> | ||
<div className="arrow" /> | ||
<div className="popover-body"> | ||
(Click to toggle between local and UTC) | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export function TimestampToggle({ unixTimestamp }: { unixTimestamp: number }) { | ||
const [isTimestampTypeUtc, toggleTimestampType] = useState(true); | ||
const [showTooltip, toggleTooltip] = useState<State>("hide"); | ||
|
||
const toggle = () => { | ||
toggleTimestampType(!isTimestampTypeUtc); | ||
}; | ||
|
||
const tooltipContainer = { | ||
cursor: "pointer", | ||
}; | ||
|
||
return ( | ||
<div className="popover-container w-100" style={tooltipContainer}> | ||
<span | ||
onClick={toggle} | ||
onMouseOver={() => toggleTooltip("show")} | ||
onMouseOut={() => toggleTooltip("hide")} | ||
> | ||
{isTimestampTypeUtc === true | ||
? displayTimestampUtc(unixTimestamp) | ||
: displayTimestamp(unixTimestamp)} | ||
</span> | ||
<Tooltip state={showTooltip} /> | ||
</div> | ||
); | ||
} |
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
88bf3c7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deploy preview for explorer ready!
✅ Preview
https://explorer-rl39uqx4w-solana-labs.vercel.app
Built with commit 88bf3c7.
This pull request is being automatically deployed with vercel-action