picture.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import _extends from "@babel/runtime/helpers/esm/extends";
  2. import { TinyColor } from '@ctrl/tinycolor';
  3. import { clearFix, textEllipsis } from '../../style';
  4. const genPictureStyle = token => {
  5. const {
  6. componentCls,
  7. iconCls,
  8. uploadThumbnailSize,
  9. uploadProgressOffset
  10. } = token;
  11. const listCls = `${componentCls}-list`;
  12. const itemCls = `${listCls}-item`;
  13. return {
  14. [`${componentCls}-wrapper`]: {
  15. // ${listCls} 增加优先级
  16. [`${listCls}${listCls}-picture, ${listCls}${listCls}-picture-card`]: {
  17. [itemCls]: {
  18. position: 'relative',
  19. height: uploadThumbnailSize + token.lineWidth * 2 + token.paddingXS * 2,
  20. padding: token.paddingXS,
  21. border: `${token.lineWidth}px ${token.lineType} ${token.colorBorder}`,
  22. borderRadius: token.borderRadiusLG,
  23. '&:hover': {
  24. background: 'transparent'
  25. },
  26. [`${itemCls}-thumbnail`]: _extends(_extends({}, textEllipsis), {
  27. width: uploadThumbnailSize,
  28. height: uploadThumbnailSize,
  29. lineHeight: `${uploadThumbnailSize + token.paddingSM}px`,
  30. textAlign: 'center',
  31. flex: 'none',
  32. [iconCls]: {
  33. fontSize: token.fontSizeHeading2,
  34. color: token.colorPrimary
  35. },
  36. img: {
  37. display: 'block',
  38. width: '100%',
  39. height: '100%',
  40. overflow: 'hidden'
  41. }
  42. }),
  43. [`${itemCls}-progress`]: {
  44. bottom: uploadProgressOffset,
  45. width: `calc(100% - ${token.paddingSM * 2}px)`,
  46. marginTop: 0,
  47. paddingInlineStart: uploadThumbnailSize + token.paddingXS
  48. }
  49. },
  50. [`${itemCls}-error`]: {
  51. borderColor: token.colorError,
  52. // Adjust the color of the error icon : https://github.com/ant-design/ant-design/pull/24160
  53. [`${itemCls}-thumbnail ${iconCls}`]: {
  54. [`svg path[fill='#e6f7ff']`]: {
  55. fill: token.colorErrorBg
  56. },
  57. [`svg path[fill='#1890ff']`]: {
  58. fill: token.colorError
  59. }
  60. }
  61. },
  62. [`${itemCls}-uploading`]: {
  63. borderStyle: 'dashed',
  64. [`${itemCls}-name`]: {
  65. marginBottom: uploadProgressOffset
  66. }
  67. }
  68. }
  69. }
  70. };
  71. };
  72. const genPictureCardStyle = token => {
  73. const {
  74. componentCls,
  75. iconCls,
  76. fontSizeLG,
  77. colorTextLightSolid
  78. } = token;
  79. const listCls = `${componentCls}-list`;
  80. const itemCls = `${listCls}-item`;
  81. const uploadPictureCardSize = token.uploadPicCardSize;
  82. return {
  83. [`${componentCls}-wrapper${componentCls}-picture-card-wrapper`]: _extends(_extends({}, clearFix()), {
  84. display: 'inline-block',
  85. width: '100%',
  86. [`${componentCls}${componentCls}-select`]: {
  87. width: uploadPictureCardSize,
  88. height: uploadPictureCardSize,
  89. marginInlineEnd: token.marginXS,
  90. marginBottom: token.marginXS,
  91. textAlign: 'center',
  92. verticalAlign: 'top',
  93. backgroundColor: token.colorFillAlter,
  94. border: `${token.lineWidth}px dashed ${token.colorBorder}`,
  95. borderRadius: token.borderRadiusLG,
  96. cursor: 'pointer',
  97. transition: `border-color ${token.motionDurationSlow}`,
  98. [`> ${componentCls}`]: {
  99. display: 'flex',
  100. alignItems: 'center',
  101. justifyContent: 'center',
  102. height: '100%',
  103. textAlign: 'center'
  104. },
  105. [`&:not(${componentCls}-disabled):hover`]: {
  106. borderColor: token.colorPrimary
  107. }
  108. },
  109. // list
  110. [`${listCls}${listCls}-picture-card`]: {
  111. [`${listCls}-item-container`]: {
  112. display: 'inline-block',
  113. width: uploadPictureCardSize,
  114. height: uploadPictureCardSize,
  115. marginBlock: `0 ${token.marginXS}px`,
  116. marginInline: `0 ${token.marginXS}px`,
  117. verticalAlign: 'top'
  118. },
  119. '&::after': {
  120. display: 'none'
  121. },
  122. [itemCls]: {
  123. height: '100%',
  124. margin: 0,
  125. '&::before': {
  126. position: 'absolute',
  127. zIndex: 1,
  128. width: `calc(100% - ${token.paddingXS * 2}px)`,
  129. height: `calc(100% - ${token.paddingXS * 2}px)`,
  130. backgroundColor: token.colorBgMask,
  131. opacity: 0,
  132. transition: `all ${token.motionDurationSlow}`,
  133. content: '" "'
  134. }
  135. },
  136. [`${itemCls}:hover`]: {
  137. [`&::before, ${itemCls}-actions`]: {
  138. opacity: 1
  139. }
  140. },
  141. [`${itemCls}-actions`]: {
  142. position: 'absolute',
  143. insetInlineStart: 0,
  144. zIndex: 10,
  145. width: '100%',
  146. whiteSpace: 'nowrap',
  147. textAlign: 'center',
  148. opacity: 0,
  149. transition: `all ${token.motionDurationSlow}`,
  150. [`${iconCls}-eye, ${iconCls}-download, ${iconCls}-delete`]: {
  151. zIndex: 10,
  152. width: fontSizeLG,
  153. margin: `0 ${token.marginXXS}px`,
  154. fontSize: fontSizeLG,
  155. cursor: 'pointer',
  156. transition: `all ${token.motionDurationSlow}`
  157. }
  158. },
  159. [`${itemCls}-actions, ${itemCls}-actions:hover`]: {
  160. [`${iconCls}-eye, ${iconCls}-download, ${iconCls}-delete`]: {
  161. color: new TinyColor(colorTextLightSolid).setAlpha(0.65).toRgbString(),
  162. '&:hover': {
  163. color: colorTextLightSolid
  164. }
  165. }
  166. },
  167. [`${itemCls}-thumbnail, ${itemCls}-thumbnail img`]: {
  168. position: 'static',
  169. display: 'block',
  170. width: '100%',
  171. height: '100%',
  172. objectFit: 'contain'
  173. },
  174. [`${itemCls}-name`]: {
  175. display: 'none',
  176. textAlign: 'center'
  177. },
  178. [`${itemCls}-file + ${itemCls}-name`]: {
  179. position: 'absolute',
  180. bottom: token.margin,
  181. display: 'block',
  182. width: `calc(100% - ${token.paddingXS * 2}px)`
  183. },
  184. [`${itemCls}-uploading`]: {
  185. [`&${itemCls}`]: {
  186. backgroundColor: token.colorFillAlter
  187. },
  188. [`&::before, ${iconCls}-eye, ${iconCls}-download, ${iconCls}-delete`]: {
  189. display: 'none'
  190. }
  191. },
  192. [`${itemCls}-progress`]: {
  193. bottom: token.marginXL,
  194. width: `calc(100% - ${token.paddingXS * 2}px)`,
  195. paddingInlineStart: 0
  196. }
  197. }
  198. })
  199. };
  200. };
  201. export { genPictureStyle, genPictureCardStyle };