diff --git a/components/button/button.tsx b/components/button/button.tsx index 49f3c85..51852d8 100644 --- a/components/button/button.tsx +++ b/components/button/button.tsx @@ -58,8 +58,8 @@ const Button = defineComponent({ small: 'sm', middle: undefined } - const sizeFullname = compactSize?.value || size.value - return sizeClassNameMap[sizeFullname] + const sizeFullName = compactSize?.value || size.value + return sizeClassNameMap[sizeFullName] }) const disabled = useDisabled(props) const buttonRef = shallowRef(null) @@ -73,6 +73,30 @@ const Button = defineComponent({ ) 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 + 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 onMounted(() => { @@ -84,7 +108,6 @@ const Button = defineComponent({ } else { setLoading(loadingOrDelay.value.loading) } - // fixTwoCNChar() }) function cleanupTimer() { @@ -128,29 +151,8 @@ const Button = defineComponent({ const { shape, rootClassName, ghost, type, block, danger } = props const icon = getSlotsProps(slots, props, 'icon') const children = filterEmpty(slots.default?.()) - const isNeedInserted = () => { - return ( - children.length === 1 && - !slots.icon && - isUnBorderedButtonType(props.type) - ) - } - const fixTwoCNChar = () => { - // FIXME: for HOC usage like - 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() + fixTwoCNChar(children) showError() const iconType = innerLoading.value ? 'loading' : icon @@ -198,7 +200,12 @@ const Button = defineComponent({ ) } let buttonNode = ( - ) diff --git a/components/config-provider/context.ts b/components/config-provider/context.ts index 87115ea..ce1a38f 100644 --- a/components/config-provider/context.ts +++ b/components/config-provider/context.ts @@ -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 { computed } from 'vue' 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 { ConfigProviderProps } from './index' @@ -34,7 +46,10 @@ export interface ThemeConfig { } export const defaultIconPrefixCls = 'anticon' -const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => { +const defaultGetPrefixCls = ( + suffixCls?: string, + customizePrefixCls?: string +) => { if (customizePrefixCls) return customizePrefixCls return suffixCls ? `ant-${suffixCls}` : 'ant' @@ -82,11 +97,16 @@ const configState = (props: ConfigProviderProps) => { const getPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => { const { prefixCls, getPrefixCls } = props if (customizePrefixCls) return customizePrefixCls - const mergedPrefixCls = prefixCls || getPrefixCls?.('') || defaultGetPrefixCls('') + const mergedPrefixCls = + prefixCls || getPrefixCls?.('') || defaultGetPrefixCls('') return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls } - const iconPrefixCls = computed(() => props?.iconPrefixCls ?? defaultIconPrefixCls) - const shouldWrapSSR = computed(() => iconPrefixCls.value !== defaultIconPrefixCls) + const iconPrefixCls = computed( + () => props?.iconPrefixCls ?? defaultIconPrefixCls + ) + const shouldWrapSSR = computed( + () => iconPrefixCls.value !== defaultIconPrefixCls + ) const csp = computed(() => props?.csp) const componentSize = computed(() => props?.componentSize) const componentDisabled = computed(() => props?.componentDisabled) @@ -103,7 +123,8 @@ const configState = (props: ConfigProviderProps) => { direction } } -const [useProviderConfigProvide, useProviderConfigInject] = createInjectionState(configState) +const [useProviderConfigProvide, useProviderConfigInject] = + createInjectionState(configState) export { useProviderConfigProvide } export const useProviderConfigState = (): ReturnType => { @@ -115,7 +136,7 @@ export const useProviderConfigState = (): ReturnType => { componentSize: computed(() => undefined), componentDisabled: computed(() => false), direction: computed(() => undefined), - autoInsertSpaceInButton: computed(() => undefined) + autoInsertSpaceInButton: computed(() => true) } as any) ) }