ant-design/components/rate/style/index.tsx
MadCcc 9f2f9bb57f
refactor: default theme with algorithm (#36175)
* refactor: alias token

* refactor: use palettes

* refactor: default theme

* chore: code clean

* refactor: component token

* feat: light tokens

* feat: add dark theme

* feat: dark derivative

* chore: code clean

* refactor: fix colorBgContainer

* refactor: rename token

* test: fix lint

* chore: code clean

* chore: code clen

* refactor: badge shadow color

* test: add test case
2022-06-24 11:11:42 +08:00

136 lines
3.2 KiB
TypeScript

// deps-lint-skip-all
import type { CSSObject } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from '../../_util/theme';
import { genComponentStyleHook, mergeToken, resetComponent } from '../../_util/theme';
export type ComponentToken = {};
interface RateToken extends FullToken<'Rate'> {
rateStarColor: string;
rateStarSize: number;
rateStarHoverScale: CSSObject['transform'];
defaultColor: string;
}
const genRateStarStyle: GenerateStyle<RateToken, CSSObject> = token => {
const { componentCls } = token;
return {
[`${componentCls}-star`]: {
position: 'relative',
display: 'inline-block',
color: 'inherit',
cursor: 'pointer',
'&:not(:last-child)': {
marginInlineEnd: token.marginXS,
},
'> div': {
transition: `all ${token.motionDurationSlow}, outline 0s`,
'&:hover': {
transform: token.rateStarHoverScale,
},
'&:focus': {
outline: 0,
},
'&:focus-visible': {
outline: `${token.lineWidth}px dashed ${token.rateStarColor}`,
transform: token.rateStarHoverScale,
},
},
'&-first, &-second': {
color: token.defaultColor,
transition: `all ${token.motionDurationSlow}`,
userSelect: 'none',
[token.iconCls]: {
verticalAlign: 'middle',
},
},
'&-first': {
position: 'absolute',
top: 0,
insetInlineStart: 0,
width: '50%',
height: '100%',
overflow: 'hidden',
opacity: 0,
},
[`&-half ${componentCls}-star-first, &-half ${componentCls}-star-second`]: {
opacity: 1,
},
[`&-half ${componentCls}-star-first, &-full ${componentCls}-star-second`]: {
color: 'inherit',
},
},
};
};
const genRateRtlStyle = (token: RateToken): CSSObject => ({
[`&-rtl${token.componentCls}`]: {
direction: 'rtl',
},
});
const genRateStyle: GenerateStyle<RateToken> = token => {
const { componentCls } = token;
return {
[componentCls]: {
...resetComponent(token),
display: 'inline-block',
margin: 0,
padding: 0,
color: token.rateStarColor,
fontSize: token.rateStarSize,
lineHeight: 'unset',
listStyle: 'none',
outline: 'none',
// disable styles
[`&-disabled${componentCls} ${componentCls}-star`]: {
cursor: 'default',
'&:hover': {
transform: 'scale(1)',
},
},
// star styles
...genRateStarStyle(token),
// text styles
[`+ ${componentCls}-text`]: {
display: 'inline-block',
marginInlineStart: token.marginXS,
fontSize: token.fontSize,
},
// rtl styles
...genRateRtlStyle(token),
},
};
};
// ============================== Export ==============================
export default genComponentStyleHook('Rate', token => {
const { textColors } = token;
const rateToken = mergeToken<RateToken>(token, {
rateStarColor: token['yellow-6'],
rateStarSize: token.controlHeightLG * 0.5,
rateStarHoverScale: 'scale(1.1)',
defaultColor: textColors['12'],
});
return [genRateStyle(rateToken)];
});