mirror of
https://github.com/zhigang1992/react.git
synced 2026-01-30 17:18:35 +08:00
* feat(scaleable): add scaleable props to each component * chore(scaleable): update the exported type * feat: apply scaleable to components chore: remove with-default test: improve testcase for scaleable chore: resolve test warning ci: upgrade nodejs to latest lts docs: fix type error in document site * docs: update documents to be compatible with scaleable chore: fix build errors * chore: remove all size-related attributes docs: improve guide document * docs: add scaleable documentation test: update snapshots chore: remove unused * feat: add scaleable to grid components * docs: improve docs * test: update snapshots * fix(grid): fix basic component props
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import React, { ReactNode } from 'react'
|
|
import ButtonIcon from './button-icon'
|
|
import { ButtonProps } from './button'
|
|
import { ButtonGroupConfig } from '../button-group/button-group-context'
|
|
|
|
export const getButtonChildrenWithIcon = (
|
|
auto: boolean,
|
|
children: ReactNode,
|
|
icons: {
|
|
icon?: React.ReactNode
|
|
iconRight?: React.ReactNode
|
|
},
|
|
) => {
|
|
const { icon, iconRight } = icons
|
|
const hasIcon = icon || iconRight
|
|
const isRight = Boolean(iconRight)
|
|
const paddingForAutoMode = auto
|
|
? `calc(var(--geist-ui-button-height) / 2 + var(--geist-ui-button-icon-padding) * .5)`
|
|
: 0
|
|
if (!hasIcon) return <div className="text">{children}</div>
|
|
if (React.Children.count(children) === 0) {
|
|
return (
|
|
<ButtonIcon isRight={isRight} isSingle>
|
|
{hasIcon}
|
|
</ButtonIcon>
|
|
)
|
|
}
|
|
return (
|
|
<>
|
|
<ButtonIcon isRight={isRight}>{hasIcon}</ButtonIcon>
|
|
<div className={`text ${isRight ? 'right' : 'left'}`}>
|
|
{children}
|
|
<style jsx>{`
|
|
.left {
|
|
padding-left: ${paddingForAutoMode};
|
|
}
|
|
.right {
|
|
padding-right: ${paddingForAutoMode};
|
|
}
|
|
`}</style>
|
|
</div>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const filterPropsWithGroup = <T extends React.PropsWithChildren<ButtonProps>>(
|
|
props: T,
|
|
config: ButtonGroupConfig,
|
|
): T => {
|
|
if (!config.isButtonGroup) return props
|
|
return {
|
|
...props,
|
|
auto: true,
|
|
shadow: false,
|
|
ghost: config.ghost || props.ghost,
|
|
type: config.type || props.type,
|
|
disabled: config.disabled || props.disabled,
|
|
}
|
|
}
|