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] - create expandable pane for long lists of items (MystenLa…
…bs#10928) ## Description For transactions with long lists of inputs / effects / recipients, it's almost unusable to show all of them at once. Created a simple expandable list component to wrap these long lists and only show a default number of items by default. Sample Transaction: https://explorer.sui.io/txblock/EXQvxhcn2Xoubmnx6L6EKDsAWkPG8sq94B7cCLAqVYP7?network=devnet ## Test Plan How did you test the new or updated feature? --- If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process. ### Type of Change (Check all that apply) - [ ] user-visible impact - [ ] breaking change for a client SDKs - [ ] breaking change for FNs (FN binary must upgrade) - [ ] breaking change for validators or node operators (must upgrade binaries) - [ ] breaking change for on-chain data layout - [ ] necessitate either a data wipe or data migration ### Release notes
- Loading branch information
1 parent
8c4a044
commit f7fa829
Showing
6 changed files
with
174 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { ChevronDown12 } from '@mysten/icons'; | ||
import { type ReactNode, useMemo, useState } from 'react'; | ||
|
||
import { Link } from './Link'; | ||
import { Text } from './Text'; | ||
|
||
interface ExpandableListProps { | ||
items: ReactNode[]; | ||
defaultItemsToShow: number; | ||
} | ||
|
||
export function ExpandableList({ | ||
items, | ||
defaultItemsToShow, | ||
}: ExpandableListProps) { | ||
const [showAll, setShowAll] = useState(false); | ||
|
||
const itemsDisplayed = useMemo( | ||
() => (showAll ? items : items?.slice(0, defaultItemsToShow)), | ||
[showAll, items, defaultItemsToShow] | ||
); | ||
|
||
const handleShowAllClick = () => | ||
setShowAll((prevShowAll: boolean) => !prevShowAll); | ||
|
||
return ( | ||
<> | ||
{itemsDisplayed.map((item, index) => ( | ||
<div key={index}>{item}</div> | ||
))} | ||
{items.length > defaultItemsToShow && ( | ||
<div className="mt-4 flex cursor-pointer items-center gap-1 text-steel hover:text-steel-dark"> | ||
<Link | ||
variant="text" | ||
onClick={handleShowAllClick} | ||
after={ | ||
<ChevronDown12 | ||
height={12} | ||
width={12} | ||
className={showAll ? 'rotate-180' : ''} | ||
/> | ||
} | ||
> | ||
<Text variant="bodySmall/medium"> | ||
{showAll ? 'Show Less' : 'Show All'} | ||
</Text> | ||
</Link> | ||
</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
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,37 @@ | ||
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { type ReactNode } from 'react'; | ||
|
||
import { ExpandableList } from '../ExpandableList'; | ||
import { type InputProps } from '../Input'; | ||
import { Text } from '../Text'; | ||
|
||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
export default { | ||
component: ExpandableList, | ||
} as Meta; | ||
|
||
function ListItem({ children }: { children: ReactNode }) { | ||
return ( | ||
<li> | ||
<Text color="steel-darker" variant="bodySmall/normal"> | ||
{children} | ||
</Text> | ||
</li> | ||
); | ||
} | ||
|
||
export const Default: StoryObj<InputProps> = { | ||
render: () => ( | ||
<ul> | ||
<ExpandableList | ||
defaultItemsToShow={3} | ||
items={Array.from({ length: 10 }).map((_, index) => ( | ||
<ListItem key={index}>Item {index}</ListItem> | ||
))} | ||
/> | ||
</ul> | ||
), | ||
}; |