@budibase/bbui 1.0.49 → 1.0.50-alpha.3

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.
@@ -1,7 +1,12 @@
1
1
  <script>
2
+ import { createEventDispatcher } from "svelte"
3
+
2
4
  export let type = "info"
3
5
  export let icon = "Info"
4
6
  export let message = ""
7
+ export let dismissable = false
8
+
9
+ const dispatch = createEventDispatcher()
5
10
  </script>
6
11
 
7
12
  <div class="spectrum-Toast spectrum-Toast--{type}">
@@ -17,4 +22,28 @@
17
22
  <div class="spectrum-Toast-body">
18
23
  <div class="spectrum-Toast-content">{message || ""}</div>
19
24
  </div>
25
+ {#if dismissable}
26
+ <div class="spectrum-Toast-buttons">
27
+ <button
28
+ class="spectrum-ClearButton spectrum-ClearButton--overBackground spectrum-ClearButton--sizeM"
29
+ on:click={() => dispatch("dismiss")}
30
+ >
31
+ <div class="spectrum-ClearButton-fill">
32
+ <svg
33
+ class="spectrum-ClearButton-icon spectrum-Icon spectrum-UIIcon-Cross100"
34
+ focusable="false"
35
+ aria-hidden="true"
36
+ >
37
+ <use xlink:href="#spectrum-css-icon-Cross100" />
38
+ </svg>
39
+ </div>
40
+ </button>
41
+ </div>
42
+ {/if}
20
43
  </div>
44
+
45
+ <style>
46
+ .spectrum-Toast {
47
+ pointer-events: all;
48
+ }
49
+ </style>
@@ -1,7 +1,6 @@
1
1
  <script>
2
2
  import "@spectrum-css/toast/dist/index-vars.css"
3
3
  import Portal from "svelte-portal"
4
- import { flip } from "svelte/animate"
5
4
  import { notifications } from "../Stores/notifications"
6
5
  import Notification from "./Notification.svelte"
7
6
  import { fly } from "svelte/transition"
@@ -9,9 +8,15 @@
9
8
 
10
9
  <Portal target=".modal-container">
11
10
  <div class="notifications">
12
- {#each $notifications as { type, icon, message, id } (id)}
13
- <div animate:flip transition:fly={{ y: -30 }}>
14
- <Notification {type} {icon} {message} />
11
+ {#each $notifications as { type, icon, message, id, dismissable } (id)}
12
+ <div transition:fly={{ y: -30 }}>
13
+ <Notification
14
+ {type}
15
+ {icon}
16
+ {message}
17
+ {dismissable}
18
+ on:dismiss={() => notifications.dismiss(id)}
19
+ />
15
20
  </div>
16
21
  {/each}
17
22
  </div>
@@ -20,20 +20,29 @@ export const createNotificationStore = () => {
20
20
  setTimeout(() => (block = false), timeout)
21
21
  }
22
22
 
23
- const send = (message, type = "default", icon = "") => {
23
+ const send = (message, type = "default", icon = "", autoDismiss = true) => {
24
24
  if (block) {
25
25
  return
26
26
  }
27
27
  let _id = id()
28
28
  _notifications.update(state => {
29
- return [...state, { id: _id, type, message, icon }]
29
+ return [
30
+ ...state,
31
+ { id: _id, type, message, icon, dismissable: !autoDismiss },
32
+ ]
33
+ })
34
+ if (autoDismiss) {
35
+ const timeoutId = setTimeout(() => {
36
+ dismissNotification(_id)
37
+ }, NOTIFICATION_TIMEOUT)
38
+ timeoutIds.add(timeoutId)
39
+ }
40
+ }
41
+
42
+ const dismissNotification = id => {
43
+ _notifications.update(state => {
44
+ return state.filter(n => n.id !== id)
30
45
  })
31
- const timeoutId = setTimeout(() => {
32
- _notifications.update(state => {
33
- return state.filter(({ id }) => id !== _id)
34
- })
35
- }, NOTIFICATION_TIMEOUT)
36
- timeoutIds.add(timeoutId)
37
46
  }
38
47
 
39
48
  const { subscribe } = _notifications
@@ -42,10 +51,11 @@ export const createNotificationStore = () => {
42
51
  subscribe,
43
52
  send,
44
53
  info: msg => send(msg, "info", "Info"),
45
- error: msg => send(msg, "error", "Alert"),
54
+ error: msg => send(msg, "error", "Alert", false),
46
55
  warning: msg => send(msg, "warning", "Alert"),
47
56
  success: msg => send(msg, "success", "CheckmarkCircle"),
48
57
  blockNotifications,
58
+ dismiss: dismissNotification,
49
59
  }
50
60
  }
51
61
 
@@ -8,10 +8,35 @@
8
8
  copyToClipboard(value)
9
9
  }
10
10
 
11
- function copyToClipboard(value) {
12
- navigator.clipboard.writeText(value).then(() => {
13
- notifications.success("Copied")
11
+ const copyToClipboard = value => {
12
+ return new Promise(res => {
13
+ if (navigator.clipboard && window.isSecureContext) {
14
+ // Try using the clipboard API first
15
+ navigator.clipboard.writeText(value).then(res)
16
+ } else {
17
+ // Fall back to the textarea hack
18
+ let textArea = document.createElement("textarea")
19
+ textArea.value = value
20
+ textArea.style.position = "fixed"
21
+ textArea.style.left = "-9999px"
22
+ textArea.style.top = "-9999px"
23
+ document.body.appendChild(textArea)
24
+ textArea.focus()
25
+ textArea.select()
26
+ document.execCommand("copy")
27
+ textArea.remove()
28
+ res()
29
+ }
14
30
  })
31
+ .then(() => {
32
+ notifications.success("Copied to clipboard")
33
+ })
34
+ .catch(() => {
35
+ notifications.error(
36
+ "Failed to copy to clipboard. Check the dev console for the value."
37
+ )
38
+ console.warn("Failed to copy the value", value)
39
+ })
15
40
  }
16
41
  </script>
17
42
 
@@ -0,0 +1,60 @@
1
+ <script>
2
+ import Tooltip from "./Tooltip.svelte"
3
+ import Icon from "../Icon/Icon.svelte"
4
+
5
+ export let tooltip = ""
6
+ export let size = "M"
7
+
8
+ let showTooltip = false
9
+ </script>
10
+
11
+ <div class:container={!!tooltip}>
12
+ <slot />
13
+ {#if tooltip}
14
+ <div class="icon-container">
15
+ <div
16
+ class="icon"
17
+ class:icon-small={size === "M" || size === "S"}
18
+ on:mouseover={() => (showTooltip = true)}
19
+ on:mouseleave={() => (showTooltip = false)}
20
+ >
21
+ <Icon name="InfoOutline" size="S" disabled={true} />
22
+ </div>
23
+ {#if showTooltip}
24
+ <div class="tooltip">
25
+ <Tooltip textWrapping={true} direction={"bottom"} text={tooltip} />
26
+ </div>
27
+ {/if}
28
+ </div>
29
+ {/if}
30
+ </div>
31
+
32
+ <style>
33
+ .container {
34
+ display: flex;
35
+ align-items: center;
36
+ }
37
+ .icon-container {
38
+ position: relative;
39
+ display: flex;
40
+ justify-content: center;
41
+ margin-top: 1px;
42
+ margin-left: 5px;
43
+ margin-right: 5px;
44
+ }
45
+ .tooltip {
46
+ position: absolute;
47
+ display: flex;
48
+ justify-content: center;
49
+ top: 15px;
50
+ z-index: 1;
51
+ width: 160px;
52
+ }
53
+ .icon {
54
+ transform: scale(0.75);
55
+ }
56
+ .icon-small {
57
+ margin-top: -2px;
58
+ margin-bottom: -5px;
59
+ }
60
+ </style>
package/src/index.js CHANGED
@@ -60,6 +60,9 @@ export { default as StatusLight } from "./StatusLight/StatusLight.svelte"
60
60
  export { default as ColorPicker } from "./ColorPicker/ColorPicker.svelte"
61
61
  export { default as InlineAlert } from "./InlineAlert/InlineAlert.svelte"
62
62
  export { default as Banner } from "./Banner/Banner.svelte"
63
+ export { default as MarkdownEditor } from "./Markdown/MarkdownEditor.svelte"
64
+ export { default as MarkdownViewer } from "./Markdown/MarkdownViewer.svelte"
65
+ export { default as RichTextField } from "./Form/RichTextField.svelte"
63
66
 
64
67
  // Renderers
65
68
  export { default as BoldRenderer } from "./Table/BoldRenderer.svelte"