| import { unit } from '@ant-design/cssinjs'; |
|
|
| import { genFocusOutline, resetComponent } from '../../style'; |
| import type { FullToken, GenerateStyle } from '../../theme/internal'; |
| import { genStyleHooks, mergeToken } from '../../theme/internal'; |
|
|
| |
| export interface ComponentToken {} |
|
|
| |
| |
| |
| |
| interface CheckboxToken extends FullToken<'Checkbox'> { |
| |
| |
| |
| |
| checkboxCls: string; |
| |
| |
| |
| |
| checkboxSize: number; |
| } |
|
|
| |
| export const genCheckboxStyle: GenerateStyle<CheckboxToken> = (token) => { |
| const { checkboxCls } = token; |
| const wrapperCls = `${checkboxCls}-wrapper`; |
|
|
| return [ |
| |
| { |
| |
| [`${checkboxCls}-group`]: { |
| ...resetComponent(token), |
|
|
| display: 'inline-flex', |
| flexWrap: 'wrap', |
| columnGap: token.marginXS, |
|
|
| |
| [`> ${token.antCls}-row`]: { |
| flex: 1, |
| }, |
| }, |
|
|
| |
| [wrapperCls]: { |
| ...resetComponent(token), |
|
|
| display: 'inline-flex', |
| alignItems: 'baseline', |
| cursor: 'pointer', |
|
|
| |
| '&:after': { |
| display: 'inline-block', |
| width: 0, |
| overflow: 'hidden', |
| content: "'\\a0'", |
| }, |
|
|
| |
| [`& + ${wrapperCls}`]: { |
| marginInlineStart: 0, |
| }, |
|
|
| [`&${wrapperCls}-in-form-item`]: { |
| 'input[type="checkbox"]': { |
| width: 14, |
| height: 14, |
| }, |
| }, |
| }, |
|
|
| |
| [checkboxCls]: { |
| ...resetComponent(token), |
|
|
| position: 'relative', |
| whiteSpace: 'nowrap', |
| lineHeight: 1, |
| cursor: 'pointer', |
| borderRadius: token.borderRadiusSM, |
|
|
| |
| |
| alignSelf: 'center', |
|
|
| |
| [`${checkboxCls}-input`]: { |
| position: 'absolute', |
| |
| |
| |
| inset: 0, |
| zIndex: 1, |
| cursor: 'pointer', |
| opacity: 0, |
| margin: 0, |
|
|
| [`&:focus-visible + ${checkboxCls}-inner`]: { |
| ...genFocusOutline(token), |
| }, |
| }, |
|
|
| |
| [`${checkboxCls}-inner`]: { |
| boxSizing: 'border-box', |
| display: 'block', |
| width: token.checkboxSize, |
| height: token.checkboxSize, |
| direction: 'ltr', |
| backgroundColor: token.colorBgContainer, |
| border: `${unit(token.lineWidth)} ${token.lineType} ${token.colorBorder}`, |
| borderRadius: token.borderRadiusSM, |
| borderCollapse: 'separate', |
| transition: `all ${token.motionDurationSlow}`, |
|
|
| '&:after': { |
| boxSizing: 'border-box', |
| position: 'absolute', |
| top: '50%', |
| insetInlineStart: '25%', |
| display: 'table', |
| width: token.calc(token.checkboxSize).div(14).mul(5).equal(), |
| height: token.calc(token.checkboxSize).div(14).mul(8).equal(), |
| border: `${unit(token.lineWidthBold)} solid ${token.colorWhite}`, |
| borderTop: 0, |
| borderInlineStart: 0, |
| transform: 'rotate(45deg) scale(0) translate(-50%,-50%)', |
| opacity: 0, |
| content: '""', |
| transition: `all ${token.motionDurationFast} ${token.motionEaseInBack}, opacity ${token.motionDurationFast}`, |
| }, |
| }, |
|
|
| |
| '& + span': { |
| paddingInlineStart: token.paddingXS, |
| paddingInlineEnd: token.paddingXS, |
| }, |
| }, |
| }, |
|
|
| |
| { |
| |
| [` |
| ${wrapperCls}:not(${wrapperCls}-disabled), |
| ${checkboxCls}:not(${checkboxCls}-disabled) |
| `]: { |
| [`&:hover ${checkboxCls}-inner`]: { |
| borderColor: token.colorPrimary, |
| }, |
| }, |
|
|
| [`${wrapperCls}:not(${wrapperCls}-disabled)`]: { |
| [`&:hover ${checkboxCls}-checked:not(${checkboxCls}-disabled) ${checkboxCls}-inner`]: { |
| backgroundColor: token.colorPrimaryHover, |
| borderColor: 'transparent', |
| }, |
| [`&:hover ${checkboxCls}-checked:not(${checkboxCls}-disabled):after`]: { |
| borderColor: token.colorPrimaryHover, |
| }, |
| }, |
| }, |
|
|
| |
| { |
| |
| [`${checkboxCls}-checked`]: { |
| [`${checkboxCls}-inner`]: { |
| backgroundColor: token.colorPrimary, |
| borderColor: token.colorPrimary, |
|
|
| '&:after': { |
| opacity: 1, |
| transform: 'rotate(45deg) scale(1) translate(-50%,-50%)', |
| transition: `all ${token.motionDurationMid} ${token.motionEaseOutBack} ${token.motionDurationFast}`, |
| }, |
| }, |
| }, |
|
|
| [` |
| ${wrapperCls}-checked:not(${wrapperCls}-disabled), |
| ${checkboxCls}-checked:not(${checkboxCls}-disabled) |
| `]: { |
| [`&:hover ${checkboxCls}-inner`]: { |
| backgroundColor: token.colorPrimaryHover, |
| borderColor: 'transparent', |
| }, |
| }, |
| }, |
|
|
| |
| { |
| [checkboxCls]: { |
| '&-indeterminate': { |
| '&': { |
| |
| [`${checkboxCls}-inner`]: { |
| backgroundColor: `${token.colorBgContainer}`, |
| borderColor: `${token.colorBorder}`, |
|
|
| '&:after': { |
| top: '50%', |
| insetInlineStart: '50%', |
| width: token.calc(token.fontSizeLG).div(2).equal(), |
| height: token.calc(token.fontSizeLG).div(2).equal(), |
| backgroundColor: token.colorPrimary, |
| border: 0, |
| transform: 'translate(-50%, -50%) scale(1)', |
| opacity: 1, |
| content: '""', |
| }, |
| }, |
|
|
| |
| [`&:hover ${checkboxCls}-inner`]: { |
| backgroundColor: `${token.colorBgContainer}`, |
| borderColor: `${token.colorPrimary}`, |
| }, |
| }, |
| }, |
| }, |
| }, |
|
|
| |
| { |
| |
| [`${wrapperCls}-disabled`]: { |
| cursor: 'not-allowed', |
| }, |
|
|
| |
| [`${checkboxCls}-disabled`]: { |
| |
| [`&, ${checkboxCls}-input`]: { |
| cursor: 'not-allowed', |
| |
| |
| pointerEvents: 'none', |
| }, |
|
|
| |
| [`${checkboxCls}-inner`]: { |
| background: token.colorBgContainerDisabled, |
| borderColor: token.colorBorder, |
|
|
| '&:after': { |
| borderColor: token.colorTextDisabled, |
| }, |
| }, |
|
|
| '&:after': { |
| display: 'none', |
| }, |
|
|
| '& + span': { |
| color: token.colorTextDisabled, |
| }, |
|
|
| [`&${checkboxCls}-indeterminate ${checkboxCls}-inner::after`]: { |
| background: token.colorTextDisabled, |
| }, |
| }, |
| }, |
| ]; |
| }; |
|
|
| |
| export function getStyle(prefixCls: string, token: FullToken<'Checkbox'>) { |
| const checkboxToken: CheckboxToken = mergeToken<CheckboxToken>(token, { |
| checkboxCls: `.${prefixCls}`, |
| checkboxSize: token.controlInteractiveSize, |
| }); |
|
|
| return [genCheckboxStyle(checkboxToken)]; |
| } |
|
|
| export default genStyleHooks('Checkbox', (token, { prefixCls }) => [getStyle(prefixCls, token)]); |
|
|