- {html && (
-
- )}
+
+ {widthOptions.length > 0 && (
+ setFrameWidth(Number(key))}
+ >
+ {widthOptions.map((width) => (
+
+ {width}
+
+ ))}
+
+ )}
+
+ {html && (
+
+ )}
+
{showReloadButton && (
diff --git a/src/components/HtmlPreviewLoader/HtmlPreviewLoader.mdx b/src/components/HtmlPreviewLoader/HtmlPreviewLoader.mdx
index 906cd474..39d034b9 100644
--- a/src/components/HtmlPreviewLoader/HtmlPreviewLoader.mdx
+++ b/src/components/HtmlPreviewLoader/HtmlPreviewLoader.mdx
@@ -36,7 +36,7 @@ The HtmlPreviewLoader component fetches HTML markup, renders it inside an iframe
- When you need to preview HTML content such as email templates or document markup in the UI.
- When the preview content is loaded asynchronously and should show loading or error feedback.
-- When the preview should support width switching and an optional reload affordance.
+- When the preview should support width switching (via a segmented control above the preview) and an optional reload affordance.
## Peer dependencies
@@ -77,9 +77,9 @@ export const Component = () => (
| Name | Type | Required | Default | Description |
| ----------------- | ----------------------------- | -------- | ---------------------- | ------------------------------------------------------------------------- |
| `fetchHtml` | `{ (): Promise }` | Yes | N/A | Function that resolves to the HTML string to render in the preview frame. |
-| `title` | `ReactNode` | Yes | N/A | Title content shown above the preview. |
+| `title` | `ReactNode` | Yes | N/A | Title content shown above the preview. Pass markup to include a subtitle. |
| `minHeight` | `number` | No | `600` | Minimum height of the preview frame in pixels. |
-| `widthOptions` | `number[]` | No | `[320, 375, 425, 650]` | Available frame widths shown in the width selector. |
+| `widthOptions` | `number[]` | No | `[320, 375, 425, 650]` | Frame widths offered in the segmented control. Pass `[]` to hide it. |
| `defaultWidth` | `number` | No | `425` | Initial width used for the preview frame. |
| `frameBackground` | `CSSProperties['background']` | No | `'white'` | Background applied to the iframe. |
| `allowReloading` | `boolean` | No | `false` | Shows a reload button when the preview can be refreshed. |
diff --git a/src/components/HtmlPreviewLoader/sandbox.ts b/src/components/HtmlPreviewLoader/sandbox.ts
index 8af6d8d2..aff3dba8 100644
--- a/src/components/HtmlPreviewLoader/sandbox.ts
+++ b/src/components/HtmlPreviewLoader/sandbox.ts
@@ -34,6 +34,12 @@ export const componentCss = /* css */ `@import '@guardian/stand/component/htmlPr
padding-right: var(--component-html-preview-loader-padding-right);
padding-bottom: var(--component-html-preview-loader-padding-bottom);
padding-left: var(--component-html-preview-loader-padding-left);
+ border-width: var(--component-html-preview-loader-border-width);
+ border-style: var(--component-html-preview-loader-border-style);
+ border-color: var(--component-html-preview-loader-border-color);
+ display: flex;
+ flex-direction: column;
+ gap: var(--component-html-preview-loader-gap);
background: var(--component-html-preview-loader-shared-color-background);
color: var(--component-html-preview-loader-shared-color-text);
}
@@ -65,6 +71,12 @@ const styles = \`
padding-right: \${componentHtmlPreviewLoader.paddingRight};
padding-bottom: \${componentHtmlPreviewLoader.paddingBottom};
padding-left: \${componentHtmlPreviewLoader.paddingLeft};
+ border-width: \${componentHtmlPreviewLoader.borderWidth};
+ border-style: \${componentHtmlPreviewLoader.borderStyle};
+ border-color: \${componentHtmlPreviewLoader.borderColor};
+ display: flex;
+ flex-direction: column;
+ gap: \${componentHtmlPreviewLoader.gap};
background: \${componentHtmlPreviewLoader.shared.color.background};
color: \${componentHtmlPreviewLoader.shared.color.text};
\`;
diff --git a/src/components/HtmlPreviewLoader/styles.ts b/src/components/HtmlPreviewLoader/styles.ts
index b434ef22..d94b1168 100644
--- a/src/components/HtmlPreviewLoader/styles.ts
+++ b/src/components/HtmlPreviewLoader/styles.ts
@@ -23,16 +23,25 @@ export const htmlPreviewLoaderStyles = (
padding-bottom: ${theme.paddingBottom};
padding-left: ${theme.paddingLeft};
padding-right: ${theme.paddingRight};
+ border-color: ${theme.borderColor};
+ border-style: ${theme.borderStyle};
+ border-width: ${theme.borderWidth};
+ display: flex;
+ flex-direction: column;
+ gap: ${theme.gap};
position: relative;
`;
};
-export const headerStyles = (): SerializedStyles => {
+export const previewColumnStyle = ({
+ gap,
+}: HtmlPreviewLoaderTheme): SerializedStyles => {
return css`
display: flex;
- align-items: center;
- flex-wrap: wrap;
- justify-content: space-between;
+ flex-direction: column;
+ align-items: flex-start;
+ flex-shrink: 0;
+ gap: ${gap};
`;
};
@@ -58,6 +67,8 @@ export const previewFrameStyle = ({
export const iframeStyle = (isNotLoaded: boolean): SerializedStyles => {
return css`
border: none;
+ flex: 1;
+ align-self: stretch;
transition: 'filter 0.25s';
${
isNotLoaded
diff --git a/src/styleD/build/css/component/htmlPreviewLoader.css b/src/styleD/build/css/component/htmlPreviewLoader.css
index b2432eab..0a6d2146 100644
--- a/src/styleD/build/css/component/htmlPreviewLoader.css
+++ b/src/styleD/build/css/component/htmlPreviewLoader.css
@@ -3,14 +3,23 @@
*/
:root {
+ --component-html-preview-loader-border-color: #cccccc;
+ --component-html-preview-loader-border-style: solid;
+ --component-html-preview-loader-border-width: 0.0625rem;
+ --component-html-preview-loader-gap: 1rem;
--component-html-preview-loader-loading-icon-color: #8d8d8d;
--component-html-preview-loader-loading-icon-size: 3rem;
- --component-html-preview-loader-padding-bottom: 0px;
- --component-html-preview-loader-padding-left: 0.5rem;
- --component-html-preview-loader-padding-right: 0.5rem;
- --component-html-preview-loader-padding-top: 0px;
- --component-html-preview-loader-preview-frame-background-color: #ededed;
- --component-html-preview-loader-preview-frame-border-color: #545454;
+ --component-html-preview-loader-padding-bottom: 1rem;
+ --component-html-preview-loader-padding-left: 1rem;
+ --component-html-preview-loader-padding-right: 1rem;
+ --component-html-preview-loader-padding-top: 1rem;
+ --component-html-preview-loader-preview-frame-background-color: rgba(
+ 0,
+ 0,
+ 0,
+ 0
+ );
+ --component-html-preview-loader-preview-frame-border-color: rgba(0, 0, 0, 0);
--component-html-preview-loader-preview-frame-border-style: solid;
--component-html-preview-loader-preview-frame-border-width: 0.0625rem;
--component-html-preview-loader-preview-frame-padding-bottom: 0.5rem;
diff --git a/src/styleD/build/typescript/component/htmlPreviewLoader.ts b/src/styleD/build/typescript/component/htmlPreviewLoader.ts
index 68736273..38ac2434 100644
--- a/src/styleD/build/typescript/component/htmlPreviewLoader.ts
+++ b/src/styleD/build/typescript/component/htmlPreviewLoader.ts
@@ -3,17 +3,21 @@
*/
export const componentHtmlPreviewLoader = {
+ borderColor: '#cccccc',
+ borderStyle: 'solid',
+ borderWidth: '0.0625rem',
+ gap: '1rem',
loadingIcon: {
color: '#8d8d8d',
size: '3rem',
},
- paddingBottom: '0px',
- paddingLeft: '0.5rem',
- paddingRight: '0.5rem',
- paddingTop: '0px',
+ paddingBottom: '1rem',
+ paddingLeft: '1rem',
+ paddingRight: '1rem',
+ paddingTop: '1rem',
previewFrame: {
- backgroundColor: '#ededed',
- borderColor: '#545454',
+ backgroundColor: '#00000000',
+ borderColor: '#00000000',
borderStyle: 'solid',
borderWidth: '0.0625rem',
paddingBottom: '0.5rem',
diff --git a/src/styleD/tokens/component/htmlPreviewLoader.json b/src/styleD/tokens/component/htmlPreviewLoader.json
index 1b897cb1..244cdffd 100644
--- a/src/styleD/tokens/component/htmlPreviewLoader.json
+++ b/src/styleD/tokens/component/htmlPreviewLoader.json
@@ -1,6 +1,22 @@
{
"component": {
"htmlPreviewLoader": {
+ "borderColor": {
+ "$type": "color",
+ "$value": "{semantic.colors.border.weak}"
+ },
+ "borderStyle": {
+ "$type": "strokeStyle",
+ "$value": "solid"
+ },
+ "borderWidth": {
+ "$type": "dimension",
+ "$value": "{semantic.sizing.border.default}"
+ },
+ "gap": {
+ "$type": "dimension",
+ "$value": "{semantic.spacing.stackMd}"
+ },
"loadingIcon": {
"color": {
"$type": "color",
@@ -13,34 +29,28 @@
},
"paddingBottom": {
"$type": "dimension",
- "$value": {
- "unit": "px",
- "value": 0
- }
+ "$value": "{semantic.spacing.stackMd}"
},
"paddingLeft": {
"$type": "dimension",
- "$value": "{base.spacing.8Rem}"
+ "$value": "{semantic.spacing.stackMd}"
},
"paddingRight": {
"$type": "dimension",
- "$value": "{base.spacing.8Rem}"
+ "$value": "{semantic.spacing.stackMd}"
},
"paddingTop": {
"$type": "dimension",
- "$value": {
- "unit": "px",
- "value": 0
- }
+ "$value": "{semantic.spacing.stackMd}"
},
"previewFrame": {
"backgroundColor": {
"$type": "color",
- "$value": "{semantic.colors.fill.neutralWeak}"
+ "$value": "{base.colors.transparent}"
},
"borderColor": {
"$type": "color",
- "$value": "{semantic.colors.border.stronger}"
+ "$value": "{base.colors.transparent}"
},
"borderStyle": {
"$type": "strokeStyle",