Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: Drop clickOutsideOptions mixin and refactor using components #6429

Open
wants to merge 2 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ All notable changes to this project will be documented in this file.
- `NcAppNavigationItem`
- `NcBreadcrumb`
- `NcListItem`
* The `isFullscreen` and `isMobile` mixins were removed. Use the according composables instead.
* The `clickOutsideOptions`, `isFullscreen`, and `isMobile` mixins were removed. Use the according composables instead.
* The `box-sizing: border-box` is now default for following components and its content. This is done to match behaviour of `NcContent` (as they can be mounted directly to `body`):
- `NcModal`
- `NcPopover`
Expand Down
3 changes: 0 additions & 3 deletions src/assets/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,5 @@ $navigation-width: 300px;
$breakpoint-mobile: 1024px;
$breakpoint-small-mobile: math.div($breakpoint-mobile, 2);

// navigation spacing
$app-navigation-settings-margin: 3px;

// navigation items
$app-navigation-padding: calc(var(--default-grid-baseline, 4px) * 2);
200 changes: 83 additions & 117 deletions src/components/NcAppNavigationSettings/NcAppNavigationSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,145 +3,111 @@
- SPDX-License-Identifier: AGPL-3.0-or-later
-->

<script setup lang="ts">
import type { Slot } from 'vue'
import { onClickOutside } from '@vueuse/core'
import { computed, ref, useTemplateRef } from 'vue'
import { t } from '../../l10n.js'
import GenRandomId from '../../utils/GenRandomId.js'

import IconCog from 'vue-material-design-icons/Cog.vue'
import NcButton from '../NcButton/NcButton.vue'

const {
excludeClickOutsideSelectors = [],
name = t('Settings'),
} = defineProps<{
/**
* A query-selector or an array of query-selectors
* to be ignored when clicking outside an element
*/
excludeClickOutsideSelectors?: string | string[]

/**
* Text of the button
* @default 'Settings'
*/
name?: string
}>()

defineSlots<{
/**
* Content of the accordion button (the settings).
*/
default: Slot
}>()

const contentId = GenRandomId()
/**
* Are the settings open
*/
const open = ref(false)

// Close the menu when the user clicks outside of the container
const container = useTemplateRef('wrapperElement')
const ignore = computed(() => Array.isArray(excludeClickOutsideSelectors)
? excludeClickOutsideSelectors
: excludeClickOutsideSelectors.split(' '),
)
onClickOutside(container, () => { open.value = false }, { ignore })
</script>

<template>
<div id="app-settings"
v-click-outside="clickOutsideConfig"
:class="{ open }">
<div id="app-settings__header">
<button class="settings-button"
type="button"
<div ref="wrapperElement" :class="$style.container">
<div :class="$style.header">
<NcButton :aria-controls="contentId"
:aria-expanded="open ? 'true' : 'false'"
aria-controls="app-settings__content"
@click="toggleMenu">
<Cog class="settings-button__icon" :size="20" />
<span class="settings-button__label">{{ name }}</span>
</button>
@click="open = !open">
<template #icon>
<IconCog :size="20" />
</template>
{{ name }}
</NcButton>
</div>
<Transition name="slide-up">
<div v-show="open" id="app-settings__content">
<Transition :enter-active-class="$style.animationActive"
:leave-active-class="$style.animationActive"
:enter-from-class="$style.animationStop"
:leave-to-class="$style.animationStop">
<div v-show="open"
:id="contentId"
:class="$style.content">
<slot />
</div>
</Transition>
</div>
</template>

<script>
import { t } from '../../l10n.js'
import { clickOutsideOptions } from '../../mixins/index.js'

import Cog from 'vue-material-design-icons/Cog.vue'

import { vOnClickOutside as ClickOutside } from '@vueuse/components'

export default {
directives: {
ClickOutside,
},
components: {
Cog,
},
mixins: [
clickOutsideOptions,
],
props: {
name: {
type: String,
required: false,
default: t('Settings'),
},
},
data() {
return {
open: false,
}
},
computed: {
clickOutsideConfig() {
return [
this.closeMenu,
this.clickOutsideOptions,
]
},
},
methods: {
toggleMenu() {
this.open = !this.open
},
closeMenu() {
this.open = false
},
},
}
</script>
<style lang="scss" scoped>
#app-settings {
<style module>
.container {
margin-top: auto;
padding: $app-navigation-settings-margin;

&__header {
margin: 0 $app-navigation-settings-margin $app-navigation-settings-margin $app-navigation-settings-margin;

.settings-button {
display: flex;
flex: 1 1 0;
height: var(--default-clickable-area);
width: 100%;
padding: 0;
margin: 0;
background-color: transparent;
box-shadow: none;
border: 0;
border-radius: var(--body-container-radius);
text-align: left;
font-weight: normal;
font-size: 100%;
color: var(--color-main-text);
padding-right: 14px;
line-height: var(--default-clickable-area);

&:hover,
&:focus {
background-color: var(--color-background-hover);
}
padding: var(--default-grid-baseline);
}

&__icon {
width: var(--default-clickable-area);
height: var(--default-clickable-area);
min-width: var(--default-clickable-area);
}
&__label {
overflow: hidden;
max-width: 100%;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
.header {
margin-block: 0 var(--default-grid-baseline);
margin-inline: var(--default-grid-baseline);
}

&__content {
display: block;
padding: 10px;
.content {
display: block;
padding: 10px;

/* prevent scrolled contents from stopping too early */
margin-bottom: -$app-navigation-settings-margin;
/* prevent scrolled contents from stopping too early */
margin-bottom: calc(-1 * var(--default-grid-baseline));

/* restrict height of settings and make scrollable */
max-height: 300px;
overflow-y: auto;
}
/* restrict height of settings and make scrollable */
max-height: 300px;
overflow-y: auto;
}

.slide-up-leave-active,
.slide-up-enter-active {
.animationActive {
transition-duration: var(--animation-slow);
transition-property: max-height, padding;
overflow-y: hidden !important;
}

.slide-up-enter-from,
.slide-up-leave-to {
.animationStop {
max-height: 0 !important;
padding: 0 10px !important;
}

</style>
Loading
Loading