File tree Expand file tree Collapse file tree 4 files changed +45
-33
lines changed
Expand file tree Collapse file tree 4 files changed +45
-33
lines changed Original file line number Diff line number Diff line change 11import type { ExtractPropTypes , PropType } from 'vue'
22
33export type TooltipPlacement
4- = | 'top' | 'top-start' | 'top-end'
5- | 'bottom' | 'bottom-start' | 'bottom-end'
6- | 'left' | 'left-start' | 'left-end'
7- | 'right' | 'right-start' | 'right-end'
4+ = | 'top'
5+ | 'top-start'
6+ | 'top-end'
7+ | 'bottom'
8+ | 'bottom-start'
9+ | 'bottom-end'
10+ | 'left'
11+ | 'left-start'
12+ | 'left-end'
13+ | 'right'
14+ | 'right-start'
15+ | 'right-end'
816
917export type TooltipEffect = 'dark' | 'light'
1018
1119export type TooltipTrigger = 'hover' | 'click' | 'focus' | 'manual'
1220
21+ export interface TooltipEmits {
22+ 'show' : ( ) => void
23+ 'hide' : ( ) => void
24+ 'update:visible' : ( visible : boolean ) => void
25+ }
26+
1327export const tooltipProps = {
1428 // 基础属性
1529 content : {
@@ -83,9 +97,14 @@ export const tooltipProps = {
8397export type TooltipProps = ExtractPropTypes < typeof tooltipProps >
8498
8599export interface TooltipEmits {
100+ /** 显示前触发 */
86101 'before-show' : ( ) => void
102+ /** 显示时触发 */
87103 'show' : ( ) => void
104+ /** 隐藏前触发 */
88105 'before-hide' : ( ) => void
106+ /** 隐藏时触发 */
89107 'hide' : ( ) => void
108+ /** 当 visible 状态改变时触发 */
90109 'update:visible' : ( visible : boolean ) => void
91110}
Original file line number Diff line number Diff line change 6969
7070// 响应式设计
7171@media (max-width : 768px ) {
72- .ccui-tooltip__popper {
73- font-size : 14px ;
74- max-width : calc (100vw - 20px );
72+ .ccui-tooltip {
73+ & __popper {
74+ font-size : 14px ;
75+ max-width : calc (100vw - 20px );
76+ }
7577 }
7678}
Original file line number Diff line number Diff line change @@ -85,20 +85,7 @@ export default defineComponent({
8585
8686 clearTimers ( )
8787
88- if ( props . showAfter > 0 ) {
89- showTimer . value = window . setTimeout ( ( ) => {
90- emit ( 'before-show' )
91- if ( ! isControlled . value ) {
92- visible . value = true
93- }
94- emit ( 'update:visible' , true )
95- nextTick ( ( ) => {
96- update ( )
97- emit ( 'show' )
98- } )
99- } , props . showAfter )
100- }
101- else {
88+ const showTooltip = ( ) => {
10289 emit ( 'before-show' )
10390 if ( ! isControlled . value ) {
10491 visible . value = true
@@ -109,29 +96,33 @@ export default defineComponent({
10996 emit ( 'show' )
11097 } )
11198 }
99+
100+ if ( props . showAfter > 0 ) {
101+ showTimer . value = window . setTimeout ( showTooltip , props . showAfter )
102+ }
103+ else {
104+ showTooltip ( )
105+ }
112106 }
113107
114108 const doHide = ( ) => {
115109 clearTimers ( )
116110
117- if ( props . hideAfter > 0 && props . trigger !== 'click' ) {
118- hideTimer . value = window . setTimeout ( ( ) => {
119- emit ( 'before-hide' )
120- if ( ! isControlled . value ) {
121- visible . value = false
122- }
123- emit ( 'update:visible' , false )
124- emit ( 'hide' )
125- } , props . hideAfter )
126- }
127- else {
111+ const hideTooltip = ( ) => {
128112 emit ( 'before-hide' )
129113 if ( ! isControlled . value ) {
130114 visible . value = false
131115 }
132116 emit ( 'update:visible' , false )
133117 emit ( 'hide' )
134118 }
119+
120+ if ( props . hideAfter > 0 && props . trigger !== 'click' ) {
121+ hideTimer . value = window . setTimeout ( hideTooltip , props . hideAfter )
122+ }
123+ else {
124+ hideTooltip ( )
125+ }
135126 }
136127
137128 // 事件处理
Original file line number Diff line number Diff line change @@ -490,7 +490,7 @@ export default defineComponent({
490490| effect | 默认提供的主题 | string | dark/light | dark |
491491| visible / v-model: visible | 状态是否可见 | boolean | — | false |
492492| disabled | Tooltip 是否可用 | boolean | — | false |
493- | offset | 出现位置的偏移量 | number | — | 12 |
493+ | offset | 出现位置的偏移量 | number | — | 8 |
494494| show-after | 延迟出现,单位毫秒 | number | — | 0 |
495495| hide-after | 延迟关闭,单位毫秒 | number | — | 200 |
496496| show-arrow | 是否显示 Tooltip 箭头 | boolean | — | true |
You can’t perform that action at this time.
0 commit comments