2022-05-09 22:20:07 +08:00
|
|
|
import type { CSSInterpolation, CSSObject } from '@ant-design/cssinjs';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2023-08-28 21:42:39 +08:00
|
|
|
|
2022-09-09 10:53:03 +08:00
|
|
|
import { genFocusStyle } from '../../style';
|
2024-01-12 15:03:03 +08:00
|
|
|
import type { GenerateStyle } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2023-04-11 11:37:31 +08:00
|
|
|
import genGroupStyle from './group';
|
2024-01-12 15:03:03 +08:00
|
|
|
import type { ButtonToken, ComponentToken } from './token';
|
|
|
|
import { prepareComponentToken, prepareToken } from './token';
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2024-01-12 15:03:03 +08:00
|
|
|
export type { ComponentToken };
|
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-08-08 14:03:31 +08:00
|
|
|
const { componentCls, iconCls, fontWeight } = 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-08-08 14:03:31 +08:00
|
|
|
fontWeight,
|
2022-03-24 18:44:42 +08:00
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
textAlign: 'center',
|
|
|
|
backgroundImage: 'none',
|
2023-12-01 23:25:46 +08:00
|
|
|
background: 'transparent',
|
2023-11-06 10:31:51 +08:00
|
|
|
border: `${unit(token.lineWidth)} ${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',
|
|
|
|
color: token.colorText,
|
|
|
|
|
2023-06-12 10:22:32 +08:00
|
|
|
'&:disabled > *': {
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
'> 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-05-22 13:37:41 +08:00
|
|
|
[`> ${iconCls} + span, > span + ${iconCls}`]: {
|
|
|
|
marginInlineStart: token.marginXS,
|
|
|
|
},
|
|
|
|
|
2023-04-11 11:37:31 +08:00
|
|
|
[`&:not(${componentCls}-icon-only) > ${componentCls}-icon`]: {
|
|
|
|
[`&${componentCls}-loading-icon, &:not(:last-child)`]: {
|
|
|
|
marginInlineEnd: 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
|
|
|
|
2023-09-27 20:17:40 +08:00
|
|
|
[`&${componentCls}-two-chinese-chars::first-letter`]: {
|
|
|
|
letterSpacing: '0.34em',
|
|
|
|
},
|
|
|
|
|
|
|
|
[`&${componentCls}-two-chinese-chars > *:not(${iconCls})`]: {
|
|
|
|
marginInlineEnd: '-0.34em',
|
|
|
|
letterSpacing: '0.34em',
|
|
|
|
},
|
|
|
|
|
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',
|
|
|
|
},
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2023-06-30 14:19:06 +08:00
|
|
|
const genHoverActiveButtonStyle = (
|
|
|
|
btnCls: string,
|
|
|
|
hoverStyle: CSSObject,
|
|
|
|
activeStyle: CSSObject,
|
|
|
|
): CSSObject => ({
|
|
|
|
[`&:not(:disabled):not(${btnCls}-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,
|
2023-11-06 10:31:51 +08:00
|
|
|
paddingInlineStart: token.calc(token.controlHeight).div(2).equal(),
|
|
|
|
paddingInlineEnd: token.calc(token.controlHeight).div(2).equal(),
|
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',
|
2023-08-08 14:03:31 +08:00
|
|
|
borderColor: token.borderColorDisabled,
|
2022-12-17 15:48:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorBgContainerDisabled,
|
2022-12-17 15:48:29 +08:00
|
|
|
boxShadow: 'none',
|
|
|
|
});
|
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
const genGhostButtonStyle = (
|
2022-03-24 18:44:42 +08:00
|
|
|
btnCls: string,
|
2023-08-08 14:03:31 +08:00
|
|
|
background: 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,
|
2023-12-01 23:25:46 +08:00
|
|
|
background,
|
2022-02-18 14:17:32 +08:00
|
|
|
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(
|
2023-06-30 14:19:06 +08:00
|
|
|
btnCls,
|
2022-09-27 14:40:31 +08:00
|
|
|
{
|
2023-12-01 23:25:46 +08:00
|
|
|
background,
|
2022-09-27 14:40:31 +08:00
|
|
|
...hoverStyle,
|
|
|
|
},
|
|
|
|
{
|
2023-12-01 23:25:46 +08:00
|
|
|
background,
|
2022-09-27 14:40:31 +08:00
|
|
|
...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) => ({
|
2023-06-30 14:19:06 +08:00
|
|
|
[`&:disabled, &${token.componentCls}-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) => ({
|
2023-06-30 14:19:06 +08:00
|
|
|
[`&:disabled, &${token.componentCls}-disabled`]: {
|
2022-02-18 14:17:32 +08:00
|
|
|
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),
|
|
|
|
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.defaultBg,
|
2023-08-08 14:03:31 +08:00
|
|
|
borderColor: token.defaultBorderColor,
|
|
|
|
color: token.defaultColor,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2023-08-08 14:03:31 +08:00
|
|
|
boxShadow: token.defaultShadow,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
{
|
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,
|
2023-08-08 14:03:31 +08:00
|
|
|
token.ghostBg,
|
|
|
|
token.defaultGhostColor,
|
|
|
|
token.defaultGhostBorderColor,
|
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(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
{
|
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,
|
2023-08-08 14:03:31 +08:00
|
|
|
token.ghostBg,
|
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),
|
|
|
|
|
2023-08-08 14:03:31 +08:00
|
|
|
color: token.primaryColor,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorPrimary,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2023-08-08 14:03:31 +08:00
|
|
|
boxShadow: token.primaryShadow,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorTextLightSolid,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorPrimaryHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorTextLightSolid,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorPrimaryActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genGhostButtonStyle(
|
2022-04-02 22:55:02 +08:00
|
|
|
token.componentCls,
|
2023-08-08 14:03:31 +08:00
|
|
|
token.ghostBg,
|
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`]: {
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorError,
|
2023-08-08 14:03:31 +08:00
|
|
|
boxShadow: token.dangerShadow,
|
|
|
|
color: token.dangerColor,
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
...genHoverActiveButtonStyle(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
{
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorErrorHover,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
{
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorErrorActive,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...genGhostButtonStyle(
|
2022-04-02 22:55:02 +08:00
|
|
|
token.componentCls,
|
2023-08-08 14:03:31 +08:00
|
|
|
token.ghostBg,
|
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(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
{
|
2022-03-24 14:30:48 +08:00
|
|
|
color: token.colorLinkHover,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.linkHoverBg,
|
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(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
{
|
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(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-03-24 18:44:42 +08:00
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorText,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.textHoverBg,
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
{
|
2022-08-29 20:03:09 +08:00
|
|
|
color: token.colorText,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorBgTextActive,
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
),
|
|
|
|
|
|
|
|
...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(
|
2023-06-30 14:19:06 +08:00
|
|
|
token.componentCls,
|
2022-08-29 20:03:09 +08:00
|
|
|
{
|
2022-09-20 21:50:36 +08:00
|
|
|
color: token.colorErrorHover,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: token.colorErrorBg,
|
2022-08-29 20:03:09 +08:00
|
|
|
},
|
|
|
|
{
|
2022-09-20 21:50:36 +08:00
|
|
|
color: token.colorErrorHover,
|
2023-12-01 23:25:46 +08:00
|
|
|
background: 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-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),
|
2023-07-14 17:05:59 +08:00
|
|
|
[`${componentCls}-ghost`]: genGhostButtonStyle(
|
|
|
|
token.componentCls,
|
2023-08-08 14:03:31 +08:00
|
|
|
token.ghostBg,
|
2023-07-14 17:05:59 +08:00
|
|
|
token.colorBgContainer,
|
|
|
|
token.colorBgContainer,
|
|
|
|
token.colorTextDisabled,
|
|
|
|
token.colorBorder,
|
|
|
|
),
|
2022-02-18 14:17:32 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
// =============================== Size ===============================
|
2024-01-23 10:20:57 +08:00
|
|
|
const genButtonStyle = (token: ButtonToken, prefixCls: string = ''): CSSInterpolation => {
|
2023-01-06 09:46:00 +08:00
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
controlHeight,
|
|
|
|
fontSize,
|
2024-01-12 15:03:03 +08:00
|
|
|
lineHeight,
|
2023-01-06 09:46:00 +08:00
|
|
|
borderRadius,
|
|
|
|
buttonPaddingHorizontal,
|
2023-04-11 11:37:31 +08:00
|
|
|
iconCls,
|
2023-11-06 10:31:51 +08:00
|
|
|
buttonPaddingVertical,
|
2023-01-06 09:46:00 +08:00
|
|
|
} = token;
|
|
|
|
|
2022-04-02 22:55:02 +08:00
|
|
|
const iconOnlyCls = `${componentCls}-icon-only`;
|
2022-02-18 14:17:32 +08:00
|
|
|
|
|
|
|
return [
|
2022-03-24 18:44:42 +08:00
|
|
|
{
|
2024-01-23 10:20:57 +08:00
|
|
|
[`${prefixCls}`]: {
|
2023-01-06 09:46:00 +08:00
|
|
|
fontSize,
|
2024-01-12 15:03:03 +08:00
|
|
|
lineHeight,
|
2023-01-06 09:46:00 +08:00
|
|
|
height: controlHeight,
|
2023-11-06 10:31:51 +08:00
|
|
|
padding: `${unit(buttonPaddingVertical!)} ${unit(buttonPaddingHorizontal!)}`,
|
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
|
|
|
{
|
2024-01-23 10:20:57 +08:00
|
|
|
[`${componentCls}${componentCls}-circle${prefixCls}`]: genCircleButtonStyle(token),
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
|
|
|
{
|
2024-01-23 10:20:57 +08:00
|
|
|
[`${componentCls}${componentCls}-round${prefixCls}`]: genRoundButtonStyle(token),
|
2022-03-24 18:44:42 +08:00
|
|
|
},
|
2022-02-18 14:17:32 +08:00
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-01-23 10:20:57 +08:00
|
|
|
const genSizeBaseButtonStyle: GenerateStyle<ButtonToken> = (token) => {
|
|
|
|
const baseToken = mergeToken<ButtonToken>(token, {
|
|
|
|
fontSize: token.contentFontSize,
|
|
|
|
lineHeight: token.contentLineHeight,
|
|
|
|
});
|
|
|
|
return genButtonStyle(baseToken, token.componentCls);
|
|
|
|
};
|
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,
|
2023-08-17 13:51:39 +08:00
|
|
|
fontSize: token.contentFontSizeSM,
|
2024-01-12 15:03:03 +08:00
|
|
|
lineHeight: token.contentLineHeightSM,
|
2022-02-18 14:17:32 +08:00
|
|
|
padding: token.paddingXS,
|
2023-11-06 10:31:51 +08:00
|
|
|
buttonPaddingHorizontal: token.paddingInlineSM,
|
|
|
|
buttonPaddingVertical: token.paddingBlockSM,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusSM,
|
2023-08-08 14:03:31 +08:00
|
|
|
buttonIconOnlyFontSize: token.onlyIconSizeSM,
|
2022-04-01 17:00:12 +08:00
|
|
|
});
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2024-01-23 10:20:57 +08:00
|
|
|
return genButtonStyle(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,
|
2023-08-17 13:51:39 +08:00
|
|
|
fontSize: token.contentFontSizeLG,
|
2024-01-12 15:03:03 +08:00
|
|
|
lineHeight: token.contentLineHeightLG,
|
2023-08-08 14:03:31 +08:00
|
|
|
buttonPaddingHorizontal: token.paddingInlineLG,
|
2023-11-06 10:31:51 +08:00
|
|
|
buttonPaddingVertical: token.paddingBlockLG,
|
2022-11-01 15:06:38 +08:00
|
|
|
borderRadius: token.borderRadiusLG,
|
2023-08-08 14:03:31 +08:00
|
|
|
buttonIconOnlyFontSize: token.onlyIconSizeLG,
|
2022-04-01 17:00:12 +08:00
|
|
|
});
|
2022-02-18 14:17:32 +08:00
|
|
|
|
2024-01-23 10:20:57 +08:00
|
|
|
return genButtonStyle(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-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks(
|
2023-08-08 14:03:31 +08:00
|
|
|
'Button',
|
|
|
|
(token) => {
|
2023-08-28 21:56:37 +08:00
|
|
|
const buttonToken = prepareToken(token);
|
2023-08-08 14:03:31 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
// Shared
|
|
|
|
genSharedButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Size
|
|
|
|
genSizeBaseButtonStyle(buttonToken),
|
2024-01-23 10:20:57 +08:00
|
|
|
genSizeSmallButtonStyle(buttonToken),
|
2023-08-08 14:03:31 +08:00
|
|
|
genSizeLargeButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Block
|
|
|
|
genBlockButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Group (type, ghost, danger, loading)
|
|
|
|
genTypeButtonStyle(buttonToken),
|
|
|
|
|
|
|
|
// Button Group
|
|
|
|
genGroupStyle(buttonToken),
|
|
|
|
];
|
|
|
|
},
|
2023-08-28 21:56:37 +08:00
|
|
|
prepareComponentToken,
|
2023-11-29 17:23:45 +08:00
|
|
|
{
|
|
|
|
unitless: {
|
|
|
|
fontWeight: true,
|
2024-01-12 15:03:03 +08:00
|
|
|
contentLineHeight: true,
|
|
|
|
contentLineHeightSM: true,
|
|
|
|
contentLineHeightLG: true,
|
2023-11-29 17:23:45 +08:00
|
|
|
},
|
|
|
|
},
|
2023-08-08 14:03:31 +08:00
|
|
|
);
|