2022-03-11 14:29:29 +08:00
|
|
|
import { Keyframes } from '@ant-design/cssinjs';
|
2022-06-27 14:25:59 +08:00
|
|
|
import type { FullToken, GenerateStyle } from '../../theme';
|
2022-07-11 15:35:58 +08:00
|
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
|
|
|
import { resetComponent } from '../../style';
|
2022-05-31 10:10:35 +08:00
|
|
|
|
|
|
|
export interface ComponentToken {}
|
2022-04-07 18:24:45 +08:00
|
|
|
|
|
|
|
interface CheckboxToken extends FullToken<'Checkbox'> {
|
2022-03-11 14:29:29 +08:00
|
|
|
checkboxCls: string;
|
2022-05-31 10:10:35 +08:00
|
|
|
checkboxSize: number;
|
2022-03-11 14:29:29 +08:00
|
|
|
}
|
|
|
|
|
2022-03-01 21:12:00 +08:00
|
|
|
// ============================== Motion ==============================
|
|
|
|
const antCheckboxEffect = new Keyframes('antCheckboxEffect', {
|
|
|
|
'0%': {
|
|
|
|
transform: 'scale(1)',
|
|
|
|
opacity: 0.5,
|
|
|
|
},
|
|
|
|
|
|
|
|
'100%': {
|
|
|
|
transform: 'scale(1.6)',
|
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
// ============================== Styles ==============================
|
2022-04-21 02:06:22 +08:00
|
|
|
export const genCheckboxStyle: GenerateStyle<CheckboxToken> = token => {
|
2022-03-11 14:29:29 +08:00
|
|
|
const { checkboxCls } = token;
|
2022-03-01 21:12:00 +08:00
|
|
|
const wrapperCls = `${checkboxCls}-wrapper`;
|
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
return [
|
|
|
|
// ===================== Basic =====================
|
|
|
|
{
|
|
|
|
// Group
|
|
|
|
[`${checkboxCls}-group`]: {
|
|
|
|
...resetComponent(token),
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
display: 'inline-flex',
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper
|
|
|
|
[wrapperCls]: {
|
|
|
|
...resetComponent(token),
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
display: 'inline-flex',
|
|
|
|
alignItems: 'baseline',
|
|
|
|
lineHeight: 'unset',
|
2022-03-01 21:12:00 +08:00
|
|
|
cursor: 'pointer',
|
2022-03-03 14:55:19 +08:00
|
|
|
|
|
|
|
// Fix checkbox & radio in flex align #30260
|
|
|
|
'&:after': {
|
|
|
|
display: 'inline-block',
|
|
|
|
width: 0,
|
|
|
|
overflow: 'hidden',
|
|
|
|
content: "'\\a0'",
|
|
|
|
},
|
|
|
|
|
|
|
|
// Checkbox near checkbox
|
|
|
|
'& + &': {
|
|
|
|
marginInlineStart: token.marginXS,
|
|
|
|
},
|
2022-03-24 22:58:40 +08:00
|
|
|
|
|
|
|
'&&-in-form-item': {
|
|
|
|
'input[type="checkbox"]': {
|
|
|
|
width: 14, // FIXME: magic
|
|
|
|
height: 14, // FIXME: magic
|
|
|
|
},
|
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper > Checkbox
|
|
|
|
[checkboxCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
|
|
|
|
top: '0.2em',
|
2022-03-01 21:12:00 +08:00
|
|
|
position: 'relative',
|
2022-03-03 14:55:19 +08:00
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
lineHeight: 1,
|
|
|
|
cursor: 'pointer',
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper > Checkbox > input
|
|
|
|
[`${checkboxCls}-input`]: {
|
2022-03-01 21:12:00 +08:00
|
|
|
position: 'absolute',
|
2022-03-03 14:55:19 +08:00
|
|
|
inset: 0,
|
|
|
|
zIndex: 1,
|
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
|
|
|
cursor: 'pointer',
|
2022-03-01 21:12:00 +08:00
|
|
|
opacity: 0,
|
|
|
|
},
|
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper > Checkbox > inner
|
|
|
|
[`${checkboxCls}-inner`]: {
|
|
|
|
position: 'relative',
|
|
|
|
top: 0,
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: 0,
|
2022-03-03 14:55:19 +08:00
|
|
|
display: 'block',
|
2022-05-31 10:10:35 +08:00
|
|
|
width: token.checkboxSize,
|
|
|
|
height: token.checkboxSize,
|
2022-03-03 14:55:19 +08:00
|
|
|
direction: 'ltr',
|
2022-06-28 20:33:01 +08:00
|
|
|
backgroundColor: token.colorBgContainer,
|
2022-03-22 13:26:29 +08:00
|
|
|
border: `${token.controlLineWidth}px ${token.controlLineType} ${token.colorBorder}`,
|
|
|
|
borderRadius: token.controlRadius,
|
2022-03-03 14:55:19 +08:00
|
|
|
borderCollapse: 'separate',
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `all ${token.motionDurationSlow}`,
|
2022-03-03 14:55:19 +08:00
|
|
|
|
|
|
|
'&:after': {
|
|
|
|
position: 'absolute',
|
|
|
|
top: '50%',
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: '21.5%',
|
2022-03-03 14:55:19 +08:00
|
|
|
display: 'table',
|
2022-05-31 10:10:35 +08:00
|
|
|
width: (token.checkboxSize / 14) * 5,
|
|
|
|
height: (token.checkboxSize / 14) * 8,
|
2022-06-28 20:33:01 +08:00
|
|
|
border: `${token.lineWidthBold}px solid ${token.colorBgContainer}`,
|
2022-03-03 14:55:19 +08:00
|
|
|
borderTop: 0,
|
2022-03-11 17:07:16 +08:00
|
|
|
borderInlineStart: 0,
|
2022-03-03 14:55:19 +08:00
|
|
|
transform: 'rotate(45deg) scale(0) translate(-50%,-50%)',
|
|
|
|
opacity: 0,
|
2022-03-22 20:02:04 +08:00
|
|
|
transition: `all ${token.motionDurationFast} cubic-bezier(.71,-.46,.88,.6), opacity ${token.motionDurationFast}`,
|
2022-03-03 14:55:19 +08:00
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// Wrapper > Checkbox + Text
|
|
|
|
'& + span': {
|
2022-03-11 17:07:16 +08:00
|
|
|
paddingInlineStart: token.paddingXS,
|
|
|
|
paddingInlineEnd: token.paddingXS,
|
2022-03-03 14:55:19 +08:00
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ================= Indeterminate =================
|
2022-03-03 14:55:19 +08:00
|
|
|
{
|
|
|
|
[checkboxCls]: {
|
|
|
|
'&-indeterminate': {
|
|
|
|
// Wrapper > Checkbox > inner
|
|
|
|
[`${checkboxCls}-inner`]: {
|
|
|
|
'&:after': {
|
|
|
|
top: '50%',
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: '50%',
|
2022-03-03 14:55:19 +08:00
|
|
|
width: token.fontSizeLG / 2,
|
|
|
|
height: token.fontSizeLG / 2,
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorPrimary,
|
2022-03-03 14:55:19 +08:00
|
|
|
border: 0,
|
|
|
|
transform: 'translate(-50%, -50%) scale(1)',
|
|
|
|
opacity: 1,
|
|
|
|
content: '""',
|
|
|
|
},
|
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2022-03-02 20:32:25 +08:00
|
|
|
// ===================== Hover =====================
|
2022-03-03 14:55:19 +08:00
|
|
|
{
|
|
|
|
// Wrapper
|
|
|
|
[`${wrapperCls}:hover ${checkboxCls}:after`]: {
|
|
|
|
visibility: 'visible',
|
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper & Wrapper > Checkbox
|
|
|
|
[`
|
2022-03-02 20:32:25 +08:00
|
|
|
${wrapperCls}:hover:not(${wrapperCls}-disabled),
|
|
|
|
${checkboxCls}:hover:not(${checkboxCls}-disabled),
|
|
|
|
${checkboxCls}-input:focus +
|
|
|
|
`]: {
|
2022-03-03 14:55:19 +08:00
|
|
|
[`${checkboxCls}-inner`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
borderColor: token.colorPrimary,
|
2022-03-03 14:55:19 +08:00
|
|
|
},
|
2022-03-02 20:32:25 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ==================== Checked ====================
|
2022-03-03 14:55:19 +08:00
|
|
|
{
|
|
|
|
// Wrapper > Checkbox
|
|
|
|
[`${checkboxCls}-checked`]: {
|
|
|
|
[`${checkboxCls}-inner`]: {
|
2022-03-22 09:37:37 +08:00
|
|
|
backgroundColor: token.colorPrimary,
|
|
|
|
borderColor: token.colorPrimary,
|
2022-03-02 20:32:25 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
'&:after': {
|
|
|
|
opacity: 1,
|
|
|
|
transform: 'rotate(45deg) scale(1) translate(-50%,-50%)',
|
2022-03-25 17:54:57 +08:00
|
|
|
transition: `all ${token.motionDurationSlow} ${token.motionEaseOutBack} ${token.motionDurationFast}`,
|
2022-03-03 14:55:19 +08:00
|
|
|
},
|
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Checked Effect
|
2022-03-01 21:12:00 +08:00
|
|
|
'&:after': {
|
2022-03-03 14:55:19 +08:00
|
|
|
position: 'absolute',
|
|
|
|
top: 0,
|
2022-03-11 17:07:16 +08:00
|
|
|
insetInlineStart: 0,
|
2022-03-03 14:55:19 +08:00
|
|
|
width: '100%',
|
|
|
|
height: '100%',
|
2022-03-22 13:26:29 +08:00
|
|
|
border: `${token.controlLineWidth}px ${token.controlLineType} ${token.colorPrimary}`,
|
|
|
|
borderRadius: token.controlRadius,
|
2022-03-03 14:55:19 +08:00
|
|
|
visibility: 'hidden',
|
2022-04-21 02:06:22 +08:00
|
|
|
animationName: antCheckboxEffect,
|
|
|
|
animationDuration: token.motionDurationSlow,
|
|
|
|
animationTimingFunction: 'ease-in-out',
|
2022-03-03 14:55:19 +08:00
|
|
|
animationFillMode: 'backwards',
|
|
|
|
content: '""',
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
// ==================== Disable ====================
|
2022-03-03 14:55:19 +08:00
|
|
|
{
|
|
|
|
// Wrapper
|
|
|
|
[`${wrapperCls}-disabled`]: {
|
2022-03-01 21:12:00 +08:00
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper > Checkbox
|
|
|
|
[`${checkboxCls}-disabled`]: {
|
|
|
|
// Wrapper > Checkbox > input
|
|
|
|
[`&, ${checkboxCls}-input`]: {
|
|
|
|
cursor: 'not-allowed',
|
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
// Wrapper > Checkbox > inner
|
|
|
|
[`${checkboxCls}-inner`]: {
|
2022-06-28 20:33:01 +08:00
|
|
|
background: token.colorBgContainerDisabled,
|
2022-03-22 13:26:29 +08:00
|
|
|
borderColor: token.colorBorder,
|
2022-03-03 14:55:19 +08:00
|
|
|
|
|
|
|
'&:after': {
|
2022-05-06 15:58:32 +08:00
|
|
|
borderColor: token.colorTextDisabled,
|
2022-03-03 14:55:19 +08:00
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
'&:after': {
|
|
|
|
display: 'none',
|
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
|
2022-03-03 14:55:19 +08:00
|
|
|
'& + span': {
|
2022-03-22 13:26:29 +08:00
|
|
|
color: token.colorTextDisabled,
|
2022-03-03 14:55:19 +08:00
|
|
|
},
|
2022-03-01 21:12:00 +08:00
|
|
|
},
|
|
|
|
},
|
2022-03-03 14:55:19 +08:00
|
|
|
];
|
2022-03-01 21:12:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// ============================== Export ==============================
|
2022-04-21 02:06:22 +08:00
|
|
|
export function getStyle(prefixCls: string, token: FullToken<'Checkbox'>) {
|
2022-04-11 16:04:00 +08:00
|
|
|
const checkboxToken: CheckboxToken = mergeToken<CheckboxToken>(token, {
|
2022-03-11 14:29:29 +08:00
|
|
|
checkboxCls: `.${prefixCls}`,
|
2022-05-31 10:10:35 +08:00
|
|
|
checkboxSize: token.controlInteractiveSize,
|
2022-04-11 16:04:00 +08:00
|
|
|
});
|
2022-03-11 14:29:29 +08:00
|
|
|
|
2022-04-26 01:00:39 +08:00
|
|
|
return [genCheckboxStyle(checkboxToken)];
|
2022-03-02 20:32:25 +08:00
|
|
|
}
|
|
|
|
|
2022-04-21 02:06:22 +08:00
|
|
|
export default genComponentStyleHook('Checkbox', (token, { prefixCls }) => [
|
|
|
|
getStyle(prefixCls, token),
|
2022-04-07 18:24:45 +08:00
|
|
|
]);
|