@ariakit/react-core
Version:
Ariakit React core
106 lines (104 loc) • 3.03 kB
JavaScript
"use client";
import {
useComboboxProviderContext
} from "../__chunks/6C2ASARV.js";
import "../__chunks/467XRHWL.js";
import "../__chunks/2LVHRIRC.js";
import "../__chunks/FYYAZUDI.js";
import "../__chunks/NO3UEYQ2.js";
import {
useButton
} from "../__chunks/XTCKRCGH.js";
import "../__chunks/EZ4UPVW6.js";
import "../__chunks/3F6D4KUU.js";
import "../__chunks/SWN3JYXT.js";
import {
useStoreState
} from "../__chunks/SOQQIDO4.js";
import "../__chunks/CTVD4XJH.js";
import {
createElement,
createHook,
forwardRef
} from "../__chunks/L4OUMOCQ.js";
import {
useEvent,
useWrapElement
} from "../__chunks/W2TDKEPX.js";
import "../__chunks/AZVQSWGA.js";
// src/combobox/combobox-cancel.tsx
import { invariant } from "@ariakit/core/utils/misc";
import { Fragment } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
var TagName = "button";
var children = /* @__PURE__ */ jsxs(
"svg",
{
"aria-hidden": "true",
display: "block",
viewBox: "0 0 16 16",
fill: "none",
stroke: "currentColor",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: 1.5,
width: "1em",
height: "1em",
pointerEvents: "none",
children: [
/* @__PURE__ */ jsx("line", { x1: "5", y1: "5", x2: "11", y2: "11" }),
/* @__PURE__ */ jsx("line", { x1: "5", y1: "11", x2: "11", y2: "5" })
]
}
);
var useComboboxCancel = createHook(
function useComboboxCancel2({ store, hideWhenEmpty, ...props }) {
const context = useComboboxProviderContext();
store = store || context;
invariant(
store,
process.env.NODE_ENV !== "production" && "ComboboxCancel must receive a `store` prop or be wrapped in a ComboboxProvider component."
);
const onClickProp = props.onClick;
const onClick = useEvent((event) => {
onClickProp == null ? void 0 : onClickProp(event);
if (event.defaultPrevented) return;
store == null ? void 0 : store.setValue("");
store == null ? void 0 : store.move(null);
});
const comboboxId = useStoreState(store, (state) => {
var _a;
return (_a = state.baseElement) == null ? void 0 : _a.id;
});
const empty = useStoreState(store, (state) => state.value === "");
props = useWrapElement(
props,
(element) => {
if (!hideWhenEmpty) return element;
if (empty) return /* @__PURE__ */ jsx(Fragment, {});
return element;
},
[hideWhenEmpty, empty]
);
props = {
children,
"aria-label": "Clear input",
// This aria-controls will ensure the combobox popup remains visible when
// this element gets focused. This logic is done in the ComboboxPopover
// component.
"aria-controls": comboboxId,
...props,
onClick
};
props = useButton(props);
return props;
}
);
var ComboboxCancel = forwardRef(function ComboboxCancel2(props) {
const htmlProps = useComboboxCancel(props);
return createElement(TagName, htmlProps);
});
export {
ComboboxCancel,
useComboboxCancel
};