File size: 4,907 Bytes
2409829 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
<script lang="ts">
import { getContext } from "svelte";
import type { Editor } from "@graphite/editor";
import { isWidgetSpanRow, isWidgetSpanColumn, isWidgetSection, type WidgetSection as WidgetSectionFromJsMessages } from "@graphite/messages";
import LayoutCol from "@graphite/components/layout/LayoutCol.svelte";
import IconButton from "@graphite/components/widgets/buttons/IconButton.svelte";
import TextLabel from "@graphite/components/widgets/labels/TextLabel.svelte";
import WidgetSpan from "@graphite/components/widgets/WidgetSpan.svelte";
export let widgetData: WidgetSectionFromJsMessages;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export let layoutTarget: any; // TODO: Give type
let className = "";
export { className as class };
export let classes: Record<string, boolean> = {};
let expanded = true;
const editor = getContext<Editor>("editor");
</script>
<!-- TODO: Implement collapsable sections with properties system -->
<LayoutCol class={`widget-section ${className}`.trim()} {classes}>
<button class="header" class:expanded on:click|stopPropagation={() => (expanded = !expanded)} tabindex="0">
<div class="expand-arrow" />
<TextLabel tooltip={widgetData.description} bold={true}>{widgetData.name}</TextLabel>
<IconButton
icon={widgetData.pinned ? "PinActive" : "PinInactive"}
tooltip={widgetData.pinned ? "Unpin this node so it's no longer shown here when nothing is selected" : "Pin this node so it's shown here when nothing is selected"}
size={24}
action={(e) => {
editor.handle.setNodePinned(widgetData.id, !widgetData.pinned);
e?.stopPropagation();
}}
class={"show-only-on-hover"}
/>
<IconButton
icon={"Trash"}
tooltip={"Delete this node from the layer chain"}
size={24}
action={(e) => {
editor.handle.deleteNode(widgetData.id);
e?.stopPropagation();
}}
class={"show-only-on-hover"}
/>
<IconButton
icon={widgetData.visible ? "EyeVisible" : "EyeHidden"}
hoverIcon={widgetData.visible ? "EyeHide" : "EyeShow"}
tooltip={widgetData.visible ? "Hide this node" : "Show this node"}
size={24}
action={(e) => {
editor.handle.toggleNodeVisibilityLayerPanel(widgetData.id);
e?.stopPropagation();
}}
class={widgetData.visible ? "show-only-on-hover" : ""}
/>
</button>
{#if expanded}
<LayoutCol class="body">
{#each widgetData.layout as layoutGroup}
{#if isWidgetSpanRow(layoutGroup)}
<WidgetSpan widgetData={layoutGroup} {layoutTarget} />
{:else if isWidgetSpanColumn(layoutGroup)}
<TextLabel styles={{ color: "#d6536e" }}>Error: The WidgetSpan used here should be a row not a column</TextLabel>
{:else if isWidgetSection(layoutGroup)}
<svelte:self widgetData={layoutGroup} {layoutTarget} />
{:else}
<TextLabel styles={{ color: "#d6536e" }}>Error: The widget that belongs here has an invalid layout group type</TextLabel>
{/if}
{/each}
</LayoutCol>
{/if}
</LayoutCol>
<style lang="scss" global>
.widget-section {
flex: 0 0 auto;
margin: 0 4px;
margin-top: 4px;
.header {
text-align: left;
align-items: center;
display: flex;
flex: 0 0 24px;
padding-left: 8px;
padding-right: 0;
margin-bottom: 4px;
border: 0;
border-radius: 4px;
background: var(--color-2-mildblack);
&.expanded {
border-radius: 4px 4px 0 0;
margin-bottom: 0;
.expand-arrow::after {
transform: rotate(90deg);
}
}
&:hover {
background: var(--color-4-dimgray);
.expand-arrow::after {
background: var(--icon-expand-collapse-arrow-hover);
}
+ .body {
border: 1px solid var(--color-4-dimgray);
}
}
.expand-arrow {
width: 8px;
height: 8px;
margin: 0;
padding: 0;
position: relative;
flex: 0 0 auto;
display: flex;
align-items: center;
justify-content: center;
&::after {
content: "";
position: absolute;
width: 8px;
height: 8px;
background: var(--icon-expand-collapse-arrow);
}
}
.text-label {
height: 18px;
margin-left: 8px;
flex: 1 1 100%;
}
}
&:not(:hover) .header .show-only-on-hover {
display: none;
}
.body {
padding: 0 7px;
padding-top: 1px;
margin-top: -1px;
background: var(--color-3-darkgray);
border: 1px solid var(--color-2-mildblack);
border-radius: 0 0 4px 4px;
overflow: hidden;
.widget-span.row {
&:first-child {
margin-top: calc(4px - 1px);
}
&:last-child {
margin-bottom: calc(4px - 1px);
}
> .text-button:first-child {
margin-left: 16px;
}
> .text-label:first-of-type {
flex: 0 0 25%;
margin-left: 16px;
}
> .parameter-expose-button + .text-label:first-of-type {
margin-left: 8px;
}
> .text-button {
flex-grow: 1;
}
> .radio-input button {
flex: 1 1 100%;
}
}
}
}
</style>
|