chore: change info

This commit is contained in:
zhuzhengjian 2023-04-17 10:09:13 +08:00
parent 7ae7f3a878
commit 7cead859d1
2 changed files with 62 additions and 34 deletions

View File

@ -58,8 +58,8 @@ const Button = defineComponent({
small: 'sm', small: 'sm',
middle: undefined middle: undefined
} }
const sizeFullname = compactSize?.value || size.value const sizeFullName = compactSize?.value || size.value
return sizeClassNameMap[sizeFullname] return sizeClassNameMap[sizeFullName]
}) })
const disabled = useDisabled(props) const disabled = useDisabled(props)
const buttonRef = shallowRef<HTMLButtonElement | null>(null) const buttonRef = shallowRef<HTMLButtonElement | null>(null)
@ -73,6 +73,30 @@ const Button = defineComponent({
) )
const [hasTwoCNChar, setHasTwoCNChar] = useState(false) const [hasTwoCNChar, setHasTwoCNChar] = useState(false)
const isNeedInserted = (children: any) => {
return (
children.length === 1 &&
!slots.icon &&
isUnBorderedButtonType(props.type)
)
}
const fixTwoCNChar = (children: any) => {
// console.log(buttonRef)
// FIXME: for HOC usage like <FormatMessage />
if (!buttonRef.value || autoInsertSpaceInButton.value === false) {
return
}
const buttonText = buttonRef.value.textContent
if (isNeedInserted(children) && isTwoCNChar(buttonText as string)) {
if (!hasTwoCNChar) {
setHasTwoCNChar(true)
}
} else if (hasTwoCNChar) {
setHasTwoCNChar(false)
}
}
let delayTimer: number | null = null let delayTimer: number | null = null
onMounted(() => { onMounted(() => {
@ -84,7 +108,6 @@ const Button = defineComponent({
} else { } else {
setLoading(loadingOrDelay.value.loading) setLoading(loadingOrDelay.value.loading)
} }
// fixTwoCNChar()
}) })
function cleanupTimer() { function cleanupTimer() {
@ -128,29 +151,8 @@ const Button = defineComponent({
const { shape, rootClassName, ghost, type, block, danger } = props const { shape, rootClassName, ghost, type, block, danger } = props
const icon = getSlotsProps(slots, props, 'icon') const icon = getSlotsProps(slots, props, 'icon')
const children = filterEmpty(slots.default?.()) const children = filterEmpty(slots.default?.())
const isNeedInserted = () => {
return (
children.length === 1 &&
!slots.icon &&
isUnBorderedButtonType(props.type)
)
}
const fixTwoCNChar = () => { fixTwoCNChar(children)
// FIXME: for HOC usage like <FormatMessage />
if (!buttonRef.value || autoInsertSpaceInButton.value === false) {
return
}
const buttonText = buttonRef.value.textContent
if (isNeedInserted() && isTwoCNChar(buttonText as string)) {
if (!hasTwoCNChar) {
setHasTwoCNChar(true)
}
} else if (hasTwoCNChar) {
setHasTwoCNChar(false)
}
}
fixTwoCNChar()
showError() showError()
const iconType = innerLoading.value ? 'loading' : icon const iconType = innerLoading.value ? 'loading' : icon
@ -198,7 +200,12 @@ const Button = defineComponent({
) )
} }
let buttonNode = ( let buttonNode = (
<button {...attrs} onClick={handleClick} class={classes}> <button
{...attrs}
onClick={handleClick}
class={classes}
ref={buttonRef}
>
{children} {children}
</button> </button>
) )

View File

@ -1,8 +1,20 @@
import { booleanType, createInjectionState, functionType, objectType, someType, stringType } from '@v-c/utils' import {
booleanType,
createInjectionState,
functionType,
objectType,
someType,
stringType
} from '@v-c/utils'
import type { ExtractPropTypes } from 'vue' import type { ExtractPropTypes } from 'vue'
import { computed } from 'vue' import { computed } from 'vue'
import type { DerivativeFunc } from '@antd-tiny-vue/cssinjs' import type { DerivativeFunc } from '@antd-tiny-vue/cssinjs'
import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../theme/interface' import type {
AliasToken,
MapToken,
OverrideToken,
SeedToken
} from '../theme/interface'
import type { RenderEmptyHandler } from './default-render-empty' import type { RenderEmptyHandler } from './default-render-empty'
import type { ConfigProviderProps } from './index' import type { ConfigProviderProps } from './index'
@ -34,7 +46,10 @@ export interface ThemeConfig {
} }
export const defaultIconPrefixCls = 'anticon' export const defaultIconPrefixCls = 'anticon'
const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => { const defaultGetPrefixCls = (
suffixCls?: string,
customizePrefixCls?: string
) => {
if (customizePrefixCls) return customizePrefixCls if (customizePrefixCls) return customizePrefixCls
return suffixCls ? `ant-${suffixCls}` : 'ant' return suffixCls ? `ant-${suffixCls}` : 'ant'
@ -82,11 +97,16 @@ const configState = (props: ConfigProviderProps) => {
const getPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => { const getPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {
const { prefixCls, getPrefixCls } = props const { prefixCls, getPrefixCls } = props
if (customizePrefixCls) return customizePrefixCls if (customizePrefixCls) return customizePrefixCls
const mergedPrefixCls = prefixCls || getPrefixCls?.('') || defaultGetPrefixCls('') const mergedPrefixCls =
prefixCls || getPrefixCls?.('') || defaultGetPrefixCls('')
return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls
} }
const iconPrefixCls = computed(() => props?.iconPrefixCls ?? defaultIconPrefixCls) const iconPrefixCls = computed(
const shouldWrapSSR = computed(() => iconPrefixCls.value !== defaultIconPrefixCls) () => props?.iconPrefixCls ?? defaultIconPrefixCls
)
const shouldWrapSSR = computed(
() => iconPrefixCls.value !== defaultIconPrefixCls
)
const csp = computed(() => props?.csp) const csp = computed(() => props?.csp)
const componentSize = computed(() => props?.componentSize) const componentSize = computed(() => props?.componentSize)
const componentDisabled = computed(() => props?.componentDisabled) const componentDisabled = computed(() => props?.componentDisabled)
@ -103,7 +123,8 @@ const configState = (props: ConfigProviderProps) => {
direction direction
} }
} }
const [useProviderConfigProvide, useProviderConfigInject] = createInjectionState(configState) const [useProviderConfigProvide, useProviderConfigInject] =
createInjectionState(configState)
export { useProviderConfigProvide } export { useProviderConfigProvide }
export const useProviderConfigState = (): ReturnType<typeof configState> => { export const useProviderConfigState = (): ReturnType<typeof configState> => {
@ -115,7 +136,7 @@ export const useProviderConfigState = (): ReturnType<typeof configState> => {
componentSize: computed(() => undefined), componentSize: computed(() => undefined),
componentDisabled: computed(() => false), componentDisabled: computed(() => false),
direction: computed(() => undefined), direction: computed(() => undefined),
autoInsertSpaceInButton: computed(() => undefined) autoInsertSpaceInButton: computed(() => true)
} as any) } as any)
) )
} }