@budibase/bbui 2.2.12-alpha.5 → 2.2.12-alpha.51
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 -3
- package/src/Accordion/Accordion.svelte +58 -0
- package/src/ActionButton/ActionButton.svelte +1 -0
- package/src/Actions/click_outside.js +28 -9
- package/src/Actions/position_dropdown.js +59 -52
- package/src/Avatar/Avatar.svelte +1 -0
- package/src/Button/Button.svelte +8 -2
- package/src/Drawer/DrawerContent.svelte +0 -1
- package/src/FancyForm/FancyButton.svelte +30 -0
- package/src/FancyForm/FancyButtonRadio.svelte +70 -0
- package/src/FancyForm/FancyCheckbox.svelte +53 -0
- package/src/FancyForm/FancyField.svelte +126 -0
- package/src/FancyForm/FancyFieldLabel.svelte +25 -0
- package/src/FancyForm/FancyForm.svelte +40 -0
- package/src/FancyForm/FancyInput.svelte +77 -0
- package/src/FancyForm/FancySelect.svelte +147 -0
- package/src/FancyForm/index.js +6 -0
- package/src/Form/Core/DatePicker.svelte +1 -1
- package/src/Form/Core/EnvDropdown.svelte +282 -0
- package/src/Form/Core/Picker.svelte +141 -124
- package/src/Form/Core/Select.svelte +3 -0
- package/src/Form/Core/TextField.svelte +0 -4
- package/src/Form/EnvDropdown.svelte +52 -0
- package/src/Icon/IconAvatar.svelte +3 -0
- package/src/InlineAlert/InlineAlert.svelte +1 -0
- package/src/Label/Label.svelte +1 -0
- package/src/Layout/Page.svelte +82 -13
- package/src/Link/Link.svelte +4 -1
- package/src/List/ListItem.svelte +6 -3
- package/src/Modal/CustomContent.svelte +0 -1
- package/src/Modal/Modal.svench +0 -1
- package/src/Modal/ModalContent.svelte +3 -2
- package/src/Modal/QuizModal.svelte +0 -1
- package/src/Popover/Popover.svelte +33 -14
- package/src/Popover/Popover.svench +0 -1
- package/src/Table/StringRenderer.svelte +9 -1
- package/src/Table/Table.svelte +30 -19
- package/src/Tabs/Tab.svelte +5 -5
- package/src/Tags/Tag.svelte +1 -1
- package/src/Tags/Tags.svelte +10 -0
- package/src/Typography/Heading.svelte +6 -0
- package/src/bbui.css +7 -3
- package/src/context.js +1 -0
- package/src/index.js +5 -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.2.12-alpha.
|
|
4
|
+
"version": "2.2.12-alpha.51",
|
|
5
5
|
"license": "MPL-2.0",
|
|
6
6
|
"svelte": "src/index.js",
|
|
7
7
|
"module": "dist/bbui.es.js",
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@adobe/spectrum-css-workflow-icons": "1.2.1",
|
|
41
|
-
"@budibase/string-templates": "2.2.12-alpha.
|
|
41
|
+
"@budibase/string-templates": "2.2.12-alpha.51",
|
|
42
|
+
"@spectrum-css/accordion": "3.0.24",
|
|
42
43
|
"@spectrum-css/actionbutton": "1.0.1",
|
|
43
44
|
"@spectrum-css/actiongroup": "1.0.1",
|
|
44
45
|
"@spectrum-css/avatar": "3.0.2",
|
|
@@ -88,5 +89,5 @@
|
|
|
88
89
|
"resolutions": {
|
|
89
90
|
"loader-utils": "1.4.1"
|
|
90
91
|
},
|
|
91
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "70bd5e3f4b13b1a5f41f1309f3944cbeca51535e"
|
|
92
93
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import "@spectrum-css/accordion"
|
|
3
|
+
|
|
4
|
+
export let itemName
|
|
5
|
+
export let initialOpen
|
|
6
|
+
export let header
|
|
7
|
+
|
|
8
|
+
let isOpen
|
|
9
|
+
|
|
10
|
+
function getOpenClass(isOpen) {
|
|
11
|
+
if (isOpen === undefined) {
|
|
12
|
+
isOpen = initialOpen
|
|
13
|
+
}
|
|
14
|
+
return isOpen ? "is-open" : ""
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<div class="spectrum-Accordion" role={itemName}>
|
|
19
|
+
<div class="spectrum-Accordion-item {getOpenClass(isOpen)}">
|
|
20
|
+
<h3 class="spectrum-Accordion-itemHeading">
|
|
21
|
+
<button
|
|
22
|
+
class="spectrum-Accordion-itemHeader"
|
|
23
|
+
type="button"
|
|
24
|
+
on:click={() => (isOpen = !isOpen)}
|
|
25
|
+
>
|
|
26
|
+
{header}
|
|
27
|
+
</button>
|
|
28
|
+
<svg
|
|
29
|
+
class="spectrum-Icon spectrum-UIIcon-ChevronRight100 spectrum-Accordion-itemIndicator"
|
|
30
|
+
focusable="false"
|
|
31
|
+
aria-hidden="true"
|
|
32
|
+
>
|
|
33
|
+
<use xlink:href="#spectrum-css-icon-Chevron100" />
|
|
34
|
+
</svg>
|
|
35
|
+
</h3>
|
|
36
|
+
<div class="spectrum-Accordion-itemContent" role={itemName}>
|
|
37
|
+
<slot />
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<style>
|
|
43
|
+
.spectrum-Accordion {
|
|
44
|
+
margin-left: -20px;
|
|
45
|
+
}
|
|
46
|
+
.spectrum-Accordion-item {
|
|
47
|
+
border: none;
|
|
48
|
+
}
|
|
49
|
+
.spectrum-Accordion-itemContent {
|
|
50
|
+
width: 97%;
|
|
51
|
+
padding-left: 30px;
|
|
52
|
+
}
|
|
53
|
+
.spectrum-Accordion-itemHeader {
|
|
54
|
+
text-transform: none;
|
|
55
|
+
font-weight: bold;
|
|
56
|
+
font-size: 0.875rem;
|
|
57
|
+
}
|
|
58
|
+
</style>
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const ignoredClasses = [".flatpickr-calendar", ".
|
|
1
|
+
const ignoredClasses = [".flatpickr-calendar", ".spectrum-Popover"]
|
|
2
2
|
let clickHandlers = []
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Handle a body click event
|
|
6
6
|
*/
|
|
7
7
|
const handleClick = event => {
|
|
8
|
-
// Ignore click if
|
|
8
|
+
// Ignore click if this is an ignored class
|
|
9
9
|
for (let className of ignoredClasses) {
|
|
10
10
|
if (event.target.closest(className)) {
|
|
11
11
|
return
|
|
@@ -14,9 +14,18 @@ const handleClick = event => {
|
|
|
14
14
|
|
|
15
15
|
// Process handlers
|
|
16
16
|
clickHandlers.forEach(handler => {
|
|
17
|
-
if (
|
|
18
|
-
|
|
17
|
+
if (handler.element.contains(event.target)) {
|
|
18
|
+
return
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Ignore clicks for modals, unless the handler is registered from a modal
|
|
22
|
+
const sourceInModal = handler.anchor.closest(".spectrum-Modal") != null
|
|
23
|
+
const clickInModal = event.target.closest(".spectrum-Modal") != null
|
|
24
|
+
if (clickInModal && !sourceInModal) {
|
|
25
|
+
return
|
|
19
26
|
}
|
|
27
|
+
|
|
28
|
+
handler.callback?.(event)
|
|
20
29
|
})
|
|
21
30
|
}
|
|
22
31
|
document.documentElement.addEventListener("click", handleClick, true)
|
|
@@ -24,10 +33,10 @@ document.documentElement.addEventListener("click", handleClick, true)
|
|
|
24
33
|
/**
|
|
25
34
|
* Adds or updates a click handler
|
|
26
35
|
*/
|
|
27
|
-
const updateHandler = (id, element, callback) => {
|
|
36
|
+
const updateHandler = (id, element, anchor, callback) => {
|
|
28
37
|
let existingHandler = clickHandlers.find(x => x.id === id)
|
|
29
38
|
if (!existingHandler) {
|
|
30
|
-
clickHandlers.push({ id, element, callback })
|
|
39
|
+
clickHandlers.push({ id, element, anchor, callback })
|
|
31
40
|
} else {
|
|
32
41
|
existingHandler.callback = callback
|
|
33
42
|
}
|
|
@@ -42,12 +51,22 @@ const removeHandler = id => {
|
|
|
42
51
|
|
|
43
52
|
/**
|
|
44
53
|
* Svelte action to apply a click outside handler for a certain element
|
|
54
|
+
* opts.anchor is an optional param specifying the real root source of the
|
|
55
|
+
* component being observed. This is required for things like popovers, where
|
|
56
|
+
* the element using the clickoutside action is the popover, but the popover is
|
|
57
|
+
* rendered at the root of the DOM somewhere, whereas the popover anchor is the
|
|
58
|
+
* element we actually want to consider when determining the source component.
|
|
45
59
|
*/
|
|
46
|
-
export default (element,
|
|
60
|
+
export default (element, opts) => {
|
|
47
61
|
const id = Math.random()
|
|
48
|
-
|
|
62
|
+
const update = newOpts => {
|
|
63
|
+
const callback = newOpts?.callback || newOpts
|
|
64
|
+
const anchor = newOpts?.anchor || element
|
|
65
|
+
updateHandler(id, element, anchor, callback)
|
|
66
|
+
}
|
|
67
|
+
update(opts)
|
|
49
68
|
return {
|
|
50
|
-
update
|
|
69
|
+
update,
|
|
51
70
|
destroy: () => removeHandler(id),
|
|
52
71
|
}
|
|
53
72
|
}
|
|
@@ -1,75 +1,82 @@
|
|
|
1
|
-
export default function positionDropdown(
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
export default function positionDropdown(
|
|
2
|
+
element,
|
|
3
|
+
{ anchor, align, maxWidth, useAnchorWidth }
|
|
4
|
+
) {
|
|
5
|
+
const update = () => {
|
|
6
|
+
if (!anchor) {
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
const anchorBounds = anchor.getBoundingClientRect()
|
|
10
|
+
const elementBounds = element.getBoundingClientRect()
|
|
11
|
+
let styles = {
|
|
12
|
+
maxHeight: null,
|
|
13
|
+
minWidth: null,
|
|
14
|
+
maxWidth,
|
|
15
|
+
left: null,
|
|
16
|
+
top: null,
|
|
17
|
+
}
|
|
15
18
|
|
|
16
|
-
let
|
|
19
|
+
let popoverLeftPad = 20
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
y = window.innerHeight - spaceAbove + 5
|
|
21
|
+
// Determine vertical styles
|
|
22
|
+
if (window.innerHeight - anchorBounds.bottom < 100) {
|
|
23
|
+
styles.top = anchorBounds.top - elementBounds.height - 5
|
|
22
24
|
} else {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
maxHeight = spaceBelow - 20
|
|
25
|
+
styles.top = anchorBounds.bottom + 5
|
|
26
|
+
styles.maxHeight = window.innerHeight - anchorBounds.bottom - 20
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
width,
|
|
32
|
-
containerWidth: containerRect.width,
|
|
29
|
+
// Determine horizontal styles
|
|
30
|
+
if (!maxWidth && useAnchorWidth) {
|
|
31
|
+
styles.maxWidth = anchorBounds.width
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
if (useAnchorWidth) {
|
|
34
|
+
styles.minWidth = anchorBounds.width
|
|
35
|
+
}
|
|
36
|
+
if (align === "right") {
|
|
37
|
+
let left =
|
|
38
|
+
anchorBounds.left + anchorBounds.width / 2 - elementBounds.width
|
|
39
|
+
// Accommodate margin on popover: 1.25rem; ~20px
|
|
40
|
+
if (left + elementBounds.width + popoverLeftPad > window.innerWidth) {
|
|
41
|
+
left -= 20
|
|
42
|
+
}
|
|
43
|
+
styles.left = left
|
|
44
|
+
} else if (align === "right-side") {
|
|
45
|
+
styles.left = anchorBounds.left + anchorBounds.width
|
|
43
46
|
} else {
|
|
44
|
-
left =
|
|
47
|
+
styles.left = anchorBounds.left
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
// Apply styles
|
|
51
|
+
Object.entries(styles).forEach(([style, value]) => {
|
|
52
|
+
if (value) {
|
|
53
|
+
element.style[style] = `${value.toFixed(0)}px`
|
|
54
|
+
} else {
|
|
55
|
+
element.style[style] = null
|
|
56
|
+
}
|
|
57
|
+
})
|
|
48
58
|
}
|
|
49
59
|
|
|
60
|
+
// Apply initial styles which don't need to change
|
|
50
61
|
element.style.position = "absolute"
|
|
51
62
|
element.style.zIndex = "9999"
|
|
52
|
-
if (maxWidth) {
|
|
53
|
-
element.style.maxWidth = `${maxWidth}px`
|
|
54
|
-
}
|
|
55
|
-
element.style.minWidth = `${dimensions.width}px`
|
|
56
|
-
element.style.maxHeight = `${maxHeight.toFixed(0)}px`
|
|
57
|
-
element.style.transformOrigin = `center ${positionSide}`
|
|
58
|
-
element.style[positionSide] = `${dimensions[positionSide]}px`
|
|
59
|
-
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
|
|
60
63
|
|
|
64
|
+
// Observe both anchor and element and resize the popover as appropriate
|
|
61
65
|
const resizeObserver = new ResizeObserver(entries => {
|
|
62
|
-
entries.forEach(
|
|
63
|
-
dimensions = getDimensions()
|
|
64
|
-
element.style[positionSide] = `${dimensions[positionSide]}px`
|
|
65
|
-
element.style.left = `${calcLeftPosition(dimensions).toFixed(0)}px`
|
|
66
|
-
})
|
|
66
|
+
entries.forEach(update)
|
|
67
67
|
})
|
|
68
|
-
|
|
68
|
+
if (anchor) {
|
|
69
|
+
resizeObserver.observe(anchor)
|
|
70
|
+
}
|
|
69
71
|
resizeObserver.observe(element)
|
|
72
|
+
resizeObserver.observe(document.body)
|
|
73
|
+
|
|
74
|
+
document.addEventListener("scroll", update, true)
|
|
75
|
+
|
|
70
76
|
return {
|
|
71
77
|
destroy() {
|
|
72
78
|
resizeObserver.disconnect()
|
|
79
|
+
document.removeEventListener("scroll", update, true)
|
|
73
80
|
},
|
|
74
81
|
}
|
|
75
82
|
}
|
package/src/Avatar/Avatar.svelte
CHANGED
package/src/Button/Button.svelte
CHANGED
|
@@ -14,12 +14,14 @@
|
|
|
14
14
|
export let active = false
|
|
15
15
|
export let tooltip = undefined
|
|
16
16
|
export let dataCy
|
|
17
|
-
export let newStyles =
|
|
17
|
+
export let newStyles = true
|
|
18
|
+
export let id
|
|
18
19
|
|
|
19
20
|
let showTooltip = false
|
|
20
21
|
</script>
|
|
21
22
|
|
|
22
23
|
<button
|
|
24
|
+
{id}
|
|
23
25
|
class:spectrum-Button--cta={cta}
|
|
24
26
|
class:spectrum-Button--primary={primary}
|
|
25
27
|
class:spectrum-Button--secondary={secondary}
|
|
@@ -28,6 +30,7 @@
|
|
|
28
30
|
class:spectrum-Button--quiet={quiet}
|
|
29
31
|
class:new-styles={newStyles}
|
|
30
32
|
class:active
|
|
33
|
+
class:disabled
|
|
31
34
|
class="spectrum-Button spectrum-Button--size{size.toUpperCase()}"
|
|
32
35
|
{disabled}
|
|
33
36
|
data-cy={dataCy}
|
|
@@ -108,7 +111,10 @@
|
|
|
108
111
|
border-color: transparent;
|
|
109
112
|
color: var(--spectrum-global-color-gray-900);
|
|
110
113
|
}
|
|
111
|
-
.spectrum-Button--secondary.new-styles:hover {
|
|
114
|
+
.spectrum-Button--secondary.new-styles:not(.disabled):hover {
|
|
112
115
|
background: var(--spectrum-global-color-gray-300);
|
|
113
116
|
}
|
|
117
|
+
.spectrum-Button--secondary.new-styles.disabled {
|
|
118
|
+
color: var(--spectrum-global-color-gray-500);
|
|
119
|
+
}
|
|
114
120
|
</style>
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from "../Icon/Icon.svelte"
|
|
3
|
+
import FancyField from "./FancyField.svelte"
|
|
4
|
+
|
|
5
|
+
export let icon
|
|
6
|
+
export let disabled
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<FancyField on:click clickable {disabled}>
|
|
10
|
+
{#if icon}
|
|
11
|
+
{#if icon.includes("/")}
|
|
12
|
+
<img src={icon} alt="button" />
|
|
13
|
+
{:else}
|
|
14
|
+
<Icon name={icon} />
|
|
15
|
+
{/if}
|
|
16
|
+
{/if}
|
|
17
|
+
<slot name="icon" />
|
|
18
|
+
<div>
|
|
19
|
+
<slot />
|
|
20
|
+
</div>
|
|
21
|
+
</FancyField>
|
|
22
|
+
|
|
23
|
+
<style>
|
|
24
|
+
img {
|
|
25
|
+
width: 22px;
|
|
26
|
+
}
|
|
27
|
+
div {
|
|
28
|
+
font-size: var(--font-size-l);
|
|
29
|
+
}
|
|
30
|
+
</style>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher } from "svelte"
|
|
3
|
+
import FancyField from "./FancyField.svelte"
|
|
4
|
+
import FancyFieldLabel from "./FancyFieldLabel.svelte"
|
|
5
|
+
import ActionButton from "../ActionButton/ActionButton.svelte"
|
|
6
|
+
|
|
7
|
+
export let label
|
|
8
|
+
export let value
|
|
9
|
+
export let disabled = false
|
|
10
|
+
export let error = null
|
|
11
|
+
export let validate = null
|
|
12
|
+
export let options = []
|
|
13
|
+
export let getOptionLabel = option => extractProperty(option, "label")
|
|
14
|
+
export let getOptionValue = option => extractProperty(option, "value")
|
|
15
|
+
|
|
16
|
+
const dispatch = createEventDispatcher()
|
|
17
|
+
|
|
18
|
+
$: placeholder = !value
|
|
19
|
+
|
|
20
|
+
const extractProperty = (value, property) => {
|
|
21
|
+
if (value && typeof value === "object") {
|
|
22
|
+
return value[property]
|
|
23
|
+
}
|
|
24
|
+
return value
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const onChange = newValue => {
|
|
28
|
+
dispatch("change", newValue)
|
|
29
|
+
value = newValue
|
|
30
|
+
if (validate) {
|
|
31
|
+
error = validate(newValue)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<FancyField {error} {value} {validate} {disabled} autoHeight>
|
|
37
|
+
{#if label}
|
|
38
|
+
<FancyFieldLabel placeholder={false}>{label}</FancyFieldLabel>
|
|
39
|
+
{/if}
|
|
40
|
+
|
|
41
|
+
<div class="options">
|
|
42
|
+
{#each options as option}
|
|
43
|
+
<ActionButton
|
|
44
|
+
selected={getOptionValue(option) === value}
|
|
45
|
+
on:click={() => onChange(getOptionValue(option))}
|
|
46
|
+
>
|
|
47
|
+
{getOptionLabel(option)}
|
|
48
|
+
</ActionButton>
|
|
49
|
+
{/each}
|
|
50
|
+
</div>
|
|
51
|
+
</FancyField>
|
|
52
|
+
|
|
53
|
+
<style>
|
|
54
|
+
.options {
|
|
55
|
+
margin-top: 34px;
|
|
56
|
+
margin-bottom: 14px;
|
|
57
|
+
display: flex;
|
|
58
|
+
flex-direction: row;
|
|
59
|
+
justify-content: flex-start;
|
|
60
|
+
align-items: center;
|
|
61
|
+
gap: 6px;
|
|
62
|
+
flex-wrap: wrap;
|
|
63
|
+
}
|
|
64
|
+
.options :global(.spectrum-ActionButton) {
|
|
65
|
+
font-size: 15px;
|
|
66
|
+
line-height: 17px;
|
|
67
|
+
height: auto;
|
|
68
|
+
padding: 6px 10px;
|
|
69
|
+
}
|
|
70
|
+
</style>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import { createEventDispatcher } from "svelte"
|
|
3
|
+
import FancyField from "./FancyField.svelte"
|
|
4
|
+
import Checkbox from "../Form/Core/Checkbox.svelte"
|
|
5
|
+
|
|
6
|
+
export let value
|
|
7
|
+
export let text
|
|
8
|
+
export let disabled = false
|
|
9
|
+
export let error = null
|
|
10
|
+
export let validate = null
|
|
11
|
+
|
|
12
|
+
const dispatch = createEventDispatcher()
|
|
13
|
+
|
|
14
|
+
const onChange = () => {
|
|
15
|
+
const newValue = !value
|
|
16
|
+
dispatch("change", newValue)
|
|
17
|
+
value = newValue
|
|
18
|
+
if (validate) {
|
|
19
|
+
error = validate(newValue)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<FancyField {error} {value} {validate} {disabled} clickable on:click={onChange}>
|
|
25
|
+
<span>
|
|
26
|
+
<Checkbox {disabled} {value} />
|
|
27
|
+
</span>
|
|
28
|
+
<div class="text">
|
|
29
|
+
{#if text}
|
|
30
|
+
{text}
|
|
31
|
+
{/if}
|
|
32
|
+
<slot />
|
|
33
|
+
</div>
|
|
34
|
+
</FancyField>
|
|
35
|
+
|
|
36
|
+
<style>
|
|
37
|
+
span {
|
|
38
|
+
pointer-events: none;
|
|
39
|
+
}
|
|
40
|
+
.text {
|
|
41
|
+
font-size: 15px;
|
|
42
|
+
line-height: 17px;
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
display: -webkit-box;
|
|
46
|
+
-webkit-line-clamp: 2;
|
|
47
|
+
line-clamp: 2;
|
|
48
|
+
-webkit-box-orient: vertical;
|
|
49
|
+
}
|
|
50
|
+
.text > :global(*) {
|
|
51
|
+
font-size: inherit !important;
|
|
52
|
+
}
|
|
53
|
+
</style>
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Icon from "../Icon/Icon.svelte"
|
|
3
|
+
import { getContext, onMount } from "svelte"
|
|
4
|
+
import { slide } from "svelte/transition"
|
|
5
|
+
|
|
6
|
+
export let disabled = false
|
|
7
|
+
export let error = null
|
|
8
|
+
export let focused = false
|
|
9
|
+
export let clickable = false
|
|
10
|
+
export let validate
|
|
11
|
+
export let value
|
|
12
|
+
export let ref
|
|
13
|
+
export let autoHeight
|
|
14
|
+
|
|
15
|
+
const formContext = getContext("fancy-form")
|
|
16
|
+
const id = Math.random()
|
|
17
|
+
const API = {
|
|
18
|
+
validate: () => {
|
|
19
|
+
if (validate) {
|
|
20
|
+
error = validate(value)
|
|
21
|
+
}
|
|
22
|
+
return !error
|
|
23
|
+
},
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onMount(() => {
|
|
27
|
+
if (formContext) {
|
|
28
|
+
formContext.registerField(id, API)
|
|
29
|
+
}
|
|
30
|
+
return () => {
|
|
31
|
+
if (formContext) {
|
|
32
|
+
formContext.unregisterField(id)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<div
|
|
39
|
+
bind:this={ref}
|
|
40
|
+
class="fancy-field"
|
|
41
|
+
class:error
|
|
42
|
+
class:disabled
|
|
43
|
+
class:focused
|
|
44
|
+
class:clickable
|
|
45
|
+
class:auto-height={autoHeight}
|
|
46
|
+
>
|
|
47
|
+
<div class="content" on:click>
|
|
48
|
+
<div class="field">
|
|
49
|
+
<slot />
|
|
50
|
+
</div>
|
|
51
|
+
{#if error}
|
|
52
|
+
<div class="error-icon">
|
|
53
|
+
<Icon name="Alert" />
|
|
54
|
+
</div>
|
|
55
|
+
{/if}
|
|
56
|
+
</div>
|
|
57
|
+
{#if error}
|
|
58
|
+
<div transition:slide|local={{ duration: 130 }} class="error-message">
|
|
59
|
+
{error}
|
|
60
|
+
</div>
|
|
61
|
+
{/if}
|
|
62
|
+
</div>
|
|
63
|
+
|
|
64
|
+
<style>
|
|
65
|
+
.fancy-field {
|
|
66
|
+
max-width: 400px;
|
|
67
|
+
background: var(--spectrum-global-color-gray-75);
|
|
68
|
+
border: 1px solid var(--spectrum-global-color-gray-300);
|
|
69
|
+
border-radius: 4px;
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
transition: border-color 130ms ease-out, background 130ms ease-out,
|
|
72
|
+
background 130ms ease-out;
|
|
73
|
+
color: var(--spectrum-global-color-gray-800);
|
|
74
|
+
}
|
|
75
|
+
.fancy-field:hover {
|
|
76
|
+
border-color: var(--spectrum-global-color-gray-400);
|
|
77
|
+
}
|
|
78
|
+
.fancy-field.clickable:hover {
|
|
79
|
+
background: var(--spectrum-global-color-gray-200);
|
|
80
|
+
cursor: pointer;
|
|
81
|
+
}
|
|
82
|
+
.fancy-field.focused {
|
|
83
|
+
border-color: var(--spectrum-global-color-blue-400);
|
|
84
|
+
}
|
|
85
|
+
.fancy-field.error {
|
|
86
|
+
border-color: var(--spectrum-global-color-red-400);
|
|
87
|
+
}
|
|
88
|
+
.fancy-field.disabled {
|
|
89
|
+
background: var(--spectrum-global-color-gray-200);
|
|
90
|
+
color: var(--spectrum-global-color-gray-400);
|
|
91
|
+
border: 1px solid var(--spectrum-global-color-gray-300);
|
|
92
|
+
pointer-events: none;
|
|
93
|
+
}
|
|
94
|
+
.content {
|
|
95
|
+
position: relative;
|
|
96
|
+
height: 64px;
|
|
97
|
+
padding: 0 16px;
|
|
98
|
+
}
|
|
99
|
+
.fancy-field.auto-height .content {
|
|
100
|
+
height: auto;
|
|
101
|
+
}
|
|
102
|
+
.content,
|
|
103
|
+
.field {
|
|
104
|
+
display: flex;
|
|
105
|
+
flex-direction: row;
|
|
106
|
+
justify-content: flex-start;
|
|
107
|
+
align-items: center;
|
|
108
|
+
gap: 16px;
|
|
109
|
+
}
|
|
110
|
+
.field {
|
|
111
|
+
flex: 1 1 auto;
|
|
112
|
+
}
|
|
113
|
+
.error-message {
|
|
114
|
+
background: var(--spectrum-global-color-red-400);
|
|
115
|
+
color: white;
|
|
116
|
+
font-size: 14px;
|
|
117
|
+
padding: 6px 16px;
|
|
118
|
+
font-weight: 500;
|
|
119
|
+
}
|
|
120
|
+
.error-icon {
|
|
121
|
+
flex: 0 0 auto;
|
|
122
|
+
}
|
|
123
|
+
.error-icon :global(.spectrum-Icon) {
|
|
124
|
+
fill: var(--spectrum-global-color-red-400);
|
|
125
|
+
}
|
|
126
|
+
</style>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
export let placeholder = true
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
<div class:placeholder>
|
|
6
|
+
<slot />
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
<style>
|
|
10
|
+
div {
|
|
11
|
+
font-size: 14px;
|
|
12
|
+
line-height: 15px;
|
|
13
|
+
font-weight: 500;
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 10px;
|
|
16
|
+
color: var(--spectrum-global-color-gray-600);
|
|
17
|
+
transition: font-size 130ms ease-out, top 130ms ease-out,
|
|
18
|
+
transform 130ms ease-out;
|
|
19
|
+
}
|
|
20
|
+
div.placeholder {
|
|
21
|
+
top: 50%;
|
|
22
|
+
font-size: 15px;
|
|
23
|
+
transform: translateY(-50%);
|
|
24
|
+
}
|
|
25
|
+
</style>
|