You are here

form--managed-file.pcss.css in Drupal 10

Styles for the managed file widget.

This includes the styles for the file widgets and the image widgets.

File

core/themes/claro/css/components/form--managed-file.pcss.css
View source
  1. /**
  2. * @file
  3. * Styles for the managed file widget.
  4. *
  5. * This includes the styles for the file widgets and the image widgets.
  6. */
  7. :root {
  8. --file-widget-form-item-min-width: 16rem;
  9. --file-widget-form-item-max-width: 32rem;
  10. }
  11. /**
  12. * The root element of the file/image widget.
  13. */
  14. .form-managed-file.no-upload {
  15. display: inline-flex;
  16. flex-direction: column;
  17. max-width: 100%;
  18. }
  19. .form-managed-file.has-value.is-multiple {
  20. display: block;
  21. }
  22. /**
  23. * The main element of the file/image widget.
  24. *
  25. * This contains the upload input and the upload of the empty file/image
  26. * widgets, or the file name (with icon and size) and the remove button of
  27. * filled widgets.
  28. *
  29. * The inline-flex display shrinks the width to the minimal needed amount. This
  30. * helps to keep the remove as close to the other elements as possible.
  31. */
  32. .form-managed-file__main {
  33. display: inline-flex;
  34. align-items: center;
  35. max-width: 100%;
  36. }
  37. /**
  38. * Inside (draggable) tables, this should be flex-displayed. This keeps even
  39. * long file names in the same visual line where the drag handle is.
  40. */
  41. .draggable .form-managed-file.has-value .form-managed-file__main {
  42. display: flex;
  43. }
  44. /* Add some bottom margin for single widgets if no meta is present. */
  45. .form-managed-file.is-single.has-value .form-managed-file__main:last-child {
  46. margin-bottom: var(--space-m);
  47. }
  48. /**
  49. * The 'meta' element of the file/image widget.
  50. *
  51. * This element is available only if the file widget has a value AND when there
  52. * are other input options than the ones rendered in the 'main' element.
  53. * These inputs are:
  54. * - File description and/or the file display checkbox of file widgets
  55. * - Image alt and/or title text as well as the preview image of the image
  56. * widgets.
  57. *
  58. * The trick here is that we will display the alt/title inputs next to the image
  59. * preview if there is enough space left. Enough space means the value of the
  60. * '--file-widget-form-item-min-width' variable.
  61. */
  62. .form-managed-file__meta {
  63. display: flex;
  64. flex-wrap: wrap;
  65. align-items: flex-start;
  66. margin-top: var(--space-m); /* Bottom margin will be added by the child elements: because of we use flex display here, our margins won't collapse. */
  67. }
  68. /**
  69. * In tables, this should be inline-flex. This is needed to make this element be
  70. * pushed to a new line, to the bottom of the drag handle.
  71. */
  72. .draggable .form-managed-file.has-value .form-managed-file__meta {
  73. display: inline-flex;
  74. }
  75. /**
  76. * Internet Explorer 11 does not shrinks our meta elements if one of its parent
  77. * element is a table. Without this fix, the file widgets table cell would have
  78. * the same width that is needed for displaying the file name in a single line.
  79. *
  80. * @see https://github.com/philipwalton/flexbugs/issues/179
  81. */
  82. @media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  83. *::-ms-backdrop,
  84. td .form-managed-file__meta {
  85. flex-basis: 100%;
  86. }
  87. }
  88. /**
  89. * The 'image preview' element.
  90. *
  91. * This is used and display only by the image widget.
  92. */
  93. .form-managed-file__image-preview {
  94. flex: 0 0 auto;
  95. max-width: 100%;
  96. margin-bottom: var(--space-m);
  97. }
  98. /* Add some 'end' margin if there are other meta inputs. */
  99. .form-managed-file.has-meta .form-managed-file__image-preview {
  100. margin-right: var(--space-m); /* LTR */
  101. }
  102. [dir="rtl"] .form-managed-file.has-meta .form-managed-file__image-preview {
  103. margin-right: 0;
  104. margin-left: var(--space-m);
  105. }
  106. /**
  107. * If this is rendered inside a file multiple table and there are no alt or
  108. * title, we have to reduce the amount of the bottom margin.
  109. */
  110. td .form-managed-file.no-meta .form-managed-file__image-preview {
  111. margin-bottom: var(--space-xs);
  112. }
  113. /**
  114. * The children of the 'meta items' element are the inputs that were described
  115. * at the 'meta' element '.form-managed-file__meta', except of the image
  116. * preview.
  117. *
  118. * The flex-basis is set to the minimal width where we can display these inputs
  119. * next tho the preview image.
  120. *
  121. * We limit the max width directly on the '.form-item' elements.
  122. */
  123. .form-managed-file__meta-items {
  124. flex: 1 1 var(--file-widget-form-item-min-width);
  125. max-width: 100%;
  126. }
  127. /**
  128. * Internet Explorer 11 does not increase the width of those flex items that are
  129. * allowed to be wrapped. We just simply change the basis to the max-width.
  130. */
  131. @media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  132. *::-ms-backdrop,
  133. .form-managed-file__meta-items {
  134. flex-basis: var(--file-widget-form-item-max-width);
  135. }
  136. }
  137. /**
  138. * Meta items wrapper.
  139. * This markup element is needed only for working around the same IE 11 bug that
  140. * is described above, at the 'meta' element.
  141. *
  142. * @see https://github.com/philipwalton/flexbugs/issues/179
  143. */
  144. @media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  145. *::-ms-backdrop,
  146. td .form-managed-file__meta-wrapper {
  147. display: flex;
  148. }
  149. }
  150. /**
  151. * Modify component defaults for file/image widgets.
  152. */
  153. /**
  154. * File component style overrides for managed file widgets.
  155. */
  156. .form-managed-file .file {
  157. word-break: break-all;
  158. hyphens: auto;
  159. }
  160. .form-managed-file .file__size {
  161. word-break: normal;
  162. }
  163. .form-managed-file__main .file {
  164. flex: 1 1 auto;
  165. margin: var(--space-xs) var(--space-m) var(--space-xs) 0; /* LTR */
  166. }
  167. [dir="rtl"] .form-managed-file__main .file {
  168. margin-right: 0;
  169. margin-left: var(--space-m);
  170. }
  171. /**
  172. * Fix and override the table-related bug of Internet Explorer 11 (described at
  173. * the 'meta' element).
  174. *
  175. * @see https://github.com/philipwalton/flexbugs/issues/179
  176. */
  177. @media all and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  178. *::-ms-backdrop,
  179. td .form-managed-file__main .file {
  180. flex: 0 1 100%;
  181. }
  182. }
  183. /**
  184. * The file upload input.
  185. */
  186. .form-managed-file__main .form-element--api-file {
  187. flex: 1 1 auto;
  188. min-width: 1px; /* This makes the element shrink on IE11 */
  189. }
  190. /**
  191. * Remove the default button margins and prevent shrinking or growing buttons.
  192. * This applies both on the 'no-js' upload button and the remove button. The
  193. * weight of this ruleset has been increase for this to take effect on RTL.
  194. */
  195. .form-managed-file__main .button.button {
  196. flex: 0 0 auto;
  197. margin: 0;
  198. }
  199. /**
  200. * Limiting the width of form items inside the meta element.
  201. */
  202. .form-managed-file__meta .form-item {
  203. max-width: var(--file-widget-form-item-max-width);
  204. margin-top: 0; /* Top margin is added by the parent element */
  205. margin-bottom: var(--space-m);
  206. }
  207. /**
  208. * Reduce the bottom margin of the last 'meta' form-item for field multiple
  209. * tables.
  210. */
  211. .form-managed-file__meta .form-item:last-child {
  212. margin-bottom: var(--space-xs);
  213. }
  214. .form-managed-file__meta .form-element {
  215. width: 100%;
  216. }
  217. /**
  218. * Add side margins if a table precedes the managed file form element.
  219. */
  220. .file-widget-multiple.has-table .form-type--managed-file {
  221. margin-right: var(--space-m);
  222. margin-left: var(--space-m);
  223. }