-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
166 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<template> | ||
<div class="s-dropdown"> | ||
<Tooltip | ||
:trigger="trigger" | ||
:placement="placement" | ||
:popper-options="popperOptions" | ||
:open-delay="openDelay" | ||
:close-delay="closeDelay" | ||
@visible-change="visibleChange" | ||
ref="tooltipRef" | ||
> | ||
<slot></slot> | ||
<template #content> | ||
<ul class="s-dropdown__menu"> | ||
<template v-for="item in menuOptions" :key="item.key"> | ||
<li v-if="item.divided" role="separator" class="divided-placeholder"></li> | ||
<li | ||
class="s-dropdown__item" | ||
:class="{ 'is-disabled': item.disabled, 'is-divided': item.divided }" | ||
:id="`dropdown-item-${item.key}`" | ||
@click="($event) => itemClick(item)" | ||
> | ||
{{ item.label }} | ||
</li> | ||
</template> | ||
</ul> | ||
</template> | ||
</Tooltip> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import type { DropdownProps, DropdownInstance, DropdownEmits, MenuOption } from './types' | ||
import Tooltip from '../Tooltip/Tooltip.vue' | ||
import type { TooltipInstance } from '../Tooltip/types' | ||
import { ref, type Ref } from 'vue' | ||
const porps = defineProps<DropdownProps>() | ||
const emits = defineEmits<DropdownEmits>() | ||
const tooltipRef = ref() as Ref<TooltipInstance|undefined> | ||
const visibleChange = (e: boolean) => { | ||
emits('visible-change', e) | ||
} | ||
const itemClick = (e: MenuOption) => { | ||
if (e.disabled) return | ||
emits('select', e) | ||
} | ||
defineExpose<DropdownInstance>({ | ||
show: tooltipRef.value?.show!, | ||
hide: tooltipRef.value?.hide! | ||
}) | ||
</script> | ||
|
||
<style scoped></style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.vk-dropdown .vk-dropdown__menu { | ||
--vk-dropdown-menuItem-hover-fill: var(--vk-color-primary-light-9); | ||
--vk-dropdown-menuItem-hover-color: var(--vk-color-primary); | ||
--vk-dropdown-menuItem-disabled-color: var(--vk-border-color-lighter); | ||
--vk-dropdown-menuItem-divided-color: var(--vk-border-color-lighter); | ||
} | ||
.vk-dropdown { | ||
display: inline-block; | ||
.vk-tooltip { | ||
--vk-popover-padding: 5px 0; | ||
} | ||
} | ||
.vk-dropdown__menu { | ||
list-style-type: none; | ||
margin: 0; | ||
padding: 0; | ||
.vk-dropdown__item { | ||
display: flex; | ||
align-items: center; | ||
white-space: nowrap; | ||
list-style: none; | ||
line-height: 22px; | ||
padding: 5px 16px; | ||
margin: 0; | ||
font-size: var(--vk-font-size-base); | ||
color: var(--vk-text-color-regular); | ||
cursor: pointer; | ||
outline: none; | ||
&:hover { | ||
background-color: var(--vk-dropdown-menuItem-hover-fill); | ||
color: var(--vk-dropdown-menuItem-hover-color); | ||
} | ||
&.is-disabled { | ||
color: var(--vk-dropdown-menuItem-disabled-color); | ||
cursor: not-allowed; | ||
background-image: none; | ||
} | ||
} | ||
.divided-placeholder { | ||
margin: 6px 0; | ||
border-top: 1px solid var(--vk-dropdown-menuItem-divided-color); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type { VNode } from 'vue' | ||
import type { TooltipProps } from '../Tooltip/types' | ||
|
||
export interface DropdownProps extends TooltipProps { | ||
menuOptions: MenuOption[]; | ||
hideAfterClick?: boolean; | ||
} | ||
export interface MenuOption { | ||
label: string | VNode; | ||
key: string | number; | ||
disabled?: boolean; | ||
divided?: boolean; | ||
} | ||
|
||
export interface DropdownEmits { | ||
(e:'visible-change', value: boolean) : void; | ||
(e:'select', value: MenuOption) : void; | ||
} | ||
|
||
export interface DropdownInstance { | ||
show: () => void; | ||
hide: () => void; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters