Draftail.scss 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. $draftail-editor-text: theme('colors.text-context');
  2. $draftail-placeholder-text: theme('colors.text-placeholder');
  3. // w-body-text-large
  4. $draftail-editor-font-size: theme('fontSize.19');
  5. $draftail-editor-line-height: theme('lineHeight.normal');
  6. $draftail-editor-chrome: theme('colors.surface-menus');
  7. $draftail-editor-chrome-text: theme('colors.text-button');
  8. // This needs to remain a Sass value due to a limitation in Draftail.
  9. // $draftail-editor-chrome-active: theme('colors.surface-page');
  10. $draftail-editor-chrome-active: #fff;
  11. $draftail-editor-chrome-accent: transparent;
  12. $draftail-base-spacing: 0.375rem;
  13. $draftail-editor-radius: 0;
  14. $draftail-editor-border: 0;
  15. $draftail-editor-padding: theme('spacing.[2.5]') theme('spacing.5');
  16. $draftail-editor-background: theme('colors.surface-field');
  17. $draftail-block-spacing: theme('spacing.[2.5]');
  18. $draftail-toolbar-radius: theme('borderRadius.DEFAULT');
  19. $draftail-toolbar-icon-size: 1em;
  20. $draftail-trigger-additional-size: 30px;
  21. $draftail-block-hoverable-area-offset: 40px;
  22. $draftail-editor-font-family: theme('fontFamily.sans');
  23. @import '../../../../node_modules/draft-js/dist/Draft';
  24. @import '../../../../node_modules/draftail/src/index';
  25. @import './Tooltip/Tooltip';
  26. @import './CommentableEditor/CommentableEditor';
  27. @import './EditorFallback/EditorFallback';
  28. @import './decorators/TooltipEntity';
  29. @import './blocks/MediaBlock';
  30. @import './blocks/ImageBlock';
  31. @import './blocks/EmbedBlock';
  32. @include draftail-richtext-styles {
  33. h1,
  34. h2,
  35. h3,
  36. h4,
  37. h5,
  38. h6 {
  39. // Overrides for heading styles of Wagtail itself.
  40. color: inherit;
  41. line-height: theme('lineHeight.tight');
  42. font-weight: theme('fontWeight.bold');
  43. }
  44. h1 {
  45. font-size: theme('fontSize.30');
  46. }
  47. h2 {
  48. font-size: theme('fontSize.24');
  49. }
  50. h3 {
  51. font-size: theme('fontSize.22');
  52. }
  53. h4 {
  54. font-size: theme('fontSize.18');
  55. }
  56. h5 {
  57. font-size: theme('fontSize.16');
  58. }
  59. h6 {
  60. font-size: theme('fontSize.14');
  61. }
  62. }
  63. .Draftail-Editor {
  64. // Number used inside a `calc` function, which doesn’t support unitless zero.
  65. // stylelint-disable-next-line length-zero-no-unit
  66. --draftail-offset-inline-start: 0px;
  67. @include input-base();
  68. &--focus {
  69. outline: $focus-outline-width solid theme('colors.focus');
  70. }
  71. }
  72. .Draftail-Editor__wrapper {
  73. // Ensure elements within the editor are positioned according to this container.
  74. position: relative;
  75. // Make fields take up the whole available width in their container.
  76. width: 100%;
  77. }
  78. .Draftail-Toolbar {
  79. border-width: 0;
  80. border-end-start-radius: 0;
  81. border-end-end-radius: 0;
  82. background-color: $draftail-editor-background;
  83. color: $draftail-placeholder-text;
  84. .Draftail-Editor--focus & {
  85. color: $draftail-editor-text;
  86. top: calc(theme('spacing.slim-header') * 2);
  87. @include media-breakpoint-up(sm) {
  88. top: theme('spacing.slim-header');
  89. }
  90. }
  91. .Draftail-ToolbarButton--active {
  92. @include light-theme() {
  93. background-color: theme('colors.surface-header');
  94. border-color: theme('colors.border-furniture');
  95. @media (forced-colors: active) {
  96. background: Highlight;
  97. }
  98. }
  99. }
  100. }
  101. .Draftail-MetaToolbar {
  102. position: absolute;
  103. inset-inline-end: 0;
  104. visibility: hidden;
  105. background-color: transparent;
  106. &:empty {
  107. display: none;
  108. }
  109. // Make sure the toolbar is always visible for devices that do not hover.
  110. @media (hover: hover) {
  111. visibility: hidden;
  112. .Draftail-Editor:focus-within &,
  113. .Draftail-Editor:hover & {
  114. visibility: visible;
  115. }
  116. }
  117. }
  118. .Draftail-BlockToolbar {
  119. position: absolute;
  120. background: transparent;
  121. // Adds additional hoverable area so block trigger will be shown when hovering to the side of the field.
  122. width: $draftail-block-hoverable-area-offset;
  123. inset-inline-start: -$draftail-block-hoverable-area-offset;
  124. top: 0;
  125. height: 100%;
  126. display: flex;
  127. justify-content: center;
  128. }
  129. .Draftail-BlockToolbar__trigger {
  130. $icon-size: theme('spacing.4');
  131. color: theme('colors.text-button-outline-default');
  132. width: $icon-size;
  133. height: $icon-size;
  134. margin-inline-end: calc($nested-field-indent-sm - $icon-size / 2 - 2px);
  135. @include media-breakpoint-up(sm) {
  136. margin-inline-end: calc($nested-field-indent - $icon-size / 2 - 2px);
  137. }
  138. // Increase the hoverable area of the trigger button
  139. &::before {
  140. content: '';
  141. background: transparent;
  142. display: block;
  143. position: absolute;
  144. transform: translate(calc(var(--w-direction-factor) * -50%), -50%);
  145. inset-inline-start: 50%;
  146. top: 50%;
  147. width: $draftail-trigger-additional-size;
  148. height: $draftail-trigger-additional-size;
  149. border-radius: theme('borderRadius.DEFAULT');
  150. z-index: 1;
  151. }
  152. // Hide the trigger unless the editor is hovered, focused, or an element within it is focused.
  153. .Draftail-Editor:not(:hover, .Draftail-Editor--focus, :focus-within) & {
  154. // Hide even if the conditions to display it are met.
  155. // stylelint-disable-next-line declaration-no-important
  156. visibility: hidden !important;
  157. }
  158. &:hover,
  159. &:focus-visible {
  160. color: theme('colors.surface-page');
  161. background-color: theme('colors.text-button-outline-default');
  162. }
  163. .icon {
  164. transition: transform 0.3s ease;
  165. width: theme('spacing.3');
  166. height: theme('spacing.3');
  167. }
  168. &[aria-expanded='true'] .icon {
  169. transform: rotate(45deg);
  170. }
  171. }
  172. .Draftail-ToolbarGroup::before {
  173. display: none;
  174. }
  175. .Draftail-ToolbarButton {
  176. height: 1.875rem;
  177. min-width: 1.875rem;
  178. padding: 0;
  179. margin-inline-end: 0.625rem;
  180. .Draftail-ToolbarGroup:last-of-type &:last-of-type {
  181. margin-inline-end: 0;
  182. }
  183. &[disabled] {
  184. opacity: 0.3;
  185. }
  186. &:hover,
  187. &:active {
  188. border: 1px solid theme('colors.border-button-small-outline-default');
  189. }
  190. .icon {
  191. width: $draftail-toolbar-icon-size;
  192. height: $draftail-toolbar-icon-size;
  193. vertical-align: middle;
  194. }
  195. .icon-h1,
  196. .icon-h2,
  197. .icon-h3,
  198. .icon-h4,
  199. .icon-h5,
  200. .icon-h6 {
  201. width: 1.25 * $draftail-toolbar-icon-size;
  202. height: 1.25 * $draftail-toolbar-icon-size;
  203. }
  204. }
  205. .Draftail-ToolbarButton--pin {
  206. min-width: theme('spacing.6');
  207. height: theme('spacing.6');
  208. border: 1px solid theme('colors.surface-tooltip');
  209. &:hover {
  210. border-color: theme('colors.surface-tooltip');
  211. }
  212. .Draftail-Toolbar & {
  213. border-color: theme('colors.border-field-default');
  214. background-color: theme('colors.surface-page');
  215. border-top-width: 0;
  216. border-inline-end-width: 0;
  217. .Draftail-Editor:hover & {
  218. border-color: theme('colors.border-field-hover');
  219. }
  220. }
  221. }
  222. .Draftail-block--blockquote {
  223. border-inline-start: 0.25em solid theme('colors.border-field-default');
  224. color: theme('colors.text-meta');
  225. margin: 1em 0;
  226. padding: 1em 2em;
  227. }
  228. .DraftEditor-editorContainer {
  229. border: 0;
  230. }