2023-11-14 10:34:01 +08:00
|
|
|
import { unit } from '@ant-design/cssinjs';
|
2024-01-26 23:08:47 +08:00
|
|
|
import { TinyColor } from '@ctrl/tinycolor';
|
2023-11-14 10:34:01 +08:00
|
|
|
|
2023-07-17 23:43:32 +08:00
|
|
|
import { resetComponent } from '../../style';
|
2023-11-14 10:34:01 +08:00
|
|
|
import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal';
|
2023-11-29 17:23:45 +08:00
|
|
|
import { genStyleHooks, mergeToken } from '../../theme/internal';
|
2023-07-17 23:43:32 +08:00
|
|
|
|
|
|
|
export interface ComponentToken {}
|
|
|
|
|
|
|
|
interface QRCodeToken extends FullToken<'QRCode'> {
|
2023-12-30 14:52:08 +08:00
|
|
|
QRCodeTextColor: string;
|
2023-07-17 23:43:32 +08:00
|
|
|
QRCodeMaskBackgroundColor: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const genQRCodeStyle: GenerateStyle<QRCodeToken> = (token) => {
|
2023-11-14 10:34:01 +08:00
|
|
|
const { componentCls, lineWidth, lineType, colorSplit } = token;
|
2023-07-17 23:43:32 +08:00
|
|
|
return {
|
|
|
|
[componentCls]: {
|
|
|
|
...resetComponent(token),
|
|
|
|
display: 'flex',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
padding: token.paddingSM,
|
|
|
|
backgroundColor: token.colorWhite,
|
|
|
|
borderRadius: token.borderRadiusLG,
|
2023-11-14 10:34:01 +08:00
|
|
|
border: `${unit(lineWidth)} ${lineType} ${colorSplit}`,
|
2023-07-17 23:43:32 +08:00
|
|
|
position: 'relative',
|
|
|
|
overflow: 'hidden',
|
2023-11-13 18:35:23 +08:00
|
|
|
|
2023-07-17 23:43:32 +08:00
|
|
|
[`& > ${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',
|
2023-12-30 14:52:08 +08:00
|
|
|
[`& > ${componentCls}-expired, & > ${componentCls}-scanned`]: {
|
|
|
|
color: token.QRCodeTextColor,
|
2023-07-17 23:43:32 +08:00
|
|
|
},
|
|
|
|
},
|
2023-11-13 18:35:23 +08:00
|
|
|
|
|
|
|
'> canvas': {
|
|
|
|
alignSelf: 'stretch',
|
|
|
|
flex: 'auto',
|
|
|
|
minWidth: 0,
|
|
|
|
},
|
|
|
|
|
2023-07-17 23:43:32 +08:00
|
|
|
'&-icon': {
|
|
|
|
marginBlockEnd: token.marginXS,
|
|
|
|
fontSize: token.controlHeight,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
[`${componentCls}-borderless`]: {
|
|
|
|
borderColor: 'transparent',
|
2024-04-30 17:03:00 +08:00
|
|
|
padding: 0,
|
|
|
|
borderRadius: 0,
|
2023-07-17 23:43:32 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-01-26 23:08:47 +08:00
|
|
|
export const prepareComponentToken: GetDefaultToken<'QRCode'> = (token) => ({
|
|
|
|
QRCodeMaskBackgroundColor: new TinyColor(token.colorBgContainer).setAlpha(0.96).toRgbString(),
|
|
|
|
});
|
2023-11-14 10:34:01 +08:00
|
|
|
|
2023-11-29 17:23:45 +08:00
|
|
|
export default genStyleHooks<'QRCode'>(
|
2023-11-14 10:34:01 +08:00
|
|
|
'QRCode',
|
|
|
|
(token) => {
|
|
|
|
const mergedToken = mergeToken<QRCodeToken>(token, {
|
2024-01-26 23:08:47 +08:00
|
|
|
QRCodeTextColor: token.colorText,
|
2023-11-14 10:34:01 +08:00
|
|
|
});
|
2024-01-26 23:08:47 +08:00
|
|
|
|
2023-11-14 10:34:01 +08:00
|
|
|
return genQRCodeStyle(mergedToken);
|
|
|
|
},
|
|
|
|
prepareComponentToken,
|
2023-07-17 23:43:32 +08:00
|
|
|
);
|