2023-11-13 20:14:13 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
|
|
|
|
2023-05-19 14:58:40 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2023-11-13 20:14:13 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2024-04-19 17:17:56 +08:00
|
|
|
import { genStyleHooks } from '../../theme/internal';
|
2022-04-24 17:42:36 +08:00
|
|
|
|
|
|
|
export interface ComponentToken {
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 指示点宽度
|
|
|
|
* @descEN Width of indicator
|
|
|
|
*/
|
2024-07-14 00:36:43 +08:00
|
|
|
dotWidth: number | string;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 指示点高度
|
|
|
|
* @descEN Height of indicator
|
|
|
|
*/
|
2024-07-14 00:36:43 +08:00
|
|
|
dotHeight: number | string;
|
2024-04-19 17:17:56 +08:00
|
|
|
/**
|
|
|
|
* @desc 指示点之间的间距
|
|
|
|
* @descEN gap between indicator
|
|
|
|
*/
|
|
|
|
dotGap: number;
|
|
|
|
/**
|
|
|
|
* @desc 指示点距离边缘的距离
|
|
|
|
* @descEN dot offset to Carousel edge
|
|
|
|
*/
|
|
|
|
dotOffset: number;
|
2023-05-19 14:58:40 +08:00
|
|
|
/** @deprecated Use `dotActiveWidth` instead. */
|
2022-05-19 14:00:04 +08:00
|
|
|
dotWidthActive: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
/**
|
|
|
|
* @desc 激活态指示点宽度
|
|
|
|
* @descEN Width of active indicator
|
|
|
|
*/
|
2024-07-14 00:36:43 +08:00
|
|
|
dotActiveWidth: number | string;
|
2024-04-19 17:17:56 +08:00
|
|
|
/**
|
|
|
|
* @desc 切换箭头大小
|
|
|
|
* @descEN Size of arrows
|
|
|
|
*/
|
|
|
|
arrowSize: number;
|
|
|
|
/**
|
|
|
|
* @desc 切换箭头边距
|
|
|
|
* @descEN arrows offset to Carousel edge
|
|
|
|
*/
|
|
|
|
arrowOffset: number;
|
2022-03-26 17:32:36 +08:00
|
|
|
}
|
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
interface CarouselToken extends FullToken<'Carousel'> {}
|
2022-05-19 14:00:04 +08:00
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genCarouselStyle: GenerateStyle<CarouselToken> = (token) => {
|
2024-04-19 17:17:56 +08:00
|
|
|
const { componentCls, antCls } = token;
|
2022-11-07 23:32:46 +08:00
|
|
|
|
2022-03-26 17:32:36 +08:00
|
|
|
return {
|
2022-04-07 17:02:54 +08:00
|
|
|
[componentCls]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
'.slick-slider': {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
touchAction: 'pan-y',
|
|
|
|
WebkitTouchCallout: 'none',
|
|
|
|
WebkitTapHighlightColor: 'transparent',
|
|
|
|
|
|
|
|
'.slick-track, .slick-list': {
|
|
|
|
transform: 'translate3d(0, 0, 0)',
|
|
|
|
touchAction: 'pan-y',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'.slick-list': {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
|
|
|
margin: 0,
|
|
|
|
padding: 0,
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
|
|
|
'&:focus': {
|
|
|
|
outline: 'none',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.dragging': {
|
|
|
|
cursor: 'pointer',
|
|
|
|
},
|
|
|
|
|
|
|
|
'.slick-slide': {
|
|
|
|
pointerEvents: 'none',
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/23294
|
2022-04-07 17:02:54 +08:00
|
|
|
[`input${antCls}-radio-input, input${antCls}-checkbox-input`]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
visibility: 'hidden',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.slick-active': {
|
|
|
|
pointerEvents: 'auto',
|
|
|
|
|
2022-04-07 17:02:54 +08:00
|
|
|
[`input${antCls}-radio-input, input${antCls}-checkbox-input`]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
visibility: 'visible',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// fix Carousel content height not match parent node
|
|
|
|
// when children is empty node
|
|
|
|
// https://github.com/ant-design/ant-design/issues/25878
|
|
|
|
'> div > div': {
|
|
|
|
verticalAlign: 'bottom',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'.slick-track': {
|
|
|
|
position: 'relative',
|
|
|
|
top: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
display: 'block',
|
|
|
|
|
|
|
|
'&::before, &::after': {
|
|
|
|
display: 'table',
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
clear: 'both',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'.slick-slide': {
|
|
|
|
display: 'none',
|
|
|
|
float: 'left',
|
|
|
|
height: '100%',
|
|
|
|
minHeight: 1,
|
|
|
|
|
|
|
|
img: {
|
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
|
|
|
|
'&.dragging img': {
|
|
|
|
pointerEvents: 'none',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
'.slick-initialized .slick-slide': {
|
|
|
|
display: 'block',
|
|
|
|
},
|
|
|
|
|
|
|
|
'.slick-vertical .slick-slide': {
|
|
|
|
display: 'block',
|
|
|
|
height: 'auto',
|
|
|
|
},
|
2024-04-19 17:17:56 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
const genArrowsStyle: GenerateStyle<CarouselToken> = (token) => {
|
|
|
|
const { componentCls, motionDurationSlow, arrowSize, arrowOffset } = token;
|
2024-06-22 21:59:12 +08:00
|
|
|
const arrowLength = token.calc(arrowSize).div(Math.SQRT2).equal();
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
return [
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
// Arrows
|
|
|
|
'.slick-prev, .slick-next': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
|
|
|
width: arrowSize,
|
|
|
|
height: arrowSize,
|
|
|
|
transform: 'translateY(-50%)',
|
|
|
|
color: '#fff',
|
|
|
|
opacity: 0.4,
|
2022-03-26 17:32:36 +08:00
|
|
|
background: 'transparent',
|
2024-04-19 17:17:56 +08:00
|
|
|
padding: 0,
|
|
|
|
lineHeight: 0,
|
|
|
|
border: 0,
|
2022-03-26 17:32:36 +08:00
|
|
|
outline: 'none',
|
2024-04-19 17:17:56 +08:00
|
|
|
cursor: 'pointer',
|
|
|
|
zIndex: 1,
|
|
|
|
transition: `opacity ${motionDurationSlow}`,
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&:hover, &:focus': {
|
2022-03-26 17:32:36 +08:00
|
|
|
opacity: 1,
|
|
|
|
},
|
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&.slick-disabled': {
|
|
|
|
pointerEvents: 'none',
|
|
|
|
opacity: 0,
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&::after': {
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
position: 'absolute',
|
|
|
|
top: token.calc(arrowSize).sub(arrowLength).div(2).equal(),
|
|
|
|
insetInlineStart: token.calc(arrowSize).sub(arrowLength).div(2).equal(),
|
|
|
|
display: 'inline-block',
|
|
|
|
width: arrowLength,
|
|
|
|
height: arrowLength,
|
|
|
|
border: `0 solid currentcolor`,
|
|
|
|
borderInlineWidth: '2px 0',
|
|
|
|
borderBlockWidth: '2px 0',
|
|
|
|
borderRadius: 1,
|
|
|
|
content: '""',
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
},
|
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'.slick-prev': {
|
|
|
|
insetInlineStart: arrowOffset,
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&::after': {
|
|
|
|
transform: 'rotate(-45deg)',
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
},
|
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'.slick-next': {
|
|
|
|
insetInlineEnd: arrowOffset,
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&::after': {
|
|
|
|
transform: 'rotate(135deg)',
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
},
|
2024-04-19 17:17:56 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
const genDotsStyle: GenerateStyle<CarouselToken> = (token) => {
|
|
|
|
const {
|
|
|
|
componentCls,
|
|
|
|
dotOffset,
|
|
|
|
dotWidth,
|
|
|
|
dotHeight,
|
|
|
|
dotGap,
|
|
|
|
colorBgContainer,
|
|
|
|
motionDurationSlow,
|
|
|
|
} = token;
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
[componentCls]: {
|
|
|
|
'.slick-dots': {
|
|
|
|
position: 'absolute',
|
|
|
|
insetInlineEnd: 0,
|
|
|
|
bottom: 0,
|
|
|
|
insetInlineStart: 0,
|
|
|
|
zIndex: 15,
|
|
|
|
display: 'flex !important',
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingInlineStart: 0,
|
|
|
|
margin: 0,
|
|
|
|
listStyle: 'none',
|
|
|
|
|
|
|
|
'&-bottom': {
|
|
|
|
bottom: dotOffset,
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&-top': {
|
|
|
|
top: dotOffset,
|
|
|
|
bottom: 'auto',
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
li: {
|
2022-11-07 23:32:46 +08:00
|
|
|
position: 'relative',
|
2024-04-19 17:17:56 +08:00
|
|
|
display: 'inline-block',
|
|
|
|
flex: '0 1 auto',
|
|
|
|
boxSizing: 'content-box',
|
|
|
|
width: dotWidth,
|
|
|
|
height: dotHeight,
|
|
|
|
marginInline: dotGap,
|
2022-03-26 17:32:36 +08:00
|
|
|
padding: 0,
|
2024-04-19 17:17:56 +08:00
|
|
|
textAlign: 'center',
|
|
|
|
textIndent: -999,
|
|
|
|
verticalAlign: 'top',
|
|
|
|
transition: `all ${motionDurationSlow}`,
|
|
|
|
|
|
|
|
button: {
|
|
|
|
position: 'relative',
|
|
|
|
display: 'block',
|
|
|
|
width: '100%',
|
|
|
|
height: dotHeight,
|
|
|
|
padding: 0,
|
|
|
|
color: 'transparent',
|
|
|
|
fontSize: 0,
|
|
|
|
background: colorBgContainer,
|
|
|
|
border: 0,
|
|
|
|
borderRadius: dotHeight,
|
|
|
|
outline: 'none',
|
|
|
|
cursor: 'pointer',
|
|
|
|
opacity: 0.2,
|
|
|
|
transition: `all ${motionDurationSlow}`,
|
|
|
|
|
|
|
|
'&: hover, &:focus': {
|
|
|
|
opacity: 0.75,
|
|
|
|
},
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
position: 'absolute',
|
|
|
|
inset: token.calc(dotGap).mul(-1).equal(),
|
|
|
|
content: '""',
|
|
|
|
},
|
2022-11-07 23:32:46 +08:00
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&.slick-active': {
|
|
|
|
width: token.dotActiveWidth,
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'& button': {
|
|
|
|
background: colorBgContainer,
|
|
|
|
opacity: 1,
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
'&: hover, &:focus': {
|
|
|
|
opacity: 1,
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-04-19 17:17:56 +08:00
|
|
|
];
|
2022-03-26 17:32:36 +08:00
|
|
|
};
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genCarouselVerticalStyle: GenerateStyle<CarouselToken> = (token) => {
|
2024-04-19 17:17:56 +08:00
|
|
|
const { componentCls, dotOffset, arrowOffset, marginXXS } = token;
|
2022-03-26 17:32:36 +08:00
|
|
|
|
|
|
|
const reverseSizeOfDot = {
|
2022-05-19 14:00:04 +08:00
|
|
|
width: token.dotHeight,
|
|
|
|
height: token.dotWidth,
|
2022-03-26 17:32:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
2022-04-07 17:02:54 +08:00
|
|
|
[`${componentCls}-vertical`]: {
|
2024-04-19 17:17:56 +08:00
|
|
|
'.slick-prev, .slick-next': {
|
|
|
|
insetInlineStart: '50%',
|
|
|
|
marginBlockStart: 'unset',
|
|
|
|
transform: 'translateX(-50%)',
|
|
|
|
},
|
|
|
|
'.slick-prev': {
|
|
|
|
insetBlockStart: arrowOffset,
|
|
|
|
insetInlineStart: '50%',
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
transform: 'rotate(45deg)',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'.slick-next': {
|
|
|
|
insetBlockStart: 'auto',
|
|
|
|
insetBlockEnd: arrowOffset,
|
|
|
|
'&::after': {
|
|
|
|
transform: 'rotate(-135deg)',
|
|
|
|
},
|
|
|
|
},
|
2022-03-26 17:32:36 +08:00
|
|
|
'.slick-dots': {
|
|
|
|
top: '50%',
|
|
|
|
bottom: 'auto',
|
|
|
|
flexDirection: 'column',
|
2022-05-19 14:00:04 +08:00
|
|
|
width: token.dotHeight,
|
2022-03-26 17:32:36 +08:00
|
|
|
height: 'auto',
|
|
|
|
margin: 0,
|
|
|
|
transform: 'translateY(-50%)',
|
|
|
|
|
|
|
|
'&-left': {
|
|
|
|
insetInlineEnd: 'auto',
|
2024-04-19 17:17:56 +08:00
|
|
|
insetInlineStart: dotOffset,
|
2022-03-26 17:32:36 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
'&-right': {
|
2024-04-19 17:17:56 +08:00
|
|
|
insetInlineEnd: dotOffset,
|
2022-03-26 17:32:36 +08:00
|
|
|
insetInlineStart: 'auto',
|
|
|
|
},
|
|
|
|
|
|
|
|
li: {
|
|
|
|
// reverse width and height in vertical situation
|
|
|
|
...reverseSizeOfDot,
|
2023-11-13 20:14:13 +08:00
|
|
|
margin: `${unit(marginXXS)} 0`,
|
2022-03-26 17:32:36 +08:00
|
|
|
verticalAlign: 'baseline',
|
|
|
|
|
|
|
|
button: reverseSizeOfDot,
|
|
|
|
|
|
|
|
'&.slick-active': {
|
|
|
|
...reverseSizeOfDot,
|
|
|
|
|
|
|
|
button: reverseSizeOfDot,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-11-19 13:47:33 +08:00
|
|
|
const genCarouselRtlStyle: GenerateStyle<CarouselToken> = (token) => {
|
2022-04-07 17:02:54 +08:00
|
|
|
const { componentCls } = token;
|
2022-03-26 17:32:36 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
{
|
2022-04-07 17:02:54 +08:00
|
|
|
[`${componentCls}-rtl`]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
direction: 'rtl',
|
|
|
|
|
|
|
|
// Dots
|
|
|
|
'.slick-dots': {
|
2022-04-07 17:02:54 +08:00
|
|
|
[`${componentCls}-rtl&`]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
flexDirection: 'row-reverse',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2022-04-07 17:02:54 +08:00
|
|
|
[`${componentCls}-vertical`]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
'.slick-dots': {
|
2022-04-07 17:02:54 +08:00
|
|
|
[`${componentCls}-rtl&`]: {
|
2022-03-26 17:32:36 +08:00
|
|
|
flexDirection: 'column',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2024-04-19 17:17:56 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'Carousel'> = (token) => {
|
2023-11-13 20:14:13 +08:00
|
|
|
const dotActiveWidth = 24;
|
|
|
|
|
|
|
|
return {
|
2024-04-19 17:17:56 +08:00
|
|
|
arrowSize: 16,
|
|
|
|
arrowOffset: token.marginXS,
|
2023-11-13 20:14:13 +08:00
|
|
|
dotWidth: 16,
|
|
|
|
dotHeight: 3,
|
2024-04-19 17:17:56 +08:00
|
|
|
dotGap: token.marginXXS,
|
|
|
|
dotOffset: 12,
|
2023-11-13 20:14:13 +08:00
|
|
|
dotWidthActive: dotActiveWidth,
|
|
|
|
dotActiveWidth,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-03-26 17:32:36 +08:00
|
|
|
// ============================== Export ==============================
|
2023-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks(
|
2022-04-24 17:42:36 +08:00
|
|
|
'Carousel',
|
2024-04-19 17:17:56 +08:00
|
|
|
(token) => [
|
|
|
|
genCarouselStyle(token),
|
|
|
|
genArrowsStyle(token),
|
|
|
|
genDotsStyle(token),
|
|
|
|
genCarouselVerticalStyle(token),
|
|
|
|
genCarouselRtlStyle(token),
|
|
|
|
],
|
2023-11-13 20:14:13 +08:00
|
|
|
prepareComponentToken,
|
2022-04-24 17:42:36 +08:00
|
|
|
{
|
2023-05-19 14:58:40 +08:00
|
|
|
deprecatedTokens: [['dotWidthActive', 'dotActiveWidth']],
|
2022-04-24 17:42:36 +08:00
|
|
|
},
|
|
|
|
);
|