bge-ui 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -0
- package/icons/Coin/HKD.svg +6 -0
- package/icons/Coin/USD.svg +4 -0
- package/icons/Intl/CH.svg +4 -0
- package/icons/Intl/EN.svg +14 -0
- package/icons/Intl/EUR.svg +15 -0
- package/icons/Intl/HKG.svg +8 -0
- package/icons/Intl/JPN.svg +4 -0
- package/icons/Intl/KOR.svg +6 -0
- package/icons/Intl/USA.svg +6 -0
- package/icons/Intl/VNM.svg +4 -0
- package/icons/Media/Facebook.svg +3 -0
- package/icons/Media/Instagram.svg +3 -0
- package/icons/Media/Linked.svg +3 -0
- package/icons/Media/Twitter.svg +3 -0
- package/icons/Mono/International.svg +3 -0
- package/icons/Mono/add-subtract.svg +4 -0
- package/icons/Mono/add.svg +3 -0
- package/icons/Mono/android.svg +3 -0
- package/icons/Mono/api.svg +5 -0
- package/icons/Mono/apple.svg +3 -0
- package/icons/Mono/arrow-down.svg +3 -0
- package/icons/Mono/arrow-up.svg +3 -0
- package/icons/Mono/assets.svg +4 -0
- package/icons/Mono/audit.svg +3 -0
- package/icons/Mono/bank card.svg +4 -0
- package/icons/Mono/building.svg +3 -0
- package/icons/Mono/calendar.svg +3 -0
- package/icons/Mono/check-fill.svg +3 -0
- package/icons/Mono/chevron-left.svg +3 -0
- package/icons/Mono/chevron-right-double.svg +4 -0
- package/icons/Mono/chevron-right.svg +3 -0
- package/icons/Mono/classify01.svg +3 -0
- package/icons/Mono/classify02.svg +6 -0
- package/icons/Mono/close-one.svg +4 -0
- package/icons/Mono/close.svg +3 -0
- package/icons/Mono/complete.svg +3 -0
- package/icons/Mono/copy.svg +4 -0
- package/icons/Mono/docunment.svg +5 -0
- package/icons/Mono/edit.svg +4 -0
- package/icons/Mono/email01.svg +3 -0
- package/icons/Mono/email02.svg +3 -0
- package/icons/Mono/exclamationmark-fill.svg +3 -0
- package/icons/Mono/eye-close.svg +4 -0
- package/icons/Mono/eye.svg +4 -0
- package/icons/Mono/googleplay.svg +6 -0
- package/icons/Mono/help.svg +5 -0
- package/icons/Mono/less.svg +3 -0
- package/icons/Mono/logout.svg +4 -0
- package/icons/Mono/menu.svg +5 -0
- package/icons/Mono/moon.svg +3 -0
- package/icons/Mono/more.svg +5 -0
- package/icons/Mono/notification.svg +3 -0
- package/icons/Mono/other-device.svg +5 -0
- package/icons/Mono/pic-error.svg +5 -0
- package/icons/Mono/pic.svg +4 -0
- package/icons/Mono/remove.svg +4 -0
- package/icons/Mono/route.svg +5 -0
- package/icons/Mono/safety.svg +4 -0
- package/icons/Mono/search.svg +3 -0
- package/icons/Mono/sun.svg +11 -0
- package/icons/Mono/time.svg +4 -0
- package/icons/Mono/toward-fill.svg +3 -0
- package/icons/Mono/transfer.svg +4 -0
- package/icons/Mono/trash.svg +6 -0
- package/icons/Mono/wallet.svg +4 -0
- package/icons/Mono/win.svg +6 -0
- package/icons/color/c2-all.svg +4 -0
- package/icons/color/c2-api.svg +5 -0
- package/icons/color/c2-assets.svg +4 -0
- package/icons/color/c2-bill-1.svg +4 -0
- package/icons/color/c2-bill-2.svg +5 -0
- package/icons/color/c2-card.svg +4 -0
- package/icons/color/c2-complete.svg +4 -0
- package/icons/color/c2-deal.svg +5 -0
- package/icons/color/c2-email.svg +4 -0
- package/icons/color/c2-fee.svg +6 -0
- package/icons/color/c2-google.svg +4 -0
- package/icons/color/c2-home.svg +4 -0
- package/icons/color/c2-kyc.svg +5 -0
- package/icons/color/c2-language.svg +4 -0
- package/icons/color/c2-level.svg +4 -0
- package/icons/color/c2-notification.svg +4 -0
- package/icons/color/c2-pdf.svg +4 -0
- package/icons/color/c2-phone.svg +4 -0
- package/icons/color/c2-register.svg +5 -0
- package/icons/color/c2-right-down.svg +4 -0
- package/icons/color/c2-right-up.svg +4 -0
- package/icons/color/c2-safe-shield.svg +4 -0
- package/icons/color/c2-safe.svg +4 -0
- package/icons/color/c2-traffic-cone.svg +7 -0
- package/icons/color/c2-user-every.svg +9 -0
- package/icons/color/c2-user.svg +5 -0
- package/icons/color/c3-Licensing.svg +5 -0
- package/icons/color/c3-audits.svg +7 -0
- package/icons/color/c3-card.svg +5 -0
- package/icons/color/c3-company.svg +6 -0
- package/icons/color/c3-deposit.svg +6 -0
- package/icons/color/c3-establish.svg +5 -0
- package/icons/color/c3-framework.svg +5 -0
- package/icons/color/c3-kyc.svg +7 -0
- package/icons/color/c3-not-passed.svg +7 -0
- package/icons/color/c3-pass.svg +7 -0
- package/icons/color/c3-safes.svg +8 -0
- package/icons/color/c3-trading.svg +5 -0
- package/icons/color/c3-user-every.svg +11 -0
- package/icons/color/c3-user-follow.svg +6 -0
- package/icons/color/c3-user.svg +6 -0
- package/icons/color/close-fill.svg +4 -0
- package/icons/color/completed-fill.svg +4 -0
- package/icons/color/cookie.svg +16 -0
- package/icons/color/star.svg +4 -0
- package/icons/color/success-fill.svg +11 -0
- package/icons/color/time-fill.svg +4 -0
- package/icons/color/toward-fill.svg +6 -0
- package/icons/generate.ts +152 -0
- package/package.json +37 -0
- package/src/button/index.vue +120 -0
- package/src/button/type.ts +4 -0
- package/src/dropdown/index.vue +10 -0
- package/src/form/form-item.vue +234 -0
- package/src/form/index.vue +122 -0
- package/src/icons/CoinHkd.vue +80 -0
- package/src/icons/CoinUsd.vue +72 -0
- package/src/icons/ColorC2All.vue +75 -0
- package/src/icons/ColorC2Api.vue +71 -0
- package/src/icons/ColorC2Assets.vue +72 -0
- package/src/icons/ColorC2Bill1.vue +70 -0
- package/src/icons/ColorC2Bill2.vue +68 -0
- package/src/icons/ColorC2Card.vue +67 -0
- package/src/icons/ColorC2Complete.vue +72 -0
- package/src/icons/ColorC2Deal.vue +74 -0
- package/src/icons/ColorC2Email.vue +70 -0
- package/src/icons/ColorC2Fee.vue +78 -0
- package/src/icons/ColorC2Google.vue +70 -0
- package/src/icons/ColorC2Home.vue +70 -0
- package/src/icons/ColorC2Kyc.vue +73 -0
- package/src/icons/ColorC2Language.vue +70 -0
- package/src/icons/ColorC2Level.vue +72 -0
- package/src/icons/ColorC2Notification.vue +75 -0
- package/src/icons/ColorC2Pdf.vue +73 -0
- package/src/icons/ColorC2Phone.vue +67 -0
- package/src/icons/ColorC2Register.vue +68 -0
- package/src/icons/ColorC2RightDown.vue +72 -0
- package/src/icons/ColorC2RightUp.vue +72 -0
- package/src/icons/ColorC2Safe.vue +75 -0
- package/src/icons/ColorC2SafeShield.vue +72 -0
- package/src/icons/ColorC2TrafficCone.vue +79 -0
- package/src/icons/ColorC2User.vue +79 -0
- package/src/icons/ColorC2UserEvery.vue +90 -0
- package/src/icons/ColorC3Audits.vue +76 -0
- package/src/icons/ColorC3Card.vue +68 -0
- package/src/icons/ColorC3Company.vue +69 -0
- package/src/icons/ColorC3Deposit.vue +74 -0
- package/src/icons/ColorC3Establish.vue +78 -0
- package/src/icons/ColorC3Framework.vue +71 -0
- package/src/icons/ColorC3Kyc.vue +76 -0
- package/src/icons/ColorC3Licensing.vue +71 -0
- package/src/icons/ColorC3NotPassed.vue +76 -0
- package/src/icons/ColorC3Pass.vue +78 -0
- package/src/icons/ColorC3Safes.vue +83 -0
- package/src/icons/ColorC3Trading.vue +78 -0
- package/src/icons/ColorC3User.vue +78 -0
- package/src/icons/ColorC3UserEvery.vue +98 -0
- package/src/icons/ColorC3UserFollow.vue +83 -0
- package/src/icons/ColorCloseFill.vue +74 -0
- package/src/icons/ColorCompletedFill.vue +71 -0
- package/src/icons/ColorCookie.vue +99 -0
- package/src/icons/ColorStar.vue +72 -0
- package/src/icons/ColorSuccessFill.vue +78 -0
- package/src/icons/ColorTimeFill.vue +66 -0
- package/src/icons/ColorTowardFill.vue +68 -0
- package/src/icons/IntlCh.vue +76 -0
- package/src/icons/IntlEn.vue +112 -0
- package/src/icons/IntlEur.vue +116 -0
- package/src/icons/IntlHkg.vue +98 -0
- package/src/icons/IntlJpn.vue +76 -0
- package/src/icons/IntlKor.vue +88 -0
- package/src/icons/IntlUsa.vue +83 -0
- package/src/icons/IntlVnm.vue +76 -0
- package/src/icons/MediaFacebook.vue +72 -0
- package/src/icons/MediaInstagram.vue +72 -0
- package/src/icons/MediaLinked.vue +72 -0
- package/src/icons/MediaTwitter.vue +70 -0
- package/src/icons/MonoAdd.vue +70 -0
- package/src/icons/MonoAddSubtract.vue +68 -0
- package/src/icons/MonoAndroid.vue +72 -0
- package/src/icons/MonoApi.vue +77 -0
- package/src/icons/MonoApple.vue +70 -0
- package/src/icons/MonoArrowDown.vue +67 -0
- package/src/icons/MonoArrowUp.vue +67 -0
- package/src/icons/MonoAssets.vue +78 -0
- package/src/icons/MonoAudit.vue +72 -0
- package/src/icons/MonoBankCard.vue +73 -0
- package/src/icons/MonoBuilding.vue +72 -0
- package/src/icons/MonoCalendar.vue +72 -0
- package/src/icons/MonoCheckFill.vue +72 -0
- package/src/icons/MonoChevronLeft.vue +72 -0
- package/src/icons/MonoChevronRight.vue +72 -0
- package/src/icons/MonoChevronRightDouble.vue +78 -0
- package/src/icons/MonoClassify01.vue +72 -0
- package/src/icons/MonoClassify02.vue +90 -0
- package/src/icons/MonoClose.vue +70 -0
- package/src/icons/MonoCloseOne.vue +76 -0
- package/src/icons/MonoComplete.vue +72 -0
- package/src/icons/MonoCopy.vue +73 -0
- package/src/icons/MonoDocunment.vue +74 -0
- package/src/icons/MonoEdit.vue +78 -0
- package/src/icons/MonoEmail01.vue +72 -0
- package/src/icons/MonoEmail02.vue +72 -0
- package/src/icons/MonoExclamationmarkFill.vue +72 -0
- package/src/icons/MonoEye.vue +78 -0
- package/src/icons/MonoEyeClose.vue +78 -0
- package/src/icons/MonoGoogleplay.vue +82 -0
- package/src/icons/MonoHelp.vue +77 -0
- package/src/icons/MonoInternational.vue +70 -0
- package/src/icons/MonoLess.vue +67 -0
- package/src/icons/MonoLogout.vue +71 -0
- package/src/icons/MonoMenu.vue +69 -0
- package/src/icons/MonoMoon.vue +72 -0
- package/src/icons/MonoMore.vue +69 -0
- package/src/icons/MonoNotification.vue +72 -0
- package/src/icons/MonoOtherDevice.vue +74 -0
- package/src/icons/MonoPic.vue +76 -0
- package/src/icons/MonoPicError.vue +80 -0
- package/src/icons/MonoRemove.vue +73 -0
- package/src/icons/MonoRoute.vue +69 -0
- package/src/icons/MonoSafety.vue +76 -0
- package/src/icons/MonoSearch.vue +72 -0
- package/src/icons/MonoSun.vue +95 -0
- package/src/icons/MonoTime.vue +78 -0
- package/src/icons/MonoTowardFill.vue +72 -0
- package/src/icons/MonoTransfer.vue +74 -0
- package/src/icons/MonoTrash.vue +75 -0
- package/src/icons/MonoWallet.vue +73 -0
- package/src/icons/MonoWin.vue +70 -0
- package/src/icons/index.ts +231 -0
- package/src/index.ts +50 -0
- package/src/input/index.vue +256 -0
- package/src/link/index.vue +95 -0
- package/src/message/index.vue +205 -0
- package/src/message/method.ts +138 -0
- package/src/tabs/index.vue +126 -0
- package/src/tabs/tab-pane.vue +96 -0
- package/src/tooltip/index.vue +338 -0
- package/src/tooltip/only-child.tsx +70 -0
- package/src/tooltip/usePopper.ts +578 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div :class="`bge-tabs bge-tabs__${type}`">
|
|
3
|
+
<div class="bge-tabs__panes">
|
|
4
|
+
<slot></slot>
|
|
5
|
+
</div>
|
|
6
|
+
<span class="bge-tabs__active-bar" :style="barStyle"></span>
|
|
7
|
+
</div>
|
|
8
|
+
</template>
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
import { defineProps, provide, ref, watch, onMounted } from "vue"
|
|
11
|
+
defineOptions({
|
|
12
|
+
name: "Tabs",
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const props = defineProps({
|
|
16
|
+
type: {
|
|
17
|
+
default: 'bordered',
|
|
18
|
+
value: ['bordered', 'pills']
|
|
19
|
+
},
|
|
20
|
+
modelValue: {
|
|
21
|
+
type: String,
|
|
22
|
+
default: '',
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const emits = defineEmits('update:modelValue')
|
|
27
|
+
|
|
28
|
+
const panes = ref<any>([])
|
|
29
|
+
|
|
30
|
+
function addPane(pane) {
|
|
31
|
+
panes.value.push(pane)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function changeValue(value: string) {
|
|
35
|
+
emits('update:modelValue', value)
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
update()
|
|
38
|
+
}, 100);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const tabsKey = 'bge-tabs-context'
|
|
42
|
+
provide(tabsKey, {
|
|
43
|
+
addPane,
|
|
44
|
+
changeValue
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
const getBarStyle: CSSProperties = () => {
|
|
48
|
+
let offset = 0
|
|
49
|
+
let tabSize = 0
|
|
50
|
+
|
|
51
|
+
const sizeName = 'width'
|
|
52
|
+
const sizeDir = sizeName === 'width' ? 'x' : 'y'
|
|
53
|
+
const position = sizeDir === 'x' ? 'left' : 'top'
|
|
54
|
+
|
|
55
|
+
panes.value.forEach((tab) => {
|
|
56
|
+
const $el = tab.ref as HTMLElement
|
|
57
|
+
if (!$el) return false
|
|
58
|
+
if (tab.value !== props.modelValue) {
|
|
59
|
+
tab.setActive(false)
|
|
60
|
+
return true
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
tab.setActive(true)
|
|
64
|
+
offset = $el['offsetLeft']
|
|
65
|
+
tabSize = $el['clientWidth']
|
|
66
|
+
return false
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
[sizeName]: `${tabSize}px`,
|
|
71
|
+
transform: `translateX(${offset}px)`,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const barStyle = ref<CSSProperties>()
|
|
75
|
+
const update = () => (barStyle.value = getBarStyle())
|
|
76
|
+
|
|
77
|
+
onMounted(() => {
|
|
78
|
+
update()
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<style lang="scss" scoped>
|
|
84
|
+
.bge-tabs {
|
|
85
|
+
|
|
86
|
+
&.bge-tabs__bordered,
|
|
87
|
+
&.bge-tabs__pills {
|
|
88
|
+
.bge-tabs__panes {
|
|
89
|
+
display: flex;
|
|
90
|
+
align-items: flex-start;
|
|
91
|
+
position: relative;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
&.bge-tabs__bordered {
|
|
96
|
+
&::after {
|
|
97
|
+
content: "";
|
|
98
|
+
position: absolute;
|
|
99
|
+
left: 0;
|
|
100
|
+
bottom: 0;
|
|
101
|
+
width: 100%;
|
|
102
|
+
height: 1px;
|
|
103
|
+
border-radius: var(--radius-small, 0px);
|
|
104
|
+
background: var(--separator-separator, #34414D);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.bge-tabs__active-bar {
|
|
108
|
+
position: absolute;
|
|
109
|
+
bottom: 0;
|
|
110
|
+
left: 0;
|
|
111
|
+
height: 2px;
|
|
112
|
+
z-index: 1;
|
|
113
|
+
list-style: none;
|
|
114
|
+
border-radius: var(--radius-small, 0px);
|
|
115
|
+
background: var(--tc-theme, #FFFF38);
|
|
116
|
+
transition: width .3s cubic-bezier(.645, .045, .355, 1), transform .3s cubic-bezier(.645, .045, .355, 1);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
&.bge-tabs__pills {
|
|
121
|
+
.bge-tabs__active-bar {
|
|
122
|
+
display: none;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
</style>
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="bge-tab__pane" :class="{ active: isActive }" ref="tabPaneRef" @click="changeValue">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
<script setup lang="ts">
|
|
7
|
+
defineOptions({
|
|
8
|
+
name: 'tabPane'
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const props = defineProps({
|
|
12
|
+
value: {
|
|
13
|
+
default: '',
|
|
14
|
+
type: String
|
|
15
|
+
}
|
|
16
|
+
})
|
|
17
|
+
import { ref, onMounted, inject, reactive } from "vue";
|
|
18
|
+
const tabPaneRef = ref<HTMLDivElement>()
|
|
19
|
+
const tabsKey = 'bge-tabs-context'
|
|
20
|
+
const tabContext = inject(tabsKey, undefined)
|
|
21
|
+
function changeValue() {
|
|
22
|
+
tabContext.changeValue(props.value)
|
|
23
|
+
}
|
|
24
|
+
const isActive = ref<Boolean>(false)
|
|
25
|
+
function setActive(active: Boolean) {
|
|
26
|
+
isActive.value = active
|
|
27
|
+
}
|
|
28
|
+
onMounted(() => {
|
|
29
|
+
tabContext.addPane(reactive({
|
|
30
|
+
ref: tabPaneRef.value,
|
|
31
|
+
value: props.value,
|
|
32
|
+
setActive
|
|
33
|
+
}))
|
|
34
|
+
})
|
|
35
|
+
</script>
|
|
36
|
+
<style lang="scss" >
|
|
37
|
+
.bge-tabs__pills {
|
|
38
|
+
.bge-tab__pane {
|
|
39
|
+
display: flex;
|
|
40
|
+
padding: var(--layout-x-2, 8px) var(--layout-x-3, 12px);
|
|
41
|
+
justify-content: center;
|
|
42
|
+
align-items: center;
|
|
43
|
+
border-radius: var(--radius-small, 0px);
|
|
44
|
+
background: var(--bg-input, rgba(88, 126, 163, 0.08));
|
|
45
|
+
margin-right: 4px;
|
|
46
|
+
color: var(--tc-tertiary, #53677A);
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
text-align: center;
|
|
49
|
+
font-size: 14px;
|
|
50
|
+
font-style: normal;
|
|
51
|
+
font-weight: 500;
|
|
52
|
+
line-height: 24px;
|
|
53
|
+
|
|
54
|
+
&:last-child {
|
|
55
|
+
margin-right: 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
&:hover {
|
|
59
|
+
background: var(--bg-input-hover, rgba(88, 126, 163, 0.12));
|
|
60
|
+
color: var(--tc-primary, #E0E0E0);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
&.active {
|
|
64
|
+
color: var(--persistent-black, #000);
|
|
65
|
+
background: var(--btn-primary, #FFFF38);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.bge-tabs__bordered {
|
|
71
|
+
.bge-tab__pane {
|
|
72
|
+
display: flex;
|
|
73
|
+
padding: var(--layout-x-2, 8px) 0px;
|
|
74
|
+
justify-content: center;
|
|
75
|
+
align-items: center;
|
|
76
|
+
gap: var(--layout-x-1, 4px);
|
|
77
|
+
border-radius: var(--radius-small, 0px);
|
|
78
|
+
color: var(--tc-tertiary, #53677A);
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
font-size: 16px;
|
|
81
|
+
font-style: normal;
|
|
82
|
+
font-weight: 500;
|
|
83
|
+
line-height: 28px;
|
|
84
|
+
margin-right: 16px;
|
|
85
|
+
|
|
86
|
+
&:last-child {
|
|
87
|
+
margin-right: 0;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
&:hover,
|
|
91
|
+
&.active {
|
|
92
|
+
color: var(--tc-primary, #E0E0E0);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
</style>
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ui-only-child ref="triggerRef" ariaDescribedby="tooltip">
|
|
3
|
+
<slot />
|
|
4
|
+
</ui-only-child>
|
|
5
|
+
<!-- <component :is="triggerElement">
|
|
6
|
+
<slot />
|
|
7
|
+
</component> -->
|
|
8
|
+
<teleport v-if="teleported" to="body">
|
|
9
|
+
<component :is="tooltipElement">
|
|
10
|
+
<slot name="content" />
|
|
11
|
+
</component>
|
|
12
|
+
</teleport>
|
|
13
|
+
<component v-else :is="tooltipElement">
|
|
14
|
+
<slot name="content" />
|
|
15
|
+
</component>
|
|
16
|
+
</template>
|
|
17
|
+
<script setup lang="ts">
|
|
18
|
+
import { OnlyChild as UiOnlyChild } from './only-child'
|
|
19
|
+
import type { PropType } from 'vue'
|
|
20
|
+
import { computed, ref, onMounted } from 'vue';
|
|
21
|
+
import type { PositioningStrategy, Placement, Modifier } from '@popperjs/core'
|
|
22
|
+
import { usePopper } from './usePopper';
|
|
23
|
+
|
|
24
|
+
const props = defineProps({
|
|
25
|
+
/**
|
|
26
|
+
* 是否将弹出层追加到body元素下
|
|
27
|
+
*/
|
|
28
|
+
teleported: {
|
|
29
|
+
type: Boolean,
|
|
30
|
+
default: true,
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Trigger element on hover
|
|
35
|
+
*/
|
|
36
|
+
hover: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: true,
|
|
39
|
+
},
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Disable clicking outside to close
|
|
43
|
+
*/
|
|
44
|
+
disableClickOutside: {
|
|
45
|
+
type: Boolean,
|
|
46
|
+
default: false,
|
|
47
|
+
},
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* How many milliseconds to wait before opening the tooltip
|
|
51
|
+
*/
|
|
52
|
+
openDelay: {
|
|
53
|
+
type: Number,
|
|
54
|
+
default: 0,
|
|
55
|
+
validator: (value: number) => {
|
|
56
|
+
const isPositive = value >= 0;
|
|
57
|
+
if (!isPositive) {
|
|
58
|
+
console.warn('@kalimahapps/vue-popper: openDelay must be a positive number');
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* How many milliseconds to wait before closing the tooltip
|
|
67
|
+
*/
|
|
68
|
+
closeDelay: {
|
|
69
|
+
type: Number,
|
|
70
|
+
default: 0,
|
|
71
|
+
validator: (value: number) => {
|
|
72
|
+
const isPositive = value >= 0;
|
|
73
|
+
if (!isPositive) {
|
|
74
|
+
console.warn('@kalimahapps/vue-popper: closeDelay must be a positive number');
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Display an arrow on the tooltip
|
|
84
|
+
*/
|
|
85
|
+
showArrow: {
|
|
86
|
+
type: Boolean,
|
|
87
|
+
default: true,
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Whether to interact with tooltip when hover is true
|
|
92
|
+
*/
|
|
93
|
+
interactive: {
|
|
94
|
+
type: Boolean,
|
|
95
|
+
default: true,
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Set the strategy used to position the popper
|
|
100
|
+
*
|
|
101
|
+
* @values absolute | fixed
|
|
102
|
+
*/
|
|
103
|
+
strategy: {
|
|
104
|
+
type: String as PropType<PositioningStrategy>,
|
|
105
|
+
default: 'absolute',
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Set the placement of the popper
|
|
110
|
+
*/
|
|
111
|
+
placement: {
|
|
112
|
+
type: String as PropType<Placement>,
|
|
113
|
+
default: 'top',
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Set the modifiers of the popper
|
|
118
|
+
*/
|
|
119
|
+
modifiers: {
|
|
120
|
+
type: Array as PropType<Modifier<any, any>[]>,
|
|
121
|
+
default: () => {
|
|
122
|
+
return [];
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Set the type of animation
|
|
128
|
+
*
|
|
129
|
+
* @values none, fade, shift-in, shift-out, scale, CUSTOM
|
|
130
|
+
*/
|
|
131
|
+
animation: {
|
|
132
|
+
type: String,
|
|
133
|
+
default: 'shift-in',
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Animation duration in milliseconds
|
|
138
|
+
*/
|
|
139
|
+
animationDuration: {
|
|
140
|
+
type: [Number, Array],
|
|
141
|
+
default: 300,
|
|
142
|
+
validator(value) {
|
|
143
|
+
if (Array.isArray(value)) {
|
|
144
|
+
return value.every((durationValue) => {
|
|
145
|
+
return typeof durationValue === 'number' && durationValue >= 0;
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
return typeof value === 'number' && value >= 0;
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const emits = defineEmits(['opened', 'closed', 'transition']);
|
|
154
|
+
|
|
155
|
+
const triggerRef = ref()
|
|
156
|
+
|
|
157
|
+
const popperInstance = ref<any>(), tooltipElement = ref<any>(), isOpened = ref<any>(), toggleTooltip = ref<any>()
|
|
158
|
+
|
|
159
|
+
onMounted(() => {
|
|
160
|
+
const result = usePopper(triggerRef, {
|
|
161
|
+
hover: props.hover,
|
|
162
|
+
disableClickOutside: props.disableClickOutside,
|
|
163
|
+
openDelay: props.openDelay,
|
|
164
|
+
closeDelay: props.closeDelay,
|
|
165
|
+
showArrow: props.showArrow,
|
|
166
|
+
strategy: props.strategy,
|
|
167
|
+
modifiers: props.modifiers,
|
|
168
|
+
animation: props.animation,
|
|
169
|
+
placement: props.placement,
|
|
170
|
+
interactive: props.interactive,
|
|
171
|
+
animationDuration: props.animationDuration as any,
|
|
172
|
+
|
|
173
|
+
onTransition: (transition: string, element: HTMLElement) => {
|
|
174
|
+
emits('transition', transition, element);
|
|
175
|
+
},
|
|
176
|
+
onOpened: () => {
|
|
177
|
+
emits('opened');
|
|
178
|
+
},
|
|
179
|
+
onClosed: () => {
|
|
180
|
+
emits('closed');
|
|
181
|
+
},
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
popperInstance.value = result.popperInstance
|
|
185
|
+
// triggerElement.value = result.triggerElement
|
|
186
|
+
isOpened.value = result.isOpened
|
|
187
|
+
toggleTooltip.value = result.toggleTooltip
|
|
188
|
+
tooltipElement.value = result.tooltipElement
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
defineExpose({
|
|
192
|
+
popper: popperInstance,
|
|
193
|
+
isOpened: computed(() => {
|
|
194
|
+
return isOpened.value;
|
|
195
|
+
}),
|
|
196
|
+
toggleTooltip,
|
|
197
|
+
})
|
|
198
|
+
</script>
|
|
199
|
+
<style lang="scss">
|
|
200
|
+
.bge-popper-wrapper {
|
|
201
|
+
|
|
202
|
+
z-index: 20;
|
|
203
|
+
|
|
204
|
+
&[data-popper-placement^="top"]>.popper-content>[data-popper-arrow] {
|
|
205
|
+
bottom: -4px;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&[data-popper-placement^="bottom"]>.popper-content>[data-popper-arrow] {
|
|
209
|
+
top: -4px;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
&[data-popper-placement^="left"]>.popper-content>[data-popper-arrow] {
|
|
213
|
+
right: -4px;
|
|
214
|
+
top: 50% !important;
|
|
215
|
+
transform: translateY(-50%) !important;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
&[data-popper-placement^="right"]>.popper-content>[data-popper-arrow] {
|
|
219
|
+
left: -4px;
|
|
220
|
+
top: 50% !important;
|
|
221
|
+
transform: translateY(-50%) !important;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
.popper-content {
|
|
225
|
+
max-width: 360px;
|
|
226
|
+
box-shadow: 0px 12px 40px 0px rgba(0, 0, 0, 0.08);
|
|
227
|
+
border-radius: var(--radius-small, 0px);
|
|
228
|
+
background: var(--bg-tooltip, #53677A);
|
|
229
|
+
padding: var(--layout-x-3, 12px) var(--layout-x-4, 16px);
|
|
230
|
+
color: var(--persistent-tc-primary, #E0E0E0);
|
|
231
|
+
font-size: 14px;
|
|
232
|
+
font-weight: 400;
|
|
233
|
+
line-height: 24px;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
[data-popper-arrow] {
|
|
238
|
+
position: absolute;
|
|
239
|
+
width: 8px;
|
|
240
|
+
height: 8px;
|
|
241
|
+
background: var(--bg-tooltip, #53677A);
|
|
242
|
+
visibility: hidden;
|
|
243
|
+
|
|
244
|
+
&::before {
|
|
245
|
+
content: "";
|
|
246
|
+
position: absolute;
|
|
247
|
+
width: 8px;
|
|
248
|
+
height: 8px;
|
|
249
|
+
background: var(--bg-tooltip, #53677A);
|
|
250
|
+
visibility: visible;
|
|
251
|
+
transform: rotate(45deg);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.fade-enter-active {
|
|
256
|
+
transition: opacity var(--vue-popper-enter-duration, 0.3s);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
.fade-leave-active {
|
|
260
|
+
transition: opacity var(--vue-popper-leave-duration, 0.3s);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
.fade-leave-from,
|
|
264
|
+
.fade-enter-to {
|
|
265
|
+
opacity: 1;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.fade-enter-from,
|
|
269
|
+
.fade-leave-to {
|
|
270
|
+
opacity: 0;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Shift in
|
|
275
|
+
*/
|
|
276
|
+
.shift-in-enter-active {
|
|
277
|
+
transition: transform var(--vue-popper-enter-duration, 0.3s);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
.shift-in-leave-active {
|
|
281
|
+
transition: transform var(--vue-popper-leave-duration, 0.3s);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
.shift-in-leave-form,
|
|
285
|
+
.shift-in-enter-to {
|
|
286
|
+
transform: translate(0, 0);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.shift-in-enter-from,
|
|
290
|
+
.shift-in-leave-to {
|
|
291
|
+
transform: var(--vue-popper-shift-transform);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Shift Out animation
|
|
296
|
+
* Enter/leave properties are handled by JS hooks to avoid flickering
|
|
297
|
+
*/
|
|
298
|
+
.shift-out-enter-active {
|
|
299
|
+
transition: transform var(--vue-popper-enter-duration, 0.3s);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
.shift-out-leave-active {
|
|
303
|
+
transition: transform var(--vue-popper-leave-duration, 0.3s);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@keyframes shift-out {
|
|
307
|
+
0% {
|
|
308
|
+
transform: translate(0, 0);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
100% {
|
|
312
|
+
transform: var(--vue-popper-shift-transform);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Scale animation
|
|
318
|
+
*/
|
|
319
|
+
.scale-enter-active {
|
|
320
|
+
transition: transform var(--vue-popper-enter-duration, 0.3s);
|
|
321
|
+
transform-origin: var(--vue-popper-scale-transform-origin, center center);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.scale-leave-active {
|
|
325
|
+
transition: transform var(--vue-popper-leave-duration, 0.3s);
|
|
326
|
+
transform-origin: var(--vue-popper-scale-transform-origin, center center);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
.scale-enter-from,
|
|
330
|
+
.scale-leave-to {
|
|
331
|
+
transform: scale(0);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.scale-leave-form,
|
|
335
|
+
.scale-enter-to {
|
|
336
|
+
transform: scale(1);
|
|
337
|
+
}
|
|
338
|
+
</style>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Comment,
|
|
3
|
+
Fragment,
|
|
4
|
+
Text,
|
|
5
|
+
cloneVNode,
|
|
6
|
+
defineComponent,
|
|
7
|
+
inject,
|
|
8
|
+
withDirectives,
|
|
9
|
+
} from 'vue'
|
|
10
|
+
// import { NOOP, isObject } from '@vue/shared'
|
|
11
|
+
|
|
12
|
+
import type { Ref, VNode } from 'vue'
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
export const OnlyChild = defineComponent({
|
|
16
|
+
name: 'OnlyChild',
|
|
17
|
+
setup(_, { slots, attrs }) {
|
|
18
|
+
return () => {
|
|
19
|
+
const defaultSlot = slots.default?.(attrs)
|
|
20
|
+
if (!defaultSlot) return null
|
|
21
|
+
|
|
22
|
+
if (defaultSlot.length > 1) {
|
|
23
|
+
console.log('requires exact only one valid child.')
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const firstLegitNode = findFirstLegitChild(defaultSlot)
|
|
28
|
+
if (!firstLegitNode) {
|
|
29
|
+
console.log('no valid child node found')
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return withDirectives(cloneVNode(firstLegitNode!, attrs), [
|
|
34
|
+
|
|
35
|
+
])
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
function findFirstLegitChild(node: VNode[] | undefined): VNode | null {
|
|
41
|
+
if (!node) return null
|
|
42
|
+
const children = node as VNode[]
|
|
43
|
+
for (const child of children) {
|
|
44
|
+
/**
|
|
45
|
+
* when user uses h(Fragment, [text]) to render plain string,
|
|
46
|
+
* this switch case just cannot handle, when the value is primitives
|
|
47
|
+
* we should just return the wrapped string
|
|
48
|
+
*/
|
|
49
|
+
if (typeof child === 'object') {
|
|
50
|
+
switch (child.type) {
|
|
51
|
+
case Comment:
|
|
52
|
+
continue
|
|
53
|
+
case Text:
|
|
54
|
+
case 'svg':
|
|
55
|
+
return wrapTextContent(child)
|
|
56
|
+
case Fragment:
|
|
57
|
+
return findFirstLegitChild(child.children as VNode[])
|
|
58
|
+
default:
|
|
59
|
+
return child
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return wrapTextContent(child)
|
|
63
|
+
}
|
|
64
|
+
return null
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function wrapTextContent(s: string | VNode) {
|
|
68
|
+
// const ns = useNamespace('only-child')
|
|
69
|
+
<span class=""> {s}</span>
|
|
70
|
+
}
|