refactor: tree styling

This commit is contained in:
Methapon Metanipat 2024-09-30 16:54:50 +07:00
parent e4b9e186a8
commit 5754db419e

View file

@ -71,19 +71,11 @@ function toggleExpand(node: Node, ancestor?: []) {
<div <div
class="tree-container" class="tree-container"
:class="{ :class="{
'q-pl-lg': level && level > 0, 'q-pl-xl': level && level > 0,
'last-children': level && level === maxLevel, 'last-children': level && level === maxLevel,
}" }"
> >
<div <div v-for="(node, i) in nodes" class="tree-item" :key="i">
v-for="(node, i) in nodes"
class="tree-item"
:class="{
'q-pt-sm': level !== 0 && level !== maxLevel && i !== 0,
'q-pt-xs': level === maxLevel && i === 0,
}"
:key="i"
>
<slot <slot
v-if="$slots['item']" v-if="$slots['item']"
name="item" name="item"
@ -98,29 +90,31 @@ function toggleExpand(node: Node, ancestor?: []) {
() => (selectable ? $emit('select', node) : toggleExpand(node)) () => (selectable ? $emit('select', node) : toggleExpand(node))
" "
> >
<div <div style="width: var(--size-6); margin-right: var(--size-1)">
v-if="level !== maxLevel" <div
class="q-mr-md" v-if="level !== maxLevel"
:style="`color: ${ class="q-mr-md"
!node.displayDropIcon && :style="`color: ${
(!node.children || node.children.length === 0)
? 'transparent'
: $q.dark.isActive
? 'var(--gray-7)'
: 'var(--gray-4)'
}`"
>
<q-icon
name="mdi-chevron-down-circle"
size="sm"
:style="`transform: rotate(${node.opened ? '180deg' : '0'}); transition: transform 0.3s ease;`"
@click.stop="
!node.displayDropIcon && !node.displayDropIcon &&
(!node.children || node.children.length === 0) (!node.children || node.children.length === 0)
? $emit('select', node) ? 'transparent'
: toggleExpand(node) : $q.dark.isActive
" ? 'var(--gray-7)'
/> : 'var(--gray-4)'
}`"
>
<q-icon
name="mdi-chevron-down-circle"
size="sm"
:style="`transform: rotate(${node.opened ? '180deg' : '0'}); transition: transform 0.3s ease;`"
@click.stop="
!node.displayDropIcon &&
(!node.children || node.children.length === 0)
? $emit('select', node)
: toggleExpand(node)
"
/>
</div>
</div> </div>
<label <label
@ -131,6 +125,7 @@ function toggleExpand(node: Node, ancestor?: []) {
<input <input
type="checkbox" type="checkbox"
v-model="node.checked" v-model="node.checked"
:style="`accent-color: var(--blue-7)`"
@click="toggleCheck(node)" @click="toggleCheck(node)"
/> />
</label> </label>
@ -161,10 +156,12 @@ function toggleExpand(node: Node, ancestor?: []) {
</div> </div>
</div> </div>
</template> </template>
<q-separator v-if="!level" class="q-mt-sm"></q-separator>
<transition name="slide"> <transition name="slide">
<div v-if="node.opened && node.children && node.children.length > 0"> <div
v-if="node.opened && node.children && node.children.length > 0"
class="tree-children"
>
<TreeView <TreeView
:iconSize :iconSize
:hideCheckBox :hideCheckBox
@ -220,16 +217,16 @@ function toggleExpand(node: Node, ancestor?: []) {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
user-select: none; user-select: none;
gap: 8px; gap: var(--size-2);
& .tree-item { & .tree-item {
& .item__content { & .item__content {
border: solid 1px transparent; border: solid 1px transparent;
border-radius: var(--radius-2);
padding: 0.1rem 0.5rem; padding: 0.1rem 0.5rem;
&:hover { &:hover {
background: hsla(0 0% 0% / 0.1); background: hsla(0 0% 0% / 0.1);
border-radius: var(--radius-2);
} }
} }
@ -254,6 +251,10 @@ function toggleExpand(node: Node, ancestor?: []) {
color: hsla(var(--text-mute-2)); color: hsla(var(--text-mute-2));
} }
& .tree-children {
padding-top: var(--size-2);
}
& .active { & .active {
border-radius: var(--radius-2); border-radius: var(--radius-2);
border: solid 1px hsl(var(--info-bg)); border: solid 1px hsl(var(--info-bg));
@ -262,10 +263,6 @@ function toggleExpand(node: Node, ancestor?: []) {
} }
} }
.last-children {
margin-left: 50px;
}
.slide-enter-active { .slide-enter-active {
transition: all 0.1s ease-out; transition: all 0.1s ease-out;
} }