@molecule/app-sort-picker-svelte

Feature · sort-picker · App (browser) · v1.1.3 · Apache-2.0

Standalone single-select sort menu with options and label

npm install @molecule/app-sort-picker-svelte

npm · Source on GitHub

How it works

@molecule/app-sort-picker-svelte is a ready-made sort-picker feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.

<script lang="ts">
  import { SortPicker } from '@molecule/app-sort-picker-svelte'

  let sort = $state('newest')
  const options = [
    { value: 'newest', label: 'Newest' },
    { value: 'oldest', label: 'Oldest' },
    { value: 'popular', label: 'Most Popular' },
  ]
</script>

<SortPicker {options} value={sort} onChange={(value) => (sort = value)} />

Works with: @molecule/app-svelte, @molecule/app-ui, @molecule/app-ui-svelte

Reference

Svelte sort-by picker — the Svelte counterpart of @molecule/app-sort-picker-react, with the same props and the same DOM.

Exports SortPicker — a single-select wrapper around <Select> from @molecule/app-ui-svelte with a conventional "Sort by" label — and the SortOption type. Different from <FilterBar>, which manages multiple filter fields.

Props: value, onChange(value), options ({ value, label }[]), label, ariaLabel, labelPosition ('inline' | 'above', default inline), className.

Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit src/index.ts JSDoc, not this file.

Quick Start

<script lang="ts">
  import { SortPicker } from '@molecule/app-sort-picker-svelte'

  let sort = $state('newest')
  const options = [
    { value: 'newest', label: 'Newest' },
    { value: 'oldest', label: 'Oldest' },
    { value: 'popular', label: 'Most Popular' },
  ]
</script>

<SortPicker {options} value={sort} onChange={(value) => (sort = value)} />

Type

feature

Installation

npm install @molecule/app-sort-picker-svelte @molecule/app-svelte @molecule/app-ui @molecule/app-ui-svelte svelte

API

Interfaces

SortOption

A single option entry for the SortPicker select list.

interface SortOption<T extends string = string> {
  value: T
  /**
   * Option label. A native `<select>`/`<option>` can only display text,
   * so this is a plain `string` — it is rendered as the option's text
   * child (never `String()`-coerced). For a rich label above/beside the
   * control, use the `SortPickerProps.label` prop, which accepts a
   * snippet.
   */
  label: string
}

SortPickerProps

Props accepted by the SortPicker component (the React package's props).

interface SortPickerProps<T extends string = string> {
  /** The currently selected option value. */
  value: T
  /** Called with the selected value when the user picks an option. */
  onChange: (value: T) => void
  /** The options to list. */
  options: SortOption<T>[]
  /**
   * Optional label rendered above or to the left of the select. A node
   * value arrives as a snippet and renders as nodes — it is never
   * stringified. A plain string renders as text. When you pass a node, also
   * pass `SortPickerProps.ariaLabel` to give the select an accessible
   * name.
   */
  label?: Snippet | string
  /**
   * Accessible name for the underlying `<select>`. Defaults to `label`
   * when it is a plain string, otherwise the translated "Sort by".
   */
  ariaLabel?: string
  /** Where to render the label. Defaults to `'inline'`. */
  labelPosition?: 'inline' | 'above'
  /** Extra classes. */
  className?: string
}

Constants

SortPicker

const SortPicker: LegacyComponentType

Injection Notes

Requirements

Peer dependencies:

  • @molecule/app-svelte ^3.13.0 || ^4.0.0
  • @molecule/app-ui ^1.0.1
  • @molecule/app-ui-svelte ^1.1.0
  • svelte ^5.29.0

Runtime Dependencies

  • @molecule/app-svelte

  • @molecule/app-ui

  • @molecule/app-ui-svelte

  • svelte

  • Must render inside the app's i18n provider and with a ClassMap bond wired (useTranslation() / getClassMap() throw otherwise).

  • SortOption.label is a plain string — a native <select>/<option> can only display text, so it is rendered as the option's text child.

  • The outer label prop is a snippet when it is a node, so icons/styled elements display as nodes; a plain string renders as text. When it is a node, pass ariaLabel to name the select (a node cannot be an aria-label).

  • The default "Sort by" label uses the sort.label i18n key; pass label to override.

Translations

Translation strings are provided by @molecule/app-locales-sort-picker.