Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript conversion for some BBUI components #15623

Merged
merged 10 commits into from
Mar 3, 2025
6 changes: 3 additions & 3 deletions packages/bbui/src/ClearButton/ClearButton.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
export let small = false
export let disabled
<script lang="ts">
export let small: boolean = false
export let disabled: boolean = false
</script>

<button
Expand Down
22 changes: 11 additions & 11 deletions packages/bbui/src/Form/Checkbox.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<script>
<script lang="ts">
import Field from "./Field.svelte"
import Checkbox from "./Core/Checkbox.svelte"
import { createEventDispatcher } from "svelte"

export let value = null
export let label = null
export let labelPosition = "above"
export let text = null
export let disabled = false
export let error = null
export let size = "M"
export let helpText = null
export let value: boolean | undefined = undefined
export let label: string | undefined = undefined
export let labelPosition: "above" | "below" = "above"
export let text: string | undefined = undefined
export let disabled: boolean = false
export let error: string | undefined = undefined
export let size: "S" | "M" | "L" | "XL" = "M"
export let helpText: string | undefined = undefined

const dispatch = createEventDispatcher()
const onChange = e => {
const onChange = (e: CustomEvent<boolean>) => {
value = e.detail
dispatch("change", e.detail)
}
</script>

<Field {helpText} {label} {labelPosition} {error}>
<Checkbox {error} {disabled} {text} {value} {size} on:change={onChange} />
<Checkbox {disabled} {text} {value} {size} on:change={onChange} />
</Field>
2 changes: 1 addition & 1 deletion packages/bbui/src/Link/Link.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
export let secondary: boolean = false
export let overBackground: boolean = false
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 tooltip: string | null = null

Expand Down
63 changes: 0 additions & 63 deletions packages/bbui/src/SideNavigation/Item.svelte

This file was deleted.

13 changes: 0 additions & 13 deletions packages/bbui/src/SideNavigation/Navigation.svelte

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,26 @@ export const BANNER_TYPES = {
WARNING: "warning",
}

interface BannerConfig {
message?: string
type?: string
extraButtonText?: string
extraButtonAction?: () => void
onChange?: () => void
}

interface DefaultConfig {
messages: BannerConfig[]
}

export function createBannerStore() {
const DEFAULT_CONFIG = {
const DEFAULT_CONFIG: DefaultConfig = {
messages: [],
}

const banner = writable(DEFAULT_CONFIG)
const banner = writable<DefaultConfig>(DEFAULT_CONFIG)

const show = async (
// eslint-disable-next-line
config = { message, type, extraButtonText, extraButtonAction, onChange }
) => {
const show = async (config: BannerConfig = {}) => {
banner.update(store => {
return {
...store,
Expand All @@ -27,7 +36,7 @@ export function createBannerStore() {
}

const showStatus = async () => {
const config = {
const config: BannerConfig = {
message: "Some systems are experiencing issues",
type: BANNER_TYPES.NEGATIVE,
extraButtonText: "View Status",
Expand All @@ -37,18 +46,24 @@ export function createBannerStore() {
await queue([config])
}

const queue = async entries => {
const priority = {
const queue = async (entries: Array<BannerConfig>) => {
const priority: Record<string, number> = {
[BANNER_TYPES.NEGATIVE]: 0,
[BANNER_TYPES.WARNING]: 1,
[BANNER_TYPES.INFO]: 2,
}
banner.update(store => {
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 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 {
...store,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ import { writable } from "svelte/store"

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 = () => {
const timeoutIds = new Set()
const _notifications = writable([], () => {
const timeoutIds = new Set<ReturnType<typeof setTimeout>>()
const _notifications = writable<Notification[]>([], () => {
return () => {
// clear all the timers
timeoutIds.forEach(timeoutId => {
Expand All @@ -21,7 +33,7 @@ export const createNotificationStore = () => {
}

const send = (
message,
message: string,
{
type = "default",
icon = "",
Expand All @@ -30,7 +42,15 @@ export const createNotificationStore = () => {
actionMessage = null,
wide = false,
dismissTimeout = NOTIFICATION_TIMEOUT,
}
}: {
type?: string
icon?: string
autoDismiss?: boolean
action?: (() => void) | null
actionMessage?: string | null
wide?: boolean
dismissTimeout?: number
} = {}
) => {
if (block) {
return
Expand Down Expand Up @@ -60,7 +80,7 @@ export const createNotificationStore = () => {
}
}

const dismissNotification = id => {
const dismissNotification = (id: string) => {
_notifications.update(state => {
return state.filter(n => n.id !== id)
})
Expand All @@ -71,17 +91,18 @@ export const createNotificationStore = () => {
return {
subscribe,
send,
info: msg => send(msg, { type: "info", icon: "Info" }),
error: msg =>
info: (msg: string) => send(msg, { type: "info", icon: "Info" }),
error: (msg: string) =>
send(msg, { type: "error", icon: "Alert", autoDismiss: false }),
warning: msg => send(msg, { type: "warning", icon: "Alert" }),
success: msg => send(msg, { type: "success", icon: "CheckmarkCircle" }),
warning: (msg: string) => send(msg, { type: "warning", icon: "Alert" }),
success: (msg: string) =>
send(msg, { type: "success", icon: "CheckmarkCircle" }),
blockNotifications,
dismiss: dismissNotification,
}
}

function id() {
function id(): string {
return "_" + Math.random().toString(36).slice(2, 9)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/bbui/src/Table/ArrayRenderer.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script>
<script lang="ts">
import "@spectrum-css/label/dist/index-vars.css"
import Badge from "../Badge/Badge.svelte"

export let value
export let value: string | string[]

const displayLimit = 5

Expand Down
10 changes: 5 additions & 5 deletions packages/bbui/src/Table/AttachmentRenderer.svelte
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script>
<script lang="ts">
import Link from "../Link/Link.svelte"

export let value
export let value: { name: string; url: string; extension: string }[]

const displayLimit = 5
$: attachments = value?.slice(0, displayLimit) ?? []
$: leftover = (value?.length ?? 0) - attachments.length

const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
const isImage = extension => {
return imageExtensions.includes(extension?.toLowerCase())
const imageExtensions: string[] = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
const isImage = (extension: string | undefined): boolean => {
return imageExtensions.includes(extension?.toLowerCase() ?? "")
}
</script>

Expand Down
4 changes: 2 additions & 2 deletions packages/bbui/src/Table/BoldRenderer.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
export let value
<script lang="ts">
export let value: string
</script>

<div class="bold">{value}</div>
Expand Down
4 changes: 2 additions & 2 deletions packages/bbui/src/Table/BooleanRenderer.svelte
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script>
<script lang="ts">
import "@spectrum-css/checkbox/dist/index-vars.css"

export let value
export let value: boolean
</script>

<label
Expand Down
20 changes: 10 additions & 10 deletions packages/bbui/src/Table/CellRenderer.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script>
<script lang="ts">
import StringRenderer from "./StringRenderer.svelte"
import BooleanRenderer from "./BooleanRenderer.svelte"
import DateTimeRenderer from "./DateTimeRenderer.svelte"
Expand All @@ -8,14 +8,14 @@
import InternalRenderer from "./InternalRenderer.svelte"
import { processStringSync } from "@budibase/string-templates"

export let row
export let schema
export let value
export let customRenderers = []
export let snippets
export let row: Record<string, any>
export let schema: Record<string, any>
export let value: Record<string, any>
export let customRenderers: { column: string; component: any }[] = []
export let snippets: any

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same

let renderer
const typeMap = {
let renderer: any
const typeMap: Record<string, any> = {
boolean: BooleanRenderer,
datetime: DateTimeRenderer,
link: RelationshipRenderer,
Expand All @@ -33,15 +33,15 @@
$: renderer = customRenderer?.component ?? typeMap[type] ?? StringRenderer
$: 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
if (schema?.type === "datetime" && schema?.template) {
return "string"
}
return schema?.type || "string"
}

const getCellValue = (value, template) => {
const getCellValue = (value: any, template: string | undefined): any => {
if (!template) {
return value
}
Expand Down
4 changes: 2 additions & 2 deletions packages/bbui/src/Table/CodeRenderer.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
export let value
<script lang="ts">
export let value: string
</script>

<code>{value}</code>
Expand Down
Loading
Loading