Types

Every type theui-svelte exports, in alphabetical order, with what it is for and which components use it.

Importing Types

The types live in a subpath of their own, so you can pull in the ones you need without touching the components.

Typescript
import type { ANIMATE_SPEED, ROUNDED } from "theui-svelte/type"

let speed: ANIMATE_SPEED = "fast"
let corner: ROUNDED = "lg"

You rarely have to name them: passing a string straight to a prop is checked against these unions anyway. They earn their keep when you keep settings in a variable, take props of your own that you pass on to a component, or write a function that returns one.

Types vanish when your app is built. They are there for your editor and for svelte-check, and cost nothing at runtime.

Accordion Size

Padding of an accordion heading and its body. Set on Accordion, where every AccordionItem inside picks it up.

Typescript
type ACCORDION_SIZE = "compact" | "default" | "large"

Animation Speed Type

How long a transition takes. Nearly every component that moves takes it as animationSpeed, and "none" turns the transition off, which is the value to reach for when an element should not animate at all.

Typescript
type ANIMATE_SPEED = "none" | "slower" | "slow" | "normal" | "fast" | "faster"

Avatar Size Type

Diameter of an Avatar. An AvatarGroup takes it too and hands it to every avatar inside, so the stack stays even.

Typescript
type AVATAR_SIZE = "xs" | "sm" | "md" | "lg" | "xl" | "2xl"

Avatar Status Type

The dot on an Avatar. Leave status unset for no dot at all.

Typescript
type AVATAR_STATUS = "online" | "offline" | "busy" | "away"

Button Size Type

Padding and text size of a Button, and of a ButtonGroup or Pagination that passes it down. "auto" drops the padding so the button takes the size of what you put inside it.

Typescript
type BUTTON_SIZE = "xs" | "sm" | "md" | "lg" | "xl" | "auto"

Card Image Type

The img prop of a Card. Anything else you add to the object, such as loading or width, is passed to the <img> element.

Typescript
type CARD_IMAGE_TYPE = {
  class?: string
  src?: string
  alt?: string
  [key: string]: unknown
}

Combobox Item Type

What you put in the items array of a Combobox. A bare string or number is both the value and the text; an object splits the two and can disable an entry or file it under a group heading.

Typescript
type COMBOBOX_ITEM = string | number | {
  value?: unknown
  text?: string
  disabled?: boolean
  // Options with the same group name are shown together under its heading
  group?: string
}

Combobox Option Type

The same option once the component has filled in what you left out. This is the shape handed to the option snippet and to a filter function of your own, so every field is there to read.

Typescript
type COMBOBOX_OPTION = {
  value: unknown
  text: string
  disabled: boolean
  group?: string
}

Core Type

The library wide defaults you pass to setTheuiDefaults. Every key is optional. animationSpeed, shadow and reset are fallbacks, so anything you set on a component, a Form or a Fieldset beats them. rounded is an off switch instead: false squares off every component whatever its rounded prop says. See Global defaults.

Typescript
type CORE = {
  rounded?: boolean
  animationSpeed?: ANIMATE_SPEED
  reset?: boolean
  shadow?: SHADOW
}

Divider Align Type

Where the label of a Divider sits along the line.

Typescript
type DIVIDER_ALIGN = "start" | "center" | "end"

Divider Orientation Type

Which way a Divider runs. A vertical one needs a parent with a height, since it stretches to fill it.

Typescript
type DIVIDER_ORIENTATION = "horizontal" | "vertical"

Divider Variant Type

The line style of a Divider.

Typescript
type DIVIDER_VARIANT = "solid" | "dashed" | "dotted"

Dropzone Rejection Type

What FileDropzone hands to onreject for each file it turned away, with the reason it did. Remember that these checks run in the browser, so the server has to make them again.

Typescript
type DROPZONE_REJECTION = {
  file: File
  // Why the file was not accepted
  reason: "type" | "size" | "count"
}

A rejection is a good moment to tell people what went wrong, rather than letting the file disappear without a word.

Svelte
<FileDropzone
  accept="image/*"
  maxSize={2 * 1024 * 1024}
  onreject={(files) => files.forEach((f) => notify(`${f.file.name}: ${f.reason}`))}
/>

Input Size Type

Height and text size of a form control. Set it on one field, or on the Form or Fieldset around a group of them, and every field inside follows.

Typescript
type INPUT_SIZE = "sm" | "md" | "lg" | "xl"

Input Type

The type of an Input. "textarea" is in the list because the component renders a <textarea> for it instead of an <input>.

Typescript
type INPUT_TYPE =
  | "date" | "datetime-local" | "email" | "month" | "number"
  | "password" | "tel" | "text" | "time" | "url" | "week"
  | "search" | "textarea"

Input Variant Type

How a form control is drawn: with a border around it, or flat with a line under it. A flat field floats its label by default.

Typescript
type INPUT_VARIANT = "bordered" | "flat"

Notification Configuration

The third argument of notify(), which settles how that one notification behaves and looks. removeAfter is a number of milliseconds, or false to leave the notification until it is dismissed.

Typescript
type NOTIFY_CONFIG = {
  removeAfter?: number | false
  removeOnClick?: boolean
  rounded?: ROUNDED
  theme?: "default" | "soft" | "gradient"
  variant?: "card" | "borderTop" | "borderBottom" | "borderStart"
}
Svelte
notify("Saved", "success", { removeAfter: 6000, variant: "borderStart" })

Where the notifications appear is not set here: that is the position prop of the Notification component, which you place once in your layout.

Notification Data Type

One notification as the library keeps it while it is on screen. You do not build this yourself, notify() does, but it is the shape you read if you render notifications your own way.

Typescript
type NOTIFICATION_DATA_TYPE = {
  msg: string
  type: NOTIFICATION_TYPE
  CONFIG: NOTIFY_CONFIG & { id: string }
  removing?: boolean
}

Notification Position

Which corner or edge the Notification component stacks its messages in. It is set once, on the component, not per message.

Typescript
type NOTIFICATION_POSITION =
  | "top-end" | "top-center" | "top-start"
  | "bottom-end" | "bottom-center" | "bottom-start"

Notification Types

The second argument of notify(), which picks the colour and the icon of the message.

Typescript
type NOTIFICATION_TYPE = "error" | "info" | "success" | "warning"

OTP Type

What each box of an OtpInput accepts. "number" brings up the numeric keypad on a phone, and "password" hides the characters as they are typed.

Typescript
type OTP_TYPE = "text" | "number" | "password"

Placement

Where a Popover or a Tooltip opens in relation to the element it belongs to. This one comes from Floating UI, which does the positioning, so import it from @floating-ui/dom rather than from this library.

Typescript
import type { Placement } from "@floating-ui/dom"

type Placement =
  | "top" | "top-start" | "top-end"
  | "right" | "right-start" | "right-end"
  | "bottom" | "bottom-start" | "bottom-end"
  | "left" | "left-start" | "left-end"

It is a starting point, not a promise: when there is no room on that side, the element is flipped or shifted to somewhere it fits.

Range Tick Type

One mark under a Range. A number puts a mark at that value; the object form labels it as well.

Typescript
type RANGE_TICK = number | { value: number; label?: string }
Svelte
<Range min={0} max={100} ticks={[0, { value: 50, label: "Half" }, 100]} />

Rating Size Type

Size of the stars in a Rating.

Typescript
type RATING_SIZE = "sm" | "md" | "lg" | "xl"

Rounded Type

How round the corners of a component are. "none" squares them off and "full" makes a pill, which is why a full-rounded button looks different from a full-rounded card.

Typescript
type ROUNDED = "sm" | "md" | "lg" | "xl" | "2xl" | "full" | "none" | undefined

Select Data Type

One option in the data array of a Select. Leave value out and the text is submitted instead.

Typescript
type SELECT_DATA = { disabled?: boolean; text: string; value?: unknown }

Shadow Types

Depth of the shadow under a Card, a Button or a Popover. "inner" puts the shadow inside the element rather than under it.

Typescript
type SHADOW = "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | "inner" | "none"

Skeleton Animation Type

How a Skeleton shows that something is loading. Pick "none" for a still placeholder.

Typescript
type SKELETON_ANIMATION = "pulse" | "wave" | "none"

Skeleton Variant Type

The shape of a Skeleton: a block, a circle for an avatar, or lines of text.

Typescript
type SKELETON_VARIANT = "rect" | "circle" | "text"

Slider Direction Type

Which way a Slider moves. A vertical slider needs a height, and its arrow keys become up and down.

Typescript
type SLIDER_DIRECTION = "horizontal" | "vertical"

Slider Effect Type

How one slide gives way to the next.

Typescript
type SLIDER_EFFECT = "slide" | "fade" | "zoom" | "flip" | "cube"

Slider Responsive Type

Several Slider props take either one value for every screen, or a value per screen size. perView, gap and peek all work this way.

Typescript
type SLIDER_BREAKPOINT = "base" | "sm" | "md" | "lg" | "xl" | "2xl"

// A single value, or a value per screen size like { base: 1, md: 2, lg: 3 }
type SLIDER_RESPONSIVE<T> = T | Partial<Record<SLIDER_BREAKPOINT, T>>
Svelte
<Slider perView={{ base: 1, md: 2, lg: 3 }} gap={16} />

A screen size you leave out keeps the value of the size below it, so base is worth setting.

Spinner Size Type

Size of a Spinner.

Typescript
type SPINNER_SIZE = "xs" | "sm" | "md" | "lg" | "xl"

Spinner Variant Type

Which spinner is drawn: a turning ring, three bouncing dots, or a pinging circle.

Typescript
type SPINNER_VARIANT = "ring" | "dots" | "ping"

Table Data Type

The data prop of a Table: either an array of rows of plain strings, or an array of objects, in which case keys decides which fields are shown and in what order.

Typescript
type TABLE_DATA = string[] | Record<string, unknown>[]

Wizard Step Info Type

What a FormStep tells the FormWizard around it. A step whose validate returns false holds the wizard where it is, and one marked optional can be skipped.

Typescript
type WIZARD_STEP_INFO = {
  readonly title?: string
  readonly description?: string
  readonly optional?: boolean
  readonly validate?: () => boolean | Promise<boolean>
}

validate may return a promise, so a step can wait for a check on your server before it lets the wizard move on.

Internal Types

These are exported because the components pass them between themselves, through Svelte context. You never set them, and nothing asks you for one, but they are listed here so nothing in the package is a mystery.

  • ACCORDION_CONTEXT - settings an Accordion shares with its items.
  • AVATAR_GROUP_CTX - how an AvatarGroup counts its avatars and decides which to hide behind the "+N" one.
  • BTN_QAB_CTX - settings a Qab shares with its items.
  • DROPDOWN_CTX and LIST_GROUP_CTX - classes a Dropdown or a ListGroup passes to its children.
  • INPUT_CONFIG - the settings a Form or Fieldset hands down to the fields inside it, such as size, variant, rounded and floatingLabel.
  • NAV_CTX - the configuration a Navbar shares with its links, groups and dropdowns.
  • SLIDE_INFO, SLIDE_STATE and SLIDER_CTX - how a Slide registers itself with the Slider and reads back where it stands.
  • TABLE_CONTEXT and TABS_CONTEXT - what a Table or Tabs shares with its rows, cells, tabs and panels.
  • WIZARD_CTX and WIZARD_STEP_STATE - how a FormStep registers with its wizard and learns whether it is the active step.
  • ROUNDED_ITEM_TYPES and ROUNDED_SIDES - used by the roundedClass() helper to round the right corners of a cell in a group.