@molecule/app-sort-picker-vue
Feature · sort-picker · App (browser) · v1.1.2 · Apache-2.0
Standalone single-select sort menu with options and label
npm install @molecule/app-sort-picker-vueHow it works
@molecule/app-sort-picker-vue 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.
import { defineComponent, h, ref } from 'vue'
import { SortPicker } from '@molecule/app-sort-picker-vue'
const ListToolbar = defineComponent({
setup() {
const sort = ref('newest')
return () =>
h(SortPicker, {
value: sort.value,
onChange: (value: string) => {
sort.value = value
},
options: [
{ value: 'newest', label: 'Newest' },
{ value: 'oldest', label: 'Oldest' },
{ value: 'popular', label: 'Most Popular' },
],
})
},
})Works with: @molecule/app-ui, @molecule/app-ui-vue, @molecule/app-vue
Reference
Vue sort-by picker.
Exports <SortPicker> — single-select wrapper around <Select> from
@molecule/app-ui-vue with a conventional "Sort by" label — and the
SortOption type. Different from <FilterBar>, which manages multiple
filter fields. It is the Vue counterpart of
@molecule/app-sort-picker-react: the same props (React names) and the
same DOM for the same input.
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.tsJSDoc, not this file.
Quick Start
import { defineComponent, h, ref } from 'vue'
import { SortPicker } from '@molecule/app-sort-picker-vue'
const ListToolbar = defineComponent({
setup() {
const sort = ref('newest')
return () =>
h(SortPicker, {
value: sort.value,
onChange: (value: string) => {
sort.value = value
},
options: [
{ value: 'newest', label: 'Newest' },
{ value: 'oldest', label: 'Oldest' },
{ value: 'popular', label: 'Most Popular' },
],
})
},
})
Type
feature
Installation
npm install @molecule/app-sort-picker-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
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
* node.
*/
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 renders as nodes — it is never stringified. It arrives as a prop
* or as the same-named slot; both work. When you pass a non-string node,
* also pass `SortPickerProps.ariaLabel` to give the select an
* accessible name.
*/
label?: VNodeChild
/**
* 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
Standalone sort-by selector. Thin wrapper around <Select> with a
conventional "Sort by:" label and a focused single-select API.
const SortPicker: DefineComponent<
ExtractPropTypes<{
value: { type: StringConstructor; required: true }
options: { type: PropType<SortOption[]>; required: true }
label: null
ariaLabel: StringConstructor
labelPosition: { type: PropType<'inline' | 'above'>; default: string }
className: StringConstructor
}>,
() => VNode,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
'change'[],
'change',
PublicProps,
Readonly<
ExtractPropTypes<{
value: { type: StringConstructor; required: true }
options: { type: PropType<SortOption[]>; required: true }
label: null
ariaLabel: StringConstructor
labelPosition: { type: PropType<'inline' | 'above'>; default: string }
className: StringConstructor
}>
> &
Readonly<{ onChange?: ((...args: any[]) => any) | undefined }>,
{ labelPosition: 'inline' | 'above' },
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props— Component props (seeSortPickerProps).
Returns: The sort picker component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui^1.0.1@molecule/app-ui-vue^1.1.0@molecule/app-vue^3.13.0 || ^4.0.0vue^3.4.0
Runtime Dependencies
-
@molecule/app-ui -
@molecule/app-ui-vue -
@molecule/app-vue -
vue -
Must render inside the app's i18n provider and with a ClassMap bond wired (
useTranslation()/getClassMap()throw otherwise). -
SortOption.labelis a plainstring— a native<select>/<option>can only display text, so it is rendered as the option's text child. -
The outer
labelprop is a node rendered as-is, so icons/styled elements display as nodes. It arrives as a prop or as the same-named slot; both work. Whenlabelis a non-string node, passariaLabelto name the select (a node cannot be anaria-label). -
The default "Sort by" label uses the
sort.labeli18n key; passlabelto override.
Translations
Translation strings are provided by @molecule/app-locales-sort-picker.