File size: 2,671 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
import { unit } from '@ant-design/cssinjs';
import { FastColor } from '@ant-design/fast-color';
import { resetComponent } from '../../style';
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
import { genStyleHooks, mergeToken } from '../../theme/internal';
// biome-ignore lint/suspicious/noEmptyInterface: ComponentToken need to be empty by default
export interface ComponentToken {}
/**
* @desc QRCode 组件的 Token
* @descEN Token for QRCode component
*/
interface QRCodeToken extends FullToken<'QRCode'> {
/**
* @desc QRCode 文字颜色
* @descEN Text color of QRCode
*/
QRCodeTextColor: string;
/**
* @desc QRCode 遮罩背景颜色
* @descEN Mask background color of QRCode
*/
QRCodeMaskBackgroundColor: string;
}
const genQRCodeStyle: GenerateStyle<QRCodeToken> = (token) => {
const { componentCls, lineWidth, lineType, colorSplit } = token;
return {
[componentCls]: {
...resetComponent(token),
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
padding: token.paddingSM,
backgroundColor: token.colorWhite,
borderRadius: token.borderRadiusLG,
border: `${unit(lineWidth)} ${lineType} ${colorSplit}`,
position: 'relative',
overflow: 'hidden',
[`& > ${componentCls}-mask`]: {
position: 'absolute',
insetBlockStart: 0,
insetInlineStart: 0,
zIndex: 10,
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
width: '100%',
height: '100%',
color: token.colorText,
lineHeight: token.lineHeight,
background: token.QRCodeMaskBackgroundColor,
textAlign: 'center',
[`& > ${componentCls}-expired, & > ${componentCls}-scanned`]: {
color: token.QRCodeTextColor,
},
},
'> canvas': {
alignSelf: 'stretch',
flex: 'auto',
minWidth: 0,
},
'&-icon': {
marginBlockEnd: token.marginXS,
fontSize: token.controlHeight,
},
},
[`${componentCls}-borderless`]: {
borderColor: 'transparent',
padding: 0,
borderRadius: 0,
},
};
};
export const prepareComponentToken: GetDefaultToken<'QRCode'> = (token) => ({
QRCodeMaskBackgroundColor: new FastColor(token.colorBgContainer).setA(0.96).toRgbString(),
});
export default genStyleHooks<'QRCode'>(
'QRCode',
(token) => {
const mergedToken = mergeToken<QRCodeToken>(token, {
QRCodeTextColor: token.colorText,
});
return genQRCodeStyle(mergedToken);
},
prepareComponentToken,
);
|