From 41afe8f18a81542e8fb7fc626500d79a03b886da Mon Sep 17 00:00:00 2001 From: Dean Sallinen <7519573+deansallinen@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:45:33 -0800 Subject: [PATCH] refactor: description list component --- src/lib/components/descriptionlist.svelte | 25 -------- src/lib/components/descriptionlist/dd.svelte | 5 ++ src/lib/components/descriptionlist/dl.svelte | 10 ++- .../components/descriptionlist/dlrow.svelte | 21 +++++-- src/lib/components/descriptionlist/dt.svelte | 5 ++ src/lib/components/descriptionlist/index.ts | 2 + .../(account)/ram/(forms)/buy/+page.svelte | 62 +++++++++--------- .../(account)/ram/(forms)/sell/+page.svelte | 63 ++++++++++--------- .../staking/(staking)/stake/+page.svelte | 16 +++-- .../staking/(staking)/unstake/+page.svelte | 6 +- .../debug/components/sections/tables.svelte | 48 +++++++++++--- .../(explorer)/block/[number]/+page.svelte | 26 +++++--- 12 files changed, 170 insertions(+), 119 deletions(-) delete mode 100644 src/lib/components/descriptionlist.svelte create mode 100644 src/lib/components/descriptionlist/dd.svelte create mode 100644 src/lib/components/descriptionlist/dt.svelte diff --git a/src/lib/components/descriptionlist.svelte b/src/lib/components/descriptionlist.svelte deleted file mode 100644 index d8d06255..00000000 --- a/src/lib/components/descriptionlist.svelte +++ /dev/null @@ -1,25 +0,0 @@ - - -
- {#each props.items as item} -
-
{item.key}
-
{item.value}
-
- {/each} -
diff --git a/src/lib/components/descriptionlist/dd.svelte b/src/lib/components/descriptionlist/dd.svelte new file mode 100644 index 00000000..5a6a5af2 --- /dev/null +++ b/src/lib/components/descriptionlist/dd.svelte @@ -0,0 +1,5 @@ + + +
{@render props.children()}
diff --git a/src/lib/components/descriptionlist/dl.svelte b/src/lib/components/descriptionlist/dl.svelte index ef7e1cdc..f184044b 100644 --- a/src/lib/components/descriptionlist/dl.svelte +++ b/src/lib/components/descriptionlist/dl.svelte @@ -3,8 +3,8 @@ import Dlrow from './dlrow.svelte'; type DescriptionItem = { - key: string; - value: string; + title: string; + description: string; }; interface Props { @@ -17,10 +17,8 @@
{#if props.items} - {#each props.items as item} - - {item.value} - + {#each props.items as { title, description }} + {/each} {:else if props.children} {@render props.children()} diff --git a/src/lib/components/descriptionlist/dlrow.svelte b/src/lib/components/descriptionlist/dlrow.svelte index 70128fda..6bea9b8f 100644 --- a/src/lib/components/descriptionlist/dlrow.svelte +++ b/src/lib/components/descriptionlist/dlrow.svelte @@ -1,16 +1,29 @@
-
{title}
-
{@render children()}
+
{title}
+
+ {#if description} +
{description}
+ {/if} + {#if children} + {@render children()} + {/if} +
diff --git a/src/lib/components/descriptionlist/dt.svelte b/src/lib/components/descriptionlist/dt.svelte new file mode 100644 index 00000000..852406c2 --- /dev/null +++ b/src/lib/components/descriptionlist/dt.svelte @@ -0,0 +1,5 @@ + + +
{@render props.children()}
diff --git a/src/lib/components/descriptionlist/index.ts b/src/lib/components/descriptionlist/index.ts index 8947140a..6f2b22ec 100644 --- a/src/lib/components/descriptionlist/index.ts +++ b/src/lib/components/descriptionlist/index.ts @@ -1,2 +1,4 @@ export { default as DL } from './dl.svelte'; export { default as DLRow } from './dlrow.svelte'; +export { default as DD } from './dd.svelte'; +export { default as DT } from './dt.svelte'; diff --git a/src/routes/[network]/(account)/ram/(forms)/buy/+page.svelte b/src/routes/[network]/(account)/ram/(forms)/buy/+page.svelte index 6fd898ce..e8b835d1 100644 --- a/src/routes/[network]/(account)/ram/(forms)/buy/+page.svelte +++ b/src/routes/[network]/(account)/ram/(forms)/buy/+page.svelte @@ -20,6 +20,7 @@ import { BuyRAMState } from './state.svelte'; import { calAvailableSize, preventDefault } from '$lib/utils'; + import { DD, DL, DLRow } from '$lib/components/descriptionlist'; let bytesInput: BytesInput | undefined = $state(); let assetInput: AssetInput | undefined = $state(); @@ -139,34 +140,39 @@ -
-

- {m.common_labeled_unit_price({ - unit: `${context.network.chain.systemToken?.symbol.name}/RAM` - })} (KB) -

- - -
- -

{m.ram_to_purchase()}

- - -
- -

{m.ram_purchase_value()}

- - -
- -

{m.common_network_fees()} (0.5%)

- - -
- -

{m.common_total_cost()}

- -
+
+ +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+
{#if buyRamState.valid} {#if buyRamState.format === 'asset'} diff --git a/src/routes/[network]/(account)/ram/(forms)/sell/+page.svelte b/src/routes/[network]/(account)/ram/(forms)/sell/+page.svelte index f6d7ab8a..bb958358 100644 --- a/src/routes/[network]/(account)/ram/(forms)/sell/+page.svelte +++ b/src/routes/[network]/(account)/ram/(forms)/sell/+page.svelte @@ -19,6 +19,7 @@ import { SellRAMState } from './state.svelte'; import { calAvailableSize, preventDefault } from '$lib/utils'; + import { DD, DL, DLRow } from '$lib/components/descriptionlist'; let bytesInput: BytesInput | undefined = $state(); let assetInput: AssetInput | undefined = $state(); @@ -125,36 +126,40 @@ {m.common_unit_sell({ unit: 'RAM' })} - -
-

- {m.common_labeled_unit_price({ - unit: `${context.network.chain.systemToken?.symbol.name}/RAM` - })} (KB) -

- - -
- -

{m.ram_to_sell()}

- - -
- -

{m.total_proceeds()}

- - -
- -

{m.common_network_fees()} (0.5%)

- - -
- -

{m.common_expected_receive()}

- -
+
+ +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+ + +
+ +
+
+
{#if sellRamState.valid}
- +
{/if} diff --git a/src/routes/[network]/(account)/staking/(staking)/unstake/+page.svelte b/src/routes/[network]/(account)/staking/(staking)/unstake/+page.svelte index 924cf90d..c8837028 100644 --- a/src/routes/[network]/(account)/staking/(staking)/unstake/+page.svelte +++ b/src/routes/[network]/(account)/staking/(staking)/unstake/+page.svelte @@ -6,7 +6,7 @@ import Button from '$lib/components/button/button.svelte'; import Label from '$lib/components/input/label.svelte'; import TransactionSummary from '$lib/components/transactionSummary.svelte'; - import Descriptionlist from '$lib/components/descriptionlist.svelte'; + import { DL } from '$lib/components/descriptionlist'; import type { UnicoveContext } from '$lib/state/client.svelte'; import { getContext } from 'svelte'; import { UnstakeManager } from './manager.svelte'; @@ -18,7 +18,7 @@ let manager: UnstakeManager = $state(new UnstakeManager(data.network)); let hints = $derived([ - { key: m.staking_withdraw_timeframe(), value: manager.assetValue.toString() } + { title: m.staking_withdraw_timeframe(), description: manager.assetValue.toString() } ]); $effect(() => { @@ -78,6 +78,6 @@ - +
{/if} diff --git a/src/routes/[network]/(dev)/debug/components/sections/tables.svelte b/src/routes/[network]/(dev)/debug/components/sections/tables.svelte index a5f02107..51d297d0 100644 --- a/src/routes/[network]/(dev)/debug/components/sections/tables.svelte +++ b/src/routes/[network]/(dev)/debug/components/sections/tables.svelte @@ -1,6 +1,7 @@ @@ -50,8 +51,39 @@ row striping here.

+ +
+ + +

+ For displaying a component in the description, or multiple values under a single key, you can + use the components declaratively. +

+ +

+ Note: You need to wrap the child component correctly or you'll get a warning. There are CSS + rules that'll visually yell at you to fix it :) +

+
- +
+ +
+ +
+
+ +
+ +
+
+ +
+
+ + + +
diff --git a/src/routes/[network]/(explorer)/block/[number]/+page.svelte b/src/routes/[network]/(explorer)/block/[number]/+page.svelte index 1443c0e8..1091aeb7 100644 --- a/src/routes/[network]/(explorer)/block/[number]/+page.svelte +++ b/src/routes/[network]/(explorer)/block/[number]/+page.svelte @@ -4,7 +4,7 @@ import AccountText from '$lib/components/elements/account.svelte'; import Button from '$lib/components/button/button.svelte'; import { ArrowLeftRight, ArrowRight, ArrowLeft } from 'lucide-svelte'; - import { DL, DLRow } from '$lib/components/descriptionlist/index.js'; + import { DD, DL, DLRow } from '$lib/components/descriptionlist/index.js'; import { goto } from '$lib/utils'; let { data } = $props(); @@ -78,22 +78,34 @@
- {data.details.blockNumber} +
+ {data.details.blockNumber} +
- +
+ +
- {data.details.totalCpu} μs +
+ {data.details.totalCpu} μs +
- {data.details.totalNet * 8} Bytes +
+ {data.details.totalNet * 8} Bytes +
- {data.details.totalActions} +
+ {data.details.totalActions} +
- {data.details.blockId} +
+ {data.details.blockId} +