widget.css 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /*
  2. * Copyright (c) 2003-2020, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
  4. */
  5. @import "../mixins/_focus.css";
  6. @import "../mixins/_shadow.css";
  7. :root {
  8. --ck-widget-outline-thickness: 3px;
  9. --ck-widget-handler-icon-size: 16px;
  10. --ck-widget-handler-animation-duration: 200ms;
  11. --ck-widget-handler-animation-curve: ease;
  12. --ck-color-widget-blurred-border: hsl(0, 0%, 87%);
  13. --ck-color-widget-hover-border: hsl(43, 100%, 62%);
  14. --ck-color-widget-editable-focus-background: var(--ck-color-base-background);
  15. --ck-color-widget-drag-handler-icon-color: var(--ck-color-base-background);
  16. }
  17. .ck .ck-widget {
  18. outline-width: var(--ck-widget-outline-thickness);
  19. outline-style: solid;
  20. outline-color: transparent;
  21. transition: outline-color var(--ck-widget-handler-animation-duration) var(--ck-widget-handler-animation-curve);
  22. &.ck-widget_selected,
  23. &.ck-widget_selected:hover {
  24. outline: var(--ck-widget-outline-thickness) solid var(--ck-color-focus-border);
  25. }
  26. &:hover {
  27. outline-color: var(--ck-color-widget-hover-border);
  28. }
  29. }
  30. .ck .ck-editor__nested-editable {
  31. border: 1px solid transparent;
  32. /* The :focus style is applied before .ck-editor__nested-editable_focused class is rendered in the view.
  33. These styles show a different border for a blink of an eye, so `:focus` need to have same styles applied. */
  34. &.ck-editor__nested-editable_focused,
  35. &:focus {
  36. @mixin ck-focus-ring;
  37. @mixin ck-box-shadow var(--ck-inner-shadow);
  38. background-color: var(--ck-color-widget-editable-focus-background);
  39. }
  40. }
  41. .ck .ck-widget.ck-widget_with-selection-handle {
  42. & .ck-widget__selection-handle {
  43. padding: 4px;
  44. box-sizing: border-box;
  45. /* Background and opacity will be animated as the handler shows up or the widget gets selected. */
  46. background-color: transparent;
  47. opacity: 0;
  48. /* Transition:
  49. * background-color for the .ck-widget_selected state change,
  50. * visibility for hiding the handler,
  51. * opacity for the proper look of the icon when the handler disappears. */
  52. transition:
  53. background-color var(--ck-widget-handler-animation-duration) var(--ck-widget-handler-animation-curve),
  54. visibility var(--ck-widget-handler-animation-duration) var(--ck-widget-handler-animation-curve),
  55. opacity var(--ck-widget-handler-animation-duration) var(--ck-widget-handler-animation-curve);
  56. /* Make only top corners round. */
  57. border-radius: var(--ck-border-radius) var(--ck-border-radius) 0 0;
  58. /* Place the drag handler outside the widget wrapper. */
  59. transform: translateY(-100%);
  60. left: calc(0px - var(--ck-widget-outline-thickness));
  61. & .ck-icon {
  62. /* Make sure the dimensions of the icon are independent of the fon-size of the content. */
  63. width: var(--ck-widget-handler-icon-size);
  64. height: var(--ck-widget-handler-icon-size);
  65. color: var(--ck-color-widget-drag-handler-icon-color);
  66. /* The "selected" part of the icon is invisible by default */
  67. & .ck-icon__selected-indicator {
  68. opacity: 0;
  69. /* Note: The animation is longer on purpose. Simply feels better. */
  70. transition: opacity 300ms var(--ck-widget-handler-animation-curve);
  71. }
  72. }
  73. /* Advertise using the look of the icon that once clicked the handler, the widget will be selected. */
  74. &:hover .ck-icon .ck-icon__selected-indicator {
  75. opacity: 1;
  76. }
  77. }
  78. /* Show the selection handler on mouse hover over the widget. */
  79. &:hover .ck-widget__selection-handle {
  80. opacity: 1;
  81. background-color: var(--ck-color-widget-hover-border);
  82. }
  83. /* Show the selection handler when the widget is selected. */
  84. &.ck-widget_selected,
  85. &.ck-widget_selected:hover {
  86. & .ck-widget__selection-handle {
  87. opacity: 1;
  88. background-color: var(--ck-color-focus-border);
  89. /* When the widget is selected, notify the user using the proper look of the icon. */
  90. & .ck-icon .ck-icon__selected-indicator {
  91. opacity: 1;
  92. }
  93. }
  94. }
  95. }
  96. /* In a RTL environment, align the selection handler to the right side of the widget */
  97. /* stylelint-disable-next-line no-descending-specificity */
  98. .ck[dir="rtl"] .ck-widget.ck-widget_with-selection-handle .ck-widget__selection-handle {
  99. left: auto;
  100. right: calc(0px - var(--ck-widget-outline-thickness));
  101. }
  102. /* https://github.com/ckeditor/ckeditor5/issues/6415 */
  103. .ck.ck-editor__editable.ck-read-only .ck-widget {
  104. /* Prevent the :hover outline from showing up because of the used outline-color transition. */
  105. transition: none;
  106. &:not(.ck-widget_selected) {
  107. /* Disable visual effects of hover/active widget when CKEditor is in readOnly mode.
  108. * See: https://github.com/ckeditor/ckeditor5/issues/1261
  109. *
  110. * Leave the unit because this custom property is used in calc() by other features.
  111. * See: https://github.com/ckeditor/ckeditor5/issues/6775
  112. */
  113. --ck-widget-outline-thickness: 0px;
  114. }
  115. &.ck-widget_with-selection-handle {
  116. & .ck-widget__selection-handle,
  117. & .ck-widget__selection-handle:hover {
  118. background: var(--ck-color-widget-blurred-border);
  119. }
  120. }
  121. }
  122. /* Style the widget when it's selected but the editable it belongs to lost focus. */
  123. /* stylelint-disable-next-line no-descending-specificity */
  124. .ck.ck-editor__editable.ck-blurred .ck-widget {
  125. &.ck-widget_selected,
  126. &.ck-widget_selected:hover {
  127. outline-color: var(--ck-color-widget-blurred-border);
  128. &.ck-widget_with-selection-handle {
  129. & .ck-widget__selection-handle,
  130. & .ck-widget__selection-handle:hover {
  131. background: var(--ck-color-widget-blurred-border);
  132. }
  133. }
  134. }
  135. }
  136. .ck.ck-editor__editable > .ck-widget.ck-widget_with-selection-handle:first-child,
  137. .ck.ck-editor__editable blockquote > .ck-widget.ck-widget_with-selection-handle:first-child {
  138. /* Do not crop selection handler if a widget is a first-child in the blockquote or in the root editable.
  139. In fact, anything with overflow: hidden.
  140. https://github.com/ckeditor/ckeditor5-block-quote/issues/28
  141. https://github.com/ckeditor/ckeditor5-widget/issues/44
  142. https://github.com/ckeditor/ckeditor5-widget/issues/66 */
  143. margin-top: calc(1em + var(--ck-widget-handler-icon-size));
  144. }