2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2022-09-09 10:53:03 +08:00
|
|
|
import { genFocusStyle } from '../../style';
|
2022-10-28 16:09:38 +08:00
|
|
|
import { genCompactItemStyle } from '../../style/compact-item';
|
|
|
|
import { genCompactItemVerticalStyle } from '../../style/compact-item-vertical';
|
2023-04-11 11:37:31 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme/internal';
|
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme/internal';
|
|
|
|
import genGroupStyle from './group';
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
2023-05-04 13:39:38 +08:00
|
|
|
export interface ComponentToken {
|
|
|
|
buttonFontWeight: number;
|
|
|
|
}
|
2022-06-24 11:11:42 +08:00
|
|
|
|
|
|
|
export interface ButtonToken extends FullToken<'Button'> {
|
2022-06-17 18:47:47 +08:00
|
|
|
colorOutlineDefault: string;
|
2022-10-25 17:04:36 +08:00
|
|
|
buttonPaddingHorizontal: number;
|
2023-04-11 11:37:31 +08:00
|
|
|
buttonIconOnlyFontSize: number;
|
2022-03-24 18:44:42 +08:00
|
|
|
}
|
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
// ============================== Shared ==============================
|
2022-03-24 18:44:42 +08:00
|
|
|
const genSharedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token): CSSObject => {
|
2023-05-04 13:39:38 +08:00
|
|
|
const { componentCls, iconCls, buttonFontWeight } = token;
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
return {
|
2022-04-02 22:55:02 +08:00
|
|
|
[componentCls]: {
|
2022-03-24 18:44:42 +08:00
|
|
|
outline: 'none',
|
|
|
|
position: 'relative',
|
|
|
|
display: 'inline-block',
|
2023-05-04 13:39:38 +08:00
|
|
|
fontWeight: buttonFontWeight,
|
2022-03-24 18:44:42 +08:00
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textAlign: 'center',
|
|
|
|
backgroundImage: 'none',
|
|
|
|
backgroundColor: 'transparent',
|
2022-11-01 15:06:38 +08:00
|
|
|
border: `${token.lineWidth}px ${token.lineType} transparent`,
|
2022-03-24 18:44:42 +08:00
|
|
|
cursor: 'pointer',
|
2022-11-17 23:31:41 +08:00
|
|
|
transition: `all ${token.motionDurationMid} ${token.motionEaseInOut}`,
|
2022-03-24 18:44:42 +08:00
|
|
|
userSelect: 'none',
|
|
|
|
touchAction: 'manipulation',
|
|
|
|
lineHeight: token.lineHeight,
|
|
|
|
color: token.colorText,
|
|
|
|
|
|
|
|
'> span': {
|
|
|
|
display: 'inline-block',
|
|
|
|
},
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2023-04-11 11:37:31 +08:00
|
|
|
[`${componentCls}-icon`]: {
|
|
|
|
lineHeight: 0,
|
|
|
|
},
|
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
// Leave a space between icon and text.
|
2023-04-11 11:37:31 +08:00
|
|
|
[`&:not(${componentCls}-icon-only) > ${componentCls}-icon`]: {
|
|
|
|
[`&${componentCls}-loading-icon, &:not(:last-child)`]: {
|
|
|
|
marginInlineEnd: token.marginXS,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Special case for anticon after children
|
|
|
|
[`> span + ${iconCls}`]: {
|
2022-03-24 18:44:42 +08:00
|
|
|
marginInlineStart: token.marginXS,
|
|
|
|
},
|
|
|
|
|
2023-01-17 10:04:12 +08:00
|
|
|
'> a': {
|
|
|
|
color: 'currentColor',
|
|
|
|
},
|
|
|
|
|
2022-09-09 10:53:03 +08:00
|
|
|
'&:not(:disabled)': {
|
|
|
|
...genFocusStyle(token),
|
|
|
|
},
|
2022-10-28 16:09:38 +08:00
|
|
|
|
|
|
|
// make `btn-icon-only` not too narrow
|
2023-01-20 10:31:27 +08:00
|
|
|
[`&-icon-only${componentCls}-compact-item`]: {
|
2022-10-28 16:09:38 +08:00
|
|
|
flex: 'none',
|
|
|
|
},
|
|
|
|
// Special styles for Primary Button
|
|
|
|
[`&-compact-item${componentCls}-primary`]: {
|
2023-01-20 10:31:27 +08:00
|
|
|
[`&:not([disabled]) + ${componentCls}-compact-item${componentCls}-primary:not([disabled])`]:
|
|
|
|
{
|
2022-10-28 16:09:38 +08:00
|
|
|
position: 'relative',
|
|
|
|
|
2022-12-05 17:26:32 +08:00
|
|
|
'&:before': {
|
2022-10-28 16:09:38 +08:00
|
|
|
position: 'absolute',
|
2022-11-01 15:06:38 +08:00
|
|
|
top: -token.lineWidth,
|
|
|
|
insetInlineStart: -token.lineWidth,
|
2022-10-28 16:09:38 +08:00
|
|
|
display: 'inline-block',
|
2023-01-20 10:31:27 +08:00
|
|
|
width: token.lineWidth,
|
|
|
|
height: `calc(100% + ${token.lineWidth * 2}px)`,
|
2022-12-07 17:11:25 +08:00
|
|
|
backgroundColor: token.colorPrimaryHover,
|
2022-10-28 16:09:38 +08:00
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2023-01-20 10:31:27 +08:00
|
|
|
},
|
|
|
|
// Special styles for Primary Button
|
|
|
|
'&-compact-vertical-item': {
|
|
|
|
[`&${componentCls}-primary`]: {
|
|
|
|
[`&:not([disabled]) + ${componentCls}-compact-vertical-item${componentCls}-primary:not([disabled])`]:
|
|
|
|
{
|
|
|
|
position: 'relative',
|
|
|
|
|
|
|
|
'&:before': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: -token.lineWidth,
|
|
|
|
insetInlineStart: -token.lineWidth,
|
|
|
|
display: 'inline-block',
|
|
|
|
width: `calc(100% + ${token.lineWidth * 2}px)`,
|
|
|
|
height: token.lineWidth,
|
|
|
|
backgroundColor: token.colorPrimaryHover,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-10-28 16:09:38 +08:00
|
|
|
},
|
|
|
|
},
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
const genHoverActiveButtonStyle = (hoverStyle: CSSObject, activeStyle: CSSObject): CSSObject => ({
|
|
|
|
'&:not(:disabled)': {
|
2022-09-09 10:53:03 +08:00
|
|
|
'&:hover': hoverStyle,
|
2022-02-18 14:17:32 +08:00
|
|
|
'&:active': activeStyle,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// ============================== Shape ===============================
|
2022-11-17 23:31:41 +08:00
|
|
|
const genCircleButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-03-08 10:29:00 +08:00
|
|
|
minWidth: token.controlHeight,
|
2022-03-11 17:07:16 +08:00
|
|
|
paddingInlineStart: 0,
|
|
|
|
paddingInlineEnd: 0,
|
2022-02-18 14:17:32 +08:00
|
|
|
borderRadius: '50%',
|
|
|
|
});
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genRoundButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-03-08 10:29:00 +08:00
|
|
|
borderRadius: token.controlHeight,
|
2022-03-11 17:07:16 +08:00
|
|
|
paddingInlineStart: token.controlHeight / 2,
|
|
|
|
paddingInlineEnd: token.controlHeight / 2,
|
2022-02-18 14:17:32 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// =============================== Type ===============================
|
2022-12-17 15:48:29 +08:00
|
|
|
const genDisabledStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
borderColor: token.colorBorder,
|
|
|
|
color: token.colorTextDisabled,
|
|
|
|
backgroundColor: token.colorBgContainerDisabled,
|
|
|
|
boxShadow: 'none',
|
|
|
|
});
|
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
const genGhostButtonStyle = (
|
2022-03-24 18:44:42 +08:00
|
|
|
btnCls: string,
|
2022-02-18 14:17:32 +08:00
|
|
|
textColor: string | false,
|
|
|
|
borderColor: string | false,
|
|
|
|
textColorDisabled: string | false,
|
|
|
|
borderColorDisabled: string | false,
|
2022-09-27 14:40:31 +08:00
|
|
|
hoverStyle?: CSSObject,
|
|
|
|
activeStyle?: CSSObject,
|
2022-02-18 14:17:32 +08:00
|
|
|
): CSSObject => ({
|
2022-03-24 18:44:42 +08:00
|
|
|
[`&${btnCls}-background-ghost`]: {
|
2022-02-18 14:17:32 +08:00
|
|
|
color: textColor || undefined,
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
borderColor: borderColor || undefined,
|
2022-03-24 18:44:42 +08:00
|
|
|
boxShadow: 'none',
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-09-27 14:40:31 +08:00
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
...hoverStyle,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
...activeStyle,
|
|
|
|
},
|
|
|
|
),
|
2022-06-17 18:47:47 +08:00
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
'&:disabled': {
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
color: textColorDisabled || undefined,
|
|
|
|
borderColor: borderColorDisabled || undefined,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSolidDisabledButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-02-18 14:17:32 +08:00
|
|
|
'&:disabled': {
|
2022-12-17 15:48:29 +08:00
|
|
|
...genDisabledStyle(token),
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSolidButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-02-18 14:17:32 +08:00
|
|
|
...genSolidDisabledButtonStyle(token),
|
|
|
|
});
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genPureDisabledButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-02-18 14:17:32 +08:00
|
|
|
'&:disabled': {
|
|
|
|
cursor: 'not-allowed',
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Type: Default
|
2022-11-17 23:31:41 +08:00
|
|
|
const genDefaultButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-02-18 14:17:32 +08:00
|
|
|
...genSolidButtonStyle(token),
|
|
|
|
|
2022-06-28 20:33:01 +08:00
|
|
|
backgroundColor: token.colorBgContainer,
|
2022-03-22 13:26:29 +08:00
|
|
|
borderColor: token.colorBorder,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-06-29 21:24:29 +08:00
|
|
|
boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlTmpOutline}`,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorPrimaryHover,
|
|
|
|
borderColor: token.colorPrimaryHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorPrimaryActive,
|
|
|
|
borderColor: token.colorPrimaryActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genGhostButtonStyle(
|
2022-04-02 22:55:02 +08:00
|
|
|
token.componentCls,
|
2022-06-28 20:33:01 +08:00
|
|
|
token.colorBgContainer,
|
|
|
|
token.colorBgContainer,
|
2022-03-22 13:26:29 +08:00
|
|
|
token.colorTextDisabled,
|
|
|
|
token.colorBorder,
|
2022-02-18 14:17:32 +08:00
|
|
|
),
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
[`&${token.componentCls}-dangerous`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorError,
|
|
|
|
borderColor: token.colorError,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorErrorHover,
|
2022-11-25 11:43:33 +08:00
|
|
|
borderColor: token.colorErrorBorderHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorErrorActive,
|
|
|
|
borderColor: token.colorErrorActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genGhostButtonStyle(
|
2022-04-02 22:55:02 +08:00
|
|
|
token.componentCls,
|
2022-03-22 09:37:37 +08:00
|
|
|
token.colorError,
|
|
|
|
token.colorError,
|
2022-03-22 13:26:29 +08:00
|
|
|
token.colorTextDisabled,
|
|
|
|
token.colorBorder,
|
2022-02-18 14:17:32 +08:00
|
|
|
),
|
|
|
|
...genSolidDisabledButtonStyle(token),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Type: Primary
|
2022-11-17 23:31:41 +08:00
|
|
|
const genPrimaryButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-02-18 14:17:32 +08:00
|
|
|
...genSolidButtonStyle(token),
|
|
|
|
|
2022-07-05 10:35:44 +08:00
|
|
|
color: token.colorTextLightSolid,
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorPrimary,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-07-21 17:00:42 +08:00
|
|
|
boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.controlOutline}`,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorTextLightSolid,
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.colorPrimaryHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorTextLightSolid,
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.colorPrimaryActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genGhostButtonStyle(
|
2022-04-02 22:55:02 +08:00
|
|
|
token.componentCls,
|
2022-03-22 09:37:37 +08:00
|
|
|
token.colorPrimary,
|
|
|
|
token.colorPrimary,
|
2022-03-22 13:26:29 +08:00
|
|
|
token.colorTextDisabled,
|
|
|
|
token.colorBorder,
|
2022-09-27 14:40:31 +08:00
|
|
|
{
|
|
|
|
color: token.colorPrimaryHover,
|
|
|
|
borderColor: token.colorPrimaryHover,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: token.colorPrimaryActive,
|
|
|
|
borderColor: token.colorPrimaryActive,
|
|
|
|
},
|
2022-02-18 14:17:32 +08:00
|
|
|
),
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
[`&${token.componentCls}-dangerous`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorError,
|
2022-03-24 18:44:42 +08:00
|
|
|
boxShadow: `0 ${token.controlOutlineWidth}px 0 ${token.colorErrorOutline}`,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.colorErrorHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
backgroundColor: token.colorErrorActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genGhostButtonStyle(
|
2022-04-02 22:55:02 +08:00
|
|
|
token.componentCls,
|
2022-03-22 09:37:37 +08:00
|
|
|
token.colorError,
|
|
|
|
token.colorError,
|
2022-03-22 13:26:29 +08:00
|
|
|
token.colorTextDisabled,
|
|
|
|
token.colorBorder,
|
2022-09-27 14:40:31 +08:00
|
|
|
{
|
|
|
|
color: token.colorErrorHover,
|
|
|
|
borderColor: token.colorErrorHover,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: token.colorErrorActive,
|
|
|
|
borderColor: token.colorErrorActive,
|
|
|
|
},
|
2022-02-18 14:17:32 +08:00
|
|
|
),
|
|
|
|
...genSolidDisabledButtonStyle(token),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Type: Dashed
|
2022-11-17 23:31:41 +08:00
|
|
|
const genDashedButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-03-24 18:44:42 +08:00
|
|
|
...genDefaultButtonStyle(token),
|
2022-02-18 14:17:32 +08:00
|
|
|
borderStyle: 'dashed',
|
|
|
|
});
|
|
|
|
|
|
|
|
// Type: Link
|
2022-11-17 23:31:41 +08:00
|
|
|
const genLinkButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-03-24 14:30:48 +08:00
|
|
|
color: token.colorLink,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-03-24 14:30:48 +08:00
|
|
|
color: token.colorLinkHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-03-24 14:30:48 +08:00
|
|
|
color: token.colorLinkActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genPureDisabledButtonStyle(token),
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
[`&${token.componentCls}-dangerous`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
color: token.colorError,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorErrorHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-03-22 20:02:04 +08:00
|
|
|
color: token.colorErrorActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genPureDisabledButtonStyle(token),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// Type: Text
|
2022-11-17 23:31:41 +08:00
|
|
|
const genTextButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
2022-03-24 18:44:42 +08:00
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorText,
|
2022-03-24 18:44:42 +08:00
|
|
|
backgroundColor: token.colorBgTextHover,
|
|
|
|
},
|
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorText,
|
2022-03-24 18:44:42 +08:00
|
|
|
backgroundColor: token.colorBgTextActive,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genPureDisabledButtonStyle(token),
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
[`&${token.componentCls}-dangerous`]: {
|
2022-03-24 18:44:42 +08:00
|
|
|
color: token.colorError,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genPureDisabledButtonStyle(token),
|
2022-08-29 20:03:09 +08:00
|
|
|
...genHoverActiveButtonStyle(
|
|
|
|
{
|
2022-09-20 21:50:36 +08:00
|
|
|
color: token.colorErrorHover,
|
|
|
|
backgroundColor: token.colorErrorBg,
|
2022-08-29 20:03:09 +08:00
|
|
|
},
|
|
|
|
{
|
2022-09-20 21:50:36 +08:00
|
|
|
color: token.colorErrorHover,
|
|
|
|
backgroundColor: token.colorErrorBg,
|
2022-08-29 20:03:09 +08:00
|
|
|
},
|
|
|
|
),
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
});
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-12-17 15:48:29 +08:00
|
|
|
// Href and Disabled
|
|
|
|
const genDisabledButtonStyle: GenerateStyle<ButtonToken, CSSObject> = (token) => ({
|
|
|
|
...genDisabledStyle(token),
|
|
|
|
[`&${token.componentCls}:hover`]: {
|
|
|
|
...genDisabledStyle(token),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genTypeButtonStyle: GenerateStyle<ButtonToken> = (token) => {
|
2022-04-02 22:55:02 +08:00
|
|
|
const { componentCls } = token;
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
return {
|
2022-04-02 22:55:02 +08:00
|
|
|
[`${componentCls}-default`]: genDefaultButtonStyle(token),
|
|
|
|
[`${componentCls}-primary`]: genPrimaryButtonStyle(token),
|
|
|
|
[`${componentCls}-dashed`]: genDashedButtonStyle(token),
|
|
|
|
[`${componentCls}-link`]: genLinkButtonStyle(token),
|
|
|
|
[`${componentCls}-text`]: genTextButtonStyle(token),
|
2022-12-17 15:48:29 +08:00
|
|
|
[`${componentCls}-disabled`]: genDisabledButtonStyle(token),
|
2022-02-18 14:17:32 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// =============================== Size ===============================
|
2022-03-24 18:44:42 +08:00
|
|
|
const genSizeButtonStyle = (token: ButtonToken, sizePrefixCls: string = ''): CSSInterpolation => {
|
2023-01-06 09:46:00 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
controlHeight,
|
|
|
|
fontSize,
|
|
|
|
lineHeight,
|
|
|
|
lineWidth,
|
|
|
|
borderRadius,
|
|
|
|
buttonPaddingHorizontal,
|
2023-04-11 11:37:31 +08:00
|
|
|
iconCls,
|
2023-01-06 09:46:00 +08:00
|
|
|
} = token;
|
|
|
|
|
|
|
|
const paddingVertical = Math.max(0, (controlHeight - fontSize * lineHeight) / 2 - lineWidth);
|
|
|
|
const paddingHorizontal = buttonPaddingHorizontal - lineWidth;
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
const iconOnlyCls = `${componentCls}-icon-only`;
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
// Size
|
2022-03-24 18:44:42 +08:00
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
[`${componentCls}${sizePrefixCls}`]: {
|
2023-01-06 09:46:00 +08:00
|
|
|
fontSize,
|
|
|
|
height: controlHeight,
|
2022-02-18 14:17:32 +08:00
|
|
|
padding: `${paddingVertical}px ${paddingHorizontal}px`,
|
2023-01-06 09:46:00 +08:00
|
|
|
borderRadius,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
[`&${iconOnlyCls}`]: {
|
2023-01-06 09:46:00 +08:00
|
|
|
width: controlHeight,
|
2022-03-11 17:07:16 +08:00
|
|
|
paddingInlineStart: 0,
|
|
|
|
paddingInlineEnd: 0,
|
2023-01-06 09:46:00 +08:00
|
|
|
[`&${componentCls}-round`]: {
|
|
|
|
width: 'auto',
|
|
|
|
},
|
2023-04-11 11:37:31 +08:00
|
|
|
[iconCls]: {
|
|
|
|
fontSize: token.buttonIconOnlyFontSize,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Loading
|
2022-04-02 22:55:02 +08:00
|
|
|
[`&${componentCls}-loading`]: {
|
2022-06-17 18:47:47 +08:00
|
|
|
opacity: token.opacityLoading,
|
2022-02-18 14:17:32 +08:00
|
|
|
cursor: 'default',
|
|
|
|
},
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
[`${componentCls}-loading-icon`]: {
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `width ${token.motionDurationSlow} ${token.motionEaseInOut}, opacity ${token.motionDurationSlow} ${token.motionEaseInOut}`,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
},
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
// Shape - patch prefixCls again to override solid border radius style
|
2022-03-24 18:44:42 +08:00
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
[`${componentCls}${componentCls}-circle${sizePrefixCls}`]: genCircleButtonStyle(token),
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
{
|
2022-04-02 22:55:02 +08:00
|
|
|
[`${componentCls}${componentCls}-round${sizePrefixCls}`]: genRoundButtonStyle(token),
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
2022-02-18 14:17:32 +08:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSizeBaseButtonStyle: GenerateStyle<ButtonToken> = (token) => genSizeButtonStyle(token);
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSizeSmallButtonStyle: GenerateStyle<ButtonToken> = (token) => {
|
2022-08-19 10:10:51 +08:00
|
|
|
const smallToken = mergeToken<ButtonToken>(token, {
|
2022-03-08 10:29:00 +08:00
|
|
|
controlHeight: token.controlHeightSM,
|
2022-02-18 14:17:32 +08:00
|
|
|
padding: token.paddingXS,
|
2022-10-25 17:04:36 +08:00
|
|
|
buttonPaddingHorizontal: 8, // Fixed padding
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
2023-04-11 11:37:31 +08:00
|
|
|
buttonIconOnlyFontSize: token.fontSizeLG - 2,
|
2022-04-01 17:00:12 +08:00
|
|
|
});
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-08-19 10:10:51 +08:00
|
|
|
return genSizeButtonStyle(smallToken, `${token.componentCls}-sm`);
|
2022-02-18 14:17:32 +08:00
|
|
|
};
|
|
|
|
|
2022-11-17 23:31:41 +08:00
|
|
|
const genSizeLargeButtonStyle: GenerateStyle<ButtonToken> = (token) => {
|
2022-04-01 17:00:12 +08:00
|
|
|
const largeToken = mergeToken<ButtonToken>(token, {
|
2022-03-08 10:29:00 +08:00
|
|
|
controlHeight: token.controlHeightLG,
|
2022-02-18 14:17:32 +08:00
|
|
|
fontSize: token.fontSizeLG,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusLG,
|
2023-04-11 11:37:31 +08:00
|
|
|
buttonIconOnlyFontSize: token.fontSizeLG + 2,
|
2022-04-01 17:00:12 +08:00
|
|
|
});
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
return genSizeButtonStyle(largeToken, `${token.componentCls}-lg`);
|
2022-02-18 14:17:32 +08:00
|
|
|
};
|
|
|
|
|
2022-11-22 23:25:25 +08:00
|
|
|
const genBlockButtonStyle: GenerateStyle<ButtonToken> = (token) => {
|
|
|
|
const { componentCls } = token;
|
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
[`&${componentCls}-block`]: {
|
|
|
|
width: '100%',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
// ============================== Export ==============================
|
2023-05-04 13:39:38 +08:00
|
|
|
export default genComponentStyleHook(
|
|
|
|
'Button',
|
|
|
|
(token) => {
|
|
|
|
const { controlTmpOutline, paddingContentHorizontal } = token;
|
|
|
|
|
|
|
|
const buttonToken = mergeToken<ButtonToken>(token, {
|
|
|
|
colorOutlineDefault: controlTmpOutline,
|
|
|
|
buttonPaddingHorizontal: paddingContentHorizontal,
|
|
|
|
buttonIconOnlyFontSize: token.fontSizeLG,
|
|
|
|
});
|
|
|
|
|
|
|
|
return [
|
|
|
|
// Shared
|
|
|
|
genSharedButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Size
|
|
|
|
genSizeSmallButtonStyle(buttonToken),
|
|
|
|
genSizeBaseButtonStyle(buttonToken),
|
|
|
|
genSizeLargeButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Block
|
|
|
|
genBlockButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Group (type, ghost, danger, disabled, loading)
|
|
|
|
genTypeButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Button Group
|
|
|
|
genGroupStyle(buttonToken),
|
|
|
|
|
|
|
|
// Space Compact
|
|
|
|
genCompactItemStyle(token),
|
|
|
|
genCompactItemVerticalStyle(token),
|
|
|
|
];
|
|
|
|
},
|
|
|
|
{
|
|
|
|
buttonFontWeight: 400,
|
|
|
|
},
|
|
|
|
);
|