123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <!-- Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/ -->
- <script setup lang="ts">
- import { computed } from 'vue'
- import { useTouchDevice } from '#shared/composables/useTouchDevice.ts'
- import { EnumTextDirection } from '#shared/graphql/types.ts'
- import { useLocaleStore } from '#shared/stores/locale.ts'
- import CommonButton from '#desktop/components/CommonButton/CommonButton.vue'
- const { isTouchDevice } = useTouchDevice()
- interface Props {
- ownerId: string
- isCollapsed?: boolean
- group?: 'heading' | 'sidebar'
- orientation?: 'horizontal' | 'vertical'
- }
- const props = withDefaults(defineProps<Props>(), {
- orientation: 'horizontal',
- isCollapsed: false,
- })
- defineEmits<{
- 'toggle-collapse': [MouseEvent]
- }>()
- const locale = useLocaleStore()
- const collapseButtonIcon = computed(() => {
- if (props.orientation === 'vertical')
- return props.isCollapsed ? 'arrows-expand' : 'arrows-collapse'
- if (locale.localeData?.dir === EnumTextDirection.Rtl)
- return props.isCollapsed ? 'arrow-bar-left' : 'arrow-bar-right'
- return props.isCollapsed ? 'arrow-bar-right' : 'arrow-bar-left'
- })
- const parentGroupClass = computed(() => {
- // Tailwindcss must be able to scan the class names to generate CSS
- // https://tailwindcss.com/docs/content-configuration#dynamic-class-names
- switch (props.group) {
- case 'heading':
- return 'group-hover/heading:opacity-100'
- case 'sidebar':
- return 'group-hover/sidebar:opacity-100'
- default:
- return ''
- }
- })
- </script>
- <template>
- <div>
- <CommonButton
- :class="[
- { 'opacity-0 transition-opacity': !isTouchDevice && parentGroupClass },
- 'focus:opacity-100',
- parentGroupClass,
- ]"
- class="collapse-button"
- :icon="collapseButtonIcon"
- :aria-expanded="!props.isCollapsed"
- :aria-controls="ownerId"
- :aria-label="
- props.isCollapsed
- ? $t('Expand this element')
- : $t('Collapse this element')
- "
- size="small"
- variant="subtle"
- @click="$emit('toggle-collapse', $event)"
- />
- </div>
- </template>
|