_preview-panel.scss 5.8 KB

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