PromucFlow_constructor/app/client/src/utils/generators.tsx

32 lines
839 B
TypeScript
Raw Normal View History

2019-09-09 09:08:54 +00:00
import generate from "nanoid/generate";
2019-08-29 11:22:09 +00:00
const ALPHANUMERIC = "1234567890abcdefghijklmnopqrstuvwxyz";
2020-02-18 19:56:58 +00:00
// const ALPHABET = "abcdefghijklmnopqrstuvwxyz";
2019-08-29 11:22:09 +00:00
2019-09-09 09:08:54 +00:00
export const generateReactKey = ({
prefix = "",
}: { prefix?: string } = {}): string => {
return prefix + generate(ALPHANUMERIC, 10);
};
// Before you change how this works
// This className is used for the following:
// 1. Resize bounds
// 2. Property pane reference for positioning
export const generateClassName = (seed?: string) => {
return `appsmith_widget_${seed}`;
};
export const getCanvasClassName = () => "canvas";
export const getNearestParentCanvas = (el: Element | null) => {
const canvasQuerySelector = `.${getCanvasClassName()}`;
if (el) return el.closest(canvasQuerySelector);
return null;
2019-09-09 09:08:54 +00:00
};
2019-08-29 11:22:09 +00:00
export default {
2019-09-09 09:08:54 +00:00
generateReactKey,
generateClassName,
2019-09-09 09:08:54 +00:00
};