Update multiple usages of tooltips to use new tooltip

This commit is contained in:
Andrew Kingston 2023-07-07 12:09:23 +01:00
parent 6aef0f2134
commit 35150af784
9 changed files with 118 additions and 132 deletions

View File

@ -1,6 +1,7 @@
<script> <script>
import "@spectrum-css/button/dist/index-vars.css" import "@spectrum-css/button/dist/index-vars.css"
import Tooltip from "../Tooltip/Tooltip.svelte" import AbsTooltip from "../Tooltip/AbsTooltip.svelte"
import { createEventDispatcher } from "svelte"
export let type export let type
export let disabled = false export let disabled = false
@ -16,9 +17,12 @@
export let tooltip = undefined export let tooltip = undefined
export let newStyles = true export let newStyles = true
export let id export let id
const dispatch = createEventDispatcher()
</script> </script>
<button <AbsTooltip text={tooltip}>
<button
{id} {id}
{type} {type}
class:spectrum-Button--cta={cta} class:spectrum-Button--cta={cta}
@ -29,11 +33,14 @@
class:spectrum-Button--quiet={quiet} class:spectrum-Button--quiet={quiet}
class:new-styles={newStyles} class:new-styles={newStyles}
class:active class:active
class:disabled class:is-disabled={disabled}
class="spectrum-Button spectrum-Button--size{size.toUpperCase()}" class="spectrum-Button spectrum-Button--size{size.toUpperCase()}"
{disabled} on:click|preventDefault={() => {
on:click|preventDefault if (!disabled) {
> dispatch("click")
}
}}
>
{#if icon} {#if icon}
<svg <svg
class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}" class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
@ -47,17 +54,16 @@
{#if $$slots} {#if $$slots}
<span class="spectrum-Button-label"><slot /></span> <span class="spectrum-Button-label"><slot /></span>
{/if} {/if}
{#if tooltip} </button>
<div class="tooltip"> </AbsTooltip>
<Tooltip textWrapping={true} direction={"bottom"} text={tooltip} />
</div>
{/if}
</button>
<style> <style>
button { button {
position: relative; position: relative;
} }
button.is-disabled {
cursor: default;
}
.spectrum-Button-label { .spectrum-Button-label {
white-space: nowrap; white-space: nowrap;
overflow: hidden; overflow: hidden;
@ -66,23 +72,6 @@
.active { .active {
color: var(--spectrum-global-color-blue-600) !important; color: var(--spectrum-global-color-blue-600) !important;
} }
.tooltip {
position: absolute;
display: flex;
justify-content: center;
z-index: 100;
width: 160px;
text-align: center;
transform: translateX(-50%);
left: 50%;
top: 100%;
opacity: 0;
transition: opacity 130ms ease-out;
pointer-events: none;
}
button:hover .tooltip {
opacity: 1;
}
.spectrum-Button--primary.new-styles { .spectrum-Button--primary.new-styles {
background: var(--spectrum-global-color-gray-800); background: var(--spectrum-global-color-gray-800);
border-color: transparent; border-color: transparent;
@ -96,10 +85,10 @@
border-color: transparent; border-color: transparent;
color: var(--spectrum-global-color-gray-900); color: var(--spectrum-global-color-gray-900);
} }
.spectrum-Button--secondary.new-styles:not(.disabled):hover { .spectrum-Button--secondary.new-styles:not(.is-disabled):hover {
background: var(--spectrum-global-color-gray-300); background: var(--spectrum-global-color-gray-300);
} }
.spectrum-Button--secondary.new-styles.disabled { .spectrum-Button--secondary.new-styles.is-disabled {
color: var(--spectrum-global-color-gray-500); color: var(--spectrum-global-color-gray-500);
} }
</style> </style>

View File

@ -90,6 +90,6 @@
.spectrum-Popover { .spectrum-Popover {
min-width: var(--spectrum-global-dimension-size-2000); min-width: var(--spectrum-global-dimension-size-2000);
border-color: var(--spectrum-global-color-gray-300); border-color: var(--spectrum-global-color-gray-300);
overflow: visible; overflow: auto;
} }
</style> </style>

View File

@ -1,5 +1,5 @@
<script context="module"> <script context="module">
export const TooltipDirection = { export const TooltipPosition = {
Top: "top", Top: "top",
Right: "right", Right: "right",
Bottom: "bottom", Bottom: "bottom",
@ -19,8 +19,8 @@
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
import "@spectrum-css/tooltip/dist/index-vars.css" import "@spectrum-css/tooltip/dist/index-vars.css"
export let direction = TooltipDirection.Top export let position = TooltipPosition.Top
export let type = TooltipType.Positive export let type = TooltipType.Default
export let text = "" export let text = ""
let wrapper let wrapper
@ -35,16 +35,16 @@
} }
const bounds = node.getBoundingClientRect() const bounds = node.getBoundingClientRect()
if (direction === TooltipDirection.Top) { if (position === TooltipPosition.Top) {
left = bounds.left + bounds.width / 2 left = bounds.left + bounds.width / 2
top = bounds.top top = bounds.top
} else if (direction === TooltipDirection.Right) { } else if (position === TooltipPosition.Right) {
left = bounds.left + bounds.width left = bounds.left + bounds.width
top = bounds.top + bounds.height / 2 top = bounds.top + bounds.height / 2
} else if (direction === TooltipDirection.Bottom) { } else if (position === TooltipPosition.Bottom) {
left = bounds.left + bounds.width / 2 left = bounds.left + bounds.width / 2
top = bounds.top + bounds.height top = bounds.top + bounds.height
} else if (direction === TooltipDirection.Left) { } else if (position === TooltipPosition.Left) {
left = bounds.left left = bounds.left
top = bounds.top + bounds.height / 2 top = bounds.top + bounds.height / 2
} else { } else {
@ -58,18 +58,19 @@
} }
</script> </script>
<div {#if text}
<div
bind:this={wrapper} bind:this={wrapper}
class="abs-tooltip" class="abs-tooltip"
on:mouseover={show} on:mouseover={show}
on:mouseleave={hide} on:mouseleave={hide}
> >
<slot /> <slot />
</div> </div>
{#if visible} {#if visible}
<Portal target=".spectrum"> <Portal target=".spectrum">
<span <span
class="spectrum-Tooltip spectrum-Tooltip--{type} spectrum-Tooltip--{direction} is-open" class="spectrum-Tooltip spectrum-Tooltip--{type} spectrum-Tooltip--{position} is-open"
style="left:{left}px;top:{top}px;" style="left:{left}px;top:{top}px;"
transition:fade|local={{ duration: 130 }} transition:fade|local={{ duration: 130 }}
> >
@ -77,6 +78,9 @@
<span class="spectrum-Tooltip-tip" /> <span class="spectrum-Tooltip-tip" />
</span> </span>
</Portal> </Portal>
{/if}
{:else}
<slot />
{/if} {/if}
<style> <style>
@ -85,7 +89,7 @@
} }
.spectrum-Tooltip { .spectrum-Tooltip {
position: absolute; position: absolute;
z-index: 999; z-index: 9999;
pointer-events: none; pointer-events: none;
margin: 0; margin: 0;
max-width: 280px; max-width: 280px;

View File

@ -38,7 +38,7 @@ export { default as Link } from "./Link/Link.svelte"
export { default as Tooltip } from "./Tooltip/Tooltip.svelte" export { default as Tooltip } from "./Tooltip/Tooltip.svelte"
export { export {
default as AbsTooltip, default as AbsTooltip,
TooltipDirection, TooltipPosition,
TooltipType, TooltipType,
} from "./Tooltip/AbsTooltip.svelte" } from "./Tooltip/AbsTooltip.svelte"
export { default as TooltipWrapper } from "./Tooltip/TooltipWrapper.svelte" export { default as TooltipWrapper } from "./Tooltip/TooltipWrapper.svelte"

View File

@ -10,6 +10,7 @@
Link, Link,
Modal, Modal,
StatusLight, StatusLight,
AbsTooltip,
} from "@budibase/bbui" } from "@budibase/bbui"
import RevertModal from "components/deploy/RevertModal.svelte" import RevertModal from "components/deploy/RevertModal.svelte"
import VersionModal from "components/deploy/VersionModal.svelte" import VersionModal from "components/deploy/VersionModal.svelte"
@ -250,15 +251,20 @@
<Link quiet on:click={unpublishApp}>Unpublish</Link> <Link quiet on:click={unpublishApp}>Unpublish</Link>
</span> </span>
<span class="revert-link"> <span class="revert-link">
<AbsTooltip
text={$isOnlyUser
? null
: "Unavailable - another user is editing this app"}
>
<Link <Link
disabled={!$isOnlyUser} disabled={!$isOnlyUser}
quiet quiet
secondary secondary
on:click={revertApp} on:click={revertApp}
tooltip="Unavailable - another user is editing this app"
> >
Revert Revert
</Link> </Link>
</AbsTooltip>
</span> </span>
{:else} {:else}
<span class="status-text unpublished">Not published</span> <span class="status-text unpublished">Not published</span>

View File

@ -1,11 +1,8 @@
<script> <script>
import { Tooltip } from "@budibase/bbui"
export let text export let text
export let url export let url
export let active = false export let active = false
export let disabled = false export let disabled = false
export let tooltip = null
</script> </script>
<div class="side-nav-item"> <div class="side-nav-item">
@ -18,11 +15,6 @@
{text || ""} {text || ""}
</div> </div>
{/if} {/if}
{#if tooltip}
<div class="tooltip">
<Tooltip textWrapping direction="right" text={tooltip} />
</div>
{/if}
</div> </div>
<style> <style>
@ -45,17 +37,4 @@
pointer-events: none; pointer-events: none;
color: var(--spectrum-global-color-gray-500) !important; color: var(--spectrum-global-color-gray-500) !important;
} }
.tooltip {
position: absolute;
transform: translateY(-50%);
left: 100%;
top: 50%;
opacity: 0;
pointer-events: none;
transition: opacity 130ms ease-out;
z-index: 100;
}
.side-nav-item:hover .tooltip {
opacity: 1;
}
</style> </style>

View File

@ -1,6 +1,6 @@
<script> <script>
import { Content, SideNav, SideNavItem } from "components/portal/page" import { Content, SideNav, SideNavItem } from "components/portal/page"
import { Page, Layout } from "@budibase/bbui" import { Page, Layout, AbsTooltip, TooltipPosition } from "@budibase/bbui"
import { url, isActive } from "@roxi/routify" import { url, isActive } from "@roxi/routify"
import DeleteModal from "components/deploy/DeleteModal.svelte" import DeleteModal from "components/deploy/DeleteModal.svelte"
import { isOnlyUser } from "builderStore" import { isOnlyUser } from "builderStore"
@ -45,16 +45,20 @@
active={$isActive("./version")} active={$isActive("./version")}
/> />
<div class="delete-action"> <div class="delete-action">
<AbsTooltip
position={TooltipPosition.Right}
text={$isOnlyUser
? null
: "Unavailable - another user is editing this app"}
>
<SideNavItem <SideNavItem
text="Delete app" text="Delete app"
disabled={!$isOnlyUser}
on:click={() => { on:click={() => {
deleteModal.show() deleteModal.show()
}} }}
disabled={!$isOnlyUser}
tooltip={$isOnlyUser
? null
: "Unavailable - another user is editing this app"}
/> />
</AbsTooltip>
</div> </div>
</SideNav> </SideNav>
<slot /> <slot />

View File

@ -6,6 +6,8 @@
Heading, Heading,
Body, Body,
Modal, Modal,
AbsTooltip,
TooltipPosition,
} from "@budibase/bbui" } from "@budibase/bbui"
import ConfirmDialog from "components/common/ConfirmDialog.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import CreateRestoreModal from "./CreateRestoreModal.svelte" import CreateRestoreModal from "./CreateRestoreModal.svelte"
@ -46,16 +48,18 @@
</div> </div>
{#if row.type !== "restore"} {#if row.type !== "restore"}
<AbsTooltip
position={TooltipPosition.Left}
text="Unavailable - another user is editing this app"
>
<MenuItem <MenuItem
on:click={restoreDialog.show} on:click={restoreDialog.show}
icon="Revert" icon="Revert"
disabled={!$isOnlyUser} disabled={!$isOnlyUser}
tooltip={$isOnlyUser
? null
: "Unavailable - another user is editing this app"}
> >
Restore Restore
</MenuItem> </MenuItem>
</AbsTooltip>
<MenuItem on:click={deleteDialog.show} icon="Delete">Delete</MenuItem> <MenuItem on:click={deleteDialog.show} icon="Delete">Delete</MenuItem>
<MenuItem on:click={downloadExport} icon="Download">Download</MenuItem> <MenuItem on:click={downloadExport} icon="Download">Download</MenuItem>
{/if} {/if}

View File

@ -6,7 +6,7 @@
Icon, Icon,
AbsTooltip, AbsTooltip,
TooltipType, TooltipType,
TooltipDirection, TooltipPosition,
} from "@budibase/bbui" } from "@budibase/bbui"
const { const {
@ -37,7 +37,7 @@
{#if $config.allowSchemaChanges} {#if $config.allowSchemaChanges}
<AbsTooltip <AbsTooltip
text="Click here to create your first column" text="Click here to create your first column"
direction={TooltipDirection.Bottom} position={TooltipPosition.Bottom}
type={TooltipType.Info} type={TooltipType.Info}
> >
<div <div