Skip to content

Commit

Permalink
Merge pull request #682 from madeindjs/fix-collapse-button
Browse files Browse the repository at this point in the history
fix(ui): improve design of collapse button
  • Loading branch information
ramedina86 authored Dec 9, 2024
2 parents 1efc789 + 403e6d4 commit 462dcab
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 50 deletions.
30 changes: 23 additions & 7 deletions src/ui/src/components/core/base/BaseCollapseButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,37 @@
</button>
</template>

<script lang="ts">
export type Direction =
| "left-right"
| "top-bottom"
| "bottom-top"
| "right-left";
</script>

<script setup lang="ts">
import { computed, PropType } from "vue";
const props = defineProps({
direction: {
type: String as PropType<"left-right" | "top-bottom">,
required: true,
},
direction: { type: String as PropType<Direction>, required: true },
});
const isCollapsed = defineModel({ type: Boolean, required: true });
const icon = computed(() =>
props.direction === "left-right" ? "chevron_left" : "keyboard_arrow_up",
);
const icon = computed(() => {
switch (props.direction) {
case "left-right":
return "chevron_left";
case "top-bottom":
return "keyboard_arrow_up";
case "right-left":
return "chevron_right";
case "bottom-top":
return "keyboard_arrow_down";
default:
return "keyboard_arrow_up";
}
});
</script>

<style scoped>
Expand Down
31 changes: 9 additions & 22 deletions src/ui/src/components/core/layout/CoreColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
v-if="isCollapsible"
v-model="isCollapsed"
class="collapser"
direction="left-right"
:direction="collapseDirection"
/>
</div>
<div v-if="isCollapsed && fields.title.value" class="collapsedTitle">
Expand Down Expand Up @@ -48,7 +48,6 @@ import {
startCollapsed,
isCollapsible as isCollapsibleField,
} from "@/renderer/sharedStyleFields";
import BaseCollapseButton from "../base/BaseCollapseButton.vue";
const description =
"A layout component that organizes its child components in columns. Must be inside a Column Container component.";
Expand Down Expand Up @@ -100,7 +99,10 @@ export default {
<script setup lang="ts">
import { computed, ComputedRef, inject, Ref, ref, watch } from "vue";
import injectionKeys from "@/injectionKeys";
import BaseContainer from "../base/BaseContainer.vue";
import BaseContainer from "@/components/core/base/BaseContainer.vue";
import BaseCollapseButton from "@/components/core/base/BaseCollapseButton.vue";
import type { Direction } from "@/components/core/base/BaseCollapseButton.vue";
const instancePath = inject(injectionKeys.instancePath);
const instanceData = inject(injectionKeys.instanceData);
const wf = inject(injectionKeys.core);
Expand Down Expand Up @@ -138,6 +140,10 @@ const isCollapsibleToRight = computed(
columnsData.value?.value?.minimumNonCollapsiblePosition,
);
const collapseDirection = computed<Direction>(() =>
isCollapsibleToRight.value ? "right-left" : "left-right",
);
const columnsData: ComputedRef<Ref> = computed(() => {
for (let i = -1; i > -1 * instancePath.length; i--) {
const item = instancePath.at(i);
Expand Down Expand Up @@ -212,25 +218,6 @@ watch(
flex: 0 0 32px;
}
.CoreColumn > .header > .collapser > .collapserArrow {
transition: all 0.5s ease-in-out;
transform: rotate(0deg);
}
.CoreColumn:not(.collapsibleToRight).collapsed
> .header
> .collapser
> .collapserArrow {
transform: rotate(180deg);
}
.CoreColumn.collapsibleToRight:not(.collapsed)
> .header
> .collapser
> .collapserArrow {
transform: rotate(180deg);
}
.CoreColumn.collapsibleToRight > .header {
justify-content: left;
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/src/components/core/layout/CoreSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const isCollapsed = ref<boolean>(
margin: 16px 16px 0 16px;
display: grid;
grid-template-columns: 1fr auto;
align-items: center;
}
.CoreSection__title--collapsed {
margin: 16px;
Expand Down
21 changes: 0 additions & 21 deletions src/ui/src/components/core/layout/CoreSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ onMounted(() => {
margin-bottom: 16px;
}
.collapserContainer > .collapser {
flex: 0 0 32px;
}
.collapserContainer .collapserArrow {
transition: all 0.5s ease-in-out;
transform: rotate(0deg);
}
.CoreSidebar.collapsed .collapserArrow {
transform: rotate(180deg);
}
.collapserContainer > .collapser:hover {
background: var(--separatorColor);
}
@media only screen and (max-width: 768px) {
.CoreSidebar {
min-width: 100%;
Expand All @@ -164,9 +147,5 @@ onMounted(() => {
.CoreSidebar.collapsed > .collapserContainer {
margin-bottom: 0;
}
.collapserContainer > .collapser {
transform: rotate(90deg);
}
}
</style>

0 comments on commit 462dcab

Please sign in to comment.