forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[explorer] Add PageHeader component (MystenLabs#5278)
- Loading branch information
1 parent
1f7e436
commit 1da87fc
Showing
15 changed files
with
295 additions
and
12 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,11 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// eslint-disable-next-line react/no-typos | ||
import 'react'; | ||
|
||
declare module 'react' { | ||
interface CSSProperties { | ||
[key: `--${string}`]: string | number | null; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { type TransactionKindName } from '@mysten/sui.js'; | ||
import toast from 'react-hot-toast'; | ||
|
||
import { Badge } from './Badge'; | ||
import { Heading } from './Heading'; | ||
import { ReactComponent as CopyIcon } from './icons/copy.svg'; | ||
import { ReactComponent as ImageIcon } from './icons/image.svg'; | ||
import { ReactComponent as SenderIcon } from './icons/sender.svg'; | ||
import { ReactComponent as CallIcon } from './icons/transactions/call.svg'; | ||
import { ReactComponent as ChangeEpochIcon } from './icons/transactions/changeEpoch.svg'; | ||
import { ReactComponent as PayIcon } from './icons/transactions/pay.svg'; | ||
import { ReactComponent as PublishIcon } from './icons/transactions/publish.svg'; | ||
import { ReactComponent as TransferObjectIcon } from './icons/transactions/transferObject.svg'; | ||
import { ReactComponent as TransferSuiIcon } from './icons/transactions/transferSui.svg'; | ||
|
||
export type PageHeaderType = | ||
| TransactionKindName | ||
| 'Address' | ||
| 'Object' | ||
| 'Package'; | ||
|
||
export interface PageHeaderProps { | ||
title: string; | ||
type: PageHeaderType; | ||
status?: 'success' | 'failure'; | ||
} | ||
|
||
const TYPE_TO_ICON: Record<PageHeaderType, typeof CallIcon> = { | ||
Call: CallIcon, | ||
ChangeEpoch: ChangeEpochIcon, | ||
Pay: PayIcon, | ||
Publish: PublishIcon, | ||
TransferObject: TransferObjectIcon, | ||
TransferSui: TransferSuiIcon, | ||
Object: ImageIcon, | ||
Package: CallIcon, | ||
Address: () => ( | ||
<SenderIcon | ||
style={{ | ||
'--icon-primary-color': 'var(--sui-steel)', | ||
'--icon-secondary-color': 'white', | ||
}} | ||
/> | ||
), | ||
}; | ||
|
||
const STATUS_TO_TEXT = { | ||
success: 'Success', | ||
failure: 'Failure', | ||
}; | ||
|
||
export function PageHeader({ title, type, status }: PageHeaderProps) { | ||
const Icon = TYPE_TO_ICON[type]; | ||
return ( | ||
<div className="flex flex-col gap-3"> | ||
<div className="text-sui-grey-85 flex items-center gap-2"> | ||
<Icon className="text-sui-steel" /> | ||
<Heading variant="heading4" weight="semibold"> | ||
{type} | ||
</Heading> | ||
</div> | ||
<div className="flex flex-col lg:flex-row gap-2"> | ||
<div className="flex items-center gap-2 min-w-0"> | ||
<div className="break-words min-w-0"> | ||
<Heading as="h2" variant="heading2" weight="bold" mono> | ||
{title} | ||
</Heading> | ||
</div> | ||
<button | ||
onClick={() => { | ||
navigator.clipboard.writeText(title); | ||
toast.success('Copied!'); | ||
}} | ||
className="bg-transparent border-none cursor-pointer p-0 m-0 text-sui-steel flex justify-center items-center" | ||
> | ||
<CopyIcon /> | ||
</button> | ||
</div> | ||
|
||
{status && ( | ||
<div> | ||
<Badge variant={status}>{STATUS_TO_TEXT[status]}</Badge> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.