UNPKG

tldraw

Version:

A tiny little drawing editor.

84 lines (83 loc) 3.26 kB
import { jsx, jsxs } from "react/jsx-runtime"; import { tlmenus, useEditor } from "@tldraw/editor"; import classNames from "classnames"; import * as React from "react"; import { useTranslation } from "../../hooks/useTranslation/useTranslation.mjs"; import { TldrawUiButtonIcon } from "../primitives/Button/TldrawUiButtonIcon.mjs"; import { TldrawUiButtonLabel } from "../primitives/Button/TldrawUiButtonLabel.mjs"; import { TldrawUiPopover, TldrawUiPopoverContent, TldrawUiPopoverTrigger } from "../primitives/TldrawUiPopover.mjs"; import { TldrawUiToolbar, TldrawUiToolbarButton } from "../primitives/TldrawUiToolbar.mjs"; import { TldrawUiMenuContextProvider } from "../primitives/menus/TldrawUiMenuContext.mjs"; function DropdownPickerInner({ id, label, uiType, stylePanelType, style, items, type, value, onValueChange }) { const msg = useTranslation(); const editor = useEditor(); const [isOpen, setIsOpen] = React.useState(false); const icon = React.useMemo( () => items.find((item) => value.type === "shared" && item.value === value.value)?.icon, [items, value] ); const stylePanelName = msg(`style-panel.${stylePanelType}`); const titleStr = value.type === "mixed" ? msg("style-panel.mixed") : stylePanelName + " \u2014 " + msg(`${uiType}-style.${value.value}`); const labelStr = label ? msg(label) : ""; const popoverId = `style panel ${id}`; return /* @__PURE__ */ jsxs(TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [ /* @__PURE__ */ jsx(TldrawUiPopoverTrigger, { children: /* @__PURE__ */ jsxs( TldrawUiToolbarButton, { type, "data-testid": `style.${uiType}`, "data-direction": "left", title: titleStr, children: [ labelStr && /* @__PURE__ */ jsx(TldrawUiButtonLabel, { children: labelStr }), /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: icon ?? "mixed" }) ] } ) }), /* @__PURE__ */ jsx(TldrawUiPopoverContent, { side: "left", align: "center", children: /* @__PURE__ */ jsx( TldrawUiToolbar, { label: labelStr, className: classNames("tlui-buttons__grid", `tlui-buttons__${stylePanelType}`), children: /* @__PURE__ */ jsx(TldrawUiMenuContextProvider, { type: "icons", sourceId: "style-panel", children: items.map((item) => { return /* @__PURE__ */ jsx( TldrawUiToolbarButton, { type: "icon", "data-testid": `style.${uiType}.${item.value}`, title: stylePanelName + " \u2014 " + msg(`${uiType}-style.${item.value}`), isActive: icon === item.icon, onClick: () => { editor.markHistoryStoppingPoint("select style dropdown item"); onValueChange(style, item.value); tlmenus.deleteOpenMenu(popoverId, editor.contextId); setIsOpen(false); }, children: /* @__PURE__ */ jsx(TldrawUiButtonIcon, { icon: item.icon }) }, item.value ); }) }) } ) }) ] }); } const DropdownPicker = React.memo(DropdownPickerInner); export { DropdownPicker }; //# sourceMappingURL=DropdownPicker.mjs.map