Merge pull request #15623 from Budibase/feat/pc-ts-conversions
Typescript conversion for some BBUI components
This commit is contained in:
commit
355fbd1b8c
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
export let small = false
|
export let small: boolean = false
|
||||||
export let disabled
|
export let disabled: boolean = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
|
|
|
@ -1,24 +1,24 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Field from "./Field.svelte"
|
import Field from "./Field.svelte"
|
||||||
import Checkbox from "./Core/Checkbox.svelte"
|
import Checkbox from "./Core/Checkbox.svelte"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
export let value = null
|
export let value: boolean | undefined = undefined
|
||||||
export let label = null
|
export let label: string | undefined = undefined
|
||||||
export let labelPosition = "above"
|
export let labelPosition: "above" | "below" = "above"
|
||||||
export let text = null
|
export let text: string | undefined = undefined
|
||||||
export let disabled = false
|
export let disabled: boolean = false
|
||||||
export let error = null
|
export let error: string | undefined = undefined
|
||||||
export let size = "M"
|
export let size: "S" | "M" | "L" | "XL" = "M"
|
||||||
export let helpText = null
|
export let helpText: string | undefined = undefined
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const onChange = e => {
|
const onChange = (e: CustomEvent<boolean>) => {
|
||||||
value = e.detail
|
value = e.detail
|
||||||
dispatch("change", e.detail)
|
dispatch("change", e.detail)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Field {helpText} {label} {labelPosition} {error}>
|
<Field {helpText} {label} {labelPosition} {error}>
|
||||||
<Checkbox {error} {disabled} {text} {value} {size} on:change={onChange} />
|
<Checkbox {disabled} {text} {value} {size} on:change={onChange} />
|
||||||
</Field>
|
</Field>
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
export let secondary: boolean = false
|
export let secondary: boolean = false
|
||||||
export let overBackground: boolean = false
|
export let overBackground: boolean = false
|
||||||
export let target: string | undefined = undefined
|
export let target: string | undefined = undefined
|
||||||
export let download: boolean | undefined = undefined
|
export let download: string | undefined = undefined
|
||||||
export let disabled: boolean = false
|
export let disabled: boolean = false
|
||||||
export let tooltip: string | null = null
|
export let tooltip: string | null = null
|
||||||
|
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
<script>
|
|
||||||
import { getContext } from "svelte"
|
|
||||||
|
|
||||||
const multilevel = getContext("sidenav-type")
|
|
||||||
import Badge from "../Badge/Badge.svelte"
|
|
||||||
|
|
||||||
export let href = ""
|
|
||||||
export let external = false
|
|
||||||
export let heading = ""
|
|
||||||
export let icon = ""
|
|
||||||
export let selected = false
|
|
||||||
export let disabled = false
|
|
||||||
export let badge = ""
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-element-interactions -->
|
|
||||||
<li
|
|
||||||
class="spectrum-SideNav-item"
|
|
||||||
class:is-selected={selected}
|
|
||||||
class:is-disabled={disabled}
|
|
||||||
on:click
|
|
||||||
>
|
|
||||||
{#if heading}
|
|
||||||
<h2 class="spectrum-SideNav-heading" id="nav-heading-{heading}">
|
|
||||||
{heading}
|
|
||||||
</h2>
|
|
||||||
{/if}
|
|
||||||
<a
|
|
||||||
target={external ? "_blank" : ""}
|
|
||||||
{href}
|
|
||||||
class="spectrum-SideNav-itemLink"
|
|
||||||
aria-current="page"
|
|
||||||
>
|
|
||||||
{#if icon}
|
|
||||||
<svg
|
|
||||||
class="spectrum-Icon spectrum-Icon--sizeM spectrum-SideNav-itemIcon"
|
|
||||||
focusable="false"
|
|
||||||
aria-hidden="true"
|
|
||||||
>
|
|
||||||
<use xlink:href="#spectrum-icon-18-{icon}" />
|
|
||||||
</svg>
|
|
||||||
{/if}
|
|
||||||
<slot />
|
|
||||||
{#if badge}
|
|
||||||
<div class="badge">
|
|
||||||
<Badge active size="S">{badge}</Badge>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</a>
|
|
||||||
|
|
||||||
{#if multilevel && $$slots.subnav}
|
|
||||||
<ul class="spectrum-SideNav">
|
|
||||||
<slot name="subnav" />
|
|
||||||
</ul>
|
|
||||||
{/if}
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.badge {
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
</style>
|
|
|
@ -1,13 +0,0 @@
|
||||||
<script>
|
|
||||||
import { setContext } from "svelte"
|
|
||||||
import "@spectrum-css/sidenav/dist/index-vars.css"
|
|
||||||
|
|
||||||
export let multilevel = false
|
|
||||||
setContext("sidenav-type", multilevel)
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<nav>
|
|
||||||
<ul class="spectrum-SideNav" class:spectrum-SideNav--multiLevel={multilevel}>
|
|
||||||
<slot />
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
|
@ -7,17 +7,26 @@ export const BANNER_TYPES = {
|
||||||
WARNING: "warning",
|
WARNING: "warning",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface BannerConfig {
|
||||||
|
message?: string
|
||||||
|
type?: string
|
||||||
|
extraButtonText?: string
|
||||||
|
extraButtonAction?: () => void
|
||||||
|
onChange?: () => void
|
||||||
|
}
|
||||||
|
|
||||||
|
interface DefaultConfig {
|
||||||
|
messages: BannerConfig[]
|
||||||
|
}
|
||||||
|
|
||||||
export function createBannerStore() {
|
export function createBannerStore() {
|
||||||
const DEFAULT_CONFIG = {
|
const DEFAULT_CONFIG: DefaultConfig = {
|
||||||
messages: [],
|
messages: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
const banner = writable(DEFAULT_CONFIG)
|
const banner = writable<DefaultConfig>(DEFAULT_CONFIG)
|
||||||
|
|
||||||
const show = async (
|
const show = async (config: BannerConfig = {}) => {
|
||||||
// eslint-disable-next-line
|
|
||||||
config = { message, type, extraButtonText, extraButtonAction, onChange }
|
|
||||||
) => {
|
|
||||||
banner.update(store => {
|
banner.update(store => {
|
||||||
return {
|
return {
|
||||||
...store,
|
...store,
|
||||||
|
@ -27,7 +36,7 @@ export function createBannerStore() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const showStatus = async () => {
|
const showStatus = async () => {
|
||||||
const config = {
|
const config: BannerConfig = {
|
||||||
message: "Some systems are experiencing issues",
|
message: "Some systems are experiencing issues",
|
||||||
type: BANNER_TYPES.NEGATIVE,
|
type: BANNER_TYPES.NEGATIVE,
|
||||||
extraButtonText: "View Status",
|
extraButtonText: "View Status",
|
||||||
|
@ -37,18 +46,24 @@ export function createBannerStore() {
|
||||||
await queue([config])
|
await queue([config])
|
||||||
}
|
}
|
||||||
|
|
||||||
const queue = async entries => {
|
const queue = async (entries: Array<BannerConfig>) => {
|
||||||
const priority = {
|
const priority: Record<string, number> = {
|
||||||
[BANNER_TYPES.NEGATIVE]: 0,
|
[BANNER_TYPES.NEGATIVE]: 0,
|
||||||
[BANNER_TYPES.WARNING]: 1,
|
[BANNER_TYPES.WARNING]: 1,
|
||||||
[BANNER_TYPES.INFO]: 2,
|
[BANNER_TYPES.INFO]: 2,
|
||||||
}
|
}
|
||||||
banner.update(store => {
|
banner.update(store => {
|
||||||
const sorted = [...store.messages, ...entries].sort((a, b) => {
|
const sorted = [...store.messages, ...entries].sort((a, b) => {
|
||||||
if (priority[a.type] == priority[b.type]) {
|
if (
|
||||||
|
priority[a.type as keyof typeof priority] ===
|
||||||
|
priority[b.type as keyof typeof priority]
|
||||||
|
) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return priority[a.type] < priority[b.type] ? -1 : 1
|
return priority[a.type as keyof typeof priority] <
|
||||||
|
priority[b.type as keyof typeof priority]
|
||||||
|
? -1
|
||||||
|
: 1
|
||||||
})
|
})
|
||||||
return {
|
return {
|
||||||
...store,
|
...store,
|
|
@ -2,9 +2,21 @@ import { writable } from "svelte/store"
|
||||||
|
|
||||||
const NOTIFICATION_TIMEOUT = 3000
|
const NOTIFICATION_TIMEOUT = 3000
|
||||||
|
|
||||||
|
interface Notification {
|
||||||
|
id: string
|
||||||
|
type: string
|
||||||
|
message: string
|
||||||
|
icon: string
|
||||||
|
dismissable: boolean
|
||||||
|
action: (() => void) | null
|
||||||
|
actionMessage: string | null
|
||||||
|
wide: boolean
|
||||||
|
dismissTimeout: number
|
||||||
|
}
|
||||||
|
|
||||||
export const createNotificationStore = () => {
|
export const createNotificationStore = () => {
|
||||||
const timeoutIds = new Set()
|
const timeoutIds = new Set<ReturnType<typeof setTimeout>>()
|
||||||
const _notifications = writable([], () => {
|
const _notifications = writable<Notification[]>([], () => {
|
||||||
return () => {
|
return () => {
|
||||||
// clear all the timers
|
// clear all the timers
|
||||||
timeoutIds.forEach(timeoutId => {
|
timeoutIds.forEach(timeoutId => {
|
||||||
|
@ -21,7 +33,7 @@ export const createNotificationStore = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const send = (
|
const send = (
|
||||||
message,
|
message: string,
|
||||||
{
|
{
|
||||||
type = "default",
|
type = "default",
|
||||||
icon = "",
|
icon = "",
|
||||||
|
@ -30,7 +42,15 @@ export const createNotificationStore = () => {
|
||||||
actionMessage = null,
|
actionMessage = null,
|
||||||
wide = false,
|
wide = false,
|
||||||
dismissTimeout = NOTIFICATION_TIMEOUT,
|
dismissTimeout = NOTIFICATION_TIMEOUT,
|
||||||
}
|
}: {
|
||||||
|
type?: string
|
||||||
|
icon?: string
|
||||||
|
autoDismiss?: boolean
|
||||||
|
action?: (() => void) | null
|
||||||
|
actionMessage?: string | null
|
||||||
|
wide?: boolean
|
||||||
|
dismissTimeout?: number
|
||||||
|
} = {}
|
||||||
) => {
|
) => {
|
||||||
if (block) {
|
if (block) {
|
||||||
return
|
return
|
||||||
|
@ -60,7 +80,7 @@ export const createNotificationStore = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const dismissNotification = id => {
|
const dismissNotification = (id: string) => {
|
||||||
_notifications.update(state => {
|
_notifications.update(state => {
|
||||||
return state.filter(n => n.id !== id)
|
return state.filter(n => n.id !== id)
|
||||||
})
|
})
|
||||||
|
@ -71,17 +91,18 @@ export const createNotificationStore = () => {
|
||||||
return {
|
return {
|
||||||
subscribe,
|
subscribe,
|
||||||
send,
|
send,
|
||||||
info: msg => send(msg, { type: "info", icon: "Info" }),
|
info: (msg: string) => send(msg, { type: "info", icon: "Info" }),
|
||||||
error: msg =>
|
error: (msg: string) =>
|
||||||
send(msg, { type: "error", icon: "Alert", autoDismiss: false }),
|
send(msg, { type: "error", icon: "Alert", autoDismiss: false }),
|
||||||
warning: msg => send(msg, { type: "warning", icon: "Alert" }),
|
warning: (msg: string) => send(msg, { type: "warning", icon: "Alert" }),
|
||||||
success: msg => send(msg, { type: "success", icon: "CheckmarkCircle" }),
|
success: (msg: string) =>
|
||||||
|
send(msg, { type: "success", icon: "CheckmarkCircle" }),
|
||||||
blockNotifications,
|
blockNotifications,
|
||||||
dismiss: dismissNotification,
|
dismiss: dismissNotification,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function id() {
|
function id(): string {
|
||||||
return "_" + Math.random().toString(36).slice(2, 9)
|
return "_" + Math.random().toString(36).slice(2, 9)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/label/dist/index-vars.css"
|
import "@spectrum-css/label/dist/index-vars.css"
|
||||||
import Badge from "../Badge/Badge.svelte"
|
import Badge from "../Badge/Badge.svelte"
|
||||||
|
|
||||||
export let value
|
export let value: string | string[]
|
||||||
|
|
||||||
const displayLimit = 5
|
const displayLimit = 5
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Link from "../Link/Link.svelte"
|
import Link from "../Link/Link.svelte"
|
||||||
|
|
||||||
export let value
|
export let value: { name: string; url: string; extension: string }[]
|
||||||
|
|
||||||
const displayLimit = 5
|
const displayLimit = 5
|
||||||
$: attachments = value?.slice(0, displayLimit) ?? []
|
$: attachments = value?.slice(0, displayLimit) ?? []
|
||||||
$: leftover = (value?.length ?? 0) - attachments.length
|
$: leftover = (value?.length ?? 0) - attachments.length
|
||||||
|
|
||||||
const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
|
const imageExtensions: string[] = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
|
||||||
const isImage = extension => {
|
const isImage = (extension: string | undefined): boolean => {
|
||||||
return imageExtensions.includes(extension?.toLowerCase())
|
return imageExtensions.includes(extension?.toLowerCase() ?? "")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
export let value
|
export let value: string
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="bold">{value}</div>
|
<div class="bold">{value}</div>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/checkbox/dist/index-vars.css"
|
import "@spectrum-css/checkbox/dist/index-vars.css"
|
||||||
|
|
||||||
export let value
|
export let value: boolean
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<label
|
<label
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import StringRenderer from "./StringRenderer.svelte"
|
import StringRenderer from "./StringRenderer.svelte"
|
||||||
import BooleanRenderer from "./BooleanRenderer.svelte"
|
import BooleanRenderer from "./BooleanRenderer.svelte"
|
||||||
import DateTimeRenderer from "./DateTimeRenderer.svelte"
|
import DateTimeRenderer from "./DateTimeRenderer.svelte"
|
||||||
|
@ -8,14 +8,14 @@
|
||||||
import InternalRenderer from "./InternalRenderer.svelte"
|
import InternalRenderer from "./InternalRenderer.svelte"
|
||||||
import { processStringSync } from "@budibase/string-templates"
|
import { processStringSync } from "@budibase/string-templates"
|
||||||
|
|
||||||
export let row
|
export let row: Record<string, any>
|
||||||
export let schema
|
export let schema: Record<string, any>
|
||||||
export let value
|
export let value: Record<string, any>
|
||||||
export let customRenderers = []
|
export let customRenderers: { column: string; component: any }[] = []
|
||||||
export let snippets
|
export let snippets: any
|
||||||
|
|
||||||
let renderer
|
let renderer: any
|
||||||
const typeMap = {
|
const typeMap: Record<string, any> = {
|
||||||
boolean: BooleanRenderer,
|
boolean: BooleanRenderer,
|
||||||
datetime: DateTimeRenderer,
|
datetime: DateTimeRenderer,
|
||||||
link: RelationshipRenderer,
|
link: RelationshipRenderer,
|
||||||
|
@ -33,7 +33,7 @@
|
||||||
$: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer
|
$: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer
|
||||||
$: cellValue = getCellValue(value, schema.template)
|
$: cellValue = getCellValue(value, schema.template)
|
||||||
|
|
||||||
const getType = schema => {
|
const getType = (schema: any): string => {
|
||||||
// Use a string renderer for dates if we use a custom template
|
// Use a string renderer for dates if we use a custom template
|
||||||
if (schema?.type === "datetime" && schema?.template) {
|
if (schema?.type === "datetime" && schema?.template) {
|
||||||
return "string"
|
return "string"
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
return schema?.type || "string"
|
return schema?.type || "string"
|
||||||
}
|
}
|
||||||
|
|
||||||
const getCellValue = (value, template) => {
|
const getCellValue = (value: any, template: string | undefined): any => {
|
||||||
if (!template) {
|
if (!template) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
export let value
|
export let value: string
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<code>{value}</code>
|
<code>{value}</code>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
|
|
||||||
export let value
|
export let value: string | Date
|
||||||
export let schema
|
export let schema: { timeOnly?: boolean; dateOnly?: boolean }
|
||||||
|
|
||||||
// adding the 0- will turn a string like 00:00:00 into a valid ISO
|
// adding the 0- will turn a string like 00:00:00 into a valid ISO
|
||||||
// date, but will make actual ISO dates invalid
|
// date, but will make actual ISO dates invalid
|
||||||
$: time = new Date(`0-${value}`)
|
$: time = new Date(`0-${value}`)
|
||||||
$: isTimeOnly = !isNaN(time) || schema?.timeOnly
|
$: isTimeOnly = !isNaN(time as any) || schema?.timeOnly
|
||||||
$: isDateOnly = schema?.dateOnly
|
$: isDateOnly = schema?.dateOnly
|
||||||
$: format = isTimeOnly
|
$: format = isTimeOnly
|
||||||
? "HH:mm:ss"
|
? "HH:mm:ss"
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Icon from "../Icon/Icon.svelte"
|
import Icon from "../Icon/Icon.svelte"
|
||||||
import { copyToClipboard } from "../helpers"
|
import { copyToClipboard } from "../helpers"
|
||||||
import { notifications } from "../Stores/notifications"
|
import { notifications } from "../Stores/notifications"
|
||||||
|
|
||||||
export let value
|
export let value: string
|
||||||
|
|
||||||
const onClick = async e => {
|
const onClick = async (e: MouseEvent): Promise<void> => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
try {
|
try {
|
||||||
await copyToClipboard(value)
|
await copyToClipboard(value)
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/label/dist/index-vars.css"
|
import "@spectrum-css/label/dist/index-vars.css"
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import Badge from "../Badge/Badge.svelte"
|
import Badge from "../Badge/Badge.svelte"
|
||||||
|
|
||||||
export let row
|
export let row: { tableId: string; _id: string }
|
||||||
export let value
|
export let value: { primaryDisplay?: string }[] | undefined
|
||||||
export let schema
|
export let schema: { name?: string }
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
const displayLimit = 5
|
const displayLimit = 5
|
||||||
|
@ -13,7 +13,7 @@
|
||||||
$: relationships = value?.slice(0, displayLimit) ?? []
|
$: relationships = value?.slice(0, displayLimit) ?? []
|
||||||
$: leftover = (value?.length ?? 0) - relationships.length
|
$: leftover = (value?.length ?? 0) - relationships.length
|
||||||
|
|
||||||
const onClick = e => {
|
const onClick = (e: MouseEvent) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
dispatch("clickrelationship", {
|
dispatch("clickrelationship", {
|
||||||
tableId: row.tableId,
|
tableId: row.tableId,
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Checkbox from "../Form/Checkbox.svelte"
|
import Checkbox from "../Form/Checkbox.svelte"
|
||||||
import ActionButton from "../ActionButton/ActionButton.svelte"
|
import ActionButton from "../ActionButton/ActionButton.svelte"
|
||||||
|
|
||||||
export let selected
|
export let selected: boolean | undefined
|
||||||
export let onEdit
|
export let onEdit: (_e: Event) => void
|
||||||
export let allowSelectRows = false
|
export let allowSelectRows: boolean = false
|
||||||
export let allowEditRows = false
|
export let allowEditRows: boolean = false
|
||||||
export let data
|
export let data: Record<string, any>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
export let value
|
export let value: string | object
|
||||||
export let schema
|
export let schema: { capitalise?: boolean }
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class:capitalise={schema?.capitalise}>
|
<div class:capitalise={schema?.capitalise}>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from "svelte"
|
import { createEventDispatcher } from "svelte"
|
||||||
import "@spectrum-css/table/dist/index-vars.css"
|
import "@spectrum-css/table/dist/index-vars.css"
|
||||||
import CellRenderer from "./CellRenderer.svelte"
|
import CellRenderer from "./CellRenderer.svelte"
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
import ProgressCircle from "../ProgressCircle/ProgressCircle.svelte"
|
import ProgressCircle from "../ProgressCircle/ProgressCircle.svelte"
|
||||||
import Checkbox from "../Form/Checkbox.svelte"
|
import Checkbox from "../Form/Checkbox.svelte"
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
/**
|
||||||
* The expected schema is our normal couch schemas for our tables.
|
* The expected schema is our normal couch schemas for our tables.
|
||||||
* Each field schema can be enriched with a few extra properties to customise
|
* Each field schema can be enriched with a few extra properties to customise
|
||||||
|
@ -24,42 +25,42 @@
|
||||||
* borderLeft: show a left border
|
* borderLeft: show a left border
|
||||||
* borderRight: show a right border
|
* borderRight: show a right border
|
||||||
*/
|
*/
|
||||||
export let data = []
|
export let data: any[] = []
|
||||||
export let schema = {}
|
export let schema: Record<string, any> = {}
|
||||||
export let showAutoColumns = false
|
export let showAutoColumns: boolean = false
|
||||||
export let rowCount = 0
|
export let rowCount: number = 0
|
||||||
export let quiet = false
|
export let quiet: boolean = false
|
||||||
export let loading = false
|
export let loading: boolean = false
|
||||||
export let allowSelectRows
|
export let allowSelectRows: boolean = false
|
||||||
export let allowEditRows = true
|
export let allowEditRows: boolean = true
|
||||||
export let allowEditColumns = true
|
export let allowEditColumns: boolean = true
|
||||||
export let allowClickRows = true
|
export let allowClickRows: boolean = true
|
||||||
export let selectedRows = []
|
export let selectedRows: any[] = []
|
||||||
export let customRenderers = []
|
export let customRenderers: any[] = []
|
||||||
export let disableSorting = false
|
export let disableSorting: boolean = false
|
||||||
export let autoSortColumns = true
|
export let autoSortColumns: boolean = true
|
||||||
export let compact = false
|
export let compact: boolean = false
|
||||||
export let customPlaceholder = false
|
export let customPlaceholder: boolean = false
|
||||||
export let showHeaderBorder = true
|
export let showHeaderBorder: boolean = true
|
||||||
export let placeholderText = "No rows found"
|
export let placeholderText: string = "No rows found"
|
||||||
export let snippets = []
|
export let snippets: any[] = []
|
||||||
export let defaultSortColumn = undefined
|
export let defaultSortColumn: string | undefined = undefined
|
||||||
export let defaultSortOrder = "Ascending"
|
export let defaultSortOrder: "Ascending" | "Descending" = "Ascending"
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
const headerHeight = 36
|
const headerHeight: number = 36
|
||||||
$: rowHeight = compact ? 46 : 55
|
$: rowHeight = compact ? 46 : 55
|
||||||
|
|
||||||
// Sorting state
|
// Sorting state
|
||||||
let sortColumn
|
let sortColumn: string | undefined
|
||||||
let sortOrder
|
let sortOrder: "Ascending" | "Descending" | undefined
|
||||||
|
|
||||||
// Table state
|
// Table state
|
||||||
let height = 0
|
let height: number = 0
|
||||||
let loaded = false
|
let loaded: boolean = false
|
||||||
let checkboxStatus = false
|
let checkboxStatus: boolean = false
|
||||||
|
|
||||||
$: schema = fixSchema(schema)
|
$: schema = fixSchema(schema)
|
||||||
$: if (!loading) loaded = true
|
$: if (!loading) loaded = true
|
||||||
|
@ -95,8 +96,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fixSchema = schema => {
|
const fixSchema = (schema: Record<string, any>): Record<string, any> => {
|
||||||
let fixedSchema = {}
|
let fixedSchema: Record<string, any> = {}
|
||||||
Object.entries(schema || {}).forEach(([fieldName, fieldSchema]) => {
|
Object.entries(schema || {}).forEach(([fieldName, fieldSchema]) => {
|
||||||
if (typeof fieldSchema === "string") {
|
if (typeof fieldSchema === "string") {
|
||||||
fixedSchema[fieldName] = {
|
fixedSchema[fieldName] = {
|
||||||
|
@ -120,7 +121,13 @@
|
||||||
return fixedSchema
|
return fixedSchema
|
||||||
}
|
}
|
||||||
|
|
||||||
const getVisibleRowCount = (loaded, height, allRows, rowCount, rowHeight) => {
|
const getVisibleRowCount = (
|
||||||
|
loaded: boolean,
|
||||||
|
height: number,
|
||||||
|
allRows: number,
|
||||||
|
rowCount: number,
|
||||||
|
rowHeight: number
|
||||||
|
): number => {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
return rowCount || 0
|
return rowCount || 0
|
||||||
}
|
}
|
||||||
|
@ -131,12 +138,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const getHeightStyle = (
|
const getHeightStyle = (
|
||||||
visibleRowCount,
|
visibleRowCount: number,
|
||||||
rowCount,
|
rowCount: number,
|
||||||
totalRowCount,
|
totalRowCount: number,
|
||||||
rowHeight,
|
rowHeight: number,
|
||||||
loading
|
loading: boolean
|
||||||
) => {
|
): string => {
|
||||||
if (loading) {
|
if (loading) {
|
||||||
return `height: ${headerHeight + visibleRowCount * rowHeight}px;`
|
return `height: ${headerHeight + visibleRowCount * rowHeight}px;`
|
||||||
}
|
}
|
||||||
|
@ -146,7 +153,11 @@
|
||||||
return `height: ${headerHeight + visibleRowCount * rowHeight}px;`
|
return `height: ${headerHeight + visibleRowCount * rowHeight}px;`
|
||||||
}
|
}
|
||||||
|
|
||||||
const getGridStyle = (fields, schema, showEditColumn) => {
|
const getGridStyle = (
|
||||||
|
fields: string[],
|
||||||
|
schema: Record<string, any>,
|
||||||
|
showEditColumn: boolean
|
||||||
|
): string => {
|
||||||
let style = "grid-template-columns:"
|
let style = "grid-template-columns:"
|
||||||
if (showEditColumn) {
|
if (showEditColumn) {
|
||||||
style += " auto"
|
style += " auto"
|
||||||
|
@ -163,7 +174,11 @@
|
||||||
return style
|
return style
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortRows = (rows, sortColumn, sortOrder) => {
|
const sortRows = (
|
||||||
|
rows: any[],
|
||||||
|
sortColumn: string | undefined,
|
||||||
|
sortOrder: string | undefined
|
||||||
|
): any[] => {
|
||||||
sortColumn = sortColumn ?? defaultSortColumn
|
sortColumn = sortColumn ?? defaultSortColumn
|
||||||
sortOrder = sortOrder ?? defaultSortOrder
|
sortOrder = sortOrder ?? defaultSortOrder
|
||||||
if (!sortColumn || !sortOrder || disableSorting) {
|
if (!sortColumn || !sortOrder || disableSorting) {
|
||||||
|
@ -180,7 +195,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortBy = fieldSchema => {
|
const sortBy = (fieldSchema: Record<string, any>): void => {
|
||||||
if (fieldSchema.sortable === false) {
|
if (fieldSchema.sortable === false) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -193,7 +208,7 @@
|
||||||
dispatch("sort", { column: sortColumn, order: sortOrder })
|
dispatch("sort", { column: sortColumn, order: sortOrder })
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDisplayName = schema => {
|
const getDisplayName = (schema: Record<string, any>): string => {
|
||||||
let name = schema?.displayName
|
let name = schema?.displayName
|
||||||
if (schema && name === undefined) {
|
if (schema && name === undefined) {
|
||||||
name = schema.name
|
name = schema.name
|
||||||
|
@ -201,9 +216,13 @@
|
||||||
return name || ""
|
return name || ""
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFields = (schema, showAutoColumns, autoSortColumns) => {
|
const getFields = (
|
||||||
let columns = []
|
schema: Record<string, any>,
|
||||||
let autoColumns = []
|
showAutoColumns: boolean,
|
||||||
|
autoSortColumns: boolean
|
||||||
|
): string[] => {
|
||||||
|
let columns: any[] = []
|
||||||
|
let autoColumns: any[] = []
|
||||||
Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
|
Object.entries(schema || {}).forEach(([field, fieldSchema]) => {
|
||||||
if (!field || !fieldSchema) {
|
if (!field || !fieldSchema) {
|
||||||
return
|
return
|
||||||
|
@ -235,17 +254,17 @@
|
||||||
.map(column => column.name)
|
.map(column => column.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
const editColumn = (e, field) => {
|
const editColumn = (e: Event, field: any): void => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
dispatch("editcolumn", field)
|
dispatch("editcolumn", field)
|
||||||
}
|
}
|
||||||
|
|
||||||
const editRow = (e, row) => {
|
const editRow = (e: Event, row: any): void => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
dispatch("editrow", cloneDeep(row))
|
dispatch("editrow", cloneDeep(row))
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleSelectRow = row => {
|
const toggleSelectRow = (row: any): void => {
|
||||||
if (!allowSelectRows) {
|
if (!allowSelectRows) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -258,7 +277,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleSelectAll = e => {
|
const toggleSelectAll = (e: CustomEvent): void => {
|
||||||
const select = !!e.detail
|
const select = !!e.detail
|
||||||
if (select) {
|
if (select) {
|
||||||
// Add any rows which are not already in selected rows
|
// Add any rows which are not already in selected rows
|
||||||
|
@ -278,8 +297,10 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const computeCellStyles = schema => {
|
const computeCellStyles = (
|
||||||
let styles = {}
|
schema: Record<string, any>
|
||||||
|
): Record<string, string> => {
|
||||||
|
let styles: Record<string, string> = {}
|
||||||
Object.keys(schema || {}).forEach(field => {
|
Object.keys(schema || {}).forEach(field => {
|
||||||
styles[field] = ""
|
styles[field] = ""
|
||||||
if (schema[field].color) {
|
if (schema[field].color) {
|
||||||
|
|
|
@ -1,28 +1,48 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/tabs/dist/index-vars.css"
|
import "@spectrum-css/tabs/dist/index-vars.css"
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
import { onMount, setContext, createEventDispatcher } from "svelte"
|
import { onMount, setContext, createEventDispatcher } from "svelte"
|
||||||
|
|
||||||
export let selected
|
interface TabInfo {
|
||||||
export let vertical = false
|
width?: number
|
||||||
export let noPadding = false
|
height?: number
|
||||||
// added as a separate option as noPadding is used for vertical padding
|
left?: number
|
||||||
export let noHorizPadding = false
|
top?: number
|
||||||
export let quiet = false
|
}
|
||||||
export let emphasized = false
|
|
||||||
export let onTop = false
|
|
||||||
export let size = "M"
|
|
||||||
export let beforeSwitch = null
|
|
||||||
|
|
||||||
let thisSelected = undefined
|
interface TabState {
|
||||||
|
title: string
|
||||||
|
id: string
|
||||||
|
emphasized: boolean
|
||||||
|
info?: TabInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
export let selected: string
|
||||||
|
export let vertical: boolean = false
|
||||||
|
export let noPadding: boolean = false
|
||||||
|
// added as a separate option as noPadding is used for vertical padding
|
||||||
|
export let noHorizPadding: boolean = false
|
||||||
|
export let quiet: boolean = false
|
||||||
|
export let emphasized: boolean = false
|
||||||
|
export let onTop: boolean = false
|
||||||
|
export let size: "S" | "M" | "L" = "M"
|
||||||
|
export let beforeSwitch: ((_title: string) => boolean) | null = null
|
||||||
|
|
||||||
|
let thisSelected: string | undefined = undefined
|
||||||
|
let container: HTMLElement | undefined
|
||||||
|
|
||||||
let _id = id()
|
let _id = id()
|
||||||
const tab = writable({ title: selected, id: _id, emphasized })
|
const tab = writable<TabState>({ title: selected, id: _id, emphasized })
|
||||||
setContext("tab", tab)
|
setContext("tab", tab)
|
||||||
|
|
||||||
let container
|
let top: string | undefined
|
||||||
|
let left: string | undefined
|
||||||
|
let width: string | undefined
|
||||||
|
let height: string | undefined
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher<{
|
||||||
|
select: string
|
||||||
|
}>()
|
||||||
|
|
||||||
$: {
|
$: {
|
||||||
if (thisSelected !== selected) {
|
if (thisSelected !== selected) {
|
||||||
|
@ -44,29 +64,34 @@
|
||||||
}
|
}
|
||||||
if ($tab.title !== thisSelected) {
|
if ($tab.title !== thisSelected) {
|
||||||
tab.update(state => {
|
tab.update(state => {
|
||||||
state.title = thisSelected
|
state.title = thisSelected as string
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let top, left, width, height
|
$: $tab && calculateIndicatorLength()
|
||||||
$: calculateIndicatorLength($tab)
|
$: $tab && calculateIndicatorOffset()
|
||||||
$: calculateIndicatorOffset($tab)
|
|
||||||
|
|
||||||
function calculateIndicatorLength() {
|
function calculateIndicatorLength() {
|
||||||
if (!vertical) {
|
if (!vertical) {
|
||||||
width = $tab.info?.width + "px"
|
width = ($tab.info?.width ?? 0) + "px"
|
||||||
} else {
|
} else {
|
||||||
height = $tab.info?.height + 4 + "px"
|
height = ($tab.info?.height ?? 0) + 4 + "px"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculateIndicatorOffset() {
|
function calculateIndicatorOffset() {
|
||||||
if (!vertical) {
|
if (!vertical) {
|
||||||
left = $tab.info?.left - container?.getBoundingClientRect().left + "px"
|
left =
|
||||||
|
($tab.info?.left ?? 0) -
|
||||||
|
(container?.getBoundingClientRect().left ?? 0) +
|
||||||
|
"px"
|
||||||
} else {
|
} else {
|
||||||
top = $tab.info?.top - container?.getBoundingClientRect().top + "px"
|
top =
|
||||||
|
($tab.info?.top ?? 0) -
|
||||||
|
(container?.getBoundingClientRect().top ?? 0) +
|
||||||
|
"px"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +100,7 @@
|
||||||
calculateIndicatorOffset()
|
calculateIndicatorOffset()
|
||||||
})
|
})
|
||||||
|
|
||||||
function id() {
|
function id(): string {
|
||||||
return "_" + Math.random().toString(36).slice(2, 9)
|
return "_" + Math.random().toString(36).slice(2, 9)
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/tags/dist/index-vars.css"
|
import "@spectrum-css/tags/dist/index-vars.css"
|
||||||
import Avatar from "../Avatar/Avatar.svelte"
|
import Avatar from "../Avatar/Avatar.svelte"
|
||||||
import ClearButton from "../ClearButton/ClearButton.svelte"
|
import ClearButton from "../ClearButton/ClearButton.svelte"
|
||||||
|
|
||||||
export let icon = ""
|
export let icon: string = ""
|
||||||
export let avatar = ""
|
export let avatar: string = ""
|
||||||
export let invalid = false
|
export let invalid: boolean = false
|
||||||
export let disabled = false
|
export let disabled: boolean = false
|
||||||
export let closable = false
|
export let closable: boolean = false
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/tags/dist/index-vars.css"
|
import "@spectrum-css/tags/dist/index-vars.css"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import Icon from "../Icon/Icon.svelte"
|
import Icon from "../Icon/Icon.svelte"
|
||||||
import AbsTooltip from "./AbsTooltip.svelte"
|
import AbsTooltip from "./AbsTooltip.svelte"
|
||||||
|
|
||||||
export let tooltip = ""
|
export let tooltip: string = ""
|
||||||
export let size = "M"
|
export let size: "S" | "M" = "M"
|
||||||
export let disabled = true
|
export let disabled: boolean = true
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class:container={!!tooltip}>
|
<div class:container={!!tooltip}>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
export let selected = false
|
export let selected: boolean = false
|
||||||
export let open = false
|
export let open: boolean = false
|
||||||
export let href = false
|
export let href: string | null = null
|
||||||
export let title
|
export let title: string
|
||||||
export let icon
|
export let icon: string | undefined
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<li
|
<li
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/treeview/dist/index-vars.css"
|
import "@spectrum-css/treeview/dist/index-vars.css"
|
||||||
|
|
||||||
export let quiet = false
|
export let quiet: boolean = false
|
||||||
export let standalone = true
|
export let standalone: boolean = true
|
||||||
export let width = "250px"
|
export let width: string = "250px"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul
|
<ul
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/typography/dist/index-vars.css"
|
import "@spectrum-css/typography/dist/index-vars.css"
|
||||||
|
|
||||||
// Sizes
|
// Sizes
|
||||||
export let size = "M"
|
export let size: "S" | "M" | "L" = "M"
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<code class="spectrum-Code spectrum-Code--size{size}">
|
<code class="spectrum-Code spectrum-Code--size{size}">
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import "@spectrum-css/typography/dist/index-vars.css"
|
import "@spectrum-css/typography/dist/index-vars.css"
|
||||||
|
|
||||||
export let size = "M"
|
export let size: "S" | "M" | "L" = "M"
|
||||||
export let serif = false
|
export let serif: boolean = false
|
||||||
export let weight = 600
|
export let weight: number | null = null
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<p
|
<p
|
||||||
|
|
|
@ -65,8 +65,6 @@ export { default as Modal } from "./Modal/Modal.svelte"
|
||||||
export { default as ModalContent, keepOpen } from "./Modal/ModalContent.svelte"
|
export { default as ModalContent, keepOpen } from "./Modal/ModalContent.svelte"
|
||||||
export { default as NotificationDisplay } from "./Notification/NotificationDisplay.svelte"
|
export { default as NotificationDisplay } from "./Notification/NotificationDisplay.svelte"
|
||||||
export { default as Notification } from "./Notification/Notification.svelte"
|
export { default as Notification } from "./Notification/Notification.svelte"
|
||||||
export { default as SideNavigation } from "./SideNavigation/Navigation.svelte"
|
|
||||||
export { default as SideNavigationItem } from "./SideNavigation/Item.svelte"
|
|
||||||
export { default as Context } from "./context"
|
export { default as Context } from "./context"
|
||||||
export { default as Table } from "./Table/Table.svelte"
|
export { default as Table } from "./Table/Table.svelte"
|
||||||
export { default as Tabs } from "./Tabs/Tabs.svelte"
|
export { default as Tabs } from "./Tabs/Tabs.svelte"
|
||||||
|
|
Loading…
Reference in New Issue