mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-01-24 12:45:18 +08:00
refactor(tooltip): ts
This commit is contained in:
parent
963991b97a
commit
b08ac196bf
@ -26,20 +26,20 @@ type UseThemeProps<T> = Readonly<{
|
|||||||
[key: string]: unknown
|
[key: string]: unknown
|
||||||
}>
|
}>
|
||||||
|
|
||||||
export interface MergedTheme<T> {
|
export interface MergedTheme<T, R = any> {
|
||||||
common: ThemeCommonVars
|
common: ThemeCommonVars
|
||||||
self: T
|
self: T
|
||||||
peers: any
|
peers: R
|
||||||
overrides: any
|
overrides: any
|
||||||
}
|
}
|
||||||
|
|
||||||
function useTheme<T> (
|
function useTheme<T, R> (
|
||||||
resolveId: string,
|
resolveId: string,
|
||||||
mountId: string,
|
mountId: string,
|
||||||
style: CNode | undefined,
|
style: CNode | undefined,
|
||||||
defaultTheme: Theme<T>,
|
defaultTheme: Theme<T, R>,
|
||||||
props: UseThemeProps<T>
|
props: UseThemeProps<T>
|
||||||
): ComputedRef<MergedTheme<T>> {
|
): ComputedRef<MergedTheme<T, R>> {
|
||||||
if (style) {
|
if (style) {
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
style.mount({
|
style.mount({
|
||||||
|
@ -7,7 +7,7 @@ const dropdownDark: DropdownTheme = {
|
|||||||
name: 'Dropdown',
|
name: 'Dropdown',
|
||||||
common: commonDark,
|
common: commonDark,
|
||||||
peers: {
|
peers: {
|
||||||
NPopover: popoverDark
|
Popover: popoverDark
|
||||||
},
|
},
|
||||||
self (vars) {
|
self (vars) {
|
||||||
const {
|
const {
|
||||||
|
@ -52,13 +52,13 @@ export type DropdownThemeVars = ReturnType<typeof self>
|
|||||||
const dropdownLight: Theme<
|
const dropdownLight: Theme<
|
||||||
DropdownThemeVars,
|
DropdownThemeVars,
|
||||||
{
|
{
|
||||||
NPopover: PopoverTheme
|
Popover?: PopoverTheme
|
||||||
}
|
}
|
||||||
> = {
|
> = {
|
||||||
name: 'Dropdown',
|
name: 'Dropdown',
|
||||||
common: commonLight,
|
common: commonLight,
|
||||||
peers: {
|
peers: {
|
||||||
NPopover: popoverLight
|
Popover: popoverLight
|
||||||
},
|
},
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export { default as NPopover, popoverProps } from './src/Popover'
|
export { default as NPopover, popoverProps } from './src/Popover'
|
||||||
|
export type { PopoverRef } from './src/Popover'
|
||||||
|
@ -64,6 +64,10 @@ const textVNodeType = createTextVNode('').type
|
|||||||
|
|
||||||
type BodyInstance = { syncPosition: () => void; [key: string]: unknown }
|
type BodyInstance = { syncPosition: () => void; [key: string]: unknown }
|
||||||
|
|
||||||
|
export interface PopoverRef {
|
||||||
|
syncPosition(): void
|
||||||
|
}
|
||||||
|
|
||||||
export interface PopoverInjection {
|
export interface PopoverInjection {
|
||||||
handleMouseLeave: (e: MouseEvent) => void
|
handleMouseLeave: (e: MouseEvent) => void
|
||||||
handleMouseEnter: (e: MouseEvent) => void
|
handleMouseEnter: (e: MouseEvent) => void
|
||||||
|
@ -1 +0,0 @@
|
|||||||
export { default as NTooltip } from './src/Tooltip.js'
|
|
1
src/tooltip/index.ts
Normal file
1
src/tooltip/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export { default as NTooltip } from './src/Tooltip'
|
@ -1,25 +1,35 @@
|
|||||||
// Tooltip: popover wearing waistcoat
|
// Tooltip: popover wearing waistcoat
|
||||||
import { h, defineComponent, ref, computed } from 'vue'
|
import { h, defineComponent, ref, computed } from 'vue'
|
||||||
import { NPopover } from '../../popover'
|
import { NPopover, popoverProps } from '../../popover'
|
||||||
|
import type { PopoverRef } from '../../popover'
|
||||||
import { useTheme } from '../../_mixins'
|
import { useTheme } from '../../_mixins'
|
||||||
|
import type { ThemeProps } from '../../_mixins'
|
||||||
import { tooltipLight } from '../styles'
|
import { tooltipLight } from '../styles'
|
||||||
|
import type { TooltipTheme } from '../styles'
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'Tooltip',
|
name: 'Tooltip',
|
||||||
props: {
|
props: {
|
||||||
...NPopover.props,
|
...popoverProps,
|
||||||
|
...(useTheme.props as ThemeProps<TooltipTheme>),
|
||||||
showArrow: {
|
showArrow: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
setup (props) {
|
setup (props) {
|
||||||
const themeRef = useTheme('Tooltip', 'Tooltip', null, tooltipLight, props)
|
const themeRef = useTheme(
|
||||||
const popoverRef = ref(null)
|
'Tooltip',
|
||||||
|
'Tooltip',
|
||||||
|
undefined,
|
||||||
|
tooltipLight,
|
||||||
|
props
|
||||||
|
)
|
||||||
|
const popoverRef = ref<PopoverRef | null>(null)
|
||||||
return {
|
return {
|
||||||
popoverRef,
|
popoverRef,
|
||||||
syncPosition () {
|
syncPosition () {
|
||||||
popoverRef.value.syncPosition()
|
(popoverRef.value as PopoverRef).syncPosition()
|
||||||
},
|
},
|
||||||
mergedTheme: themeRef,
|
mergedTheme: themeRef,
|
||||||
popoverThemeOverrides: computed(() => {
|
popoverThemeOverrides: computed(() => {
|
@ -1,8 +1,9 @@
|
|||||||
import { commonDark } from '../../_styles/new-common'
|
import { commonDark } from '../../_styles/new-common'
|
||||||
import { popoverDark } from '../../popover/styles'
|
import { popoverDark } from '../../popover/styles'
|
||||||
import commonVars from './_common'
|
import commonVars from './_common'
|
||||||
|
import type { TooltipTheme } from './light'
|
||||||
|
|
||||||
export default {
|
const tooltipDark: TooltipTheme = {
|
||||||
name: 'Tooltip',
|
name: 'Tooltip',
|
||||||
common: commonDark,
|
common: commonDark,
|
||||||
peers: {
|
peers: {
|
||||||
@ -19,3 +20,5 @@ export default {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default tooltipDark
|
@ -1,2 +0,0 @@
|
|||||||
export { default as tooltipDark } from './dark.js'
|
|
||||||
export { default as tooltipLight } from './light.js'
|
|
3
src/tooltip/styles/index.ts
Normal file
3
src/tooltip/styles/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
export { default as tooltipDark } from './dark'
|
||||||
|
export { default as tooltipLight } from './light'
|
||||||
|
export type { TooltipThemeVars, TooltipTheme } from './light'
|
@ -1,21 +0,0 @@
|
|||||||
import { commonLight } from '../../_styles/new-common'
|
|
||||||
import { popoverLight } from '../../popover/styles'
|
|
||||||
import commonVars from './_common'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'Tooltip',
|
|
||||||
common: commonLight,
|
|
||||||
peers: {
|
|
||||||
Popover: popoverLight
|
|
||||||
},
|
|
||||||
self (vars) {
|
|
||||||
const { borderRadius, boxShadow2, baseColor } = vars
|
|
||||||
return {
|
|
||||||
...commonVars,
|
|
||||||
borderRadius: borderRadius,
|
|
||||||
boxShadow: boxShadow2,
|
|
||||||
color: 'rgba(0, 0, 0, .85)',
|
|
||||||
textColor: baseColor
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
35
src/tooltip/styles/light.ts
Normal file
35
src/tooltip/styles/light.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { commonLight } from '../../_styles/new-common'
|
||||||
|
import type { ThemeCommonVars } from '../../_styles/new-common'
|
||||||
|
import { popoverLight, PopoverTheme } from '../../popover/styles'
|
||||||
|
import commonVars from './_common'
|
||||||
|
import type { Theme } from '../../_mixins/use-theme'
|
||||||
|
|
||||||
|
const self = (vars: ThemeCommonVars) => {
|
||||||
|
const { borderRadius, boxShadow2, baseColor } = vars
|
||||||
|
return {
|
||||||
|
...commonVars,
|
||||||
|
borderRadius: borderRadius,
|
||||||
|
boxShadow: boxShadow2,
|
||||||
|
color: 'rgba(0, 0, 0, .85)',
|
||||||
|
textColor: baseColor
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TooltipThemeVars = ReturnType<typeof self>
|
||||||
|
|
||||||
|
const tooltipLight: Theme<
|
||||||
|
TooltipThemeVars,
|
||||||
|
{
|
||||||
|
Popover?: PopoverTheme
|
||||||
|
}
|
||||||
|
> = {
|
||||||
|
name: 'Tooltip',
|
||||||
|
common: commonLight,
|
||||||
|
peers: {
|
||||||
|
Popover: popoverLight
|
||||||
|
},
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
|
export default tooltipLight
|
||||||
|
export type TooltipTheme = typeof tooltipLight
|
Loading…
Reference in New Issue
Block a user