Add icons to component list and update style of nav items

This commit is contained in:
Andrew Kingston 2022-05-13 10:12:16 +01:00
parent ad6a0c74f6
commit 76471bfcc4
4 changed files with 52 additions and 11 deletions

View File

@ -157,7 +157,8 @@
<style> <style>
.datasource-icon { .datasource-icon {
margin-right: 3px; display: grid;
padding-top: 3px; place-items: center;
flex: 0 0 24px;
} }
</style> </style>

View File

@ -46,7 +46,7 @@
class:border class:border
class:selected class:selected
class:withActions class:withActions
style={`padding-left: calc(var(--spacing-l) + ${indentLevel * 14}px)`} style={`padding-left: calc(${indentLevel * 14}px)`}
{draggable} {draggable}
on:dragend on:dragend
on:dragstart on:dragstart
@ -59,7 +59,13 @@
> >
<div class="nav-item-content" bind:this={contentRef}> <div class="nav-item-content" bind:this={contentRef}>
{#if withArrow} {#if withArrow}
<div class:opened class="icon arrow" on:click={onIconClick}> <div
class:opened
class:relative={indentLevel === 0}
class:absolute={indentLevel > 0}
class="icon arrow"
on:click={onIconClick}
>
<Icon size="S" name="ChevronRight" /> <Icon size="S" name="ChevronRight" />
</div> </div>
{/if} {/if}
@ -126,25 +132,40 @@
width: max-content; width: max-content;
overflow: hidden; overflow: hidden;
position: relative; position: relative;
padding-left: var(--spacing-l);
} }
.icon { .icon {
font-size: 16px; font-size: 16px;
flex: 0 0 20px; flex: 0 0 24px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: center; justify-content: center;
align-items: center; align-items: center;
color: var(--spectrum-global-color-gray-600);
} }
.icon.arrow { .icon.arrow {
margin: 0 -2px 0 -6px; flex: 0 0 20px;
font-size: 12px; }
.icon.arrow.absolute {
position: absolute;
left: 0;
padding: 8px;
margin-left: -8px;
}
.icon.arrow :global(svg) {
width: 12px;
height: 12px;
}
.icon.arrow.relative {
position: relative;
margin: 0 -6px 0 -4px;
} }
.icon.arrow.opened { .icon.arrow.opened {
transform: rotate(90deg); transform: rotate(90deg);
} }
.icon + .icon { .icon + .icon {
margin-left: -4px; /*margin-left: -4px;*/
} }
.iconText { .iconText {
margin-top: 1px; margin-top: 1px;
@ -154,11 +175,12 @@
.text { .text {
font-weight: 600; font-weight: 600;
font-size: var(--spectrum-global-dimension-font-size-75); font-size: 12px;
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
flex: 1 1 auto; flex: 1 1 auto;
color: var(--spectrum-global-color-gray-800);
} }
.scrollable .text { .scrollable .text {
flex: 0 0 auto; flex: 0 0 auto;

View File

@ -70,11 +70,11 @@
<div class="nav-items-container" bind:this={scrollRef}> <div class="nav-items-container" bind:this={scrollRef}>
<NavItem <NavItem
text="Screen" text="Screen"
withArrow
indentLevel={0} indentLevel={0}
selected={$store.selectedComponentId === $selectedScreen?.props._id} selected={$store.selectedComponentId === $selectedScreen?.props._id}
opened opened
scrollable scrollable
icon="WebPage"
on:click={() => { on:click={() => {
$store.selectedComponentId = $selectedScreen?.props._id $store.selectedComponentId = $selectedScreen?.props._id
}} }}

View File

@ -51,6 +51,16 @@
return capitalise(type) return capitalise(type)
} }
const getComponentIcon = component => {
const def = store.actions.components.getDefinition(component?._component)
return def?.icon
}
const componentHasChildren = component => {
const def = store.actions.components.getDefinition(component?._component)
return def?.hasChildren && component._children?.length
}
function toggleNodeOpen(componentId) { function toggleNodeOpen(componentId) {
if (closedNodes[componentId]) { if (closedNodes[componentId]) {
delete closedNodes[componentId] delete closedNodes[componentId]
@ -105,7 +115,8 @@
on:iconClick={() => toggleNodeOpen(component._id)} on:iconClick={() => toggleNodeOpen(component._id)}
on:drop={onDrop} on:drop={onDrop}
text={getComponentText(component)} text={getComponentText(component)}
withArrow icon={getComponentIcon(component)}
withArrow={componentHasChildren(component)}
indentLevel={level + 1} indentLevel={level + 1}
selected={$store.selectedComponentId === component._id} selected={$store.selectedComponentId === component._id}
opened={isOpen(component, $selectedComponentPath, closedNodes)} opened={isOpen(component, $selectedComponentPath, closedNodes)}
@ -143,6 +154,13 @@
padding-left: 0; padding-left: 0;
margin: 0; margin: 0;
} }
ul :global(.icon.arrow) {
transition: opacity 130ms ease-out;
opacity: 0;
}
ul:hover :global(.icon.arrow) {
opacity: 1;
}
ul, ul,
li { li {
min-width: max-content; min-width: max-content;