Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added iframe component #237

Merged
merged 9 commits into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/docs/public/components/iframe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions ui/src/core/templateMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import CoreSeparator from "../core_components/CoreSeparator.vue";
import CoreTab from "../core_components/CoreTab.vue";
import CoreTabs from "../core_components/CoreTabs.vue";
import CoreImage from "../core_components/CoreImage.vue";
import CoreIFrame from "../core_components/CoreIFrame.vue";
import CoreTimer from "../core_components/CoreTimer.vue";
import CoreWebcamCapture from "../core_components/CoreWebcamCapture.vue";
import CoreVegaLiteChart from "../core_components/CoreVegaLiteChart.vue";
Expand Down Expand Up @@ -64,6 +65,7 @@ const templateMap = {
horizontalstack: CoreHorizontalStack,
separator: CoreSeparator,
image: CoreImage,
iframe: CoreIFrame,
icon: CoreIcon,
timer: CoreTimer,
textinput: CoreTextInput,
Expand Down
98 changes: 98 additions & 0 deletions ui/src/core_components/CoreIFrame.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<template>
<div class="CoreIFrame" v-on:click="handleClick" ref="rootEl">
<iframe
@load="handleLoad"
:src="fields.src.value"
draggable="false"
/>
<div class="mask" />
raaymax marked this conversation as resolved.
Show resolved Hide resolved
</div>
</template>

<script lang="ts">
import { FieldCategory, FieldType } from "../streamsyncTypes";
import { cssClasses, secondaryTextColor } from "../renderer/sharedStyleFields";
import { getClick } from "../renderer/syntheticEvents";

const description = "A component to embed an external resource in an iframe.";

const loadHandlerStub = `
def load_handler(state):

# Sets status message when resource is loaded

state["status"] = "Page loaded"`;

export default {
streamsync: {
name: "IFrame",
description,
category: "Content",
raaymax marked this conversation as resolved.
Show resolved Hide resolved
fields: {
src: {
name: "Source",
default: '',
desc: "A valid URL. Alternatively, you can provide a state reference to a Matplotlib figure or a packed file.",
raaymax marked this conversation as resolved.
Show resolved Hide resolved
type: FieldType.Text,
},
cssClasses,
},
events: {
"ss-load": {
desc: "Fires when the resource has successfully loaded.",
stub: loadHandlerStub.trim(),
},
},
},
};
</script>

<script setup lang="ts">
import { Ref, computed, inject, ref } from "vue";
import injectionKeys from "../injectionKeys";

const rootEl:Ref<HTMLElement> = ref(null);
const fields = inject(injectionKeys.evaluatedFields);

function handleClick(ev: MouseEvent) {
raaymax marked this conversation as resolved.
Show resolved Hide resolved
const ssEv = getClick(ev);
rootEl.value.dispatchEvent(ssEv);
}
function handleLoad(ev) {
const event = new CustomEvent("ss-load");
rootEl.value.dispatchEvent(event);
}
</script>

<style scoped>
@import "../renderer/sharedStyles.css";

.CoreIFrame {
position: relative;
width: 100%;
height: 80vh;
}

.CoreIFrame iframe {
width: 100%;
height: 100%;
display: block;
margin: auto;
border-radius: 12px;
raaymax marked this conversation as resolved.
Show resolved Hide resolved
border: 1px solid var(--separatorColor);
}

.CoreIFrame .mask {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0);
border-radius: 12px;
raaymax marked this conversation as resolved.
Show resolved Hide resolved
}

.CoreIFrame.selected .mask {
display: none;
}
</style>