@budibase/bbui 2.8.21 → 2.8.22-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/bbui",
3
3
  "description": "A UI solution used in the different Budibase projects.",
4
- "version": "2.8.21",
4
+ "version": "2.8.22-alpha.1",
5
5
  "license": "MPL-2.0",
6
6
  "svelte": "src/index.js",
7
7
  "module": "dist/bbui.es.js",
@@ -38,8 +38,8 @@
38
38
  ],
39
39
  "dependencies": {
40
40
  "@adobe/spectrum-css-workflow-icons": "1.2.1",
41
- "@budibase/shared-core": "2.8.21",
42
- "@budibase/string-templates": "2.8.21",
41
+ "@budibase/shared-core": "2.8.22-alpha.1",
42
+ "@budibase/string-templates": "2.8.22-alpha.1",
43
43
  "@spectrum-css/accordion": "3.0.24",
44
44
  "@spectrum-css/actionbutton": "1.0.1",
45
45
  "@spectrum-css/actiongroup": "1.0.1",
@@ -104,5 +104,5 @@
104
104
  }
105
105
  }
106
106
  },
107
- "gitHead": "26c531ec81a0bdfb5805f2c8a85d6bbcc5ac7d81"
107
+ "gitHead": "efcef8d6f8ce0744d1f80f8161a41f55ef6c8ea4"
108
108
  }
@@ -1,6 +1,7 @@
1
1
  <script>
2
2
  import "@spectrum-css/button/dist/index-vars.css"
3
- import Tooltip from "../Tooltip/Tooltip.svelte"
3
+ import AbsTooltip from "../Tooltip/AbsTooltip.svelte"
4
+ import { createEventDispatcher } from "svelte"
4
5
 
5
6
  export let type
6
7
  export let disabled = false
@@ -17,65 +18,52 @@
17
18
  export let newStyles = true
18
19
  export let id
19
20
 
20
- let showTooltip = false
21
+ const dispatch = createEventDispatcher()
21
22
  </script>
22
23
 
23
- <button
24
- {id}
25
- {type}
26
- class:spectrum-Button--cta={cta}
27
- class:spectrum-Button--primary={primary}
28
- class:spectrum-Button--secondary={secondary}
29
- class:spectrum-Button--warning={warning}
30
- class:spectrum-Button--overBackground={overBackground}
31
- class:spectrum-Button--quiet={quiet}
32
- class:new-styles={newStyles}
33
- class:active
34
- class:disabled
35
- class="spectrum-Button spectrum-Button--size{size.toUpperCase()}"
36
- {disabled}
37
- on:click|preventDefault
38
- on:mouseover={() => (showTooltip = true)}
39
- on:focus={() => (showTooltip = true)}
40
- on:mouseleave={() => (showTooltip = false)}
41
- >
42
- {#if icon}
43
- <svg
44
- class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
45
- focusable="false"
46
- aria-hidden="true"
47
- aria-label={icon}
48
- >
49
- <use xlink:href="#spectrum-icon-18-{icon}" />
50
- </svg>
51
- {/if}
52
- {#if $$slots}
53
- <span class="spectrum-Button-label"><slot /></span>
54
- {/if}
55
- {#if !disabled && tooltip}
56
- <div class="tooltip-icon">
24
+ <AbsTooltip text={tooltip}>
25
+ <button
26
+ {id}
27
+ {type}
28
+ class:spectrum-Button--cta={cta}
29
+ class:spectrum-Button--primary={primary}
30
+ class:spectrum-Button--secondary={secondary}
31
+ class:spectrum-Button--warning={warning}
32
+ class:spectrum-Button--overBackground={overBackground}
33
+ class:spectrum-Button--quiet={quiet}
34
+ class:new-styles={newStyles}
35
+ class:active
36
+ class:is-disabled={disabled}
37
+ class="spectrum-Button spectrum-Button--size{size.toUpperCase()}"
38
+ on:click|preventDefault={() => {
39
+ if (!disabled) {
40
+ dispatch("click")
41
+ }
42
+ }}
43
+ >
44
+ {#if icon}
57
45
  <svg
58
46
  class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}"
59
47
  focusable="false"
60
48
  aria-hidden="true"
61
- aria-label="Info"
49
+ aria-label={icon}
62
50
  >
63
- <use xlink:href="#spectrum-icon-18-InfoOutline" />
51
+ <use xlink:href="#spectrum-icon-18-{icon}" />
64
52
  </svg>
65
- </div>
66
- {/if}
67
- {#if showTooltip && tooltip}
68
- <div class="tooltip">
69
- <Tooltip textWrapping={true} direction={"bottom"} text={tooltip} />
70
- </div>
71
- {/if}
72
- </button>
53
+ {/if}
54
+ {#if $$slots}
55
+ <span class="spectrum-Button-label"><slot /></span>
56
+ {/if}
57
+ </button>
58
+ </AbsTooltip>
73
59
 
74
60
  <style>
75
61
  button {
76
62
  position: relative;
77
63
  }
78
-
64
+ button.is-disabled {
65
+ cursor: default;
66
+ }
79
67
  .spectrum-Button-label {
80
68
  white-space: nowrap;
81
69
  overflow: hidden;
@@ -84,21 +72,6 @@
84
72
  .active {
85
73
  color: var(--spectrum-global-color-blue-600) !important;
86
74
  }
87
- .tooltip {
88
- position: absolute;
89
- display: flex;
90
- justify-content: center;
91
- z-index: 100;
92
- width: 160px;
93
- text-align: center;
94
- transform: translateX(-50%);
95
- left: 50%;
96
- top: calc(100% - 3px);
97
- }
98
- .tooltip-icon {
99
- padding-left: var(--spacing-m);
100
- line-height: 0;
101
- }
102
75
  .spectrum-Button--primary.new-styles {
103
76
  background: var(--spectrum-global-color-gray-800);
104
77
  border-color: transparent;
@@ -112,10 +85,10 @@
112
85
  border-color: transparent;
113
86
  color: var(--spectrum-global-color-gray-900);
114
87
  }
115
- .spectrum-Button--secondary.new-styles:not(.disabled):hover {
88
+ .spectrum-Button--secondary.new-styles:not(.is-disabled):hover {
116
89
  background: var(--spectrum-global-color-gray-300);
117
90
  }
118
- .spectrum-Button--secondary.new-styles.disabled {
91
+ .spectrum-Button--secondary.new-styles.is-disabled {
119
92
  color: var(--spectrum-global-color-gray-500);
120
93
  }
121
94
  </style>
@@ -15,8 +15,6 @@
15
15
 
16
16
  const dispatch = createEventDispatcher()
17
17
 
18
- $: placeholder = !value
19
-
20
18
  const extractProperty = (value, property) => {
21
19
  if (value && typeof value === "object") {
22
20
  return value[property]
@@ -12,23 +12,24 @@
12
12
  export let getOptionValue = option => option
13
13
 
14
14
  const dispatch = createEventDispatcher()
15
+
15
16
  const onChange = e => {
16
- let tempValue = value
17
- let isChecked = e.target.checked
18
- if (!tempValue.includes(e.target.value) && isChecked) {
19
- tempValue.push(e.target.value)
17
+ const optionValue = e.target.value
18
+ if (e.target.checked && !value.includes(optionValue)) {
19
+ dispatch("change", [...value, optionValue])
20
+ } else {
21
+ dispatch(
22
+ "change",
23
+ value.filter(x => x !== optionValue)
24
+ )
20
25
  }
21
- value = tempValue
22
- dispatch(
23
- "change",
24
- tempValue.filter(val => val !== e.target.value || isChecked)
25
- )
26
26
  }
27
27
  </script>
28
28
 
29
29
  <div class={`spectrum-FieldGroup spectrum-FieldGroup--${direction}`}>
30
30
  {#if options && Array.isArray(options)}
31
31
  {#each options as option}
32
+ {@const optionValue = getOptionValue(option)}
32
33
  <div
33
34
  title={getOptionLabel(option)}
34
35
  class="spectrum-Checkbox spectrum-FieldGroup-item"
@@ -39,11 +40,11 @@
39
40
  >
40
41
  <input
41
42
  on:change={onChange}
42
- value={getOptionValue(option)}
43
43
  type="checkbox"
44
44
  class="spectrum-Checkbox-input"
45
+ value={optionValue}
46
+ checked={value.includes(optionValue)}
45
47
  {disabled}
46
- checked={value.includes(getOptionValue(option))}
47
48
  />
48
49
  <span class="spectrum-Checkbox-box">
49
50
  <svg
@@ -150,7 +150,7 @@
150
150
  </div>
151
151
  {:else if variables.length}
152
152
  <div style="max-height: 100px">
153
- {#each variables as variable, idx}
153
+ {#each variables as variable}
154
154
  <li
155
155
  class="spectrum-Menu-item"
156
156
  role="option"
@@ -1,6 +1,7 @@
1
1
  <script>
2
2
  import "@spectrum-css/link/dist/index-vars.css"
3
3
  import { createEventDispatcher } from "svelte"
4
+ import Tooltip from "../Tooltip/Tooltip.svelte"
4
5
 
5
6
  export let href = "#"
6
7
  export let size = "M"
@@ -10,18 +11,61 @@
10
11
  export let overBackground = false
11
12
  export let target
12
13
  export let download
14
+ export let disabled = false
15
+ export let tooltip = null
13
16
 
14
17
  const dispatch = createEventDispatcher()
18
+
19
+ const onClick = e => {
20
+ if (!disabled) {
21
+ dispatch("click")
22
+ e.stopPropagation()
23
+ }
24
+ }
15
25
  </script>
16
26
 
17
27
  <a
18
- on:click={e => dispatch("click") && e.stopPropagation()}
28
+ on:click={onClick}
19
29
  {href}
20
30
  {target}
21
31
  {download}
32
+ class:disabled
22
33
  class:spectrum-Link--primary={primary}
23
34
  class:spectrum-Link--secondary={secondary}
24
35
  class:spectrum-Link--overBackground={overBackground}
25
36
  class:spectrum-Link--quiet={quiet}
26
- class="spectrum-Link spectrum-Link--size{size}"><slot /></a
37
+ class="spectrum-Link spectrum-Link--size{size}"
27
38
  >
39
+ <slot />
40
+ {#if tooltip}
41
+ <div class="tooltip">
42
+ <Tooltip textWrapping direction="bottom" text={tooltip} />
43
+ </div>
44
+ {/if}
45
+ </a>
46
+
47
+ <style>
48
+ a {
49
+ position: relative;
50
+ }
51
+ a.disabled {
52
+ color: var(--spectrum-global-color-gray-500);
53
+ }
54
+ a.disabled:hover {
55
+ text-decoration: none;
56
+ cursor: default;
57
+ }
58
+ .tooltip {
59
+ position: absolute;
60
+ left: 50%;
61
+ top: 100%;
62
+ transform: translateX(-50%);
63
+ opacity: 0;
64
+ transition: 130ms ease-out;
65
+ pointer-events: none;
66
+ z-index: 100;
67
+ }
68
+ a:hover .tooltip {
69
+ opacity: 1;
70
+ }
71
+ </style>
@@ -1,3 +1,7 @@
1
+ <script context="module">
2
+ export const keepOpen = Symbol("keepOpen")
3
+ </script>
4
+
1
5
  <script>
2
6
  import "@spectrum-css/dialog/dist/index-vars.css"
3
7
  import { getContext } from "svelte"
@@ -30,7 +34,7 @@
30
34
 
31
35
  async function secondary(e) {
32
36
  loading = true
33
- if (!secondaryAction || (await secondaryAction(e)) !== false) {
37
+ if (!secondaryAction || (await secondaryAction(e)) !== keepOpen) {
34
38
  hide()
35
39
  }
36
40
  loading = false
@@ -38,7 +42,7 @@
38
42
 
39
43
  async function confirm() {
40
44
  loading = true
41
- if (!onConfirm || (await onConfirm()) !== false) {
45
+ if (!onConfirm || (await onConfirm()) !== keepOpen) {
42
46
  hide()
43
47
  }
44
48
  loading = false
@@ -46,7 +50,7 @@
46
50
 
47
51
  async function close() {
48
52
  loading = true
49
- if (!onCancel || (await onCancel()) !== false) {
53
+ if (!onCancel || (await onCancel()) !== keepOpen) {
50
54
  cancel()
51
55
  }
52
56
  loading = false
@@ -29,7 +29,6 @@
29
29
  $: type = getType(schema)
30
30
  $: customRenderer = customRenderers?.find(x => x.column === schema?.name)
31
31
  $: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer
32
- $: width = schema?.width || "150px"
33
32
  $: cellValue = getCellValue(value, schema.template)
34
33
 
35
34
  const getType = schema => {
@@ -379,7 +379,7 @@
379
379
  </div>
380
380
  {/if}
381
381
  {#if sortedRows?.length}
382
- {#each sortedRows as row, idx}
382
+ {#each sortedRows as row}
383
383
  <div class="spectrum-Table-row" class:clickable={allowClickRows}>
384
384
  {#if showEditColumn}
385
385
  <div
@@ -0,0 +1,157 @@
1
+ <script context="module">
2
+ export const TooltipPosition = {
3
+ Top: "top",
4
+ Right: "right",
5
+ Bottom: "bottom",
6
+ Left: "left",
7
+ }
8
+ export const TooltipType = {
9
+ Default: "default",
10
+ Info: "info",
11
+ Positive: "positive",
12
+ Negative: "negative",
13
+ }
14
+ </script>
15
+
16
+ <script>
17
+ import Portal from "svelte-portal"
18
+ import { fade } from "svelte/transition"
19
+ import "@spectrum-css/tooltip/dist/index-vars.css"
20
+ import { onDestroy } from "svelte"
21
+
22
+ export let position = TooltipPosition.Top
23
+ export let type = TooltipType.Default
24
+ export let text = ""
25
+ export let fixed = false
26
+ export let color = null
27
+
28
+ let wrapper
29
+ let hovered = false
30
+ let left
31
+ let top
32
+ let visible = false
33
+ let timeout
34
+ let interval
35
+
36
+ $: {
37
+ if (hovered || fixed) {
38
+ // Debounce showing by 200ms to avoid flashing tooltip
39
+ timeout = setTimeout(show, 200)
40
+ } else {
41
+ hide()
42
+ }
43
+ }
44
+ $: tooltipStyle = color ? `background:${color};` : null
45
+ $: tipStyle = color ? `border-top-color:${color};` : null
46
+
47
+ // Computes the position of the tooltip
48
+ const updateTooltipPosition = () => {
49
+ const node = wrapper?.children?.[0]
50
+ if (!node) {
51
+ left = null
52
+ top = null
53
+ return
54
+ }
55
+ const bounds = node.getBoundingClientRect()
56
+
57
+ // Determine where to render tooltip based on position prop
58
+ if (position === TooltipPosition.Top) {
59
+ left = bounds.left + bounds.width / 2
60
+ top = bounds.top
61
+ } else if (position === TooltipPosition.Right) {
62
+ left = bounds.left + bounds.width
63
+ top = bounds.top + bounds.height / 2
64
+ } else if (position === TooltipPosition.Bottom) {
65
+ left = bounds.left + bounds.width / 2
66
+ top = bounds.top + bounds.height
67
+ } else if (position === TooltipPosition.Left) {
68
+ left = bounds.left
69
+ top = bounds.top + bounds.height / 2
70
+ }
71
+ }
72
+
73
+ // Computes the position of the tooltip then shows it.
74
+ // We set up a poll to frequently update the position of the tooltip in case
75
+ // the target moves.
76
+ const show = () => {
77
+ updateTooltipPosition()
78
+ interval = setInterval(updateTooltipPosition, 100)
79
+ visible = true
80
+ }
81
+
82
+ // Hides the tooltip
83
+ const hide = () => {
84
+ clearTimeout(timeout)
85
+ clearInterval(interval)
86
+ visible = false
87
+ }
88
+
89
+ // Ensure we clean up interval and timeout
90
+ onDestroy(hide)
91
+ </script>
92
+
93
+ <div
94
+ bind:this={wrapper}
95
+ class="abs-tooltip"
96
+ on:focus={null}
97
+ on:mouseover={() => (hovered = true)}
98
+ on:mouseleave={() => (hovered = false)}
99
+ >
100
+ <slot />
101
+ </div>
102
+
103
+ {#if visible && text && left != null && top != null}
104
+ <Portal target=".spectrum">
105
+ <span
106
+ class="spectrum-Tooltip spectrum-Tooltip--{type} spectrum-Tooltip--{position} is-open"
107
+ style={`left:${left}px;top:${top}px;${tooltipStyle}`}
108
+ transition:fade|local={{ duration: 130 }}
109
+ >
110
+ <span class="spectrum-Tooltip-label">{text}</span>
111
+ <span class="spectrum-Tooltip-tip" style={tipStyle} />
112
+ </span>
113
+ </Portal>
114
+ {/if}
115
+
116
+ <style>
117
+ .abs-tooltip {
118
+ display: contents;
119
+ }
120
+ .spectrum-Tooltip {
121
+ position: absolute;
122
+ z-index: 9999;
123
+ pointer-events: none;
124
+ margin: 0;
125
+ max-width: 280px;
126
+ transition: top 130ms ease-out, left 130ms ease-out;
127
+ }
128
+ .spectrum-Tooltip-label {
129
+ text-overflow: ellipsis;
130
+ white-space: nowrap;
131
+ overflow: hidden;
132
+ font-size: 12px;
133
+ font-weight: 600;
134
+ }
135
+
136
+ /* Colour overrides for default type */
137
+ .spectrum-Tooltip--default {
138
+ background: var(--spectrum-global-color-gray-500);
139
+ }
140
+ .spectrum-Tooltip--default .spectrum-Tooltip-tip {
141
+ border-top-color: var(--spectrum-global-color-gray-500);
142
+ }
143
+
144
+ /* Position styles */
145
+ .spectrum-Tooltip--top {
146
+ transform: translateX(-50%) translateY(calc(-100% - 8px));
147
+ }
148
+ .spectrum-Tooltip--right {
149
+ transform: translateX(8px) translateY(-50%);
150
+ }
151
+ .spectrum-Tooltip--bottom {
152
+ transform: translateX(-50%) translateY(8px);
153
+ }
154
+ .spectrum-Tooltip--left {
155
+ transform: translateX(calc(-100% - 8px)) translateY(-50%);
156
+ }
157
+ </style>
@@ -0,0 +1,39 @@
1
+ <script>
2
+ import AbsTooltip from "./AbsTooltip.svelte"
3
+ import { onDestroy } from "svelte"
4
+
5
+ export let text = null
6
+ export let condition = true
7
+ export let duration = 3000
8
+ export let position
9
+ export let type
10
+
11
+ let visible = false
12
+ let timeout
13
+
14
+ $: {
15
+ if (condition) {
16
+ showTooltip()
17
+ } else {
18
+ hideTooltip()
19
+ }
20
+ }
21
+
22
+ const showTooltip = () => {
23
+ visible = true
24
+ timeout = setTimeout(() => {
25
+ visible = false
26
+ }, duration)
27
+ }
28
+
29
+ const hideTooltip = () => {
30
+ visible = false
31
+ clearTimeout(timeout)
32
+ }
33
+
34
+ onDestroy(hideTooltip)
35
+ </script>
36
+
37
+ <AbsTooltip {position} {type} text={visible ? text : null} fixed={visible}>
38
+ <slot />
39
+ </AbsTooltip>
package/src/index.js CHANGED
@@ -36,13 +36,19 @@ export { default as Layout } from "./Layout/Layout.svelte"
36
36
  export { default as Page } from "./Layout/Page.svelte"
37
37
  export { default as Link } from "./Link/Link.svelte"
38
38
  export { default as Tooltip } from "./Tooltip/Tooltip.svelte"
39
+ export { default as TempTooltip } from "./Tooltip/TempTooltip.svelte"
40
+ export {
41
+ default as AbsTooltip,
42
+ TooltipPosition,
43
+ TooltipType,
44
+ } from "./Tooltip/AbsTooltip.svelte"
39
45
  export { default as TooltipWrapper } from "./Tooltip/TooltipWrapper.svelte"
40
46
  export { default as Menu } from "./Menu/Menu.svelte"
41
47
  export { default as MenuSection } from "./Menu/Section.svelte"
42
48
  export { default as MenuSeparator } from "./Menu/Separator.svelte"
43
49
  export { default as MenuItem } from "./Menu/Item.svelte"
44
50
  export { default as Modal } from "./Modal/Modal.svelte"
45
- export { default as ModalContent } from "./Modal/ModalContent.svelte"
51
+ export { default as ModalContent, keepOpen } from "./Modal/ModalContent.svelte"
46
52
  export { default as NotificationDisplay } from "./Notification/NotificationDisplay.svelte"
47
53
  export { default as Notification } from "./Notification/Notification.svelte"
48
54
  export { default as SideNavigation } from "./SideNavigation/Navigation.svelte"