@budibase/bbui 2.4.27-alpha.7 → 2.4.27-alpha.9
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.es.js +3 -3
- package/dist/bbui.es.js.map +1 -1
- package/package.json +4 -4
- package/src/Form/Core/File.svelte +115 -0
- package/src/Form/Core/index.js +1 -0
- package/src/Form/File.svelte +37 -0
- package/src/index.js +1 -0
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.4.27-alpha.
|
|
4
|
+
"version": "2.4.27-alpha.9",
|
|
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.4.27-alpha.
|
|
42
|
-
"@budibase/string-templates": "2.4.27-alpha.
|
|
41
|
+
"@budibase/shared-core": "2.4.27-alpha.9",
|
|
42
|
+
"@budibase/string-templates": "2.4.27-alpha.9",
|
|
43
43
|
"@spectrum-css/accordion": "3.0.24",
|
|
44
44
|
"@spectrum-css/actionbutton": "1.0.1",
|
|
45
45
|
"@spectrum-css/actiongroup": "1.0.1",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"resolutions": {
|
|
91
91
|
"loader-utils": "1.4.1"
|
|
92
92
|
},
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "b48f6ecdc939ed804ef5645c7e0869ccfbf2ec74"
|
|
94
94
|
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import ActionButton from "../../ActionButton/ActionButton.svelte"
|
|
3
|
+
import { uuid } from "../../helpers"
|
|
4
|
+
import Icon from "../../Icon/Icon.svelte"
|
|
5
|
+
import { createEventDispatcher } from "svelte"
|
|
6
|
+
|
|
7
|
+
export let value = null
|
|
8
|
+
export let title = "Upload file"
|
|
9
|
+
export let disabled = false
|
|
10
|
+
export let allowClear = null
|
|
11
|
+
export let extensions = null
|
|
12
|
+
export let handleFileTooLarge = null
|
|
13
|
+
export let fileSizeLimit = BYTES_IN_MB * 20
|
|
14
|
+
export let id = null
|
|
15
|
+
export let previewUrl = null
|
|
16
|
+
|
|
17
|
+
const fieldId = id || uuid()
|
|
18
|
+
const BYTES_IN_KB = 1000
|
|
19
|
+
const BYTES_IN_MB = 1000000
|
|
20
|
+
|
|
21
|
+
const dispatch = createEventDispatcher()
|
|
22
|
+
|
|
23
|
+
let fileInput
|
|
24
|
+
|
|
25
|
+
$: inputAccept = Array.isArray(extensions) ? extensions.join(",") : "*"
|
|
26
|
+
|
|
27
|
+
async function processFile(targetFile) {
|
|
28
|
+
if (handleFileTooLarge && targetFile?.size >= fileSizeLimit) {
|
|
29
|
+
handleFileTooLarge(targetFile)
|
|
30
|
+
return
|
|
31
|
+
}
|
|
32
|
+
dispatch("change", targetFile)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function handleFile(evt) {
|
|
36
|
+
processFile(evt.target.files[0])
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function clearFile() {
|
|
40
|
+
dispatch("change", null)
|
|
41
|
+
}
|
|
42
|
+
</script>
|
|
43
|
+
|
|
44
|
+
<input
|
|
45
|
+
id={fieldId}
|
|
46
|
+
{disabled}
|
|
47
|
+
type="file"
|
|
48
|
+
accept={inputAccept}
|
|
49
|
+
bind:this={fileInput}
|
|
50
|
+
on:change={handleFile}
|
|
51
|
+
/>
|
|
52
|
+
|
|
53
|
+
<div class="field">
|
|
54
|
+
{#if value}
|
|
55
|
+
<div class="file-view">
|
|
56
|
+
{#if previewUrl}
|
|
57
|
+
<img class="preview" alt="" src={previewUrl} />
|
|
58
|
+
{/if}
|
|
59
|
+
<div class="filename">{value.name}</div>
|
|
60
|
+
{#if value.size}
|
|
61
|
+
<div class="filesize">
|
|
62
|
+
{#if value.size <= BYTES_IN_MB}
|
|
63
|
+
{`${value.size / BYTES_IN_KB} KB`}
|
|
64
|
+
{:else}
|
|
65
|
+
{`${value.size / BYTES_IN_MB} MB`}
|
|
66
|
+
{/if}
|
|
67
|
+
</div>
|
|
68
|
+
{/if}
|
|
69
|
+
{#if !disabled || (allowClear === true && disabled)}
|
|
70
|
+
<div class="delete-button" on:click={clearFile}>
|
|
71
|
+
<Icon name="Close" size="XS" />
|
|
72
|
+
</div>
|
|
73
|
+
{/if}
|
|
74
|
+
</div>
|
|
75
|
+
{/if}
|
|
76
|
+
<ActionButton {disabled} on:click={fileInput.click()}>{title}</ActionButton>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<style>
|
|
80
|
+
.field {
|
|
81
|
+
display: flex;
|
|
82
|
+
gap: var(--spacing-m);
|
|
83
|
+
}
|
|
84
|
+
.file-view {
|
|
85
|
+
display: flex;
|
|
86
|
+
gap: var(--spacing-l);
|
|
87
|
+
align-items: center;
|
|
88
|
+
border: 1px solid var(--spectrum-alias-border-color);
|
|
89
|
+
border-radius: var(--spectrum-global-dimension-size-50);
|
|
90
|
+
padding: 0px var(--spectrum-alias-item-padding-m);
|
|
91
|
+
}
|
|
92
|
+
input[type="file"] {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
.delete-button {
|
|
96
|
+
transition: all 0.3s;
|
|
97
|
+
margin-left: 10px;
|
|
98
|
+
display: flex;
|
|
99
|
+
}
|
|
100
|
+
.delete-button:hover {
|
|
101
|
+
cursor: pointer;
|
|
102
|
+
color: var(--red);
|
|
103
|
+
}
|
|
104
|
+
.filesize {
|
|
105
|
+
white-space: nowrap;
|
|
106
|
+
}
|
|
107
|
+
.filename {
|
|
108
|
+
overflow: hidden;
|
|
109
|
+
white-space: nowrap;
|
|
110
|
+
text-overflow: ellipsis;
|
|
111
|
+
}
|
|
112
|
+
.preview {
|
|
113
|
+
height: 1.5em;
|
|
114
|
+
}
|
|
115
|
+
</style>
|
package/src/Form/Core/index.js
CHANGED
|
@@ -13,3 +13,4 @@ export { default as CoreDropzone } from "./Dropzone.svelte"
|
|
|
13
13
|
export { default as CoreStepper } from "./Stepper.svelte"
|
|
14
14
|
export { default as CoreRichTextField } from "./RichTextField.svelte"
|
|
15
15
|
export { default as CoreSlider } from "./Slider.svelte"
|
|
16
|
+
export { default as CoreFile } from "./File.svelte"
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Field from "./Field.svelte"
|
|
3
|
+
import { CoreFile } from "./Core"
|
|
4
|
+
import { createEventDispatcher } from "svelte"
|
|
5
|
+
|
|
6
|
+
export let label = null
|
|
7
|
+
export let labelPosition = "above"
|
|
8
|
+
export let disabled = false
|
|
9
|
+
export let allowClear = null
|
|
10
|
+
export let handleFileTooLarge = () => {}
|
|
11
|
+
export let previewUrl = null
|
|
12
|
+
export let extensions = null
|
|
13
|
+
export let error = null
|
|
14
|
+
export let title = null
|
|
15
|
+
export let value = null
|
|
16
|
+
export let tooltip = null
|
|
17
|
+
|
|
18
|
+
const dispatch = createEventDispatcher()
|
|
19
|
+
const onChange = e => {
|
|
20
|
+
value = e.detail
|
|
21
|
+
dispatch("change", e.detail)
|
|
22
|
+
}
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<Field {label} {labelPosition} {error} {tooltip}>
|
|
26
|
+
<CoreFile
|
|
27
|
+
{error}
|
|
28
|
+
{disabled}
|
|
29
|
+
{allowClear}
|
|
30
|
+
{title}
|
|
31
|
+
{value}
|
|
32
|
+
{previewUrl}
|
|
33
|
+
{handleFileTooLarge}
|
|
34
|
+
{extensions}
|
|
35
|
+
on:change={onChange}
|
|
36
|
+
/>
|
|
37
|
+
</Field>
|
package/src/index.js
CHANGED
|
@@ -77,6 +77,7 @@ export { default as IconSideNav } from "./IconSideNav/IconSideNav.svelte"
|
|
|
77
77
|
export { default as IconSideNavItem } from "./IconSideNav/IconSideNavItem.svelte"
|
|
78
78
|
export { default as Slider } from "./Form/Slider.svelte"
|
|
79
79
|
export { default as Accordion } from "./Accordion/Accordion.svelte"
|
|
80
|
+
export { default as File } from "./Form/File.svelte"
|
|
80
81
|
|
|
81
82
|
// Renderers
|
|
82
83
|
export { default as BoldRenderer } from "./Table/BoldRenderer.svelte"
|