picture.js 6.8 KB

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