2
0

_preview-panel.scss 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. .w-preview {
  2. --w-preview-background-color: var(--w-color-white);
  3. --w-preview-color-scheme: normal;
  4. --preview-width-ratio: min(
  5. 1,
  6. var(--preview-panel-width, 450) / var(--preview-device-width, 375)
  7. );
  8. --preview-iframe-width: calc(1px * var(--preview-device-width, 375));
  9. height: 100%;
  10. display: flex;
  11. flex-direction: column;
  12. &__area {
  13. height: 100%;
  14. display: flex;
  15. flex-direction: column-reverse;
  16. justify-content: space-between;
  17. // Needed for the warning message when the data is not valid.
  18. overflow: hidden;
  19. }
  20. &__wrapper {
  21. position: relative;
  22. width: calc(var(--preview-iframe-width) * var(--preview-width-ratio));
  23. height: 100%;
  24. margin-inline-start: auto;
  25. margin-inline-end: auto;
  26. }
  27. &__iframe {
  28. transform-origin: top left;
  29. width: var(--preview-iframe-width);
  30. height: calc(100% / var(--preview-width-ratio));
  31. transform: scale(var(--preview-width-ratio));
  32. display: block;
  33. &:empty {
  34. // Ensure that sites without a background show with a fallback, only when iframe has loaded
  35. background-color: var(--w-preview-background-color);
  36. // Sites that do not have a background but have color-scheme will have the
  37. // colors (background, text, etc.) automatically styled by the browser.
  38. // If the color-scheme matches Wagtail's current color-scheme, the browser
  39. // will give the iframe a transparent background. If we only set the
  40. // white background-color above, the white background will be used
  41. // while the rest of the content follows the color-scheme of the site,
  42. // which might result in white text on a white background.
  43. // Since we cannot know the actual value of the content's color-scheme,
  44. // we set the color-scheme to normal to ensure the iframe stays opaque.
  45. color-scheme: var(--w-preview-color-scheme);
  46. }
  47. [dir='rtl'] & {
  48. // Transform with the top-right physical corner as the origin since the layout is reversed.
  49. transform-origin: top right;
  50. }
  51. // Prevent the iframe from capturing pointer events when resizing the panel, which
  52. // would consume the pointerup event and leaving the panel stuck in a resizing state.
  53. .side-panel-resizing & {
  54. pointer-events: none;
  55. }
  56. }
  57. &__sizes {
  58. @apply w-border-border-furniture w-border-b;
  59. display: flex;
  60. align-items: center;
  61. justify-content: center;
  62. gap: 0.75rem;
  63. padding-bottom: 1rem;
  64. margin-bottom: 1rem;
  65. padding-inline: 1rem;
  66. @include more-contrast() {
  67. border-color: theme('colors.border-furniture-more-contrast');
  68. }
  69. }
  70. &__size-button {
  71. @apply w-text-text-meta w-transition hover:w-transform hover:w-scale-110 hover:w-text-text-label focus:w-text-text-label;
  72. width: 2rem;
  73. height: 2rem;
  74. background: transparent;
  75. padding: 0;
  76. border-radius: 5px;
  77. display: grid;
  78. place-items: center;
  79. cursor: pointer;
  80. &--selected,
  81. &--selected:hover {
  82. @apply w-bg-surface-menus w-text-text-button w-transform-none w-border w-border-transparent;
  83. }
  84. &:focus-within:has(:focus-visible) {
  85. @include focus-outline;
  86. }
  87. .icon {
  88. @include svg-icon(1rem);
  89. &.icon-tablet-alt,
  90. &.icon-desktop {
  91. @include svg-icon(1.25rem);
  92. }
  93. &.icon-link-external {
  94. @include svg-icon(0.9rem);
  95. }
  96. }
  97. }
  98. &__refresh-button.button--icon {
  99. display: flex;
  100. align-items: center;
  101. justify-content: center;
  102. position: absolute;
  103. top: 1rem;
  104. width: 2rem;
  105. height: 2rem;
  106. padding: 0;
  107. inset-inline-end: 1.5rem;
  108. // Use element and class selectors to beat .button-longrunning specificity
  109. svg.icon,
  110. svg.icon-spinner {
  111. margin-inline-end: 0;
  112. width: 1rem;
  113. height: 1rem;
  114. }
  115. }
  116. &__spinner {
  117. position: absolute;
  118. top: 1.25rem;
  119. inset-inline-end: 1.5rem;
  120. }
  121. &__controls {
  122. @apply w-border-t w-border-transparent w-duration-500 w-ease-in-out;
  123. transition-property: border-color, margin-top, padding-top;
  124. margin-top: 0;
  125. padding-top: 0;
  126. // Show the border only if there's an error,
  127. // but always show it if there are multiple preview modes
  128. .w-preview--has-errors &:not(&--multiple),
  129. &--multiple {
  130. @apply w-border-border-furniture w-border-t;
  131. padding-top: 1rem;
  132. margin-top: 1rem;
  133. }
  134. }
  135. &__error-banner {
  136. @apply w-text-text-context w-duration-1000 w-ease-in-out w-translate-y-20;
  137. transition-property: max-height, transform, visibility;
  138. visibility: hidden;
  139. max-height: 0;
  140. display: flex;
  141. align-items: center;
  142. gap: 1rem;
  143. position: relative;
  144. z-index: -1;
  145. .icon {
  146. @apply w-text-warning-100;
  147. }
  148. }
  149. &--has-errors &__error-banner {
  150. @apply w-translate-y-0;
  151. visibility: visible;
  152. max-height: 6rem;
  153. }
  154. &__error-title {
  155. @apply w-label-2;
  156. color: inherit;
  157. margin-top: 0;
  158. margin-bottom: 0.25rem;
  159. }
  160. &__error-details {
  161. color: inherit;
  162. }
  163. &__modes {
  164. margin-bottom: 0;
  165. background-color: theme('colors.surface-page');
  166. .w-field__input {
  167. padding-inline-end: 0;
  168. }
  169. }
  170. &__mode-select {
  171. @apply w-outline-offset-inside;
  172. }
  173. // A hidden element that is only rendered for functionality purposes,
  174. // but is not visible to the user. Used by radio inputs for preview sizes and
  175. // the iframe while it's loading. We nest the selector rather than suffixing
  176. // the parent selector to beat the specificity of input[type="radio"] styles
  177. .w-preview__proxy {
  178. position: absolute;
  179. width: 0;
  180. height: 0;
  181. opacity: 0;
  182. }
  183. }