tldraw
Version:
A tiny little drawing editor.
110 lines (109 loc) • 5.31 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var DropdownPicker_exports = {};
__export(DropdownPicker_exports, {
DropdownPicker: () => DropdownPicker
});
module.exports = __toCommonJS(DropdownPicker_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_editor = require("@tldraw/editor");
var import_classnames = __toESM(require("classnames"));
var React = __toESM(require("react"));
var import_useTranslation = require("../../hooks/useTranslation/useTranslation");
var import_TldrawUiButtonIcon = require("../primitives/Button/TldrawUiButtonIcon");
var import_TldrawUiButtonLabel = require("../primitives/Button/TldrawUiButtonLabel");
var import_TldrawUiPopover = require("../primitives/TldrawUiPopover");
var import_TldrawUiToolbar = require("../primitives/TldrawUiToolbar");
var import_TldrawUiMenuContext = require("../primitives/menus/TldrawUiMenuContext");
function DropdownPickerInner({
id,
label,
uiType,
stylePanelType,
style,
items,
type,
value,
onValueChange
}) {
const msg = (0, import_useTranslation.useTranslation)();
const editor = (0, import_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__ */ (0, import_jsx_runtime.jsxs)(import_TldrawUiPopover.TldrawUiPopover, { id: popoverId, open: isOpen, onOpenChange: setIsOpen, children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
import_TldrawUiToolbar.TldrawUiToolbarButton,
{
type,
"data-testid": `style.${uiType}`,
"data-direction": "left",
title: titleStr,
children: [
labelStr && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonLabel.TldrawUiButtonLabel, { children: labelStr }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: icon ?? "mixed" })
]
}
) }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverContent, { side: "left", align: "center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_TldrawUiToolbar.TldrawUiToolbar,
{
label: labelStr,
className: (0, import_classnames.default)("tlui-buttons__grid", `tlui-buttons__${stylePanelType}`),
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiMenuContext.TldrawUiMenuContextProvider, { type: "icons", sourceId: "style-panel", children: items.map((item) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
import_TldrawUiToolbar.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);
import_editor.tlmenus.deleteOpenMenu(popoverId, editor.contextId);
setIsOpen(false);
},
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { icon: item.icon })
},
item.value
);
}) })
}
) })
] });
}
const DropdownPicker = React.memo(DropdownPickerInner);
//# sourceMappingURL=DropdownPicker.js.map