UNPKG

@loke/ui

Version:
182 lines (176 loc) • 10.2 kB
"use client"; var __create = Object.create; var { getPrototypeOf: __getProtoOf, defineProperty: __defProp, getOwnPropertyNames: __getOwnPropNames, getOwnPropertyDescriptor: __getOwnPropDesc } = Object, __hasOwnProp = Object.prototype.hasOwnProperty; function __accessProp(key) { return this[key]; } var __toESMCache_node, __toESMCache_esm, __toESM = (mod, isNodeMode, target) => { var canCache = mod != null && typeof mod === "object"; if (canCache) { var cache = isNodeMode ? __toESMCache_node ??= /* @__PURE__ */ new WeakMap : __toESMCache_esm ??= /* @__PURE__ */ new WeakMap, cached = cache.get(mod); if (cached) return cached; } target = mod != null ? __create(__getProtoOf(mod)) : {}; let to = isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target; if (mod && typeof mod === "object" || typeof mod === "function") { for (let key of __getOwnPropNames(mod)) if (!__hasOwnProp.call(to, key)) __defProp(to, key, { get: __accessProp.bind(mod, key), enumerable: !0 }); } if (canCache) cache.set(mod, to); return to; }, __toCommonJS = (from) => { var entry = (__moduleCache ??= /* @__PURE__ */ new WeakMap).get(from), desc; if (entry) return entry; if (entry = __defProp({}, "__esModule", { value: !0 }), from && typeof from === "object" || typeof from === "function") { for (var key of __getOwnPropNames(from)) if (!__hasOwnProp.call(entry, key)) __defProp(entry, key, { get: __accessProp.bind(from, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return __moduleCache.set(from, entry), entry; }, __moduleCache; var __returnValue = (v) => v; function __exportSetter(name, newValue) { this[name] = __returnValue.bind(null, newValue); } var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0, configurable: !0, set: __exportSetter.bind(all, name) }); }; // src/components/alert-dialog/index.ts var exports_alert_dialog = {}; __export(exports_alert_dialog, { Action: () => Action, AlertDialog: () => AlertDialog, AlertDialogAction: () => AlertDialogAction, AlertDialogCancel: () => AlertDialogCancel, AlertDialogContent: () => AlertDialogContent, AlertDialogDescription: () => AlertDialogDescription, AlertDialogOverlay: () => AlertDialogOverlay, AlertDialogPortal: () => AlertDialogPortal, AlertDialogTitle: () => AlertDialogTitle, AlertDialogTrigger: () => AlertDialogTrigger, Cancel: () => Cancel, Content: () => Content2, Description: () => Description2, Overlay: () => Overlay2, Portal: () => Portal2, Root: () => Root2, Title: () => Title2, Trigger: () => Trigger2, createAlertDialogScope: () => createAlertDialogScope }); module.exports = __toCommonJS(exports_alert_dialog); // src/components/alert-dialog/alert-dialog.tsx var import_compose_events = require("@loke/ui/compose-events"), import_compose_refs = require("@loke/ui/compose-refs"), import_context = require("@loke/ui/context"), DialogPrimitive = __toESM(require("@loke/ui/dialog"), 1), import_dialog = require("@loke/ui/dialog"), import_slot = require("@loke/ui/slot"), import_react = require("react"), jsx_runtime = require("react/jsx-runtime"), ROOT_NAME = "AlertDialog", [createAlertDialogContext, createAlertDialogScope] = import_context.createContextScope(ROOT_NAME, [import_dialog.createDialogScope]), useDialogScope = import_dialog.createDialogScope(), AlertDialog = /* @__PURE__ */ Object.assign((props) => { let { __scopeAlertDialog, ...alertDialogProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Root, { ...dialogScope, ...alertDialogProps, modal: !0 }); }, { displayName: ROOT_NAME }), TRIGGER_NAME = "AlertDialogTrigger", AlertDialogTrigger = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, ...triggerProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Trigger, { ...dialogScope, ...triggerProps, ref: forwardedRef }); }), { displayName: TRIGGER_NAME }), PORTAL_NAME = "AlertDialogPortal", AlertDialogPortal = /* @__PURE__ */ Object.assign((props) => { let { __scopeAlertDialog, ...portalProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Portal, { ...dialogScope, ...portalProps }); }, { displayName: PORTAL_NAME }), OVERLAY_NAME = "AlertDialogOverlay", AlertDialogOverlay = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, ...overlayProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Overlay, { ...dialogScope, ...overlayProps, ref: forwardedRef }); }), { displayName: OVERLAY_NAME }), CONTENT_NAME = "AlertDialogContent", [AlertDialogContentProvider, useAlertDialogContentContext] = createAlertDialogContext(CONTENT_NAME), Slottable = import_slot.createSlottable("AlertDialogContent"), AlertDialogContent = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, children, ...contentProps } = props, dialogScope = useDialogScope(__scopeAlertDialog), contentRef = import_react.useRef(null), composedRefs = import_compose_refs.useComposedRefs(forwardedRef, contentRef), cancelRef = import_react.useRef(null); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.WarningProvider, { contentName: CONTENT_NAME, docsSlug: "alert-dialog", titleName: TITLE_NAME, children: /* @__PURE__ */ jsx_runtime.jsx(AlertDialogContentProvider, { cancelRef, scope: __scopeAlertDialog, children: /* @__PURE__ */ jsx_runtime.jsxs(DialogPrimitive.Content, { role: "alertdialog", ...dialogScope, ...contentProps, onInteractOutside: (event) => event.preventDefault(), onOpenAutoFocus: import_compose_events.composeEventHandlers(contentProps.onOpenAutoFocus, (event) => { event.preventDefault(), cancelRef.current?.focus({ preventScroll: !0 }); }), onPointerDownOutside: (event) => event.preventDefault(), ref: composedRefs, children: [ /* @__PURE__ */ jsx_runtime.jsx(Slottable, { children }), process.env.NODE_ENV === "development" && /* @__PURE__ */ jsx_runtime.jsx(DescriptionWarning, { contentRef }) ] }) }) }); }), { displayName: CONTENT_NAME }), TITLE_NAME = "AlertDialogTitle", AlertDialogTitle = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, ...titleProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Title, { ...dialogScope, ...titleProps, ref: forwardedRef }); }), { displayName: TITLE_NAME }), DESCRIPTION_NAME = "AlertDialogDescription", AlertDialogDescription = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, ...descriptionProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Description, { ...dialogScope, ...descriptionProps, ref: forwardedRef }); }), { displayName: DESCRIPTION_NAME }), ACTION_NAME = "AlertDialogAction", AlertDialogAction = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, ...actionProps } = props, dialogScope = useDialogScope(__scopeAlertDialog); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Close, { ...dialogScope, ...actionProps, ref: forwardedRef }); }), { displayName: ACTION_NAME }), CANCEL_NAME = "AlertDialogCancel", AlertDialogCancel = /* @__PURE__ */ Object.assign(/* @__PURE__ */ import_react.forwardRef((props, forwardedRef) => { let { __scopeAlertDialog, ...cancelProps } = props, { cancelRef } = useAlertDialogContentContext(CANCEL_NAME, __scopeAlertDialog), dialogScope = useDialogScope(__scopeAlertDialog), ref = import_compose_refs.useComposedRefs(forwardedRef, cancelRef); return /* @__PURE__ */ jsx_runtime.jsx(DialogPrimitive.Close, { ...dialogScope, ...cancelProps, ref }); }), { displayName: CANCEL_NAME }), ARIA_ID_SEPARATOR = /\s+/, DescriptionWarning = ({ contentRef }) => { let MESSAGE = `\`${CONTENT_NAME}\` requires a description for the component to be accessible for screen reader users. You can add a description to the \`${CONTENT_NAME}\` by passing a \`${DESCRIPTION_NAME}\` component as a child, which also benefits sighted users by adding visible context to the dialog. Alternatively, you can use your own component as a description by assigning it an \`id\` and passing the same value to the \`aria-describedby\` prop in \`${CONTENT_NAME}\`. If the description is confusing or duplicative for sighted users, you can use the \`@loke/ui/visually-hidden\` primitive as a wrapper around your description component. For more information, see https://design.loke.global/docs/components/alert-dialog`; return import_react.useEffect(() => { let timer = window.setTimeout(() => { if (!contentRef.current?.getAttribute("aria-describedby")?.split(ARIA_ID_SEPARATOR).some((id) => id && document.getElementById(id))) console.warn(MESSAGE); }, 0); return () => window.clearTimeout(timer); }, [MESSAGE, contentRef]), null; }, Root2 = AlertDialog, Trigger2 = AlertDialogTrigger, Portal2 = AlertDialogPortal, Overlay2 = AlertDialogOverlay, Content2 = AlertDialogContent, Action = AlertDialogAction, Cancel = AlertDialogCancel, Title2 = AlertDialogTitle, Description2 = AlertDialogDescription;