32 lines
1.8 KiB
Plaintext
32 lines
1.8 KiB
Plaintext
component DeviceFrame {
|
|
props {
|
|
@event change = function
|
|
@event rotate = function
|
|
size = "default"
|
|
color = "primary"
|
|
title = "Device Frame"
|
|
description = ""
|
|
items = []
|
|
variant = "default"
|
|
device = "phone"
|
|
orientation = "portrait"
|
|
src = ""
|
|
srcdoc = ""
|
|
frameTitle = "Device preview"
|
|
showToolbar = true
|
|
allow = ""
|
|
class = ""
|
|
}
|
|
state currentOrientation = orientation
|
|
functions {
|
|
function setDevice(nextDevice, sourceEvent) { $emit("change", { device: nextDevice, orientation: currentOrientation, sourceEvent: sourceEvent }) }
|
|
function rotateFrame(sourceEvent) { currentOrientation = currentOrientation === "portrait" ? "landscape" : "portrait"; $emit("rotate", { device: device, orientation: currentOrientation, sourceEvent: sourceEvent }); $emit("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>
|
|
}
|
|
}
|