-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify Table ordering by passing instance of
tableOrderStore
inst…
…ead of `orderBy`, `orderDirection`, and handling `on:headerClick`. Also fixes display of clickable headers when order is not used, and improves sort arrow size.
- Loading branch information
Showing
5 changed files
with
52 additions
and
23 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,29 @@ | ||
--- | ||
"svelte-ux": minor | ||
--- | ||
|
||
Breaking change: Simplify Table ordering by passing instance of `tableOrderStore` instead of `orderBy`, `orderDirection`, and handling `on:headerClick`. Also fixes display of clickable headers when order is not used, and improves sort arrow size. | ||
|
||
## Before | ||
|
||
```svelte | ||
<script> | ||
const order = tableOrderStore(); | ||
</script> | ||
<Table | ||
orderBy={$order.by} | ||
orderDirection={$order.direction} | ||
on:headerClick={order.onHeaderClick} | ||
/> | ||
``` | ||
|
||
## After | ||
|
||
```svelte | ||
<script> | ||
const order = tableOrderStore(); | ||
</script> | ||
<Table {order} /> | ||
``` |
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
20 changes: 11 additions & 9 deletions
20
packages/svelte-ux/src/lib/components/TableOrderIcon.svelte
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 |
---|---|---|
@@ -1,19 +1,21 @@ | ||
<script lang="ts"> | ||
import { mdiArrowUp } from '@mdi/js'; | ||
import type { TableOrderState } from '../stores/tableOrderStore.js'; | ||
import type tableOrderStore from '../stores/tableOrderStore.js'; | ||
import type { ColumnDef } from '../types/table.js'; | ||
import Icon from '../components/Icon.svelte'; | ||
import { cls } from '$lib/utils/styles.js'; | ||
export let order: TableOrderState; | ||
export let order: ReturnType<typeof tableOrderStore>; | ||
export let column: ColumnDef; | ||
</script> | ||
|
||
{#if order.by && (order.by === column.value || order.by === column.name || order.by === column.orderBy)} | ||
<div | ||
class="TableOrderIcon inline-block transition duration-100 transform" | ||
class:rotate-180={order.direction === 'desc'} | ||
> | ||
<Icon data={mdiArrowUp} /> | ||
</div> | ||
{#if $order.by && ($order.by === column.value || $order.by === column.name || $order.by === column.orderBy)} | ||
<span class="TableOrderIcon"> | ||
<Icon | ||
data={mdiArrowUp} | ||
size="1rem" | ||
class={cls('transition duration-100 transform', $order.direction === 'desc' && 'rotate-180')} | ||
/> | ||
</span> | ||
{/if} |
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