budibase/packages/builder/src/components/start/ChooseIconModal.svelte

142 lines
2.5 KiB
Svelte
Raw Normal View History

2021-12-08 19:51:24 +01:00
<script>
import {
ModalContent,
Modal,
Icon,
ColorPicker,
Label,
notifications,
} from "@budibase/bbui"
2021-12-08 19:51:24 +01:00
import { apps } from "stores/portal"
export let app
let modal
$: selectedIcon = app?.icon?.name || "Apps"
2021-12-09 12:52:47 +01:00
$: selectedColor = app?.icon?.color
2021-12-08 19:51:24 +01:00
let iconsList = [
"Apps",
2021-12-09 10:21:38 +01:00
"Actions",
2021-12-09 11:10:16 +01:00
"ConversionFunnel",
2021-12-09 10:21:38 +01:00
"App",
"Briefcase",
"Money",
"ShoppingCart",
"Form",
"Help",
"Monitoring",
"Sandbox",
"Project",
"Organisations",
"Magnify",
"Launch",
2021-12-09 11:10:16 +01:00
"Car",
"Camera",
"Bug",
"Channel",
"Calculator",
"Calendar",
"GraphDonut",
"GraphBarHorizontal",
"Demographic",
2021-12-08 19:51:24 +01:00
]
export const show = () => {
modal.show()
}
export const hide = () => {
modal.hide()
}
const onCancel = () => {
2021-12-09 12:52:47 +01:00
selectedIcon = ""
selectedColor = ""
2021-12-08 19:51:24 +01:00
hide()
}
const changeColor = val => {
selectedColor = val
}
const save = async () => {
try {
await apps.update(app.instance._id, {
icon: {
name: selectedIcon,
color: selectedColor,
},
})
} catch (error) {
notifications.error("Error updating app")
}
2021-12-08 19:51:24 +01:00
}
</script>
2021-12-08 19:52:06 +01:00
<Modal bind:this={modal} on:hide={onCancel}>
2021-12-08 19:51:24 +01:00
<ModalContent
title={"Edit Icon"}
confirmText={"Save"}
onConfirm={() => save()}
>
<div class="scrollable-icons">
<div class="title-spacing">
<Label>Select an icon</Label>
2021-12-08 19:51:24 +01:00
</div>
<div class="grid">
{#each iconsList as item}
<div
class="icon-item"
class:selected={item === selectedIcon}
2021-12-09 10:24:40 +01:00
on:click={() => (selectedIcon = item)}
2021-12-08 19:51:24 +01:00
>
2021-12-09 10:21:38 +01:00
<Icon name={item} />
2021-12-08 19:51:24 +01:00
</div>
{/each}
</div>
</div>
<div class="color-selection">
<div>
<Label>Select a color</Label>
2021-12-08 19:51:24 +01:00
</div>
<div class="color-selection-item">
<ColorPicker
2021-12-09 12:52:47 +01:00
bind:value={selectedColor}
2021-12-08 19:51:24 +01:00
on:change={e => changeColor(e.detail)}
/>
</div>
</div>
</ModalContent>
</Modal>
<style>
.scrollable-icons {
overflow-y: auto;
2021-12-09 11:10:16 +01:00
height: 230px;
2021-12-08 19:51:24 +01:00
}
.grid {
display: grid;
grid-gap: 20px;
grid-template-columns: 1fr 1fr 1fr 1fr 1fr;
}
.color-selection {
display: flex;
align-items: center;
}
.color-selection-item {
margin-left: 20px;
}
.title-spacing {
margin-bottom: 20px;
}
.icon-item {
cursor: pointer;
}
.icon-item.selected {
color: var(--spectrum-global-color-blue-600);
}
2021-12-08 19:51:24 +01:00
</style>