perfs
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { SortDirection } from './sort';
|
import { HeaderComponent, SortDirection } from './sort';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
currentSortKey: string | null;
|
currentSortKey: string | null;
|
||||||
@@ -7,6 +7,7 @@ interface Props {
|
|||||||
showColumn?: (k: string) => boolean;
|
showColumn?: (k: string) => boolean;
|
||||||
unsortable?: boolean;
|
unsortable?: boolean;
|
||||||
sortKey: string;
|
sortKey: string;
|
||||||
|
headerComponent?: HeaderComponent;
|
||||||
}
|
}
|
||||||
interface Emit {
|
interface Emit {
|
||||||
(e: 'sort', key: string, direction: SortDirection): void;
|
(e: 'sort', key: string, direction: SortDirection): void;
|
||||||
@@ -14,24 +15,25 @@ interface Emit {
|
|||||||
|
|
||||||
withDefaults(defineProps<Props>(), {
|
withDefaults(defineProps<Props>(), {
|
||||||
showColumn: () => () => true,
|
showColumn: () => () => true,
|
||||||
unsortable: false
|
unsortable: false,
|
||||||
|
headerComponent: 'th',
|
||||||
});
|
});
|
||||||
const emit = defineEmits<Emit>();
|
const emit = defineEmits<Emit>();
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<th v-if="showColumn(sortKey)">
|
<component v-if="showColumn(sortKey)" :is="headerComponent" class="sort-header">
|
||||||
<slot />
|
<slot />
|
||||||
<template v-if="!unsortable">
|
<template v-if="!unsortable">
|
||||||
<span class="asc" :class="{'opacity-20': (currentSortKey != sortKey || sortDirection != 'asc')}" @click="emit('sort', sortKey, 'asc')">▲</span>
|
<span class="asc" :class="{'opacity-20': (currentSortKey != sortKey || sortDirection != 'asc')}" @click="emit('sort', sortKey, 'asc')">▲</span>
|
||||||
<span class="desc" :class="{'opacity-20': (currentSortKey != sortKey || sortDirection != 'desc')}" @click="emit('sort', sortKey, 'desc')">▼</span>
|
<span class="desc" :class="{'opacity-20': (currentSortKey != sortKey || sortDirection != 'desc')}" @click="emit('sort', sortKey, 'desc')">▼</span>
|
||||||
</template>
|
</template>
|
||||||
</th>
|
</component>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped lang="postcss">
|
<style scoped lang="postcss">
|
||||||
th {
|
.sort-header {
|
||||||
@apply relative h-8 pe-3;
|
@apply relative h-8 pe-3;
|
||||||
}
|
}
|
||||||
span.asc, span.desc {
|
span.asc, span.desc {
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import { MaybeRefOrGetter, computed, ref, toValue } from "vue";
|
import { Component, DefineComponent, MaybeRefOrGetter, computed, ref, toValue } from "vue";
|
||||||
|
|
||||||
|
export type HeaderComponent = Component | DefineComponent | string;
|
||||||
export type SortDirection = "asc" | "desc";
|
export type SortDirection = "asc" | "desc";
|
||||||
export type UseSortOptions = {
|
export type UseSortOptions = {
|
||||||
defaultSortKey?: string;
|
defaultSortKey?: string;
|
||||||
defaultSortDirection?: SortDirection;
|
defaultSortDirection?: SortDirection;
|
||||||
ignoredColums?: MaybeRefOrGetter<string[]>;
|
ignoredColums?: MaybeRefOrGetter<string[]>;
|
||||||
|
headerComponent?: HeaderComponent;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSort = <T>(array: MaybeRefOrGetter<T[]>, options?: UseSortOptions) => {
|
export const useSort = <T>(array: MaybeRefOrGetter<T[]>, options?: UseSortOptions) => {
|
||||||
@@ -19,7 +21,8 @@ export const useSort = <T>(array: MaybeRefOrGetter<T[]>, options?: UseSortOption
|
|||||||
onSort: sortBy,
|
onSort: sortBy,
|
||||||
showColumn,
|
showColumn,
|
||||||
currentSortKey: sortKey.value,
|
currentSortKey: sortKey.value,
|
||||||
sortDirection: sortDirection.value
|
sortDirection: sortDirection.value,
|
||||||
|
headerComponent: options?.headerComponent,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const sortedArray = computed(() => toValue(array).sort((a, b) => {
|
const sortedArray = computed(() => toValue(array).sort((a, b) => {
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ watchEffect(async () => {
|
|||||||
<template>
|
<template>
|
||||||
<div @click="() => isOpen = true" v-on-click-outside="() => isOpen = false">
|
<div @click="() => isOpen = true" v-on-click-outside="() => isOpen = false">
|
||||||
<div class="fake-input">
|
<div class="fake-input">
|
||||||
<img v-if="value?.id" :src="`https://images.evetech.net/types/${value.id}/icon`" alt="" />
|
<img v-if="value?.id" :src="`https://images.evetech.net/types/${value.id}/icon?size=32`" alt="" />
|
||||||
<input type="text" v-model="name" @keyup.enter="submit" @keyup.down="moveDown" @keyup.up="moveUp" />
|
<input type="text" v-model="name" @keyup.enter="submit" @keyup.down="moveDown" @keyup.up="moveUp" />
|
||||||
</div>
|
</div>
|
||||||
<div v-if="suggestions.length > 1" class="z-10 absolute w-96">
|
<div v-if="suggestions.length > 1" class="z-10 absolute w-96">
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ withDefaults(defineProps<Props>(), {
|
|||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div v-if="id || name">
|
<div v-if="id || name">
|
||||||
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon`" class="inline-block w-5 h-5 me-1" alt="" />
|
<img v-if="id" :src="`https://images.evetech.net/types/${id}/icon?size=32`" class="inline-block w-5 h-5 me-1" alt="" />
|
||||||
<template v-if="name">
|
<template v-if="name">
|
||||||
{{ name }}
|
{{ name }}
|
||||||
<RouterLink v-if="id" :to="{ name: 'market-types', params: { type: id } }" custom #default="{ navigate }">
|
<RouterLink v-if="id" :to="{ name: 'market-types', params: { type: id } }" custom #default="{ navigate }">
|
||||||
|
|||||||
@@ -21,30 +21,36 @@
|
|||||||
@apply border rounded bg-slate-500 w-full;
|
@apply border rounded bg-slate-500 w-full;
|
||||||
}
|
}
|
||||||
|
|
||||||
table {
|
table, .table {
|
||||||
@apply table-auto border-collapse border-slate-500 w-full;
|
@apply table-auto border-collapse border-slate-500 w-full;
|
||||||
|
}
|
||||||
|
.table-header {
|
||||||
|
@apply table-cell;
|
||||||
|
}
|
||||||
|
.table-cell {
|
||||||
|
@apply pt-px pb-px;
|
||||||
|
}
|
||||||
|
th, .table-header {
|
||||||
|
@apply border bg-slate-600 px-1;
|
||||||
|
}
|
||||||
|
td, .table-cell {
|
||||||
|
@apply border px-1;
|
||||||
|
}
|
||||||
|
tr, .table-row {
|
||||||
|
@apply hover:bg-slate-900;
|
||||||
|
|
||||||
th {
|
&.line-red {
|
||||||
@apply border bg-slate-600 px-1;
|
@apply bg-amber-900 hover:bg-amber-950;
|
||||||
}
|
}
|
||||||
td {
|
&.line-blue {
|
||||||
@apply border px-1;
|
@apply bg-sky-600 hover:bg-sky-800;
|
||||||
}
|
}
|
||||||
tr {
|
&.line-green {
|
||||||
@apply hover:bg-slate-900;
|
@apply bg-emerald-500 hover:bg-emerald-600;
|
||||||
|
|
||||||
&.line-red {
|
|
||||||
@apply bg-amber-900 hover:bg-amber-950;
|
|
||||||
}
|
|
||||||
&.line-blue {
|
|
||||||
@apply bg-sky-600 hover:bg-sky-800;
|
|
||||||
}
|
|
||||||
&.line-green {
|
|
||||||
@apply bg-emerald-500 hover:bg-emerald-600;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
::-webkit-scrollbar {
|
::-webkit-scrollbar {
|
||||||
@apply w-3;
|
@apply w-3;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user