From b95b376451c492bf48bf783f5306c4f3fed22fdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ramirez=20Vargas=2C=20Jos=C3=A9=20Pablo?= Date: Fri, 16 Aug 2024 20:35:32 -0600 Subject: [PATCH] feat(demo): Add per-column features demonstration Closes Enhance the demo page to allow demonstration of per-column features #12 --- src/demolib/AllColumnsDropdown.svelte | 34 +++++ src/demolib/ColumnList.svelte | 80 +++++++++++ src/demolib/FavButtonMenuItem.svelte | 29 ++++ src/demolib/FavMenuItem.svelte | 29 ++++ src/demolib/GlassyDropdownMenu.svelte | 26 ++++ src/demolib/HeaderCell.svelte | 182 ++++++++++++++++++++++++++ src/index.html | 2 +- src/routes/+layout.svelte | 6 +- src/routes/+page.svelte | 65 +++++---- src/routes/sales/+page.svelte | 20 ++- src/routes/sales/ByCityView.svelte | 20 ++- src/routes/sales/DetailedView.svelte | 39 +++++- src/routes/sales/HeaderCell.svelte | 58 -------- 13 files changed, 494 insertions(+), 96 deletions(-) create mode 100644 src/demolib/AllColumnsDropdown.svelte create mode 100644 src/demolib/ColumnList.svelte create mode 100644 src/demolib/FavButtonMenuItem.svelte create mode 100644 src/demolib/FavMenuItem.svelte create mode 100644 src/demolib/GlassyDropdownMenu.svelte create mode 100644 src/demolib/HeaderCell.svelte delete mode 100644 src/routes/sales/HeaderCell.svelte diff --git a/src/demolib/AllColumnsDropdown.svelte b/src/demolib/AllColumnsDropdown.svelte new file mode 100644 index 0000000..a6225f0 --- /dev/null +++ b/src/demolib/AllColumnsDropdown.svelte @@ -0,0 +1,34 @@ + + diff --git a/src/demolib/ColumnList.svelte b/src/demolib/ColumnList.svelte new file mode 100644 index 0000000..c49f58a --- /dev/null +++ b/src/demolib/ColumnList.svelte @@ -0,0 +1,80 @@ + + + + +
+
Available Columns
+ + +
+
+ + + {#each { length: numRows } as _, rowIndex} + + {#each { length: numColumns } as _, colIndex} + {@const remainder = columns.length % numColumns} + {@const remainderConsumed = colIndex >= remainder} + {@const col = + remainderConsumed && remainder > 0 && rowIndex + 1 === numRows + ? undefined + : columns[ + (remainderConsumed ? remainder : colIndex) * numRows + + (remainderConsumed ? colIndex - remainder : 0) * + (numRows - (remainder > 0 ? 1 : 0)) + + rowIndex + ]} + + {/each} + + {/each} + +
+ {#if col} + + + {/if} +
+
+ + diff --git a/src/demolib/FavButtonMenuItem.svelte b/src/demolib/FavButtonMenuItem.svelte new file mode 100644 index 0000000..68e4048 --- /dev/null +++ b/src/demolib/FavButtonMenuItem.svelte @@ -0,0 +1,29 @@ + + + + + diff --git a/src/demolib/FavMenuItem.svelte b/src/demolib/FavMenuItem.svelte new file mode 100644 index 0000000..f72eef3 --- /dev/null +++ b/src/demolib/FavMenuItem.svelte @@ -0,0 +1,29 @@ + + +
+ {@render children()} + + + + +
diff --git a/src/demolib/GlassyDropdownMenu.svelte b/src/demolib/GlassyDropdownMenu.svelte new file mode 100644 index 0000000..305d31e --- /dev/null +++ b/src/demolib/GlassyDropdownMenu.svelte @@ -0,0 +1,26 @@ + + + + + diff --git a/src/demolib/HeaderCell.svelte b/src/demolib/HeaderCell.svelte new file mode 100644 index 0000000..c7d7194 --- /dev/null +++ b/src/demolib/HeaderCell.svelte @@ -0,0 +1,182 @@ + + + +
+ +
+ {#if col.pinnedFunctions.align} + + {/if} + {#if col.pinnedFunctions.textWrap} + + + {/if} + {#if col.pinnedFunctions.hide} + + {/if} + {#if col.pinnedFunctions.pin} + + {/if} +
+
+ + diff --git a/src/index.html b/src/index.html index 42068d8..d12b3c6 100644 --- a/src/index.html +++ b/src/index.html @@ -20,6 +20,6 @@
%sveltekit.body%
- + diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index f638b0d..ffcaa1c 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,13 +1,17 @@
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ddd7e34..df7fb8c 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,11 +2,13 @@ import { goto } from "$app/navigation"; import { base } from "$app/paths"; import { page } from "$app/stores"; - import WjDataView, { type WjDvColumn, type WjDvRow } from "$lib/WjDataView/WjDataView.svelte"; + import WjDataView, { type WjDvRow } from "$lib/WjDataView/WjDataView.svelte"; import WjDataViewTheme from "$lib/WjDataViewTheme/WjDataViewTheme.svelte"; import type { Person } from "../data-models.js"; + import AllColumnsDropdown from "../demolib/AllColumnsDropdown.svelte"; import { demoOptions } from "../demolib/demoOptions.svelte.js"; import EditInGitHub from "../demolib/EditInGitHub.svelte"; + import HeaderCell, { type HeaderColumn } from "../demolib/HeaderCell.svelte"; import Numeric from "../demolib/Numeric.svelte"; import { themeOptions } from "../demolib/themeOptions.svelte.js"; import MoreInfo from "./MoreInfo.svelte"; @@ -24,52 +26,75 @@ gridData = data.data; }); - let columns = $state[]>([ + let columns = $state[]>([ { key: 'id', text: 'ID', width: 5, resizable: false, - pinned: true + pinned: true, + alignment: 'start', + pinnedFunctions: {}, }, { key: 'first_name', text: 'First Name', minWidth: 5, - hidden: false + hidden: false, + alignment: 'start', + pinnedFunctions: {}, }, { key: 'last_name', text: 'Last Name', + alignment: 'start', + pinnedFunctions: {}, + }, + { + key: 'full_name', + text: 'Full Name', + width: 9, + get: (r) => `${r.gender === 'Female' ? 'Mrs.' : 'Mr.' } ${r.last_name}, ${r.first_name}`, + alignment: 'start', + pinnedFunctions: {}, }, { key: 'email', text: 'E-Mail', - pinned: true + pinned: true, + alignment: 'start', + pinnedFunctions: {}, }, { key: 'gender', text: 'Gender', - alignment: 'center' + alignment: 'center', + pinnedFunctions: {}, }, { key: 'birth_date', text: 'Birth Date', noTextWrap: true, + alignment: 'start', + pinnedFunctions: {}, }, { key: 'country_code', text: 'Country Code', + alignment: 'start', + pinnedFunctions: {}, }, { key: 'credit_score', text: 'Credit Score', - alignment: 'end' + alignment: 'end', + pinnedFunctions: {}, }, { key: 'net_worth', text: 'Net Worth', - alignment: 'end' + alignment: 'end', + pinnedFunctions: {}, }, ]); @@ -152,7 +177,7 @@ import { WjDataView } from '@wjfe/dataview'; }} > {#snippet controlHeaderCell()} -
+
checked={!!allSelected} oninput="{ev => selectAllData(ev.currentTarget.checked)}" > +
{/snippet} {#snippet controlDataCell(ctx)}
- + +
{/snippet} {#snippet headerCell(ctx)} -
- {ctx.col.text} - -
+ + {/snippet} {#snippet dataCell(ctx)} -
+
{#if ctx.col.key === 'credit_score' || ctx.col.key === 'net_worth'} {:else} - {ctx.row[ctx.col.key as keyof typeof ctx.row]} + {ctx.getFn(ctx.row)} {/if}
{/snippet} diff --git a/src/routes/sales/+page.svelte b/src/routes/sales/+page.svelte index 87ff306..365d3d2 100644 --- a/src/routes/sales/+page.svelte +++ b/src/routes/sales/+page.svelte @@ -1,9 +1,11 @@ - - - -
- {col.text} - - -