177 lines
5.7 KiB
Plaintext
177 lines
5.7 KiB
Plaintext
component DeviceFrame {
|
|
outputs {
|
|
change(payload: { device: string; orientation: string; sourceEvent: Event })
|
|
rotate(payload: { device: string; orientation: string; sourceEvent: Event })
|
|
}
|
|
|
|
props {
|
|
size: string = "default"
|
|
color: string = "primary"
|
|
title: string = "Device Frame"
|
|
description: string = ""
|
|
items: unknown[] = []
|
|
variant: string = "default"
|
|
device: string = "phone"
|
|
orientation: string = "portrait"
|
|
src: string = ""
|
|
srcdoc: string = ""
|
|
frameTitle: string = "Device preview"
|
|
showToolbar: boolean = true
|
|
allow: string = ""
|
|
class: string = ""
|
|
}
|
|
state currentOrientation = orientation
|
|
functions {
|
|
client function setDevice(nextDevice, sourceEvent) { output.change({ device: nextDevice, orientation: currentOrientation, sourceEvent: sourceEvent }) }
|
|
client function rotateFrame(sourceEvent) { currentOrientation = currentOrientation === "portrait" ? "landscape" : "portrait"; output.rotate({ device: device, orientation: currentOrientation, sourceEvent: sourceEvent }); output.change({ device: device, orientation: currentOrientation, sourceEvent: sourceEvent }) }
|
|
}
|
|
view {
|
|
<section {...attrs} class="wire-component wire-component--color-{color} wire-component--size-{size} wire-next--device-frame wire-next--variant-{variant} {class}" data-device="{device}" data-orientation="{currentOrientation}">
|
|
<header><div>{#if title}<strong>{title}</strong>{/if}{#if description}<p>{description}</p>{/if}</div>{#if showToolbar}<div class="wire-next__device-actions" role="toolbar" aria-label="Preview device">{#each items as item}<button type="button" aria-pressed="{item.value === device}" @click="setDevice(item.value, event)">{item.label}</button>{/each}<button type="button" aria-label="Rotate preview" @click="rotateFrame(event)">↻</button></div>{/if}</header>
|
|
<div class="wire-next__device-shell">{#if src || srcdoc}<iframe title="{frameTitle}" src="{src}" srcdoc="{srcdoc}" allow="{allow}"></iframe>{:else}<div class="wire-next__device-content"><slot /></div>{/if}</div>
|
|
</section>
|
|
}
|
|
|
|
style {
|
|
.wire-next--device-frame {
|
|
display: grid;
|
|
gap: 0.75rem;
|
|
padding: 1rem;
|
|
border: 1px solid var(--wire-color-border);
|
|
border-radius: var(--wire-radius-md);
|
|
background: var(--wire-color-surface);
|
|
box-shadow: var(--wire-shadow-1);
|
|
}
|
|
|
|
.wire-next--device-frame > header {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
gap: 1rem;
|
|
}
|
|
|
|
.wire-next__device-actions {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 0.4rem;
|
|
}
|
|
|
|
.wire-next__device-actions button {
|
|
min-height: 2.25rem;
|
|
padding-inline: 0.7rem;
|
|
border: 1px solid var(--wire-color-border);
|
|
border-radius: var(--wire-radius-sm);
|
|
background: var(--wire-color-surface-2);
|
|
color: inherit;
|
|
}
|
|
|
|
.wire-next__device-shell {
|
|
overflow: hidden;
|
|
width: min(100%, 24rem);
|
|
min-height: 28rem;
|
|
margin-inline: auto;
|
|
border: 0.65rem solid var(--wire-color-text);
|
|
border-radius: 2rem;
|
|
background: var(--wire-color-background);
|
|
transition: width var(--wire-motion-normal) var(--wire-ease-standard);
|
|
}
|
|
|
|
.wire-next--device-frame[data-device="tablet"] .wire-next__device-shell {
|
|
width: min(100%, 42rem);
|
|
}
|
|
|
|
.wire-next--device-frame[data-device="desktop"] .wire-next__device-shell {
|
|
width: 100%;
|
|
border-width: 0.4rem;
|
|
border-radius: var(--wire-radius-md);
|
|
}
|
|
|
|
.wire-next--device-frame[data-orientation="landscape"] .wire-next__device-shell {
|
|
width: min(100%, 48rem);
|
|
min-height: 20rem;
|
|
}
|
|
|
|
.wire-next__device-shell :is(iframe, .wire-next__device-content) {
|
|
width: 100%;
|
|
min-height: inherit;
|
|
border: 0;
|
|
}
|
|
|
|
@media (max-width: 640px) {
|
|
.wire-next--device-frame > header {
|
|
align-items: stretch;
|
|
flex-direction: column;
|
|
}
|
|
}
|
|
|
|
/* Shared component foundation. */
|
|
|
|
.wire-component {
|
|
--wire-component-color: var(--wire-color-primary);
|
|
--wire-component-scale: 1;
|
|
margin: 0;
|
|
color: var(--wire-color-text);
|
|
font-family: var(--wrn-font-sans, inherit);
|
|
}
|
|
|
|
.wire-component--color-primary {
|
|
--wire-component-color: var(--wire-color-primary);
|
|
}
|
|
|
|
.wire-component--color-secondary {
|
|
--wire-component-color: var(--wire-color-secondary);
|
|
}
|
|
|
|
.wire-component--color-success {
|
|
--wire-component-color: var(--wire-color-success);
|
|
}
|
|
|
|
.wire-component--color-warning {
|
|
--wire-component-color: var(--wire-color-warning);
|
|
}
|
|
|
|
.wire-component--color-danger {
|
|
--wire-component-color: var(--wire-color-danger);
|
|
}
|
|
|
|
.wire-component--color-info {
|
|
--wire-component-color: var(--wire-color-info);
|
|
}
|
|
|
|
.wire-component--size-xs {
|
|
--wire-component-scale: 0.78;
|
|
}
|
|
|
|
.wire-component--size-sm {
|
|
--wire-component-scale: 0.88;
|
|
}
|
|
|
|
.wire-component--size-default,
|
|
.wire-component--size-md {
|
|
--wire-component-scale: 1;
|
|
}
|
|
|
|
.wire-component--size-lg {
|
|
--wire-component-scale: 1.14;
|
|
}
|
|
|
|
.wire-component--size-xl {
|
|
--wire-component-scale: 1.28;
|
|
}
|
|
|
|
.wire-component:not(.wire-btn) {
|
|
font-size: calc(1em * var(--wire-component-scale));
|
|
}
|
|
|
|
.wire-component :is(a, button, input, select, textarea):focus-visible {
|
|
outline-color: var(--wire-component-color);
|
|
}
|
|
|
|
.wire-component p {
|
|
margin: 0;
|
|
color: var(--wire-color-muted);
|
|
line-height: 1.6;
|
|
}
|
|
}
|
|
}
|