35 lines
2.0 KiB
Plaintext
35 lines
2.0 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-next wire-next--color-{color} wire-next--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>
|
|
}
|
|
}
|