| | import type { CSSInterpolation } from '@ant-design/cssinjs'; |
| |
|
| | import type { FullToken, GenerateStyle, GetDefaultToken } from '../../theme/internal'; |
| | import { genStyleHooks, mergeToken } from '../../theme/internal'; |
| | import { alignItemsValues, flexWrapValues, justifyContentValues } from '../utils'; |
| |
|
| | |
| | |
| | export interface ComponentToken {} |
| |
|
| | export interface FlexToken extends FullToken<'Flex'> { |
| | |
| | |
| | |
| | |
| | |
| | |
| | flexGapSM: number; |
| | |
| | |
| | |
| | |
| | |
| | |
| | flexGap: number; |
| | |
| | |
| | |
| | |
| | |
| | |
| | flexGapLG: number; |
| | } |
| |
|
| | const genFlexStyle: GenerateStyle<FlexToken> = (token) => { |
| | const { componentCls } = token; |
| | return { |
| | [componentCls]: { |
| | display: 'flex', |
| | margin: 0, |
| | padding: 0, |
| | '&-vertical': { |
| | flexDirection: 'column', |
| | }, |
| | '&-rtl': { |
| | direction: 'rtl', |
| | }, |
| | '&:empty': { |
| | display: 'none', |
| | }, |
| | }, |
| | }; |
| | }; |
| |
|
| | const genFlexGapStyle: GenerateStyle<FlexToken> = (token) => { |
| | const { componentCls } = token; |
| | return { |
| | [componentCls]: { |
| | '&-gap-small': { |
| | gap: token.flexGapSM, |
| | }, |
| | '&-gap-middle': { |
| | gap: token.flexGap, |
| | }, |
| | '&-gap-large': { |
| | gap: token.flexGapLG, |
| | }, |
| | }, |
| | }; |
| | }; |
| |
|
| | const genFlexWrapStyle: GenerateStyle<FlexToken> = (token) => { |
| | const { componentCls } = token; |
| | const wrapStyle: CSSInterpolation = {}; |
| | flexWrapValues.forEach((value) => { |
| | wrapStyle[`${componentCls}-wrap-${value}`] = { flexWrap: value }; |
| | }); |
| | return wrapStyle; |
| | }; |
| |
|
| | const genAlignItemsStyle: GenerateStyle<FlexToken> = (token) => { |
| | const { componentCls } = token; |
| | const alignStyle: CSSInterpolation = {}; |
| | alignItemsValues.forEach((value) => { |
| | alignStyle[`${componentCls}-align-${value}`] = { alignItems: value }; |
| | }); |
| | return alignStyle; |
| | }; |
| |
|
| | const genJustifyContentStyle: GenerateStyle<FlexToken> = (token) => { |
| | const { componentCls } = token; |
| | const justifyStyle: CSSInterpolation = {}; |
| | justifyContentValues.forEach((value) => { |
| | justifyStyle[`${componentCls}-justify-${value}`] = { justifyContent: value }; |
| | }); |
| | return justifyStyle; |
| | }; |
| |
|
| | export const prepareComponentToken: GetDefaultToken<'Flex'> = () => ({}); |
| |
|
| | export default genStyleHooks( |
| | 'Flex', |
| | (token) => { |
| | const { paddingXS, padding, paddingLG } = token; |
| | const flexToken = mergeToken<FlexToken>(token, { |
| | flexGapSM: paddingXS, |
| | flexGap: padding, |
| | flexGapLG: paddingLG, |
| | }); |
| | return [ |
| | genFlexStyle(flexToken), |
| | genFlexGapStyle(flexToken), |
| | genFlexWrapStyle(flexToken), |
| | genAlignItemsStyle(flexToken), |
| | genJustifyContentStyle(flexToken), |
| | ]; |
| | }, |
| | prepareComponentToken, |
| | { |
| | |
| | |
| | resetStyle: false, |
| | }, |
| | ); |
| |
|