Skip to content

Commit

Permalink
change default for cards
Browse files Browse the repository at this point in the history
  • Loading branch information
plam-ml committed Oct 25, 2023
1 parent 1707cf6 commit ba93150
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CollapsibleCard } from '~/ui/collapsible/CollapsibleCard';
interface ProgrammableTxnBlockCardProps {
items: ReactNode[];
itemsLabel: string;
defaultItemsToShow: number;
defaultItemsToShow?: number;
noExpandableList?: boolean;
count?: number;
initialClose?: boolean;
Expand All @@ -19,20 +19,21 @@ interface ProgrammableTxnBlockCardProps {
export function ProgrammableTxnBlockCard({
items,
itemsLabel,
defaultItemsToShow,
noExpandableList,
count,
initialClose,
defaultItemsToShow,
}: ProgrammableTxnBlockCardProps) {
if (!items?.length) {
return null;
}

const cardTitle = count ? `${count} ${itemsLabel}` : itemsLabel;
const itemsToShow = defaultItemsToShow || items.length;

return (
<CollapsibleCard collapsible initialClose={initialClose} title={cardTitle}>
<ExpandableList items={items} defaultItemsToShow={defaultItemsToShow} itemsLabel={itemsLabel}>
<ExpandableList items={items} defaultItemsToShow={itemsToShow} itemsLabel={itemsLabel}>
<div
className={clsx(
'flex flex-col gap-6 overflow-y-auto',
Expand All @@ -42,7 +43,7 @@ export function ProgrammableTxnBlockCard({
{noExpandableList ? <>{items}</> : <ExpandableListItems />}
</div>

{items.length > defaultItemsToShow && (
{items.length > itemsToShow && (
<div className="mt-6">
<ExpandableListControl />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,18 @@ import { AddressLink, ObjectLink } from '~/ui/InternalLink';
import { CollapsibleSection } from '~/ui/collapsible/CollapsibleSection';

const REGEX_NUMBER = /^\d+$/;
const DEFAULT_ITEMS_TO_SHOW = 10;

interface InputsCardProps {
inputs: SuiCallArg[];
}

export function InputsCard({ inputs }: InputsCardProps) {
const defaultOpen = inputs.length < DEFAULT_ITEMS_TO_SHOW;

if (!inputs?.length) {
return null;
}

const expandableItems = inputs.map((input, index) => (
<CollapsibleSection key={index} title={`Input ${index}`} defaultOpen={defaultOpen}>
<CollapsibleSection key={index} title={`Input ${index}`} defaultOpen>
<div data-testid="inputs-card-content" className="flex flex-col gap-2">
{Object.entries(input).map(([key, value]) => {
let renderValue;
Expand Down Expand Up @@ -71,8 +68,6 @@ export function InputsCard({ inputs }: InputsCardProps) {
items={expandableItems}
itemsLabel={inputs.length > 1 ? 'Inputs' : 'Input'}
count={inputs.length}
defaultItemsToShow={DEFAULT_ITEMS_TO_SHOW}
noExpandableList={defaultOpen}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { Transaction } from './Transaction';
import { ProgrammableTxnBlockCard } from '~/components/transactions/ProgTxnBlockCard';
import { CollapsibleSection } from '~/ui/collapsible/CollapsibleSection';

const DEFAULT_ITEMS_TO_SHOW = 5;

interface TransactionsCardProps {
transactions: SuiTransaction[];
}
Expand Down Expand Up @@ -36,8 +34,6 @@ export function TransactionsCard({ transactions }: TransactionsCardProps) {
items={expandableItems}
itemsLabel={transactions.length > 1 ? 'Transactions' : 'Transaction'}
count={transactions.length}
defaultItemsToShow={DEFAULT_ITEMS_TO_SHOW}
noExpandableList={transactions.length < DEFAULT_ITEMS_TO_SHOW}
/>
);
}
19 changes: 15 additions & 4 deletions apps/explorer/src/ui/collapsible/CollapsibleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ function CollapsibleCardHeader({ open, size, title, collapsible }: CollapsibleCa
<div
className={clsx(
'flex w-full justify-between',
open && size === 'md' && 'pb-6',
open && size === 'sm' && 'pb-4.5',
size === 'md' ? 'px-6' : 'px-4',
size === 'sm' && 'pb-4.5',
open && size === 'md' && 'pb-6 pt-7',
open && size === 'sm' && 'pt-4.5',
!open && size === 'md' && 'py-7',
!open && size === 'sm' && 'py-4.5',
)}
>
{typeof title === 'string' ? (
Expand Down Expand Up @@ -84,11 +88,18 @@ export function CollapsibleCard({
<Collapsible.Root
open={open}
onOpenChange={setOpen}
className={clsx(size === 'md' ? 'px-6 py-7' : 'px-4 py-4.5')}
className={clsx(
!title && size === 'md' && 'pt-7',
!title && size === 'sm' && 'pt-4.5',
open && size === 'md' && 'pb-7',
open && size === 'sm' && 'pb-4.5',
)}
>
<CollapsibleCardHeader open={open} size={size} title={title} collapsible={collapsible} />

<Collapsible.Content>{children}</Collapsible.Content>
<div className={clsx(size === 'md' ? 'px-6' : 'px-4')}>
<Collapsible.Content>{children}</Collapsible.Content>
</div>
</Collapsible.Root>

{footer && (
Expand Down

0 comments on commit ba93150

Please sign in to comment.