2023-09-22 14:19:53 +08:00
|
|
|
|
import type * as React from 'react';
|
2022-05-09 22:20:07 +08:00
|
|
|
|
import type { CSSObject } from '@ant-design/cssinjs';
|
2024-04-08 14:04:08 +08:00
|
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2022-09-20 21:50:36 +08:00
|
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2023-09-22 14:19:53 +08:00
|
|
|
|
|
2023-02-19 16:24:20 +08:00
|
|
|
|
import { resetComponent } from '../../style';
|
2023-11-14 15:59:23 +08:00
|
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
2022-03-29 15:57:39 +08:00
|
|
|
|
// Direction naming standard:
|
|
|
|
|
// Horizontal base:
|
|
|
|
|
// -0-------------
|
|
|
|
|
// vertical: part (水平时,垂直方向命名为 part)
|
|
|
|
|
// horizontal: full (水平时,水平方向命名为 full)
|
|
|
|
|
|
|
|
|
|
export interface ComponentToken {
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑动输入高度
|
|
|
|
|
* @descEN Height of slider
|
|
|
|
|
*/
|
2022-03-29 15:57:39 +08:00
|
|
|
|
controlSize: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 轨道高度
|
|
|
|
|
* @descEN Height of rail
|
|
|
|
|
*/
|
2022-03-14 19:12:10 +08:00
|
|
|
|
railSize: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块尺寸
|
|
|
|
|
* @descEN Size of handle
|
|
|
|
|
*/
|
2022-03-29 15:57:39 +08:00
|
|
|
|
handleSize: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块尺寸(悬浮态)
|
|
|
|
|
* @descEN Size of handle when hover
|
|
|
|
|
*/
|
2022-09-20 21:50:36 +08:00
|
|
|
|
handleSizeHover: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块边框宽度
|
|
|
|
|
* @descEN Border width of handle
|
|
|
|
|
*/
|
2024-07-12 10:12:56 +08:00
|
|
|
|
handleLineWidth: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块边框宽度(悬浮态)
|
|
|
|
|
* @descEN Border width of handle when hover
|
|
|
|
|
*/
|
2024-07-12 10:12:56 +08:00
|
|
|
|
handleLineWidthHover: number;
|
2023-07-05 17:49:59 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块圆点尺寸
|
|
|
|
|
* @descEN Size of dot
|
|
|
|
|
*/
|
2022-03-14 19:12:10 +08:00
|
|
|
|
dotSize: number;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 轨道背景色
|
|
|
|
|
* @descEN Background color of rail
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
railBg: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 轨道背景色(悬浮态)
|
|
|
|
|
* @descEN Background color of rail when hover
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
railHoverBg: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 轨道已覆盖部分背景色
|
|
|
|
|
* @descEN Background color of track
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
trackBg: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 轨道已覆盖部分背景色(悬浮态)
|
|
|
|
|
* @descEN Background color of track when hover
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
trackHoverBg: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块颜色
|
|
|
|
|
* @descEN Color of handle
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
handleColor: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
2024-06-28 22:10:15 +08:00
|
|
|
|
* @desc 滑块激活态边框色
|
|
|
|
|
* @descEN Border color of handle when active
|
2023-11-22 20:53:48 +08:00
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
handleActiveColor: string;
|
2024-06-28 22:10:15 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块激活态外框色
|
|
|
|
|
* @descEN Outline color of handle when active
|
|
|
|
|
*/
|
|
|
|
|
handleActiveOutlineColor: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 滑块禁用颜色
|
|
|
|
|
* @descEN Color of handle when disabled
|
|
|
|
|
*/
|
|
|
|
|
handleColorDisabled: string;
|
|
|
|
|
/**
|
|
|
|
|
* @desc 圆点边框颜色
|
|
|
|
|
* @descEN Border color of dot
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
dotBorderColor: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 圆点激活态边框颜色
|
|
|
|
|
* @descEN Border color of dot when active
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
dotActiveBorderColor: string;
|
2023-11-22 20:53:48 +08:00
|
|
|
|
/**
|
|
|
|
|
* @desc 轨道禁用态背景色
|
|
|
|
|
* @descEN Background color of track when disabled
|
|
|
|
|
*/
|
2023-06-15 10:22:17 +08:00
|
|
|
|
trackBgDisabled: string;
|
2022-03-14 19:12:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
interface SliderToken extends FullToken<'Slider'> {
|
2023-11-14 15:59:23 +08:00
|
|
|
|
marginFull: number | string;
|
|
|
|
|
marginPart: number | string;
|
|
|
|
|
marginPartWithMark: number | string;
|
2022-03-29 15:57:39 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-14 19:12:10 +08:00
|
|
|
|
// =============================== Base ===============================
|
2022-11-17 23:31:41 +08:00
|
|
|
|
const genBaseStyle: GenerateStyle<SliderToken> = (token) => {
|
2023-07-07 23:28:35 +08:00
|
|
|
|
const {
|
|
|
|
|
componentCls,
|
|
|
|
|
antCls,
|
|
|
|
|
controlSize,
|
|
|
|
|
dotSize,
|
|
|
|
|
marginFull,
|
|
|
|
|
marginPart,
|
|
|
|
|
colorFillContentHover,
|
2023-11-22 20:53:48 +08:00
|
|
|
|
handleColorDisabled,
|
2023-11-14 15:59:23 +08:00
|
|
|
|
calc,
|
2024-06-28 22:10:15 +08:00
|
|
|
|
handleSize,
|
|
|
|
|
handleSizeHover,
|
|
|
|
|
handleActiveColor,
|
|
|
|
|
handleActiveOutlineColor,
|
|
|
|
|
handleLineWidth,
|
|
|
|
|
handleLineWidthHover,
|
|
|
|
|
motionDurationMid,
|
2023-07-07 23:28:35 +08:00
|
|
|
|
} = token;
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
|
|
|
|
return {
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[componentCls]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
|
|
position: 'relative',
|
2022-03-29 15:57:39 +08:00
|
|
|
|
height: controlSize,
|
2023-11-14 15:59:23 +08:00
|
|
|
|
margin: `${unit(marginPart)} ${unit(marginFull)}`,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
padding: 0,
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
touchAction: 'none',
|
|
|
|
|
|
2024-06-22 21:59:12 +08:00
|
|
|
|
'&-vertical': {
|
2023-11-14 15:59:23 +08:00
|
|
|
|
margin: `${unit(marginFull)} ${unit(marginPart)}`,
|
2022-03-29 15:57:39 +08:00
|
|
|
|
},
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-rail`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
2023-06-15 10:22:17 +08:00
|
|
|
|
backgroundColor: token.railBg,
|
2022-11-01 15:06:38 +08:00
|
|
|
|
borderRadius: token.borderRadiusXS,
|
2024-06-28 22:10:15 +08:00
|
|
|
|
transition: `background-color ${motionDurationMid}`,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-09-22 14:19:53 +08:00
|
|
|
|
[`${componentCls}-track,${componentCls}-tracks`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
2024-06-28 22:10:15 +08:00
|
|
|
|
transition: `background-color ${motionDurationMid}`,
|
2023-09-22 14:19:53 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`${componentCls}-track`]: {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
backgroundColor: token.trackBg,
|
2022-11-01 15:06:38 +08:00
|
|
|
|
borderRadius: token.borderRadiusXS,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-09-02 00:16:01 +08:00
|
|
|
|
[`${componentCls}-track-draggable`]: {
|
|
|
|
|
boxSizing: 'content-box',
|
|
|
|
|
backgroundClip: 'content-box',
|
|
|
|
|
border: 'solid rgba(0,0,0,0)',
|
|
|
|
|
},
|
|
|
|
|
|
2022-11-14 15:01:07 +08:00
|
|
|
|
'&:hover': {
|
|
|
|
|
[`${componentCls}-rail`]: {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
backgroundColor: token.railHoverBg,
|
2022-11-14 15:01:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`${componentCls}-track`]: {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
backgroundColor: token.trackHoverBg,
|
2022-11-14 15:01:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`${componentCls}-dot`]: {
|
|
|
|
|
borderColor: colorFillContentHover,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`${componentCls}-handle::after`]: {
|
2024-06-28 22:10:15 +08:00
|
|
|
|
boxShadow: `0 0 0 ${unit(handleLineWidth)} ${token.colorPrimaryBorderHover}`,
|
2022-11-14 15:01:07 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`${componentCls}-dot-active`]: {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
borderColor: token.dotActiveBorderColor,
|
2022-11-14 15:01:07 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-handle`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
2024-06-28 22:10:15 +08:00
|
|
|
|
width: handleSize,
|
|
|
|
|
height: handleSize,
|
2022-11-14 15:01:07 +08:00
|
|
|
|
outline: 'none',
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
2022-09-20 21:50:36 +08:00
|
|
|
|
// 扩大选区
|
|
|
|
|
'&::before': {
|
|
|
|
|
content: '""',
|
|
|
|
|
position: 'absolute',
|
2024-06-28 22:10:15 +08:00
|
|
|
|
insetInlineStart: calc(handleLineWidth).mul(-1).equal(),
|
|
|
|
|
insetBlockStart: calc(handleLineWidth).mul(-1).equal(),
|
|
|
|
|
width: calc(handleSize).add(calc(handleLineWidth).mul(2)).equal(),
|
|
|
|
|
height: calc(handleSize).add(calc(handleLineWidth).mul(2)).equal(),
|
2022-09-20 21:50:36 +08:00
|
|
|
|
backgroundColor: 'transparent',
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'&::after': {
|
|
|
|
|
content: '""',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
insetBlockStart: 0,
|
|
|
|
|
insetInlineStart: 0,
|
2024-06-28 22:10:15 +08:00
|
|
|
|
width: handleSize,
|
|
|
|
|
height: handleSize,
|
2022-12-09 17:52:34 +08:00
|
|
|
|
backgroundColor: token.colorBgElevated,
|
2024-06-28 22:10:15 +08:00
|
|
|
|
boxShadow: `0 0 0 ${unit(handleLineWidth)} ${token.handleColor}`,
|
|
|
|
|
outline: `0px solid transparent`,
|
2022-09-20 21:50:36 +08:00
|
|
|
|
borderRadius: '50%',
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
transition: `
|
2024-06-28 22:10:15 +08:00
|
|
|
|
inset-inline-start ${motionDurationMid},
|
|
|
|
|
inset-block-start ${motionDurationMid},
|
|
|
|
|
width ${motionDurationMid},
|
|
|
|
|
height ${motionDurationMid},
|
|
|
|
|
box-shadow ${motionDurationMid},
|
|
|
|
|
outline ${motionDurationMid}
|
2022-09-20 21:50:36 +08:00
|
|
|
|
`,
|
|
|
|
|
},
|
|
|
|
|
|
2022-11-14 15:01:07 +08:00
|
|
|
|
'&:hover, &:active, &:focus': {
|
2022-09-20 21:50:36 +08:00
|
|
|
|
'&::before': {
|
2024-06-28 22:10:15 +08:00
|
|
|
|
insetInlineStart: calc(handleSizeHover)
|
|
|
|
|
.sub(handleSize)
|
2023-11-14 15:59:23 +08:00
|
|
|
|
.div(2)
|
2024-06-28 22:10:15 +08:00
|
|
|
|
.add(handleLineWidthHover)
|
2023-11-14 15:59:23 +08:00
|
|
|
|
.mul(-1)
|
|
|
|
|
.equal(),
|
2024-06-28 22:10:15 +08:00
|
|
|
|
insetBlockStart: calc(handleSizeHover)
|
|
|
|
|
.sub(handleSize)
|
2023-11-14 15:59:23 +08:00
|
|
|
|
.div(2)
|
2024-06-28 22:10:15 +08:00
|
|
|
|
.add(handleLineWidthHover)
|
2023-11-14 15:59:23 +08:00
|
|
|
|
.mul(-1)
|
|
|
|
|
.equal(),
|
2024-06-28 22:10:15 +08:00
|
|
|
|
width: calc(handleSizeHover).add(calc(handleLineWidthHover).mul(2)).equal(),
|
|
|
|
|
height: calc(handleSizeHover).add(calc(handleLineWidthHover).mul(2)).equal(),
|
2022-09-20 21:50:36 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'&::after': {
|
2024-06-28 22:10:15 +08:00
|
|
|
|
boxShadow: `0 0 0 ${unit(handleLineWidthHover)} ${handleActiveColor}`,
|
|
|
|
|
outline: `6px solid ${handleActiveOutlineColor}`,
|
|
|
|
|
width: handleSizeHover,
|
|
|
|
|
height: handleSizeHover,
|
|
|
|
|
insetInlineStart: token.calc(handleSize).sub(handleSizeHover).div(2).equal(),
|
|
|
|
|
insetBlockStart: token.calc(handleSize).sub(handleSizeHover).div(2).equal(),
|
2022-09-20 21:50:36 +08:00
|
|
|
|
},
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2024-04-22 10:26:14 +08:00
|
|
|
|
[`&-lock ${componentCls}-handle`]: {
|
2024-06-22 21:59:12 +08:00
|
|
|
|
'&::before, &::after': {
|
2024-04-22 10:26:14 +08:00
|
|
|
|
transition: 'none',
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-mark`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
|
|
|
|
fontSize: token.fontSize,
|
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-mark-text`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
|
|
|
|
display: 'inline-block',
|
2022-08-04 16:16:50 +08:00
|
|
|
|
color: token.colorTextDescription,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
textAlign: 'center',
|
|
|
|
|
wordBreak: 'keep-all',
|
|
|
|
|
cursor: 'pointer',
|
|
|
|
|
userSelect: 'none',
|
|
|
|
|
|
|
|
|
|
'&-active': {
|
2022-03-22 09:37:37 +08:00
|
|
|
|
color: token.colorText,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-step`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
|
|
|
|
background: 'transparent',
|
2023-02-27 16:26:19 +08:00
|
|
|
|
pointerEvents: 'none',
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-dot`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
|
|
|
|
width: dotSize,
|
|
|
|
|
height: dotSize,
|
2022-12-09 17:52:34 +08:00
|
|
|
|
backgroundColor: token.colorBgElevated,
|
2024-06-28 22:10:15 +08:00
|
|
|
|
border: `${unit(handleLineWidth)} solid ${token.dotBorderColor}`,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
borderRadius: '50%',
|
|
|
|
|
cursor: 'pointer',
|
2022-03-22 20:02:04 +08:00
|
|
|
|
transition: `border-color ${token.motionDurationSlow}`,
|
2023-02-27 16:26:19 +08:00
|
|
|
|
pointerEvents: 'auto',
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
|
|
|
|
'&-active': {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
borderColor: token.dotActiveBorderColor,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
|
2023-01-20 10:31:27 +08:00
|
|
|
|
[`&${componentCls}-disabled`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-rail`]: {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
backgroundColor: `${token.railBg} !important`,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-track`]: {
|
2023-06-15 10:22:17 +08:00
|
|
|
|
backgroundColor: `${token.trackBgDisabled} !important`,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
[`
|
2022-04-07 20:56:27 +08:00
|
|
|
|
${componentCls}-dot
|
2022-03-14 19:12:10 +08:00
|
|
|
|
`]: {
|
2022-12-09 17:52:34 +08:00
|
|
|
|
backgroundColor: token.colorBgElevated,
|
2023-06-15 10:22:17 +08:00
|
|
|
|
borderColor: token.trackBgDisabled,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
boxShadow: 'none',
|
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
|
},
|
|
|
|
|
|
2022-09-20 21:50:36 +08:00
|
|
|
|
[`${componentCls}-handle::after`]: {
|
2022-12-09 17:52:34 +08:00
|
|
|
|
backgroundColor: token.colorBgElevated,
|
2022-10-24 15:59:56 +08:00
|
|
|
|
cursor: 'not-allowed',
|
2024-06-28 22:10:15 +08:00
|
|
|
|
width: handleSize,
|
|
|
|
|
height: handleSize,
|
|
|
|
|
boxShadow: `0 0 0 ${unit(handleLineWidth)} ${handleColorDisabled}`,
|
2022-09-20 21:50:36 +08:00
|
|
|
|
insetInlineStart: 0,
|
|
|
|
|
insetBlockStart: 0,
|
|
|
|
|
},
|
|
|
|
|
|
2022-03-14 19:12:10 +08:00
|
|
|
|
[`
|
2022-04-07 20:56:27 +08:00
|
|
|
|
${componentCls}-mark-text,
|
|
|
|
|
${componentCls}-dot
|
2022-03-14 19:12:10 +08:00
|
|
|
|
`]: {
|
|
|
|
|
cursor: `not-allowed !important`,
|
|
|
|
|
},
|
|
|
|
|
},
|
2023-07-07 18:58:54 +08:00
|
|
|
|
|
2023-07-07 23:28:35 +08:00
|
|
|
|
[`&-tooltip ${antCls}-tooltip-inner`]: {
|
|
|
|
|
minWidth: 'unset',
|
2023-07-07 18:58:54 +08:00
|
|
|
|
},
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================ Horizontal ============================
|
|
|
|
|
const genDirectionStyle = (token: SliderToken, horizontal: boolean): CSSObject => {
|
2023-11-14 15:59:23 +08:00
|
|
|
|
const { componentCls, railSize, handleSize, dotSize, marginFull, calc } = token;
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
|
|
|
|
const railPadding: keyof React.CSSProperties = horizontal ? 'paddingBlock' : 'paddingInline';
|
2022-03-29 15:57:39 +08:00
|
|
|
|
const full: keyof React.CSSProperties = horizontal ? 'width' : 'height';
|
|
|
|
|
const part: keyof React.CSSProperties = horizontal ? 'height' : 'width';
|
2022-03-14 19:12:10 +08:00
|
|
|
|
const handlePos: keyof React.CSSProperties = horizontal ? 'insetBlockStart' : 'insetInlineStart';
|
|
|
|
|
const markInset: keyof React.CSSProperties = horizontal ? 'top' : 'insetInlineStart';
|
|
|
|
|
|
2023-11-14 15:59:23 +08:00
|
|
|
|
const handlePosSize = calc(railSize).mul(3).sub(handleSize).div(2).equal();
|
|
|
|
|
const draggableBorderSize = calc(handleSize).sub(railSize).div(2).equal();
|
2023-09-02 00:16:01 +08:00
|
|
|
|
|
|
|
|
|
const draggableBorder: React.CSSProperties = horizontal
|
|
|
|
|
? {
|
2023-11-14 15:59:23 +08:00
|
|
|
|
borderWidth: `${unit(draggableBorderSize)} 0`,
|
|
|
|
|
transform: `translateY(${unit(calc(draggableBorderSize).mul(-1).equal())})`,
|
2023-09-02 00:16:01 +08:00
|
|
|
|
}
|
|
|
|
|
: {
|
2023-11-14 15:59:23 +08:00
|
|
|
|
borderWidth: `0 ${unit(draggableBorderSize)}`,
|
|
|
|
|
transform: `translateX(${unit(token.calc(draggableBorderSize).mul(-1).equal())})`,
|
2023-09-02 00:16:01 +08:00
|
|
|
|
};
|
|
|
|
|
|
2022-03-14 19:12:10 +08:00
|
|
|
|
return {
|
|
|
|
|
[railPadding]: railSize,
|
2023-11-14 15:59:23 +08:00
|
|
|
|
[part]: calc(railSize).mul(3).equal(),
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-rail`]: {
|
2022-03-29 15:57:39 +08:00
|
|
|
|
[full]: '100%',
|
|
|
|
|
[part]: railSize,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-09-22 14:19:53 +08:00
|
|
|
|
[`${componentCls}-track,${componentCls}-tracks`]: {
|
2022-03-29 15:57:39 +08:00
|
|
|
|
[part]: railSize,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2023-09-02 00:16:01 +08:00
|
|
|
|
[`${componentCls}-track-draggable`]: {
|
|
|
|
|
...draggableBorder,
|
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-handle`]: {
|
2023-09-02 00:16:01 +08:00
|
|
|
|
[handlePos]: handlePosSize,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-mark`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
// Reset all
|
|
|
|
|
insetInlineStart: 0,
|
|
|
|
|
top: 0,
|
2023-07-26 17:38:27 +08:00
|
|
|
|
// https://github.com/ant-design/ant-design/issues/43731
|
2023-11-14 15:59:23 +08:00
|
|
|
|
[markInset]: calc(railSize)
|
|
|
|
|
.mul(3)
|
|
|
|
|
.add(horizontal ? 0 : marginFull)
|
|
|
|
|
.equal(),
|
2022-03-29 15:57:39 +08:00
|
|
|
|
[full]: '100%',
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-step`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
// Reset all
|
|
|
|
|
insetInlineStart: 0,
|
|
|
|
|
top: 0,
|
|
|
|
|
[markInset]: railSize,
|
2022-03-29 15:57:39 +08:00
|
|
|
|
[full]: '100%',
|
|
|
|
|
[part]: railSize,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-dot`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
position: 'absolute',
|
2023-11-14 15:59:23 +08:00
|
|
|
|
[handlePos]: calc(railSize).sub(dotSize).div(2).equal(),
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
// ============================ Horizontal ============================
|
2022-11-17 23:31:41 +08:00
|
|
|
|
const genHorizontalStyle: GenerateStyle<SliderToken> = (token) => {
|
2022-04-07 20:56:27 +08:00
|
|
|
|
const { componentCls, marginPartWithMark } = token;
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
|
|
|
|
return {
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-horizontal`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
...genDirectionStyle(token, true),
|
|
|
|
|
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`&${componentCls}-with-marks`]: {
|
2022-03-29 15:57:39 +08:00
|
|
|
|
marginBottom: marginPartWithMark,
|
2022-03-14 19:12:10 +08:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================= Vertical =============================
|
2022-11-17 23:31:41 +08:00
|
|
|
|
const genVerticalStyle: GenerateStyle<SliderToken> = (token) => {
|
2022-04-07 20:56:27 +08:00
|
|
|
|
const { componentCls } = token;
|
2022-03-14 19:12:10 +08:00
|
|
|
|
|
|
|
|
|
return {
|
2022-04-07 20:56:27 +08:00
|
|
|
|
[`${componentCls}-vertical`]: {
|
2022-03-14 19:12:10 +08:00
|
|
|
|
...genDirectionStyle(token, false),
|
|
|
|
|
height: '100%',
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2023-11-14 15:59:23 +08:00
|
|
|
|
export const prepareComponentToken: GetDefaultToken<'Slider'> = (token) => {
|
|
|
|
|
// Handle line width is always width-er 1px
|
|
|
|
|
const increaseHandleWidth = 1;
|
|
|
|
|
const controlSize = token.controlHeightLG / 4;
|
|
|
|
|
const controlSizeHover = token.controlHeightSM / 2;
|
|
|
|
|
const handleLineWidth = token.lineWidth + increaseHandleWidth;
|
2024-06-28 22:10:15 +08:00
|
|
|
|
const handleLineWidthHover = token.lineWidth + increaseHandleWidth * 1.5;
|
|
|
|
|
const handleActiveColor = token.colorPrimary;
|
|
|
|
|
const handleActiveOutlineColor = new TinyColor(handleActiveColor).setAlpha(0.2).toRgbString();
|
|
|
|
|
|
2023-11-14 15:59:23 +08:00
|
|
|
|
return {
|
|
|
|
|
controlSize,
|
|
|
|
|
railSize: 4,
|
|
|
|
|
handleSize: controlSize,
|
|
|
|
|
handleSizeHover: controlSizeHover,
|
|
|
|
|
dotSize: 8,
|
|
|
|
|
handleLineWidth,
|
|
|
|
|
handleLineWidthHover,
|
|
|
|
|
railBg: token.colorFillTertiary,
|
|
|
|
|
railHoverBg: token.colorFillSecondary,
|
|
|
|
|
trackBg: token.colorPrimaryBorder,
|
|
|
|
|
trackHoverBg: token.colorPrimaryBorderHover,
|
|
|
|
|
handleColor: token.colorPrimaryBorder,
|
2024-06-28 22:10:15 +08:00
|
|
|
|
handleActiveColor,
|
|
|
|
|
handleActiveOutlineColor,
|
2023-11-22 20:53:48 +08:00
|
|
|
|
handleColorDisabled: new TinyColor(token.colorTextDisabled)
|
|
|
|
|
.onBackground(token.colorBgContainer)
|
|
|
|
|
.toHexShortString(),
|
2023-11-14 15:59:23 +08:00
|
|
|
|
dotBorderColor: token.colorBorderSecondary,
|
|
|
|
|
dotActiveBorderColor: token.colorPrimaryBorder,
|
|
|
|
|
trackBgDisabled: token.colorBgContainerDisabled,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
|
export default genStyleHooks(
|
2022-04-07 20:56:27 +08:00
|
|
|
|
'Slider',
|
2022-11-17 23:31:41 +08:00
|
|
|
|
(token) => {
|
2022-04-11 16:04:00 +08:00
|
|
|
|
const sliderToken = mergeToken<SliderToken>(token, {
|
2023-11-14 15:59:23 +08:00
|
|
|
|
marginPart: token.calc(token.controlHeight).sub(token.controlSize).div(2).equal(),
|
|
|
|
|
marginFull: token.calc(token.controlSize).div(2).equal(),
|
|
|
|
|
marginPartWithMark: token.calc(token.controlHeightLG).sub(token.controlSize).equal(),
|
2022-04-11 16:04:00 +08:00
|
|
|
|
});
|
2022-04-07 20:56:27 +08:00
|
|
|
|
return [
|
2022-04-21 02:06:22 +08:00
|
|
|
|
genBaseStyle(sliderToken),
|
2022-04-07 20:56:27 +08:00
|
|
|
|
genHorizontalStyle(sliderToken),
|
|
|
|
|
genVerticalStyle(sliderToken),
|
|
|
|
|
];
|
|
|
|
|
},
|
2023-11-14 15:59:23 +08:00
|
|
|
|
prepareComponentToken,
|
2022-04-07 20:56:27 +08:00
|
|
|
|
);
|