/** * (c) 2026, Micro:bit Educational Foundation and contributors * * SPDX-License-Identifier: MIT */ import { ButtonGroup, Icon, IconButton, NativeSelect } from "@microbit/ui"; import { RiArrowDownLine, RiArrowUpLine } from "react-icons/ri"; import { useIntl } from "react-intl"; import { uiPatternsMessage } from "../messages"; import { ProjectSortField, ProjectSortDirection } from "./types"; export interface ProjectSortInputProps { field: ProjectSortField; onFieldChange: (field: ProjectSortField) => void; direction: ProjectSortDirection; onToggleDirection: () => void; /** * While searching, results are ranked by relevance and the controls are * disabled, showing "Relevance" in place of the field. */ hasSearchQuery: boolean; className?: string; } /** * Sort field select with an attached direction button. */ export const ProjectSortInput = ({ field, onFieldChange, direction, onToggleDirection, hasSearchQuery, className, }: ProjectSortInputProps) => { const intl = useIntl(); const message = (id: Parameters[0]) => intl.formatMessage(uiPatternsMessage(id)); const descending = hasSearchQuery || direction === "desc"; return ( onFieldChange(e.target.value as ProjectSortField)} aria-label={message("ui-patterns.sort-projects-label")} // The adjacent direction button keeps the control from reading as a // plain text field. hideChevron disabled={hasSearchQuery} // Lets the select shrink below its longest option when space is // tight, clipping the text. css={{ fontSize: "lg", background: "white", flex: 1, minW: 0 }} > {hasSearchQuery ? ( ) : ( <> )} ); };