tldraw
Version:
A tiny little drawing editor.
123 lines (122 loc) • 6.27 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 StylePanelDropdownPicker_exports = {};
__export(StylePanelDropdownPicker_exports, {
StylePanelDropdownPicker: () => StylePanelDropdownPicker,
StylePanelDropdownPickerInline: () => StylePanelDropdownPickerInline
});
module.exports = __toCommonJS(StylePanelDropdownPicker_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_editor = require("@tldraw/editor");
var React = __toESM(require("react"), 1);
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");
var import_StylePanelContext = require("./StylePanelContext");
function StylePanelDropdownPickerInner(props) {
const msg = (0, import_useTranslation.useTranslation)();
const toolbarLabel = props.label ? msg(props.label) : msg(`style-panel.${props.stylePanelType}`);
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiToolbar.TldrawUiToolbar, { label: toolbarLabel, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StylePanelDropdownPickerInline, { ...props }) });
}
function StylePanelDropdownPickerInlineInner(props) {
const ctx = (0, import_StylePanelContext.useStylePanelContext)();
const {
id,
label,
uiType,
stylePanelType,
style,
items,
type,
value,
onValueChange = ctx.onValueChange,
testIdType = uiType
} = props;
const msg = (0, import_useTranslation.useTranslation)();
const editor = (0, import_editor.useEditor)();
const [isOpen, setIsOpen] = React.useState(false);
const icon = React.useMemo(() => {
if (value.type === "mixed") return "mixed";
const match = items.find((item) => item.value === value.value)?.icon;
return match ?? items[0]?.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,
className: "tlui-style-panel__dropdown-picker",
children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
import_TldrawUiToolbar.TldrawUiToolbarButton,
{
type,
"data-testid": `style.${testIdType}`,
"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 })
]
}
) }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiPopover.TldrawUiPopoverContent, { side: "left", align: "center", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiToolbar.TldrawUiToolbar, { orientation: items.length > 4 ? "grid" : "horizontal", label: labelStr, 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.${testIdType}.${item.value}`,
title: stylePanelName + " \u2014 " + msg(`${uiType}-style.${item.value}`),
isActive: icon === item.icon,
onClick: () => {
ctx.onHistoryMark("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 StylePanelDropdownPicker = React.memo(StylePanelDropdownPickerInner);
const StylePanelDropdownPickerInline = React.memo(StylePanelDropdownPickerInlineInner);
//# sourceMappingURL=StylePanelDropdownPicker.js.map