-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
src/BIMDataComponents/BIMDataTable/column-filters/ColumnFilters.vue
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,73 @@ | ||
<template> | ||
<div class="column-filters p-12"> | ||
<slot name="column-filters"> | ||
<div | ||
v-for="element in columnElements" | ||
:key="element.text" | ||
class="column-filters__element flex justify-center" | ||
> | ||
<BIMDataCheckbox | ||
:text="element.text" | ||
:modelValue="element.checked" | ||
@update:modelValue="toggle(element, $event)" | ||
/> | ||
</div> | ||
</slot> | ||
</div> | ||
</template> | ||
<script> | ||
import { computed } from "vue"; | ||
import BIMDataCheckbox from "../../BIMDataCheckbox/BIMDataCheckbox.vue"; | ||
export default { | ||
components: { | ||
BIMDataCheckbox, | ||
}, | ||
props: { | ||
column: { | ||
type: Object, | ||
required: true, | ||
}, | ||
rows: { | ||
type: Array, | ||
required: true, | ||
}, | ||
filters: { | ||
type: Array, | ||
required: true, | ||
}, | ||
}, | ||
setup(props, { emit }) { | ||
const columnFilters = computed( | ||
() => | ||
props.filters.find(filter => filter.columnKey === props.column.id) | ||
?.columnFilters ?? [], | ||
); | ||
const elements = [ | ||
...new Set(props.rows.map(row => row.data[props.column.id])), | ||
]; | ||
const columnElements = computed(() => | ||
elements.map(element => ({ | ||
text: element, | ||
checked: columnFilters.value.includes(element), | ||
})), | ||
); | ||
const toggle = (element, checked) => { | ||
const newColumnFilters = checked | ||
? [...columnFilters.value, element.text] | ||
: columnFilters.value.filter(filter => filter !== element.text); | ||
emit("filter", { | ||
columnKey: props.column.id, | ||
columnFilters: newColumnFilters, | ||
}); | ||
}; | ||
return { | ||
columnElements, | ||
toggle, | ||
}; | ||
}, | ||
}; | ||
</script> | ||
<style scoped lang="scss" src="./_ColumnFilters.scss"></style> |
13 changes: 13 additions & 0 deletions
13
src/BIMDataComponents/BIMDataTable/column-filters/_ColumnFilters.scss
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,13 @@ | ||
.column-filters { | ||
width: 100%; | ||
display: grid; | ||
position: absolute; | ||
left: 0; | ||
background-color: var(--color-white); | ||
box-shadow: var(--box-shadow); | ||
gap: calc(var(--spacing-unit) / 2); | ||
border-radius: calc(var(--spacing-unit) / 2); | ||
.bimdata-checkbox { | ||
font-weight: 400; | ||
} | ||
} |