1
0
Fork 0
mirror of synced 2024-07-07 07:15:43 +12:00

Add icons to app preview selection indicators

This commit is contained in:
Andrew Kingston 2022-05-17 14:33:12 +01:00
parent 2b5b6ae282
commit 976904686e
5 changed files with 60 additions and 25 deletions

View file

@ -20,7 +20,6 @@
} from "utils/componentProps" } from "utils/componentProps"
import { builderStore, devToolsStore, componentStore, appStore } from "stores" import { builderStore, devToolsStore, componentStore, appStore } from "stores"
import { Helpers } from "@budibase/bbui" import { Helpers } from "@budibase/bbui"
import Manifest from "manifest.json"
import { getActiveConditions, reduceConditionActions } from "utils/conditions" import { getActiveConditions, reduceConditionActions } from "utils/conditions"
import Placeholder from "components/app/Placeholder.svelte" import Placeholder from "components/app/Placeholder.svelte"
@ -171,8 +170,9 @@
} }
// Pull definition and constructor // Pull definition and constructor
constructor = getComponentConstructor(instance._component) const component = instance._component
definition = getComponentDefinition(instance._component) constructor = getComponentConstructor(component)
definition = componentStore.actions.getComponentDefinition(component)
if (!definition) { if (!definition) {
return return
} }
@ -217,13 +217,6 @@
return AppComponents[name] return AppComponents[name]
} }
// Gets this component's definition from the manifest
const getComponentDefinition = component => {
const prefix = "@budibase/standard-components/"
const type = component?.replace(prefix, "")
return type ? Manifest[type] : null
}
const getSettingsDefinitionMap = settingsDefinition => { const getSettingsDefinitionMap = settingsDefinition => {
let map = {} let map = {}
settingsDefinition?.forEach(setting => { settingsDefinition?.forEach(setting => {
@ -382,7 +375,7 @@
if (!node) { if (!node) {
return return
} }
node.style.scrollMargin = "80px" node.style.scrollMargin = "86px"
node.scrollIntoView({ node.scrollIntoView({
behavior: "smooth", behavior: "smooth",
block: "start", block: "start",

View file

@ -1,18 +1,20 @@
<script> <script>
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
import { Icon } from "@budibase/bbui"
export let top export let top
export let left export let left
export let width export let width
export let height export let height
export let text export let text
export let icon
export let color export let color
export let zIndex export let zIndex
export let transition = false export let transition = false
export let line = false export let line = false
export let alignRight = false export let alignRight = false
$: flipped = top < 20 $: flipped = top < 26
</script> </script>
<div <div
@ -26,14 +28,22 @@
style="top: {top}px; left: {left}px; width: {width}px; height: {height}px; --color: {color}; --zIndex: {zIndex};" style="top: {top}px; left: {left}px; width: {width}px; height: {height}px; --color: {color}; --zIndex: {zIndex};"
class:withText={!!text} class:withText={!!text}
> >
{#if text} {#if text || icon}
<div class="text" class:flipped class:line class:right={alignRight}> <div class="label" class:flipped class:line class:right={alignRight}>
{text} {#if icon}
<Icon name={icon} size="S" color="white" />
{/if}
{#if text}
<div class="text">
{text}
</div>
{/if}
</div> </div>
{/if} {/if}
</div> </div>
<style> <style>
/* Indicator styles */
.indicator { .indicator {
right: 0; right: 0;
position: absolute; position: absolute;
@ -51,16 +61,16 @@
.indicator.line { .indicator.line {
border-radius: 4px !important; border-radius: 4px !important;
} }
.text {
/* Label styles */
.label {
background-color: var(--color); background-color: var(--color);
color: white;
position: absolute; position: absolute;
top: 0; top: 0;
left: -2px; left: -2px;
height: 20px; height: 26px;
padding: 0 8px 2px 8px; padding: 0 6px 2px 6px;
transform: translateY(-100%); transform: translateY(-100%);
font-size: 11px;
border-top-left-radius: 4px; border-top-left-radius: 4px;
border-top-right-radius: 4px; border-top-right-radius: 4px;
border-bottom-right-radius: 4px; border-bottom-right-radius: 4px;
@ -69,18 +79,30 @@
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
gap: 6px;
} }
.text.line { .label.line {
transform: translateY(-50%); transform: translateY(-50%);
border-radius: 4px; border-radius: 4px;
} }
.text.flipped { .label.flipped {
border-radius: 4px; border-radius: 4px;
transform: translateY(0%); transform: translateY(0%);
top: -2px; top: -2px;
} }
.text.right { .label.right {
right: -2px; right: -2px;
left: auto; left: auto;
} }
/* Text styles */
.text {
color: white;
font-size: 11px;
font-weight: 600;
}
/* Icon styles */
.label :global(.spectrum-Icon + .text) {
}
</style> </style>

View file

@ -2,7 +2,7 @@
import { onMount, onDestroy } from "svelte" import { onMount, onDestroy } from "svelte"
import Indicator from "./Indicator.svelte" import Indicator from "./Indicator.svelte"
import { domDebounce } from "utils/domDebounce" import { domDebounce } from "utils/domDebounce"
import { builderStore } from "stores" import { builderStore, componentStore } from "stores"
export let componentId export let componentId
export let color export let color
@ -15,12 +15,24 @@
let text let text
$: visibleIndicators = indicators.filter(x => x.visible) $: visibleIndicators = indicators.filter(x => x.visible)
$: offset = $builderStore.inBuilder ? 0 : 2 $: offset = $builderStore.inBuilder ? 0 : 2
$: icon = getComponentIcon(componentId)
$: console.log(icon)
let updating = false let updating = false
let observers = [] let observers = []
let callbackCount = 0 let callbackCount = 0
let nextIndicators = [] let nextIndicators = []
const getComponentIcon = id => {
if (!id) {
return null
}
const component = componentStore.actions.getComponentById(id)
const type = component?._component
const definition = componentStore.actions.getComponentDefinition(type)
return definition?.icon
}
const createIntersectionCallback = idx => entries => { const createIntersectionCallback = idx => entries => {
if (callbackCount >= observers.length) { if (callbackCount >= observers.length) {
return return
@ -121,6 +133,7 @@
width={indicator.width} width={indicator.width}
height={indicator.height} height={indicator.height}
text={idx === 0 ? text : null} text={idx === 0 ? text : null}
icon={idx === 0 ? icon : null}
{transition} {transition}
{zIndex} {zIndex}
{color} {color}

View file

@ -6,7 +6,7 @@
import { builderStore, componentStore } from "stores" import { builderStore, componentStore } from "stores"
import { domDebounce } from "utils/domDebounce" import { domDebounce } from "utils/domDebounce"
const verticalOffset = 28 const verticalOffset = 34
const horizontalOffset = 2 const horizontalOffset = 2
let top = 0 let top = 0

View file

@ -67,6 +67,12 @@ const createComponentStore = () => {
return findComponentById(asset?.props, id) return findComponentById(asset?.props, id)
} }
const getComponentDefinition = type => {
const prefix = "@budibase/standard-components/"
type = type?.replace(prefix, "")
return type ? Manifest[type] : null
}
return { return {
...derivedStore, ...derivedStore,
actions: { actions: {
@ -74,6 +80,7 @@ const createComponentStore = () => {
unregisterInstance, unregisterInstance,
isComponentRegistered, isComponentRegistered,
getComponentById, getComponentById,
getComponentDefinition,
}, },
} }
} }