picture.js 7.2 KB

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