Skip to content

Commit 1ea8bf9

Browse files
feat(jetv-ui): add disabled state for menu options and fix rollup error
1 parent 90fb97e commit 1ea8bf9

File tree

5 files changed

+61
-16
lines changed

5 files changed

+61
-16
lines changed

jetv-ui/gallery/pages/MenuGallery.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts" setup>
22
import { ref } from 'vue'
33
4+
import type { JeMenuOptionProps } from '../../src'
45
import { JeButton, JeMenu } from '../../src'
56
import GalleryCard from '../components/GalleryCard.vue'
67
import ShowcaseFrame from '../components/ShowcaseFrame.vue'
@@ -9,11 +10,11 @@ const showDefaultMenu = ref(false)
910
const showGroupMenu = ref(false)
1011
const showChildMenu = ref(false)
1112
12-
const defaultOptions = [
13+
const defaultOptions: JeMenuOptionProps = [
1314
{ value: 'new', label: 'New File', shortcutKey: ['Ctrl', 'N'] },
1415
{ value: 'open', label: 'Open File', shortcutKey: ['Ctrl', 'O'] },
1516
{ isLine: true, value: 'line1' },
16-
{ value: 'save', label: 'Save', shortcutKey: ['Ctrl', 'S'] },
17+
{ value: 'save', label: 'Save', shortcutKey: ['Ctrl', 'S'], disabled: true },
1718
{ value: 'exit', label: 'Exit' },
1819
]
1920

jetv-ui/src/components/Menu/JeMenu.vue

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<script lang="ts" setup>
22
import { onClickOutside } from '@vueuse/core'
33
4-
import { capitalize, toUpperCase } from '../../utils/common'
4+
import { capitalize, toUpperCase } from '~/utils/common'
5+
56
import { JeLine } from '../Frame'
67
import { JeGroup } from '../Group'
78
import { JePopup } from '../Popup'
@@ -65,6 +66,10 @@ function setHoveredOption(index: string | number | null) {
6566
* @param option - 被点击的菜单项
6667
*/
6768
function handleOptionClick(option: JeMenuOptionProps) {
69+
// 禁用状态不响应点击
70+
if (option.disabled)
71+
return
72+
6873
if (option.onClick) {
6974
option.onClick() // 调用选项的 onClick 回调函数
7075
}
@@ -137,11 +142,17 @@ function checkMenuPosition() {
137142
<li
138143
v-else
139144
class="je-menu__option-item"
140-
:class="{ hovered: option.childMenu && hoveredOptionIndex === index }"
141-
:tabindex="0"
145+
:class="{
146+
hovered: option.childMenu && hoveredOptionIndex === index && !option.disabled,
147+
disabled: option.disabled,
148+
}"
149+
:tabindex="option.disabled ? -1 : 0"
150+
role="menuitem"
151+
:aria-disabled="option.disabled || undefined"
142152
@click="handleOptionClick(option)"
143153
@keydown.enter="handleOptionClick(option)"
144-
@mouseenter="setHoveredOption(index)"
154+
@mouseenter="!option.disabled && setHoveredOption(index)"
155+
@mouseleave="setHoveredOption(null)"
145156
>
146157
<div class="je-menu__option-item-left">
147158
<!-- Option Icon -->
@@ -198,7 +209,7 @@ function checkMenuPosition() {
198209

199210
<!-- 子菜单递归渲染 -->
200211
<div
201-
v-if="option.childMenu && hoveredOptionIndex === index"
212+
v-if="option.childMenu && !option.disabled && hoveredOptionIndex === index"
202213
class="je-menu__child-menu-wrapper"
203214
:style="{ left: childMenuPosition === 'right' ? '100%' : 'auto', right: childMenuPosition === 'left' ? '100%' : 'auto' }"
204215
>
@@ -234,11 +245,17 @@ function checkMenuPosition() {
234245
<li
235246
v-else
236247
class="je-menu__option-item"
237-
:class="{ hovered: groupOption.childMenu && hoveredOptionIndex === `${index}-${groupIndex}` }"
238-
:tabindex="0"
248+
:class="{
249+
hovered: groupOption.childMenu && hoveredOptionIndex === `${index}-${groupIndex}` && !groupOption.disabled,
250+
disabled: groupOption.disabled,
251+
}"
252+
:tabindex="groupOption.disabled ? -1 : 0"
253+
role="menuitem"
254+
:aria-disabled="groupOption.disabled || undefined"
239255
@click="handleOptionClick(groupOption)"
240256
@keydown.enter="handleOptionClick(groupOption)"
241-
@mouseenter="setHoveredOption(`${index}-${groupIndex}`)"
257+
@mouseenter="!groupOption.disabled && setHoveredOption(`${index}-${groupIndex}`)"
258+
@mouseleave="setHoveredOption(null)"
242259
>
243260
<div class="je-menu__option-item-left">
244261
<!-- Option Icon -->
@@ -295,7 +312,7 @@ function checkMenuPosition() {
295312

296313
<!-- 子菜单递归渲染 -->
297314
<div
298-
v-if="groupOption.childMenu && hoveredOptionIndex === `${index}-${groupIndex}`"
315+
v-if="groupOption.childMenu && !groupOption.disabled && hoveredOptionIndex === `${index}-${groupIndex}`"
299316
class="je-menu__child-menu-wrapper"
300317
:style="{ left: childMenuPosition === 'right' ? '100%' : 'auto', right: childMenuPosition === 'left' ? '100%' : 'auto' }"
301318
>
@@ -345,6 +362,24 @@ function checkMenuPosition() {
345362
&:hover {
346363
@apply light:bg-$blue-11 dark:bg-$blue-2;
347364
}
365+
366+
&.disabled {
367+
@apply opacity-60 cursor-not-allowed;
368+
/* 禁用时禁用悬停高亮 */
369+
&:hover {
370+
@apply bg-transparent light:bg-transparent dark:bg-transparent;
371+
}
372+
373+
.je-menu__option-label:not(.custom-color),
374+
.je-menu__option-description,
375+
.je-menu__option-shortcut {
376+
@apply light:color-$gray-6 dark:color-$gray-8;
377+
}
378+
379+
.je-menu__icon-drop-down {
380+
@apply opacity-60;
381+
}
382+
}
348383
}
349384
350385
.je-menu__option-item-left,
@@ -385,11 +420,11 @@ function checkMenuPosition() {
385420
}
386421
387422
.je-menu__option-line {
388-
JeLine {
423+
:deep(.je-line) {
389424
@apply my-1px;
390425
}
391426
392-
&.je-menu__option-group JeLine {
427+
&.je-menu__option-group :deep(.je-line) {
393428
@apply ml-6px;
394429
}
395430
}

jetv-ui/src/components/Menu/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ export interface JeMenuOptionProps {
6666
*/
6767
ellipsis?: boolean
6868

69+
/**
70+
* 是否禁用该选项。
71+
*
72+
* 如果设置为 `true`,该选项将不可点击,并且通常会以灰色显示以表示其禁用状态。
73+
*/
74+
disabled?: boolean
75+
6976
/**
7077
* 是否为分割线,标识该选项是否作为分隔线使用。
7178
*

jetv-ui/src/components/Shortcut/JeShortcut.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts" setup>
2-
import { capitalize } from '../../utils/common'
2+
import { capitalize } from '~/utils/common'
3+
34
import type { JeShortcutProps } from './types.ts'
45
56
withDefaults(defineProps<JeShortcutProps>(), {

jetv-ui/tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525
"skipLibCheck": true
2626
},
2727
"include": [
28-
"src/**/*",
28+
"shims-vue.d.ts",
2929
"src/**/*.vue",
30-
"src/**/*.ts"
30+
"src/**/*.ts",
31+
"src/**/*.d.ts"
3132
],
3233
"exclude": [
3334
"dist",

0 commit comments

Comments
 (0)