mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-05 01:19:45 +08:00
a05b9d92c5
* feat: add FloatButton * feat: add FloatButton * feat: FloatButton * feat: FloatButton * fix: fix * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * feat: FloatButton * fix: add groupShape * feat: mergeShape * fix: fix * fix: fix style * fix: style fix * fix: fix * fix: style fix * fix: fix * fix: fix * fix: fix * fix: fix style * fix: fix style * fix: fix style * fix: style fix * feat: back-top * fix: style bug fix * fix: fix erroe * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * fix: add tiggerElement * feat: add useMemo * docs: add docs * fix: bugFix * fix: bugFix * fix: bugfix * fix: style fix * fix: bugfix * test: add test case * fix: style fix * fix: style fix * fix: fix style * fix: fix style * fix: fix trigger action * fix: fix style * feat: add demo * fix: add demo * feat: add docs * fix: style ifx * feat: update maxSize of bundlesize * feat: add animation for group * fix: fix * fix: fix style * fix: fix test case * fix: fix test case * fix: fix type * fix: fix type * fix: update bundlesize * fix: fix * fix: fix style * fix: fix style * fix: updata snap * fix: fix CI * fix: fix style * fix: rename float button motion * fix: fix style * fix: bugFix * fix: fix style * fix: bugFix * fix: update docs * refactor: float button trigger * test: fix test case & update snapshot * fix: delete rest * docs: update demo * test: update snapshot * fix: fix eslint error * test: update snapshot * style: update icon fontSize to 18 * fix: fix style * fix: style fix * fix: test case fix * test: add test case * fix: style fix * test: update snap * fix: style fix * fix: style fix * fix: style fix * docs: demo update * fix: style fix * docs: update demo * test: update snapshot Co-authored-by: 黑雨 <wangning4567@163.com> Co-authored-by: MadCcc <1075746765@qq.com>
300 lines
8.9 KiB
TypeScript
300 lines
8.9 KiB
TypeScript
import type { CSSObject } from '@ant-design/cssinjs';
|
|
import { Keyframes } from '@ant-design/cssinjs';
|
|
import type { FullToken, GenerateStyle } from '../../theme';
|
|
import { genComponentStyleHook, mergeToken } from '../../theme';
|
|
import { resetComponent } from '../../style';
|
|
|
|
/** Component only token. Which will handle additional calculation of alias token */
|
|
export interface ComponentToken {
|
|
zIndexPopup: number;
|
|
}
|
|
|
|
type FloatButtonToken = FullToken<'FloatButton'> & {
|
|
floatButtonColor: string;
|
|
floatButtonBackgroundColor: string;
|
|
floatButtonHoverBackgroundColor: string;
|
|
floatButtonFontSize: number;
|
|
floatButtonSize: number;
|
|
floatButtonIconSize: number;
|
|
|
|
// Position
|
|
floatButtonInsetBlockEnd: number;
|
|
floatButtonInsetInlineEnd: number;
|
|
};
|
|
|
|
// ============================== Group ==============================
|
|
const floatButtonGroupStyle: GenerateStyle<FloatButtonToken, CSSObject> = token => {
|
|
const { componentCls, floatButtonSize, margin, radiusBase, motionDurationSlow } = token;
|
|
const groupPrefixCls = `${componentCls}-group`;
|
|
const moveDownIn = new Keyframes('antFloatButtonMoveDownIn', {
|
|
'0%': {
|
|
transform: `translate3d(0, ${floatButtonSize}px, 0)`,
|
|
transformOrigin: '0 0',
|
|
opacity: 0,
|
|
},
|
|
|
|
'100%': {
|
|
transform: 'translate3d(0, 0, 0)',
|
|
transformOrigin: '0 0',
|
|
opacity: 1,
|
|
},
|
|
});
|
|
const moveDownOut = new Keyframes('antFloatButtonMoveDownOut', {
|
|
'0%': {
|
|
transform: 'translate3d(0, 0, 0)',
|
|
transformOrigin: '0 0',
|
|
opacity: 1,
|
|
},
|
|
|
|
'100%': {
|
|
transform: `translate3d(0, ${floatButtonSize}px, 0)`,
|
|
transformOrigin: '0 0',
|
|
opacity: 0,
|
|
},
|
|
});
|
|
return {
|
|
[groupPrefixCls]: {
|
|
...resetComponent(token),
|
|
zIndex: 99,
|
|
display: 'block',
|
|
border: 'none',
|
|
position: 'fixed',
|
|
width: floatButtonSize,
|
|
height: 'auto',
|
|
boxShadow: 'none',
|
|
minHeight: floatButtonSize,
|
|
insetInlineEnd: token.floatButtonInsetInlineEnd,
|
|
insetBlockEnd: token.floatButtonInsetBlockEnd,
|
|
backgroundColor: token.colorBgContainer,
|
|
borderRadius: token.radiusBase,
|
|
[`${groupPrefixCls}-wrap`]: {
|
|
zIndex: -1,
|
|
display: 'block',
|
|
position: 'relative',
|
|
marginBottom: margin,
|
|
},
|
|
'&&-rtl': {
|
|
direction: 'rtl',
|
|
},
|
|
[componentCls]: {
|
|
position: 'static',
|
|
},
|
|
},
|
|
[`${groupPrefixCls}-circle`]: {
|
|
[`${componentCls}-circle:not(:last-child)`]: {
|
|
marginBottom: token.margin,
|
|
[`${componentCls}-body`]: {
|
|
width: floatButtonSize,
|
|
height: floatButtonSize,
|
|
},
|
|
},
|
|
},
|
|
[`${groupPrefixCls}-square`]: {
|
|
[`${componentCls}-square`]: {
|
|
borderRadius: 0,
|
|
padding: 0,
|
|
'&:first-child': {
|
|
borderStartStartRadius: radiusBase,
|
|
borderStartEndRadius: radiusBase,
|
|
},
|
|
'&:last-child': {
|
|
borderEndStartRadius: radiusBase,
|
|
borderEndEndRadius: radiusBase,
|
|
},
|
|
'&:not(:last-child)': {
|
|
borderBottom: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
|
|
},
|
|
},
|
|
[`${groupPrefixCls}-wrap`]: {
|
|
display: 'block',
|
|
borderRadius: radiusBase,
|
|
boxShadow: token.boxShadowSecondary,
|
|
overflow: 'hidden',
|
|
[`${componentCls}-square`]: {
|
|
boxShadow: 'none',
|
|
marginTop: 0,
|
|
borderRadius: 0,
|
|
padding: token.paddingXXS,
|
|
'&:first-child': {
|
|
borderStartStartRadius: radiusBase,
|
|
borderStartEndRadius: radiusBase,
|
|
},
|
|
'&:last-child': {
|
|
borderEndStartRadius: radiusBase,
|
|
borderEndEndRadius: radiusBase,
|
|
},
|
|
'&:not(:last-child)': {
|
|
borderBottom: `${token.lineWidth}px ${token.lineType} ${token.colorSplit}`,
|
|
},
|
|
[`${componentCls}-body`]: {
|
|
width: floatButtonSize - token.paddingXXS * 2,
|
|
height: floatButtonSize - token.paddingXXS * 2,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
[`${groupPrefixCls}-wrap-enter,${groupPrefixCls}-wrap-enter-active`]: {
|
|
animationName: moveDownIn,
|
|
animationDuration: motionDurationSlow,
|
|
},
|
|
[`${groupPrefixCls}-wrap-leave`]: {
|
|
animationName: moveDownOut,
|
|
animationDuration: motionDurationSlow,
|
|
},
|
|
|
|
[`${groupPrefixCls}-circle-shadow`]: {
|
|
boxShadow: 'none',
|
|
},
|
|
[`${groupPrefixCls}-square-shadow`]: {
|
|
boxShadow: token.boxShadowSecondary,
|
|
[`${componentCls}-square`]: {
|
|
boxShadow: 'none',
|
|
padding: token.paddingXXS,
|
|
[`${componentCls}-body`]: {
|
|
width: floatButtonSize - token.paddingXXS * 2,
|
|
height: floatButtonSize - token.paddingXXS * 2,
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
// ============================== Shared ==============================
|
|
const sharedFloatButtonStyle: GenerateStyle<FloatButtonToken, CSSObject> = token => {
|
|
const { componentCls, floatButtonIconSize, floatButtonSize } = token;
|
|
return {
|
|
[componentCls]: {
|
|
...resetComponent(token),
|
|
border: 'none',
|
|
position: 'fixed',
|
|
cursor: 'pointer',
|
|
overflow: 'hidden',
|
|
zIndex: 99,
|
|
display: 'block',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
width: floatButtonSize,
|
|
height: floatButtonSize,
|
|
insetInlineEnd: token.floatButtonInsetInlineEnd,
|
|
insetBlockEnd: token.floatButtonInsetBlockEnd,
|
|
boxShadow: token.boxShadowSecondary,
|
|
'&:empty': {
|
|
display: 'none',
|
|
},
|
|
[`${componentCls}-body`]: {
|
|
width: floatButtonSize,
|
|
height: floatButtonSize,
|
|
display: 'flex',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
transition: `all ${token.motionDurationFast}`,
|
|
[`${componentCls}-content`]: {
|
|
overflow: 'hidden',
|
|
textAlign: 'center',
|
|
minHeight: floatButtonSize,
|
|
display: 'flex',
|
|
flexDirection: 'column',
|
|
justifyContent: 'center',
|
|
alignItems: 'center',
|
|
padding: `2px 4px`,
|
|
[`${componentCls}-icon`]: {
|
|
textAlign: 'center',
|
|
margin: 'auto',
|
|
width: floatButtonIconSize,
|
|
fontSize: floatButtonIconSize,
|
|
lineHeight: 1,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
[`${componentCls}-circle`]: {
|
|
height: floatButtonSize,
|
|
borderRadius: '50%',
|
|
[`${componentCls}-body`]: {
|
|
borderRadius: '50%',
|
|
},
|
|
},
|
|
[`${componentCls}-square`]: {
|
|
height: 'auto',
|
|
minHeight: floatButtonSize,
|
|
borderRadius: token.radiusBase,
|
|
[`${componentCls}-body`]: {
|
|
height: 'auto',
|
|
borderRadius: token.radiusSM,
|
|
},
|
|
},
|
|
[`${componentCls}-default`]: {
|
|
backgroundColor: token.colorBgContainer,
|
|
transition: `background-color ${token.motionDurationFast}`,
|
|
[`${componentCls}-body`]: {
|
|
backgroundColor: token.colorBgContainer,
|
|
transition: `background-color ${token.motionDurationFast}`,
|
|
'&:hover': {
|
|
backgroundColor: token.colorFillContent,
|
|
},
|
|
[`${componentCls}-content`]: {
|
|
[`${componentCls}-icon`]: {
|
|
color: token.colorText,
|
|
},
|
|
[`${componentCls}-description`]: {
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
lineHeight: `${token.fontSizeLG}px`,
|
|
color: token.colorText,
|
|
fontSize: token.fontSizeSM,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
[`${componentCls}-primary`]: {
|
|
backgroundColor: token.colorPrimary,
|
|
[`${componentCls}-body`]: {
|
|
backgroundColor: token.colorPrimary,
|
|
transition: `background-color ${token.motionDurationFast}`,
|
|
'&:hover': {
|
|
backgroundColor: token.colorPrimaryHover,
|
|
},
|
|
[`${componentCls}-content`]: {
|
|
[`${componentCls}-icon`]: {
|
|
color: token.colorTextLightSolid,
|
|
},
|
|
[`${componentCls}-description`]: {
|
|
display: 'flex',
|
|
alignItems: 'center',
|
|
lineHeight: `${token.fontSizeLG}px`,
|
|
color: token.colorTextLightSolid,
|
|
fontSize: token.fontSizeSM,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
};
|
|
};
|
|
|
|
// ============================== Export ==============================
|
|
export default genComponentStyleHook<'FloatButton'>('FloatButton', token => {
|
|
const {
|
|
colorTextLightSolid,
|
|
colorBgContainer,
|
|
controlHeightLG,
|
|
marginXXL,
|
|
marginLG,
|
|
fontSize,
|
|
fontSizeIcon,
|
|
controlItemBgHover,
|
|
} = token;
|
|
const floatButtonToken = mergeToken<FloatButtonToken>(token, {
|
|
floatButtonBackgroundColor: colorBgContainer,
|
|
floatButtonColor: colorTextLightSolid,
|
|
floatButtonHoverBackgroundColor: controlItemBgHover,
|
|
floatButtonFontSize: fontSize,
|
|
floatButtonIconSize: fontSizeIcon * 1.5,
|
|
floatButtonSize: controlHeightLG,
|
|
|
|
floatButtonInsetBlockEnd: marginXXL,
|
|
floatButtonInsetInlineEnd: marginLG,
|
|
});
|
|
return [floatButtonGroupStyle(floatButtonToken), sharedFloatButtonStyle(floatButtonToken)];
|
|
});
|