|
| 1 | +import type { CSSObject } from '../../_util/cssinjs'; |
| 2 | +import type { SelectToken } from '.'; |
| 3 | +import { |
| 4 | + initMoveMotion, |
| 5 | + initSlideMotion, |
| 6 | + slideDownIn, |
| 7 | + slideDownOut, |
| 8 | + slideUpIn, |
| 9 | + slideUpOut, |
| 10 | +} from '../../_style/motion'; |
| 11 | +import type { GenerateStyle } from '../../theme/internal'; |
| 12 | +import { resetComponent, textEllipsis } from '../../_style'; |
| 13 | + |
| 14 | +const genItemStyle: GenerateStyle<SelectToken, CSSObject> = token => { |
| 15 | + const { controlPaddingHorizontal } = token; |
| 16 | + |
| 17 | + return { |
| 18 | + position: 'relative', |
| 19 | + display: 'block', |
| 20 | + minHeight: token.controlHeight, |
| 21 | + padding: `${ |
| 22 | + (token.controlHeight - token.fontSize * token.lineHeight) / 2 |
| 23 | + }px ${controlPaddingHorizontal}px`, |
| 24 | + color: token.colorText, |
| 25 | + fontWeight: 'normal', |
| 26 | + fontSize: token.fontSize, |
| 27 | + lineHeight: token.lineHeight, |
| 28 | + boxSizing: 'border-box', |
| 29 | + }; |
| 30 | +}; |
| 31 | + |
| 32 | +const genSingleStyle: GenerateStyle<SelectToken> = token => { |
| 33 | + const { antCls, componentCls } = token; |
| 34 | + |
| 35 | + const selectItemCls = `${componentCls}-item`; |
| 36 | + |
| 37 | + return [ |
| 38 | + { |
| 39 | + [`${componentCls}-dropdown`]: { |
| 40 | + // ========================== Popup ========================== |
| 41 | + ...resetComponent(token), |
| 42 | + |
| 43 | + position: 'absolute', |
| 44 | + top: -9999, |
| 45 | + zIndex: token.zIndexPopup, |
| 46 | + boxSizing: 'border-box', |
| 47 | + padding: token.paddingXXS, |
| 48 | + overflow: 'hidden', |
| 49 | + fontSize: token.fontSize, |
| 50 | + // Fix select render lag of long text in chrome |
| 51 | + // https://github.com/ant-design/ant-design/issues/11456 |
| 52 | + // https://github.com/ant-design/ant-design/issues/11843 |
| 53 | + fontVariant: 'initial', |
| 54 | + backgroundColor: token.colorBgElevated, |
| 55 | + borderRadius: token.borderRadiusLG, |
| 56 | + outline: 'none', |
| 57 | + boxShadow: token.boxShadowSecondary, |
| 58 | + |
| 59 | + [` |
| 60 | + &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-bottomLeft, |
| 61 | + &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-bottomLeft |
| 62 | + `]: { |
| 63 | + animationName: slideUpIn, |
| 64 | + }, |
| 65 | + |
| 66 | + [` |
| 67 | + &${antCls}-slide-up-enter${antCls}-slide-up-enter-active${componentCls}-dropdown-placement-topLeft, |
| 68 | + &${antCls}-slide-up-appear${antCls}-slide-up-appear-active${componentCls}-dropdown-placement-topLeft |
| 69 | + `]: { |
| 70 | + animationName: slideDownIn, |
| 71 | + }, |
| 72 | + |
| 73 | + [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-bottomLeft`]: |
| 74 | + { |
| 75 | + animationName: slideUpOut, |
| 76 | + }, |
| 77 | + |
| 78 | + [`&${antCls}-slide-up-leave${antCls}-slide-up-leave-active${componentCls}-dropdown-placement-topLeft`]: |
| 79 | + { |
| 80 | + animationName: slideDownOut, |
| 81 | + }, |
| 82 | + |
| 83 | + '&-hidden': { |
| 84 | + display: 'none', |
| 85 | + }, |
| 86 | + |
| 87 | + '&-empty': { |
| 88 | + color: token.colorTextDisabled, |
| 89 | + }, |
| 90 | + |
| 91 | + // ========================= Options ========================= |
| 92 | + [`${selectItemCls}-empty`]: { |
| 93 | + ...genItemStyle(token), |
| 94 | + color: token.colorTextDisabled, |
| 95 | + }, |
| 96 | + |
| 97 | + [`${selectItemCls}`]: { |
| 98 | + ...genItemStyle(token), |
| 99 | + cursor: 'pointer', |
| 100 | + transition: `background ${token.motionDurationSlow} ease`, |
| 101 | + borderRadius: token.borderRadiusSM, |
| 102 | + |
| 103 | + // =========== Group ============ |
| 104 | + '&-group': { |
| 105 | + color: token.colorTextDescription, |
| 106 | + fontSize: token.fontSizeSM, |
| 107 | + cursor: 'default', |
| 108 | + }, |
| 109 | + |
| 110 | + // =========== Option =========== |
| 111 | + '&-option': { |
| 112 | + display: 'flex', |
| 113 | + |
| 114 | + '&-content': { |
| 115 | + flex: 'auto', |
| 116 | + ...textEllipsis, |
| 117 | + }, |
| 118 | + |
| 119 | + '&-state': { |
| 120 | + flex: 'none', |
| 121 | + }, |
| 122 | + |
| 123 | + [`&-active:not(${selectItemCls}-option-disabled)`]: { |
| 124 | + backgroundColor: token.controlItemBgHover, |
| 125 | + }, |
| 126 | + |
| 127 | + [`&-selected:not(${selectItemCls}-option-disabled)`]: { |
| 128 | + color: token.colorText, |
| 129 | + fontWeight: token.fontWeightStrong, |
| 130 | + backgroundColor: token.controlItemBgActive, |
| 131 | + |
| 132 | + [`${selectItemCls}-option-state`]: { |
| 133 | + color: token.colorPrimary, |
| 134 | + }, |
| 135 | + }, |
| 136 | + '&-disabled': { |
| 137 | + [`&${selectItemCls}-option-selected`]: { |
| 138 | + backgroundColor: token.colorBgContainerDisabled, |
| 139 | + }, |
| 140 | + |
| 141 | + color: token.colorTextDisabled, |
| 142 | + cursor: 'not-allowed', |
| 143 | + }, |
| 144 | + |
| 145 | + '&-grouped': { |
| 146 | + paddingInlineStart: token.controlPaddingHorizontal * 2, |
| 147 | + }, |
| 148 | + }, |
| 149 | + }, |
| 150 | + |
| 151 | + // =========================== RTL =========================== |
| 152 | + '&-rtl': { |
| 153 | + direction: 'rtl', |
| 154 | + }, |
| 155 | + }, |
| 156 | + }, |
| 157 | + |
| 158 | + // Follow code may reuse in other components |
| 159 | + initSlideMotion(token, 'slide-up'), |
| 160 | + initSlideMotion(token, 'slide-down'), |
| 161 | + initMoveMotion(token, 'move-up'), |
| 162 | + initMoveMotion(token, 'move-down'), |
| 163 | + ]; |
| 164 | +}; |
| 165 | + |
| 166 | +export default genSingleStyle; |
0 commit comments