UNPKG

@mantine/spotlight

Version:

Command center components for react and Mantine

90 lines (89 loc) 3.14 kB
"use client"; import { spotlight, spotlightStore } from "./spotlight.store.mjs"; import { isActionsGroup } from "./is-actions-group.mjs"; import { defaultSpotlightFilter } from "./default-spotlight-filter.mjs"; import { limitActions } from "./limit-actions.mjs"; import Spotlight_module_default from "./Spotlight.module.mjs"; import { SpotlightAction } from "./SpotlightAction.mjs"; import { SpotlightActionsGroup } from "./SpotlightActionsGroup.mjs"; import { SpotlightActionsList } from "./SpotlightActionsList.mjs"; import { SpotlightEmpty } from "./SpotlightEmpty.mjs"; import { SpotlightFooter } from "./SpotlightFooter.mjs"; import { SpotlightRoot } from "./SpotlightRoot.mjs"; import { SpotlightSearch } from "./SpotlightSearch.mjs"; import { useUncontrolled } from "@mantine/hooks"; import { factory, getDefaultZIndex, useProps } from "@mantine/core"; import { jsx, jsxs } from "react/jsx-runtime"; //#region packages/@mantine/spotlight/src/Spotlight.tsx const defaultProps = { size: 600, yOffset: 80, limit: Infinity, zIndex: getDefaultZIndex("max"), overlayProps: { backgroundOpacity: .35, blur: 7 }, transitionProps: { duration: 200, transition: "pop" }, store: spotlightStore, filter: defaultSpotlightFilter, clearQueryOnClose: true, closeOnActionTrigger: true, shortcut: "mod + K" }; const Spotlight = factory((_props) => { const { searchProps, filter, query, onQueryChange, actions, nothingFound, highlightQuery, limit, scrollAreaProps, ...others } = useProps("Spotlight", defaultProps, _props); const [_query, setQuery] = useUncontrolled({ value: query, defaultValue: "", finalValue: "", onChange: onQueryChange }); const filteredActions = limitActions(filter(_query, actions), limit).map((item) => { if (isActionsGroup(item)) { const items = item.actions.map(({ id, ...actionData }) => /* @__PURE__ */ jsx(SpotlightAction, { highlightQuery, ...actionData }, id)); return /* @__PURE__ */ jsx(SpotlightActionsGroup, { label: item.group, children: items }, item.group); } return /* @__PURE__ */ jsx(SpotlightAction, { highlightQuery, ...item }, item.id); }); return /* @__PURE__ */ jsxs(SpotlightRoot, { ...others, query: _query, onQueryChange: setQuery, children: [ /* @__PURE__ */ jsx(SpotlightSearch, { ...searchProps }), filteredActions.length > 0 && /* @__PURE__ */ jsx(SpotlightActionsList, { ...scrollAreaProps, children: filteredActions }), filteredActions.length === 0 && nothingFound && /* @__PURE__ */ jsx(SpotlightEmpty, { children: nothingFound }) ] }); }); Spotlight.classes = Spotlight_module_default; Spotlight.displayName = "@mantine/spotlight/Spotlight"; Spotlight.Search = SpotlightSearch; Spotlight.ActionsList = SpotlightActionsList; Spotlight.Action = SpotlightAction; Spotlight.Empty = SpotlightEmpty; Spotlight.ActionsGroup = SpotlightActionsGroup; Spotlight.Footer = SpotlightFooter; Spotlight.Root = SpotlightRoot; Spotlight.open = spotlight.open; Spotlight.close = spotlight.close; Spotlight.toggle = spotlight.toggle; //#endregion export { Spotlight }; //# sourceMappingURL=Spotlight.mjs.map