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

dropdown with tooltip #594

Merged
merged 3 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 13 additions & 21 deletions spx-gui/src/components/editor/common/EditorList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,19 @@
<ul class="items">
<slot></slot>
</ul>
<UIDropdown trigger="click">
<UIDropdownWithTooltip>
<template #dropdown-content>
<slot name="add-options"></slot>
</template>
<template #tooltip-content>
{{ addText }}
</template>
<template #trigger>
<!--
TODO:
1. dropdown & tooltip should not be both visible: when dropdown visible, hide the tooltip
2. the empty `div` should be avoided. It is now required due to `Runtime directive used on component with non-element root node. The directives will not function as intended.`
-->
<div>
<UITooltip>
<template #trigger>
<button class="add">
<UIIcon class="icon" type="plus" />
</button>
</template>
{{ addText }}
</UITooltip>
</div>
<button class="add">
<UIIcon class="icon" type="plus" />
</button>
</template>
<slot name="add-options"></slot>
</UIDropdown>
</UIDropdownWithTooltip>
</div>
<slot name="detail"></slot>
</div>
Expand All @@ -33,11 +26,10 @@
import { computed } from 'vue'
import {
UIIcon,
UIDropdown,
UITooltip,
type Color,
useUIVariables,
getCssVars
getCssVars,
UIDropdownWithTooltip
} from '@/components/ui'

const props = defineProps<{
Expand Down
2 changes: 1 addition & 1 deletion spx-gui/src/components/editor/stage/BackdropDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</template>

<script setup lang="ts">
import { useModal } from '@/components/ui'
import { useModal, UILoading } from '@/components/ui'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: 这个问题有办法通过配置我们的 lint 或者类型检查工具查出来不

import { useFileUrl } from '@/utils/file'
import type { Backdrop } from '@/models/backdrop'
import { useEditorCtx } from '../EditorContextProvider.vue'
Expand Down
5 changes: 5 additions & 0 deletions spx-gui/src/components/ui/UIDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:show-arrow="false"
:style="{ marginTop: offset.y + 'px', marginLeft: offset.x + 'px' }"
raw
@update:show="(v) => emit('update:visible', v)"
>
<template #trigger>
<slot name="trigger"></slot>
Expand Down Expand Up @@ -58,6 +59,10 @@ withDefaults(
}
)

const emit = defineEmits<{
'update:visible': [boolean]
}>()

const attachTo = usePopupContainer()

const nPopoverRef = ref<InstanceType<typeof NPopover>>()
Expand Down
43 changes: 43 additions & 0 deletions spx-gui/src/components/ui/UIDropdownWithTooltip.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<template>
<UIDropdown
trigger="click"
:visible="dropdownVisible"
@update:visible="handleDropdownVisibleChange"
>
<template #trigger>
<div>
<!--
TODO:
The empty `div` should be avoided. It is now required due to a warning:
`Runtime directive used on component with non-element root node. The directives will not function as intended.`
-->
<UITooltip :visible="tooltipVisible" @update:visible="handleTooltipVisibleChange">
ComfyFluffy marked this conversation as resolved.
Show resolved Hide resolved
<template #trigger>
<slot name="trigger"></slot>
</template>
<slot name="tooltip-content"></slot>
</UITooltip>
</div>
</template>
<slot name="dropdown-content"></slot>
</UIDropdown>
</template>

<script setup lang="ts">
import { UIDropdown, UITooltip } from '@/components/ui'
import { ref } from 'vue'

const dropdownVisible = ref(false)
const tooltipVisible = ref(false)

const handleDropdownVisibleChange = (v: boolean) => {
dropdownVisible.value = v
if (v) {
tooltipVisible.value = false
}
}

const handleTooltipVisibleChange = (v: boolean) => {
tooltipVisible.value = v && !dropdownVisible.value
}
</script>
17 changes: 15 additions & 2 deletions spx-gui/src/components/ui/UITooltip.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<template>
<NTooltip class="ui-tooltip" trigger="hover" :to="attachTo" :placement="placement">
<NTooltip
class="ui-tooltip"
trigger="hover"
:to="attachTo"
:placement="placement"
:show="visible"
@update:show="(v) => emit('update:visible', v)"
>
<template #trigger>
<slot name="trigger"></slot>
</template>
Expand All @@ -16,12 +23,18 @@ export type Placement = 'top' | 'top-start' | 'top-end' | 'bottom' | 'bottom-sta
withDefaults(
defineProps<{
placement?: Placement
visible?: boolean
}>(),
{
placement: 'top'
placement: 'top',
visible: undefined
}
)

const emit = defineEmits<{
'update:visible': [boolean]
}>()

const attachTo = usePopupContainer()
</script>

Expand Down
1 change: 1 addition & 0 deletions spx-gui/src/components/ui/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ export * from './tab'
export { default as UICode } from './UICode.vue'
export { default as UIButtonGroup } from './UIButtonGroup.vue'
export { default as UIButtonGroupItem } from './UIButtonGroupItem.vue'
export { default as UIDropdownWithTooltip } from './UIDropdownWithTooltip.vue'
Loading