mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-02 09:08:52 +08:00
* feat: added status prop to set color by states test: check status success, warning and error * docs: added playground example and API reference fix: replaced ´_´ as it's not recommended to use fix: removed redundant return refactor: renamed prop from status to type test: update test with the renamed prop * docs: update prop references from status to type fix: status prop not updated to type fix: missing return * fix(select): set icons and hover state to follow the theme * test(slider): update snapshots * chore: always use relative paths when import types Co-authored-by: unix <unix.bio@gmail.com>
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import React, { ReactNode } from 'react'
|
|
import { NormalSizes } from '../utils/prop-types'
|
|
import ButtonIcon from './button-icon'
|
|
import { ButtonProps } from './button'
|
|
import { ButtonGroupConfig } from '../button-group/button-group-context'
|
|
|
|
export const getButtonChildrenWithIcon = (
|
|
auto: boolean,
|
|
size: NormalSizes,
|
|
children: ReactNode,
|
|
icons: {
|
|
icon?: React.ReactNode
|
|
iconRight?: React.ReactNode
|
|
},
|
|
) => {
|
|
const { icon, iconRight } = icons
|
|
const hasIcon = icon || iconRight
|
|
const isRight = Boolean(iconRight)
|
|
const paddingForAutoMode =
|
|
auto || size === 'mini'
|
|
? `calc(var(--geist-ui-button-height) / 2 + var(--geist-ui-button-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 = (
|
|
props: React.PropsWithChildren<ButtonProps>,
|
|
config: ButtonGroupConfig,
|
|
): ButtonProps => {
|
|
if (!config.isButtonGroup) return props
|
|
return {
|
|
...props,
|
|
auto: true,
|
|
shadow: false,
|
|
ghost: config.ghost || props.ghost,
|
|
size: config.size || props.size,
|
|
type: config.type || props.type,
|
|
disabled: config.disabled || props.disabled,
|
|
}
|
|
}
|