forked from tsai/budibase
6 changed files with 96 additions and 66 deletions
@ -1,73 +1,20 @@ |
|||||
<script> |
<script> |
||||
import "@spectrum-css/fieldlabel/dist/index-vars.css" |
import "@spectrum-css/fieldlabel/dist/index-vars.css" |
||||
import Tooltip from "../Tooltip/Tooltip.svelte" |
import TooltipWrapper from "../Tooltip/TooltipWrapper.svelte" |
||||
import Icon from "../Icon/Icon.svelte" |
|
||||
|
|
||||
export let size = "M" |
export let size = "M" |
||||
export let tooltip = "" |
export let tooltip = "" |
||||
export let showTooltip = false |
|
||||
</script> |
</script> |
||||
|
|
||||
{#if tooltip} |
<TooltipWrapper {tooltip} {size}> |
||||
<div class="container"> |
|
||||
<label |
|
||||
for="" |
|
||||
class={`spectrum-FieldLabel spectrum-FieldLabel--size${size}`} |
|
||||
> |
|
||||
<slot /> |
|
||||
</label> |
|
||||
<div class="icon-container"> |
|
||||
<div |
|
||||
class="icon" |
|
||||
class:icon-small={size === "M" || size === "S"} |
|
||||
on:mouseover={() => (showTooltip = true)} |
|
||||
on:mouseleave={() => (showTooltip = false)} |
|
||||
> |
|
||||
<Icon name="InfoOutline" size="S" disabled={true} /> |
|
||||
</div> |
|
||||
{#if showTooltip} |
|
||||
<div class="tooltip"> |
|
||||
<Tooltip textWrapping={true} direction={"bottom"} text={tooltip} /> |
|
||||
</div> |
|
||||
{/if} |
|
||||
</div> |
|
||||
</div> |
|
||||
{:else} |
|
||||
<label for="" class={`spectrum-FieldLabel spectrum-FieldLabel--size${size}`}> |
<label for="" class={`spectrum-FieldLabel spectrum-FieldLabel--size${size}`}> |
||||
<slot /> |
<slot /> |
||||
</label> |
</label> |
||||
{/if} |
</TooltipWrapper> |
||||
|
|
||||
<style> |
<style> |
||||
label { |
label { |
||||
padding: 0; |
padding: 0; |
||||
white-space: nowrap; |
white-space: nowrap; |
||||
} |
} |
||||
.container { |
|
||||
display: flex; |
|
||||
align-items: center; |
|
||||
} |
|
||||
.icon-container { |
|
||||
position: relative; |
|
||||
display: flex; |
|
||||
justify-content: center; |
|
||||
margin-top: 1px; |
|
||||
margin-left: 5px; |
|
||||
margin-right: 5px; |
|
||||
} |
|
||||
.tooltip { |
|
||||
position: absolute; |
|
||||
display: flex; |
|
||||
justify-content: center; |
|
||||
top: 15px; |
|
||||
z-index: 1; |
|
||||
width: 160px; |
|
||||
} |
|
||||
.icon { |
|
||||
transform: scale(0.75); |
|
||||
} |
|
||||
.icon-small { |
|
||||
margin-top: -2px; |
|
||||
margin-bottom: -5px; |
|
||||
} |
|
||||
</style> |
</style> |
||||
|
|||||
@ -0,0 +1,60 @@ |
|||||
|
<script> |
||||
|
import Tooltip from "./Tooltip.svelte" |
||||
|
import Icon from "../Icon/Icon.svelte" |
||||
|
|
||||
|
export let tooltip = "" |
||||
|
export let size = "M" |
||||
|
|
||||
|
let showTooltip = false |
||||
|
</script> |
||||
|
|
||||
|
<div class:container={!!tooltip}> |
||||
|
<slot /> |
||||
|
{#if tooltip} |
||||
|
<div class="icon-container"> |
||||
|
<div |
||||
|
class="icon" |
||||
|
class:icon-small={size === "M" || size === "S"} |
||||
|
on:mouseover={() => (showTooltip = true)} |
||||
|
on:mouseleave={() => (showTooltip = false)} |
||||
|
> |
||||
|
<Icon name="InfoOutline" size="S" disabled={true} /> |
||||
|
</div> |
||||
|
{#if showTooltip} |
||||
|
<div class="tooltip"> |
||||
|
<Tooltip textWrapping={true} direction={"bottom"} text={tooltip} /> |
||||
|
</div> |
||||
|
{/if} |
||||
|
</div> |
||||
|
{/if} |
||||
|
</div> |
||||
|
|
||||
|
<style> |
||||
|
.container { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
} |
||||
|
.icon-container { |
||||
|
position: relative; |
||||
|
display: flex; |
||||
|
justify-content: center; |
||||
|
margin-top: 1px; |
||||
|
margin-left: 5px; |
||||
|
margin-right: 5px; |
||||
|
} |
||||
|
.tooltip { |
||||
|
position: absolute; |
||||
|
display: flex; |
||||
|
justify-content: center; |
||||
|
top: 15px; |
||||
|
z-index: 1; |
||||
|
width: 160px; |
||||
|
} |
||||
|
.icon { |
||||
|
transform: scale(0.75); |
||||
|
} |
||||
|
.icon-small { |
||||
|
margin-top: -2px; |
||||
|
margin-bottom: -5px; |
||||
|
} |
||||
|
</style> |
||||
Loading…
Reference in new issue