@budibase/bbui 3.5.2 → 3.6.0
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/dist/bbui.mjs +14368 -16206
- package/package.json +2 -2
- package/src/ActionMenu/ActionMenu.svelte +14 -13
- package/src/Avatar/Avatar.svelte +1 -1
- package/src/ColorPicker/ColorPicker.svelte +66 -34
- package/src/Form/Core/File.svelte +27 -21
- package/src/Form/Core/Multiselect.svelte +1 -1
- package/src/Form/Core/TextArea.svelte +49 -17
- package/src/Form/DatePicker.svelte +1 -1
- package/src/Form/File.svelte +14 -15
- package/src/Form/Multiselect.svelte +15 -14
- package/src/Form/Select.svelte +6 -9
- package/src/Form/TextArea.svelte +15 -6
- package/src/Form/Toggle.svelte +2 -2
- package/src/Icon/Icon.svelte +1 -1
- package/src/Icon/IconAvatar.svelte +7 -8
- package/src/IconPicker/IconPicker.svelte +16 -11
- package/src/InlineAlert/InlineAlert.svelte +10 -10
- package/src/Input/CopyInput.svelte +13 -11
- package/src/Label/Label.svelte +4 -4
- package/src/Layout/Layout.svelte +14 -9
- package/src/Layout/Page.svelte +6 -6
- package/src/List/List.svelte +2 -2
- package/src/List/ListItem.svelte +2 -2
- package/src/Markdown/MarkdownEditor.svelte +12 -12
- package/src/Markdown/MarkdownViewer.svelte +5 -4
- package/src/Markdown/SpectrumMDE.svelte +11 -11
- package/src/Menu/Item.svelte +7 -7
- package/src/Menu/Menu.svelte +1 -1
- package/src/Menu/Section.svelte +2 -2
- package/src/Modal/Content.svelte +2 -2
- package/src/Modal/CustomContent.svelte +4 -4
- package/src/Modal/Modal.svelte +36 -33
- package/src/Modal/ModalContent.svelte +33 -31
- package/src/Notification/Notification.svelte +9 -9
- package/src/Notification/NotificationDisplay.svelte +1 -1
- package/src/Pagination/Pagination.svelte +6 -8
- package/src/ProgressBar/ProgressBar.svelte +15 -14
- package/src/ProgressCircle/ProgressCircle.svelte +11 -11
- package/src/Tooltip/TooltipWrapper.svelte +1 -1
- package/src/bbui.css +10 -0
- package/src/context.d.ts +8 -0
- package/src/index.ts +0 -3
- package/src/types/actionMenu.ts +3 -0
- package/src/Form/PickerDropdown.svelte +0 -132
- package/src/IconSideNav/IconSideNav.svelte +0 -14
- package/src/IconSideNav/IconSideNavItem.svelte +0 -58
- package/src/Menu/Menu.svench +0 -19
- package/src/Modal/Modal.svench +0 -116
- package/src/Modal/QuizModal.svelte +0 -53
- package/src/Stores/Notifications.svench.svx +0 -78
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import Icon from "./Icon.svelte"
|
|
3
|
-
|
|
4
3
|
import Tooltip from "../Tooltip/Tooltip.svelte"
|
|
5
4
|
import { fade } from "svelte/transition"
|
|
6
5
|
|
|
7
|
-
export let icon
|
|
8
|
-
export let background
|
|
9
|
-
export let color
|
|
10
|
-
export let size = "M"
|
|
11
|
-
export let tooltip
|
|
6
|
+
export let icon: string | undefined = undefined
|
|
7
|
+
export let background: string | undefined = undefined
|
|
8
|
+
export let color: string | undefined = undefined
|
|
9
|
+
export let size: "XS" | "S" | "M" | "L" = "M"
|
|
10
|
+
export let tooltip: string | undefined = undefined
|
|
12
11
|
|
|
13
|
-
let showTooltip = false
|
|
12
|
+
let showTooltip: boolean = false
|
|
14
13
|
</script>
|
|
15
14
|
|
|
16
15
|
<!-- svelte-ignore a11y-no-static-element-interactions -->
|
|
@@ -1,19 +1,24 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import "@spectrum-css/popover/dist/index-vars.css"
|
|
3
3
|
import clickOutside from "../Actions/click_outside"
|
|
4
4
|
import { fly } from "svelte/transition"
|
|
5
5
|
import Icon from "../Icon/Icon.svelte"
|
|
6
6
|
import { createEventDispatcher } from "svelte"
|
|
7
7
|
|
|
8
|
-
export let value
|
|
9
|
-
export let size = "M"
|
|
10
|
-
export let alignRight = false
|
|
8
|
+
export let value: string | undefined
|
|
9
|
+
export let size: "S" | "M" | "L" = "M"
|
|
10
|
+
export let alignRight: boolean = false
|
|
11
11
|
|
|
12
|
-
let open = false
|
|
12
|
+
let open: boolean = false
|
|
13
13
|
|
|
14
14
|
const dispatch = createEventDispatcher()
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
interface IconCategory {
|
|
17
|
+
label: string
|
|
18
|
+
icons: string[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const iconList: IconCategory[] = [
|
|
17
22
|
{
|
|
18
23
|
label: "Icons",
|
|
19
24
|
icons: [
|
|
@@ -45,12 +50,12 @@
|
|
|
45
50
|
},
|
|
46
51
|
]
|
|
47
52
|
|
|
48
|
-
const onChange = value => {
|
|
53
|
+
const onChange = (value: string) => {
|
|
49
54
|
dispatch("change", value)
|
|
50
55
|
open = false
|
|
51
56
|
}
|
|
52
57
|
|
|
53
|
-
const handleOutsideClick = event => {
|
|
58
|
+
const handleOutsideClick = (event: MouseEvent) => {
|
|
54
59
|
if (open) {
|
|
55
60
|
event.stopPropagation()
|
|
56
61
|
open = false
|
|
@@ -77,11 +82,11 @@
|
|
|
77
82
|
class="spectrum-Popover spectrum-Popover--bottom spectrum-Picker-popover is-open"
|
|
78
83
|
class:spectrum-Popover--align-right={alignRight}
|
|
79
84
|
>
|
|
80
|
-
{#each iconList as
|
|
85
|
+
{#each iconList as iconList}
|
|
81
86
|
<div class="category">
|
|
82
|
-
<div class="heading">{
|
|
87
|
+
<div class="heading">{iconList.label}</div>
|
|
83
88
|
<div class="icons">
|
|
84
|
-
{#each
|
|
89
|
+
{#each iconList.icons as icon}
|
|
85
90
|
<div
|
|
86
91
|
on:click={() => {
|
|
87
92
|
onChange(icon)
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import "@spectrum-css/inlinealert/dist/index-vars.css"
|
|
3
3
|
import Button from "../Button/Button.svelte"
|
|
4
4
|
import Icon from "../Icon/Icon.svelte"
|
|
5
5
|
|
|
6
|
-
export let type = "info"
|
|
7
|
-
export let header = ""
|
|
8
|
-
export let message = ""
|
|
9
|
-
export let onConfirm = undefined
|
|
10
|
-
export let buttonText = ""
|
|
11
|
-
export let cta = false
|
|
12
|
-
export let link = ""
|
|
13
|
-
export let linkText = ""
|
|
6
|
+
export let type: "info" | "error" | "success" | "help" | "negative" = "info"
|
|
7
|
+
export let header: string = ""
|
|
8
|
+
export let message: string = ""
|
|
9
|
+
export let onConfirm: (() => void) | undefined = undefined
|
|
10
|
+
export let buttonText: string = ""
|
|
11
|
+
export let cta: boolean = false
|
|
12
|
+
export let link: string = ""
|
|
13
|
+
export let linkText: string = ""
|
|
14
14
|
|
|
15
15
|
$: icon = selectIcon(type)
|
|
16
16
|
// if newlines used, convert them to different elements
|
|
17
17
|
$: split = message.split("\n")
|
|
18
18
|
|
|
19
|
-
function selectIcon(alertType) {
|
|
19
|
+
function selectIcon(alertType: string): string {
|
|
20
20
|
switch (alertType) {
|
|
21
21
|
case "error":
|
|
22
22
|
case "negative":
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import Input from "../Form/Input.svelte"
|
|
3
3
|
import Icon from "../Icon/Icon.svelte"
|
|
4
4
|
import { notifications } from "../Stores/notifications"
|
|
5
5
|
|
|
6
|
-
export let label =
|
|
7
|
-
export let value
|
|
6
|
+
export let label: string | undefined = undefined
|
|
7
|
+
export let value: string | undefined = undefined
|
|
8
8
|
|
|
9
|
-
const copyToClipboard = val => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const copyToClipboard = (val: string | undefined) => {
|
|
10
|
+
if (val) {
|
|
11
|
+
const dummy = document.createElement("textarea")
|
|
12
|
+
document.body.appendChild(dummy)
|
|
13
|
+
dummy.value = val
|
|
14
|
+
dummy.select()
|
|
15
|
+
document.execCommand("copy")
|
|
16
|
+
document.body.removeChild(dummy)
|
|
17
|
+
notifications.success(`Copied to clipboard`)
|
|
18
|
+
}
|
|
17
19
|
}
|
|
18
20
|
</script>
|
|
19
21
|
|
package/src/Label/Label.svelte
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import "@spectrum-css/fieldlabel/dist/index-vars.css"
|
|
3
3
|
import TooltipWrapper from "../Tooltip/TooltipWrapper.svelte"
|
|
4
4
|
|
|
5
|
-
export let size = "M"
|
|
6
|
-
export let tooltip = ""
|
|
7
|
-
export let muted = undefined
|
|
5
|
+
export let size: "S" | "M" | "L" = "M"
|
|
6
|
+
export let tooltip: string = ""
|
|
7
|
+
export let muted: boolean | undefined = undefined
|
|
8
8
|
</script>
|
|
9
9
|
|
|
10
10
|
<TooltipWrapper {tooltip} {size}>
|
package/src/Layout/Layout.svelte
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export let horizontal = false
|
|
3
|
-
export let paddingX = "M"
|
|
4
|
-
export let paddingY = "M"
|
|
5
|
-
export let noPadding = false
|
|
6
|
-
export let gap = "M"
|
|
7
|
-
export let noGap = false
|
|
8
|
-
export let alignContent
|
|
9
|
-
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export let horizontal: boolean = false
|
|
3
|
+
export let paddingX: "S" | "M" | "L" | "XL" | "XXL" = "M"
|
|
4
|
+
export let paddingY: "S" | "M" | "L" | "XL" | "XXL" = "M"
|
|
5
|
+
export let noPadding: boolean = false
|
|
6
|
+
export let gap: "XXS" | "XS" | "S" | "M" | "L" | "XL" = "M"
|
|
7
|
+
export let noGap: boolean = false
|
|
8
|
+
export let alignContent:
|
|
9
|
+
| "start"
|
|
10
|
+
| "center"
|
|
11
|
+
| "space-between"
|
|
12
|
+
| "space-around"
|
|
13
|
+
| "normal" = "normal"
|
|
14
|
+
export let justifyItems: "stretch" | "start" | "center" | "end" = "stretch"
|
|
10
15
|
</script>
|
|
11
16
|
|
|
12
17
|
<div
|
package/src/Layout/Page.svelte
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import { setContext } from "svelte"
|
|
3
3
|
import clickOutside from "../Actions/click_outside"
|
|
4
4
|
|
|
5
|
-
export let wide = false
|
|
6
|
-
export let narrow = false
|
|
7
|
-
export let narrower = false
|
|
8
|
-
export let noPadding = false
|
|
5
|
+
export let wide: boolean = false
|
|
6
|
+
export let narrow: boolean = false
|
|
7
|
+
export let narrower: boolean = false
|
|
8
|
+
export let noPadding: boolean = false
|
|
9
9
|
|
|
10
|
-
let sidePanelVisible = false
|
|
10
|
+
let sidePanelVisible: boolean = false
|
|
11
11
|
|
|
12
12
|
setContext("side-panel", {
|
|
13
13
|
open: () => (sidePanelVisible = true),
|
package/src/List/List.svelte
CHANGED
package/src/List/ListItem.svelte
CHANGED
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
/* Selection is only meant for standalone list items (non stacked) so we just set a fixed border radius */
|
|
90
90
|
.list-item.selected {
|
|
91
91
|
background-color: var(--spectrum-global-color-blue-100);
|
|
92
|
-
border
|
|
92
|
+
border: none;
|
|
93
93
|
}
|
|
94
94
|
.list-item.selected:after {
|
|
95
95
|
content: "";
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
pointer-events: none;
|
|
101
101
|
top: 0;
|
|
102
102
|
left: 0;
|
|
103
|
-
border-radius:
|
|
103
|
+
border-radius: inherit;
|
|
104
104
|
box-sizing: border-box;
|
|
105
105
|
z-index: 1;
|
|
106
106
|
opacity: 0.5;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import SpectrumMDE from "./SpectrumMDE.svelte"
|
|
3
3
|
import { createEventDispatcher } from "svelte"
|
|
4
4
|
|
|
5
|
-
export let value = null
|
|
6
|
-
export let height = null
|
|
7
|
-
export let placeholder = null
|
|
8
|
-
export let id = null
|
|
9
|
-
export let fullScreenOffset =
|
|
10
|
-
export let disabled = false
|
|
11
|
-
export let readonly = false
|
|
12
|
-
export let easyMDEOptions
|
|
5
|
+
export let value: string | null = null
|
|
6
|
+
export let height: string | null = null
|
|
7
|
+
export let placeholder: string | null = null
|
|
8
|
+
export let id: string | null = null
|
|
9
|
+
export let fullScreenOffset: { x: string; y: string } | null = null
|
|
10
|
+
export let disabled: boolean = false
|
|
11
|
+
export let readonly: boolean = false
|
|
12
|
+
export let easyMDEOptions: Record<string, any> = {}
|
|
13
13
|
|
|
14
14
|
const dispatch = createEventDispatcher()
|
|
15
15
|
|
|
16
|
-
let latestValue
|
|
17
|
-
let mde
|
|
16
|
+
let latestValue: string | null
|
|
17
|
+
let mde: any
|
|
18
18
|
|
|
19
19
|
// Ensure the value is updated if the value prop changes outside the editor's
|
|
20
20
|
// control
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
mde?.togglePreview()
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
const checkValue = val => {
|
|
27
|
+
const checkValue = (val: string | null) => {
|
|
28
28
|
if (mde && val !== latestValue) {
|
|
29
29
|
mde.value(val)
|
|
30
30
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import SpectrumMDE from "./SpectrumMDE.svelte"
|
|
3
3
|
|
|
4
|
-
export let value
|
|
5
|
-
export let height
|
|
4
|
+
export let value: string | undefined = undefined
|
|
5
|
+
export let height: string | undefined = undefined
|
|
6
6
|
|
|
7
|
-
let mde
|
|
7
|
+
let mde: any
|
|
8
8
|
|
|
9
9
|
// Keep the value up to date
|
|
10
10
|
$: mde && mde.value(value || "")
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
border: none;
|
|
41
41
|
background: transparent;
|
|
42
42
|
padding: 0;
|
|
43
|
+
color: inherit;
|
|
43
44
|
}
|
|
44
45
|
.markdown-viewer :global(.EasyMDEContainer) {
|
|
45
46
|
background: transparent;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import EasyMDE from "easymde"
|
|
3
3
|
import "easymde/dist/easymde.min.css"
|
|
4
4
|
import { onMount } from "svelte"
|
|
5
5
|
|
|
6
|
-
export let height = null
|
|
7
|
-
export let scroll = true
|
|
8
|
-
export let easyMDEOptions = null
|
|
9
|
-
export let mde = null
|
|
10
|
-
export let id = null
|
|
11
|
-
export let fullScreenOffset = null
|
|
12
|
-
export let disabled = false
|
|
6
|
+
export let height: string | null = null
|
|
7
|
+
export let scroll: boolean = true
|
|
8
|
+
export let easyMDEOptions: Record<string, any> | null = null
|
|
9
|
+
export let mde: EasyMDE | null = null
|
|
10
|
+
export let id: string | null = null
|
|
11
|
+
export let fullScreenOffset: { x: string; y: string } | null = null
|
|
12
|
+
export let disabled: boolean = false
|
|
13
13
|
|
|
14
|
-
let element
|
|
14
|
+
let element: HTMLTextAreaElement | undefined = undefined
|
|
15
15
|
|
|
16
16
|
onMount(() => {
|
|
17
17
|
height = height || "200px"
|
|
@@ -27,13 +27,13 @@
|
|
|
27
27
|
|
|
28
28
|
// Revert the editor when we unmount
|
|
29
29
|
return () => {
|
|
30
|
-
mde
|
|
30
|
+
mde?.toTextArea()
|
|
31
31
|
}
|
|
32
32
|
})
|
|
33
33
|
|
|
34
34
|
$: styleString = getStyleString(fullScreenOffset)
|
|
35
35
|
|
|
36
|
-
const getStyleString = offset => {
|
|
36
|
+
const getStyleString = (offset: { x?: string; y?: string } | null) => {
|
|
37
37
|
let string = ""
|
|
38
38
|
string += `--fullscreen-offset-x:${offset?.x || "0px"};`
|
|
39
39
|
string += `--fullscreen-offset-y:${offset?.y || "0px"};`
|
package/src/Menu/Item.svelte
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import { createEventDispatcher, getContext } from "svelte"
|
|
3
3
|
import Icon from "../Icon/Icon.svelte"
|
|
4
4
|
|
|
5
5
|
const dispatch = createEventDispatcher()
|
|
6
|
-
const actionMenu = getContext("actionMenu")
|
|
6
|
+
const actionMenu = getContext("actionMenu") as { hideAll: () => void }
|
|
7
7
|
|
|
8
|
-
export let icon = undefined
|
|
9
|
-
export let disabled = undefined
|
|
10
|
-
export let noClose = false
|
|
11
|
-
export let keyBind = undefined
|
|
8
|
+
export let icon: string | undefined = undefined
|
|
9
|
+
export let disabled: boolean | undefined = undefined
|
|
10
|
+
export let noClose: boolean = false
|
|
11
|
+
export let keyBind: string | undefined = undefined
|
|
12
12
|
|
|
13
13
|
$: keys = getKeys(keyBind)
|
|
14
14
|
|
|
15
|
-
const getKeys = keyBind => {
|
|
15
|
+
const getKeys = (keyBind: string | undefined): string[] => {
|
|
16
16
|
let keys = keyBind?.split("+") || []
|
|
17
17
|
for (let i = 0; i < keys.length; i++) {
|
|
18
18
|
if (
|
package/src/Menu/Menu.svelte
CHANGED
package/src/Menu/Section.svelte
CHANGED
package/src/Modal/Content.svelte
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import { getContext } from "svelte"
|
|
3
3
|
import Context from "../context"
|
|
4
4
|
|
|
5
|
-
const { hide } = getContext(Context.Modal)
|
|
5
|
+
const { hide } = getContext(Context.Modal) as { hide: () => void }
|
|
6
6
|
|
|
7
|
-
let count = 0
|
|
8
|
-
const clicks = 5
|
|
7
|
+
let count: number = 0
|
|
8
|
+
const clicks: number = 5
|
|
9
9
|
$: if (count === clicks) hide()
|
|
10
10
|
$: remaining = clicks - count
|
|
11
11
|
|
package/src/Modal/Modal.svelte
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<script>
|
|
1
|
+
<script lang="ts">
|
|
2
2
|
import "@spectrum-css/modal/dist/index-vars.css"
|
|
3
3
|
import "@spectrum-css/underlay/dist/index-vars.css"
|
|
4
4
|
import { createEventDispatcher, setContext, tick, onMount } from "svelte"
|
|
@@ -6,33 +6,37 @@
|
|
|
6
6
|
import Portal from "svelte-portal"
|
|
7
7
|
import Context from "../context"
|
|
8
8
|
|
|
9
|
-
export let fixed = false
|
|
10
|
-
export let inline = false
|
|
11
|
-
export let disableCancel = false
|
|
12
|
-
export let autoFocus = true
|
|
13
|
-
export let zIndex = 1001
|
|
9
|
+
export let fixed: boolean = false
|
|
10
|
+
export let inline: boolean = false
|
|
11
|
+
export let disableCancel: boolean = false
|
|
12
|
+
export let autoFocus: boolean = true
|
|
13
|
+
export let zIndex: number = 1001
|
|
14
14
|
|
|
15
|
-
const dispatch = createEventDispatcher
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const dispatch = createEventDispatcher<{
|
|
16
|
+
show: void
|
|
17
|
+
hide: void
|
|
18
|
+
cancel: void
|
|
19
|
+
}>()
|
|
20
|
+
let visible: boolean = fixed || inline
|
|
21
|
+
let modal: HTMLElement | undefined
|
|
18
22
|
|
|
19
23
|
$: dispatch(visible ? "show" : "hide")
|
|
20
24
|
|
|
21
|
-
export function show() {
|
|
25
|
+
export function show(): void {
|
|
22
26
|
if (visible) {
|
|
23
27
|
return
|
|
24
28
|
}
|
|
25
29
|
visible = true
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
export function hide() {
|
|
32
|
+
export function hide(): void {
|
|
29
33
|
if (!visible || fixed || inline) {
|
|
30
34
|
return
|
|
31
35
|
}
|
|
32
36
|
visible = false
|
|
33
37
|
}
|
|
34
38
|
|
|
35
|
-
export function toggle() {
|
|
39
|
+
export function toggle(): void {
|
|
36
40
|
if (visible) {
|
|
37
41
|
hide()
|
|
38
42
|
} else {
|
|
@@ -40,7 +44,7 @@
|
|
|
40
44
|
}
|
|
41
45
|
}
|
|
42
46
|
|
|
43
|
-
export function cancel() {
|
|
47
|
+
export function cancel(): void {
|
|
44
48
|
if (!visible || disableCancel) {
|
|
45
49
|
return
|
|
46
50
|
}
|
|
@@ -48,34 +52,33 @@
|
|
|
48
52
|
hide()
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
function handleKey(e) {
|
|
55
|
+
function handleKey(e: KeyboardEvent): void {
|
|
52
56
|
if (visible && e.key === "Escape") {
|
|
53
57
|
cancel()
|
|
54
58
|
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
|
|
58
|
-
if (!autoFocus)
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
// Otherwise try to focus confirmation button
|
|
70
|
-
else if (modal) {
|
|
71
|
-
const confirm = modal.querySelector(".confirm-wrap .spectrum-Button")
|
|
72
|
-
if (confirm) {
|
|
73
|
-
confirm.focus()
|
|
61
|
+
function focusModal(node: HTMLElement): void {
|
|
62
|
+
if (!autoFocus) return
|
|
63
|
+
tick().then(() => {
|
|
64
|
+
const inputs = node.querySelectorAll("input")
|
|
65
|
+
if (inputs?.length) {
|
|
66
|
+
inputs[0].focus()
|
|
67
|
+
} else if (modal) {
|
|
68
|
+
const confirm = modal.querySelector(".confirm-wrap .spectrum-Button")
|
|
69
|
+
if (confirm) {
|
|
70
|
+
;(confirm as HTMLElement).focus()
|
|
71
|
+
}
|
|
74
72
|
}
|
|
75
|
-
}
|
|
73
|
+
})
|
|
76
74
|
}
|
|
77
75
|
|
|
78
|
-
setContext(Context.Modal, {
|
|
76
|
+
setContext(Context.Modal, {
|
|
77
|
+
show,
|
|
78
|
+
hide,
|
|
79
|
+
toggle,
|
|
80
|
+
cancel,
|
|
81
|
+
} as { show: () => void; hide: () => void; toggle: () => void; cancel: () => void })
|
|
79
82
|
|
|
80
83
|
onMount(() => {
|
|
81
84
|
document.addEventListener("keydown", handleKey)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
<script context="module">
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
2
|
export const keepOpen = Symbol("keepOpen")
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
|
-
<script>
|
|
5
|
+
<script lang="ts">
|
|
6
6
|
import "@spectrum-css/dialog/dist/index-vars.css"
|
|
7
7
|
import { getContext } from "svelte"
|
|
8
8
|
import Button from "../Button/Button.svelte"
|
|
@@ -11,31 +11,36 @@
|
|
|
11
11
|
import Context from "../context"
|
|
12
12
|
import ProgressCircle from "../ProgressCircle/ProgressCircle.svelte"
|
|
13
13
|
|
|
14
|
-
export let title = undefined
|
|
15
|
-
export let size = "S"
|
|
16
|
-
export let cancelText = "Cancel"
|
|
17
|
-
export let confirmText = "Confirm"
|
|
18
|
-
export let showCancelButton = true
|
|
19
|
-
export let showConfirmButton = true
|
|
20
|
-
export let showCloseIcon = true
|
|
21
|
-
export let onConfirm = undefined
|
|
22
|
-
export let onCancel = undefined
|
|
23
|
-
export let disabled = false
|
|
24
|
-
export let showDivider = true
|
|
25
|
-
|
|
26
|
-
export let showSecondaryButton = false
|
|
27
|
-
export let secondaryButtonText = undefined
|
|
28
|
-
export let secondaryAction
|
|
29
|
-
|
|
30
|
-
export let
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
14
|
+
export let title: string | undefined = undefined
|
|
15
|
+
export let size: "S" | "M" | "L" | "XL" = "S"
|
|
16
|
+
export let cancelText: string = "Cancel"
|
|
17
|
+
export let confirmText: string = "Confirm"
|
|
18
|
+
export let showCancelButton: boolean = true
|
|
19
|
+
export let showConfirmButton: boolean = true
|
|
20
|
+
export let showCloseIcon: boolean = true
|
|
21
|
+
export let onConfirm: (() => Promise<any> | any) | undefined = undefined
|
|
22
|
+
export let onCancel: (() => Promise<any> | any) | undefined = undefined
|
|
23
|
+
export let disabled: boolean = false
|
|
24
|
+
export let showDivider: boolean = true
|
|
25
|
+
|
|
26
|
+
export let showSecondaryButton: boolean = false
|
|
27
|
+
export let secondaryButtonText: string | undefined = undefined
|
|
28
|
+
export let secondaryAction: ((_e: Event) => Promise<any> | any) | undefined =
|
|
29
|
+
undefined
|
|
30
|
+
export let secondaryButtonWarning: boolean = false
|
|
31
|
+
export let custom: boolean = false
|
|
32
|
+
|
|
33
|
+
const { hide, cancel } = getContext(Context.Modal) as {
|
|
34
|
+
hide: () => void
|
|
35
|
+
cancel: () => void
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let loading: boolean = false
|
|
39
|
+
|
|
40
|
+
let confirmDisabled: boolean
|
|
36
41
|
$: confirmDisabled = disabled || loading
|
|
37
42
|
|
|
38
|
-
async function secondary(e) {
|
|
43
|
+
async function secondary(e: Event): Promise<void> {
|
|
39
44
|
loading = true
|
|
40
45
|
if (!secondaryAction || (await secondaryAction(e)) !== keepOpen) {
|
|
41
46
|
hide()
|
|
@@ -43,7 +48,7 @@
|
|
|
43
48
|
loading = false
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
export async function confirm() {
|
|
51
|
+
export async function confirm(): Promise<void> {
|
|
47
52
|
loading = true
|
|
48
53
|
if (!onConfirm || (await onConfirm()) !== keepOpen) {
|
|
49
54
|
hide()
|
|
@@ -51,7 +56,7 @@
|
|
|
51
56
|
loading = false
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
async function close() {
|
|
59
|
+
async function close(): Promise<void> {
|
|
55
60
|
loading = true
|
|
56
61
|
if (!onCancel || (await onCancel()) !== keepOpen) {
|
|
57
62
|
cancel()
|
|
@@ -90,7 +95,6 @@
|
|
|
90
95
|
{/if}
|
|
91
96
|
{/if}
|
|
92
97
|
|
|
93
|
-
<!-- TODO: Remove content-grid class once Layout components are in bbui -->
|
|
94
98
|
<section class="spectrum-Dialog-content content-grid">
|
|
95
99
|
<slot {loading} />
|
|
96
100
|
</section>
|
|
@@ -102,7 +106,6 @@
|
|
|
102
106
|
{#if showSecondaryButton && secondaryButtonText && secondaryAction}
|
|
103
107
|
<div class="secondary-action">
|
|
104
108
|
<Button
|
|
105
|
-
group
|
|
106
109
|
secondary
|
|
107
110
|
warning={secondaryButtonWarning}
|
|
108
111
|
on:click={secondary}>{secondaryButtonText}</Button
|
|
@@ -111,14 +114,13 @@
|
|
|
111
114
|
{/if}
|
|
112
115
|
|
|
113
116
|
{#if showCancelButton}
|
|
114
|
-
<Button
|
|
117
|
+
<Button secondary on:click={close}>
|
|
115
118
|
{cancelText}
|
|
116
119
|
</Button>
|
|
117
120
|
{/if}
|
|
118
121
|
{#if showConfirmButton}
|
|
119
122
|
<span class="confirm-wrap">
|
|
120
123
|
<Button
|
|
121
|
-
group
|
|
122
124
|
cta
|
|
123
125
|
{...$$restProps}
|
|
124
126
|
disabled={confirmDisabled}
|