Skip to content

Commit

Permalink
add ColumnFilters component
Browse files Browse the repository at this point in the history
  • Loading branch information
LrxGaelle committed Mar 18, 2024
1 parent 38c51b6 commit 172320f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
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>
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;
}
}

0 comments on commit 172320f

Please sign in to comment.