* feat: update prettier configuration for print width * chore: apply code formatting to entire repository * fix: remove build files * fix: format issue --------- Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
45 lines
1.4 KiB
TypeScript
45 lines
1.4 KiB
TypeScript
import { Chip } from "@mantine/core";
|
|
|
|
import { useScopedI18n } from "@homarr/translation/client";
|
|
|
|
import { selectNextAction, selectPreviousAction, spotlightStore, triggerSelectedAction } from "./spotlight-store";
|
|
import type { SpotlightActionGroup } from "./type";
|
|
|
|
const disableArrowUpAndDown = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
if (event.key === "ArrowDown") {
|
|
selectNextAction(spotlightStore);
|
|
event.preventDefault();
|
|
} else if (event.key === "ArrowUp") {
|
|
selectPreviousAction(spotlightStore);
|
|
event.preventDefault();
|
|
} else if (event.key === "Enter") {
|
|
triggerSelectedAction(spotlightStore);
|
|
}
|
|
};
|
|
|
|
const focusActiveByDefault = (event: React.FocusEvent<HTMLInputElement>) => {
|
|
const relatedTarget = event.relatedTarget;
|
|
|
|
const isPreviousTargetRadio = relatedTarget && "type" in relatedTarget && relatedTarget.type === "radio";
|
|
if (isPreviousTargetRadio) return;
|
|
|
|
const group = event.currentTarget.parentElement?.parentElement;
|
|
if (!group) return;
|
|
const label = group.querySelector<HTMLLabelElement>("label[data-checked]");
|
|
if (!label) return;
|
|
label.focus();
|
|
};
|
|
|
|
interface Props {
|
|
group: SpotlightActionGroup;
|
|
}
|
|
|
|
export const GroupChip = ({ group }: Props) => {
|
|
const t = useScopedI18n("common.search.group");
|
|
return (
|
|
<Chip key={group} value={group} onFocus={focusActiveByDefault} onKeyDown={disableArrowUpAndDown}>
|
|
{t(group)}
|
|
</Chip>
|
|
);
|
|
};
|