@plasmicapp/react-web 0.2.201 → 0.2.202
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/all.d.ts +1926 -1925
- package/dist/auth/PlasmicPageGuard.d.ts +11 -11
- package/dist/common.d.ts +10 -10
- package/dist/data-sources/index.d.ts +1 -1
- package/dist/host/index.d.ts +1 -1
- package/dist/index-common.d.ts +18 -18
- package/dist/index-skinny.d.ts +1 -1
- package/dist/index.cjs.js +3495 -3495
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +11 -11
- package/dist/plume/button/index.d.ts +36 -36
- package/dist/plume/checkbox/index.d.ts +47 -47
- package/dist/plume/collection-utils.d.ts +191 -191
- package/dist/plume/collection-utils.spec.d.ts +1 -1
- package/dist/plume/menu/context.d.ts +8 -8
- package/dist/plume/menu/index.d.ts +3 -3
- package/dist/plume/menu/menu-group.d.ts +23 -23
- package/dist/plume/menu/menu-item.d.ts +23 -23
- package/dist/plume/menu/menu.d.ts +39 -39
- package/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
- package/dist/plume/menu-button/index.d.ts +2 -2
- package/dist/plume/menu-button/menu-button.d.ts +72 -72
- package/dist/plume/menu-button/menu-trigger.d.ts +21 -21
- package/dist/plume/plume-utils.d.ts +41 -41
- package/dist/plume/props-utils.d.ts +15 -15
- package/dist/plume/select/context.d.ts +3 -3
- package/dist/plume/select/index.d.ts +4 -4
- package/dist/plume/select/select-option-group.d.ts +23 -23
- package/dist/plume/select/select-option.d.ts +23 -23
- package/dist/plume/select/select.d.ts +111 -111
- package/dist/plume/switch/index.d.ts +39 -39
- package/dist/plume/text-input/index.d.ts +36 -36
- package/dist/plume/triggered-overlay/context.d.ts +14 -14
- package/dist/plume/triggered-overlay/index.d.ts +2 -2
- package/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
- package/dist/query/index.d.ts +1 -1
- package/dist/react-utils.d.ts +21 -21
- package/dist/react-utils.spec.d.ts +1 -1
- package/dist/react-web.esm.js +3496 -3496
- package/dist/react-web.esm.js.map +1 -1
- package/dist/render/PlasmicHead/index.d.ts +37 -37
- package/dist/render/PlasmicIcon.d.ts +4 -4
- package/dist/render/PlasmicImg/index.d.ts +81 -81
- package/dist/render/PlasmicLink.d.ts +2 -2
- package/dist/render/PlasmicSlot.d.ts +11 -11
- package/dist/render/Stack.d.ts +51 -51
- package/dist/render/elements.d.ts +74 -74
- package/dist/render/global-variants.d.ts +1 -1
- package/dist/render/screen-variants.d.ts +5 -5
- package/dist/render/ssr.d.ts +21 -21
- package/dist/render/translation.d.ts +19 -19
- package/dist/render/triggers.d.ts +39 -39
- package/dist/states/errors.d.ts +13 -13
- package/dist/states/graph.d.ts +25 -25
- package/dist/states/helpers.d.ts +43 -43
- package/dist/states/index.d.ts +4 -4
- package/dist/states/types.d.ts +66 -66
- package/dist/states/valtio.d.ts +10 -10
- package/dist/states/vanilla.d.ts +3 -3
- package/dist/stories/PlasmicImg.stories.d.ts +6 -6
- package/dist/stories/UseDollarState.stories.d.ts +78 -78
- package/lib/data-sources/index.d.ts +1 -1
- package/lib/host/index.d.ts +1 -1
- package/lib/query/index.d.ts +1 -1
- package/package.json +8 -9
- package/skinny/dist/auth/PlasmicPageGuard.d.ts +11 -11
- package/skinny/dist/{collection-utils-0967eaf0.js → collection-utils-2f28e4eb.js} +297 -297
- package/skinny/dist/{collection-utils-0967eaf0.js.map → collection-utils-2f28e4eb.js.map} +1 -1
- package/skinny/dist/{common-9d6d348d.js → common-ed411407.js} +130 -130
- package/skinny/dist/{common-9d6d348d.js.map → common-ed411407.js.map} +1 -1
- package/skinny/dist/common.d.ts +10 -10
- package/skinny/dist/data-sources/index.d.ts +1 -1
- package/skinny/dist/host/index.d.ts +1 -1
- package/skinny/dist/index-common.d.ts +18 -18
- package/skinny/dist/index-skinny.d.ts +1 -1
- package/skinny/dist/index.d.ts +11 -11
- package/skinny/dist/index.js +1559 -1559
- package/skinny/dist/index.js.map +1 -1
- package/skinny/dist/plume/button/index.d.ts +36 -36
- package/skinny/dist/plume/button/index.js +21 -21
- package/skinny/dist/plume/checkbox/index.d.ts +47 -47
- package/skinny/dist/plume/checkbox/index.js +64 -64
- package/skinny/dist/plume/collection-utils.d.ts +191 -191
- package/skinny/dist/plume/collection-utils.spec.d.ts +1 -1
- package/skinny/dist/plume/menu/context.d.ts +8 -8
- package/skinny/dist/plume/menu/index.d.ts +3 -3
- package/skinny/dist/plume/menu/index.js +165 -165
- package/skinny/dist/plume/menu/menu-group.d.ts +23 -23
- package/skinny/dist/plume/menu/menu-item.d.ts +23 -23
- package/skinny/dist/plume/menu/menu.d.ts +39 -39
- package/skinny/dist/plume/menu-button/DropdownMenu.d.ts +34 -34
- package/skinny/dist/plume/menu-button/index.d.ts +2 -2
- package/skinny/dist/plume/menu-button/index.js +125 -125
- package/skinny/dist/plume/menu-button/index.js.map +1 -1
- package/skinny/dist/plume/menu-button/menu-button.d.ts +72 -72
- package/skinny/dist/plume/menu-button/menu-trigger.d.ts +21 -21
- package/skinny/dist/plume/plume-utils.d.ts +41 -41
- package/skinny/dist/plume/props-utils.d.ts +15 -15
- package/skinny/dist/plume/select/context.d.ts +3 -3
- package/skinny/dist/plume/select/index.d.ts +4 -4
- package/skinny/dist/plume/select/index.js +250 -250
- package/skinny/dist/plume/select/index.js.map +1 -1
- package/skinny/dist/plume/select/select-option-group.d.ts +23 -23
- package/skinny/dist/plume/select/select-option.d.ts +23 -23
- package/skinny/dist/plume/select/select.d.ts +111 -111
- package/skinny/dist/plume/switch/index.d.ts +39 -39
- package/skinny/dist/plume/switch/index.js +61 -61
- package/skinny/dist/plume/text-input/index.d.ts +36 -36
- package/skinny/dist/plume/text-input/index.js +45 -45
- package/skinny/dist/plume/triggered-overlay/context.d.ts +14 -14
- package/skinny/dist/plume/triggered-overlay/index.d.ts +2 -2
- package/skinny/dist/plume/triggered-overlay/index.js +100 -100
- package/skinny/dist/plume/triggered-overlay/index.js.map +1 -1
- package/skinny/dist/plume/triggered-overlay/triggered-overlay.d.ts +24 -24
- package/skinny/dist/{plume-utils-7d68bcc0.js → plume-utils-e699cd08.js} +30 -30
- package/skinny/dist/{plume-utils-7d68bcc0.js.map → plume-utils-e699cd08.js.map} +1 -1
- package/skinny/dist/{props-utils-9f9c761a.js → props-utils-9d74371f.js} +4 -4
- package/skinny/dist/{props-utils-9f9c761a.js.map → props-utils-9d74371f.js.map} +1 -1
- package/skinny/dist/query/index.d.ts +1 -1
- package/skinny/dist/{react-utils-ee4e03ba.js → react-utils-5ff031c2.js} +195 -195
- package/skinny/dist/{react-utils-ee4e03ba.js.map → react-utils-5ff031c2.js.map} +1 -1
- package/skinny/dist/react-utils.d.ts +21 -21
- package/skinny/dist/react-utils.spec.d.ts +1 -1
- package/skinny/dist/render/PlasmicHead/index.d.ts +37 -37
- package/skinny/dist/render/PlasmicHead/index.js +54 -54
- package/skinny/dist/render/PlasmicIcon.d.ts +4 -4
- package/skinny/dist/render/PlasmicImg/index.d.ts +81 -81
- package/skinny/dist/render/PlasmicImg/index.js +297 -297
- package/skinny/dist/render/PlasmicLink.d.ts +2 -2
- package/skinny/dist/render/PlasmicSlot.d.ts +11 -11
- package/skinny/dist/render/Stack.d.ts +51 -51
- package/skinny/dist/render/elements.d.ts +74 -74
- package/skinny/dist/render/global-variants.d.ts +1 -1
- package/skinny/dist/render/screen-variants.d.ts +5 -5
- package/skinny/dist/render/ssr.d.ts +21 -21
- package/skinny/dist/render/translation.d.ts +19 -19
- package/skinny/dist/render/triggers.d.ts +39 -39
- package/skinny/dist/{ssr-c9834f50.js → ssr-8625df04.js} +107 -107
- package/skinny/dist/{ssr-c9834f50.js.map → ssr-8625df04.js.map} +1 -1
- package/skinny/dist/states/errors.d.ts +13 -13
- package/skinny/dist/states/graph.d.ts +25 -25
- package/skinny/dist/states/helpers.d.ts +43 -43
- package/skinny/dist/states/index.d.ts +4 -4
- package/skinny/dist/states/types.d.ts +66 -66
- package/skinny/dist/states/valtio.d.ts +10 -10
- package/skinny/dist/states/vanilla.d.ts +3 -3
- package/skinny/dist/stories/PlasmicImg.stories.d.ts +6 -6
- package/skinny/dist/stories/UseDollarState.stories.d.ts +78 -78
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import { b as __assign, p as pick, d as __spreadArray, e as __read } from '../../common-
|
|
1
|
+
import { b as __assign, p as pick, d as __spreadArray, e as __read } from '../../common-ed411407.js';
|
|
2
2
|
import { useSwitch as useSwitch$1 } from '@react-aria/switch';
|
|
3
3
|
import { VisuallyHidden } from '@react-aria/visually-hidden';
|
|
4
4
|
import { useToggleState } from '@react-stately/toggle';
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { m as mergeProps } from '../../react-utils-
|
|
7
|
-
import { a as useEnsureSSRProvider } from '../../ssr-
|
|
8
|
-
import { m as mergeVariantToggles } from '../../plume-utils-
|
|
9
|
-
import { g as getStyleProps } from '../../props-utils-
|
|
6
|
+
import { m as mergeProps } from '../../react-utils-5ff031c2.js';
|
|
7
|
+
import { a as useEnsureSSRProvider } from '../../ssr-8625df04.js';
|
|
8
|
+
import { m as mergeVariantToggles } from '../../plume-utils-e699cd08.js';
|
|
9
|
+
import { g as getStyleProps } from '../../props-utils-9d74371f.js';
|
|
10
10
|
import 'classnames';
|
|
11
11
|
import '@plasmicapp/data-sources-context';
|
|
12
12
|
import '@react-aria/ssr';
|
|
13
13
|
import '../../render/PlasmicHead/index.js';
|
|
14
14
|
|
|
15
|
-
function asAriaSwitchProps(props) {
|
|
16
|
-
var ariaProps = __assign(__assign({}, props), { isSelected: props.isChecked, defaultSelected: props.defaultChecked });
|
|
17
|
-
delete ariaProps["isChecked"];
|
|
18
|
-
delete ariaProps["defaultChecked"];
|
|
19
|
-
return ariaProps;
|
|
20
|
-
}
|
|
21
|
-
function useSwitch(plasmicClass, props, config, ref) {
|
|
22
|
-
var _a, _b;
|
|
23
|
-
if (ref === void 0) { ref = null; }
|
|
24
|
-
var children = props.children, isDisabled = props.isDisabled;
|
|
25
|
-
useEnsureSSRProvider();
|
|
26
|
-
var inputRef = React.useRef(null);
|
|
27
|
-
var rootRef = React.useRef(null);
|
|
28
|
-
var ariaProps = asAriaSwitchProps(props);
|
|
29
|
-
var state = useToggleState(ariaProps);
|
|
30
|
-
var inputProps = useSwitch$1(ariaProps, state, inputRef).inputProps;
|
|
31
|
-
var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({
|
|
32
|
-
def: config.isDisabledVariant,
|
|
33
|
-
active: isDisabled
|
|
34
|
-
}, {
|
|
35
|
-
def: config.isCheckedVariant,
|
|
36
|
-
active: state.isSelected
|
|
37
|
-
}, {
|
|
38
|
-
def: config.noLabelVariant,
|
|
39
|
-
active: !children
|
|
40
|
-
}));
|
|
41
|
-
var overrides = (_a = {},
|
|
42
|
-
_a[config.root] = {
|
|
43
|
-
as: "label",
|
|
44
|
-
props: mergeProps(getStyleProps(props), {
|
|
45
|
-
ref: rootRef
|
|
46
|
-
}),
|
|
47
|
-
wrapChildren: function (children) { return (React.createElement(React.Fragment, null,
|
|
48
|
-
React.createElement(VisuallyHidden, null,
|
|
49
|
-
React.createElement("input", __assign({}, inputProps, { ref: inputRef }))),
|
|
50
|
-
children)); }
|
|
51
|
-
},
|
|
52
|
-
_a);
|
|
53
|
-
var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (config.labelSlot ? (_b = {}, _b[config.labelSlot] = children, _b) : {}));
|
|
54
|
-
var plumeState = React.useMemo(function () { return ({
|
|
55
|
-
setChecked: function (checked) { return state.setSelected(checked); }
|
|
56
|
-
}); }, [state]);
|
|
57
|
-
React.useImperativeHandle(ref, function () { return ({
|
|
58
|
-
getRoot: function () { return rootRef.current; },
|
|
59
|
-
focus: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
60
|
-
blur: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
|
|
61
|
-
setChecked: function (checked) { return plumeState.setChecked(checked); }
|
|
62
|
-
}); }, [rootRef, inputRef, plumeState]);
|
|
63
|
-
return {
|
|
64
|
-
plasmicProps: {
|
|
65
|
-
variants: variants,
|
|
66
|
-
overrides: overrides,
|
|
67
|
-
args: args
|
|
68
|
-
},
|
|
69
|
-
state: plumeState
|
|
70
|
-
};
|
|
15
|
+
function asAriaSwitchProps(props) {
|
|
16
|
+
var ariaProps = __assign(__assign({}, props), { isSelected: props.isChecked, defaultSelected: props.defaultChecked });
|
|
17
|
+
delete ariaProps["isChecked"];
|
|
18
|
+
delete ariaProps["defaultChecked"];
|
|
19
|
+
return ariaProps;
|
|
20
|
+
}
|
|
21
|
+
function useSwitch(plasmicClass, props, config, ref) {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
if (ref === void 0) { ref = null; }
|
|
24
|
+
var children = props.children, isDisabled = props.isDisabled;
|
|
25
|
+
useEnsureSSRProvider();
|
|
26
|
+
var inputRef = React.useRef(null);
|
|
27
|
+
var rootRef = React.useRef(null);
|
|
28
|
+
var ariaProps = asAriaSwitchProps(props);
|
|
29
|
+
var state = useToggleState(ariaProps);
|
|
30
|
+
var inputProps = useSwitch$1(ariaProps, state, inputRef).inputProps;
|
|
31
|
+
var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({
|
|
32
|
+
def: config.isDisabledVariant,
|
|
33
|
+
active: isDisabled,
|
|
34
|
+
}, {
|
|
35
|
+
def: config.isCheckedVariant,
|
|
36
|
+
active: state.isSelected,
|
|
37
|
+
}, {
|
|
38
|
+
def: config.noLabelVariant,
|
|
39
|
+
active: !children,
|
|
40
|
+
}));
|
|
41
|
+
var overrides = (_a = {},
|
|
42
|
+
_a[config.root] = {
|
|
43
|
+
as: "label",
|
|
44
|
+
props: mergeProps(getStyleProps(props), {
|
|
45
|
+
ref: rootRef,
|
|
46
|
+
}),
|
|
47
|
+
wrapChildren: function (children) { return (React.createElement(React.Fragment, null,
|
|
48
|
+
React.createElement(VisuallyHidden, null,
|
|
49
|
+
React.createElement("input", __assign({}, inputProps, { ref: inputRef }))),
|
|
50
|
+
children)); },
|
|
51
|
+
},
|
|
52
|
+
_a);
|
|
53
|
+
var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (config.labelSlot ? (_b = {}, _b[config.labelSlot] = children, _b) : {}));
|
|
54
|
+
var plumeState = React.useMemo(function () { return ({
|
|
55
|
+
setChecked: function (checked) { return state.setSelected(checked); },
|
|
56
|
+
}); }, [state]);
|
|
57
|
+
React.useImperativeHandle(ref, function () { return ({
|
|
58
|
+
getRoot: function () { return rootRef.current; },
|
|
59
|
+
focus: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
60
|
+
blur: function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); },
|
|
61
|
+
setChecked: function (checked) { return plumeState.setChecked(checked); },
|
|
62
|
+
}); }, [rootRef, inputRef, plumeState]);
|
|
63
|
+
return {
|
|
64
|
+
plasmicProps: {
|
|
65
|
+
variants: variants,
|
|
66
|
+
overrides: overrides,
|
|
67
|
+
args: args,
|
|
68
|
+
},
|
|
69
|
+
state: plumeState,
|
|
70
|
+
};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
export { useSwitch };
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { AnyPlasmicClass, PlasmicClassArgs, PlasmicClassOverrides, PlasmicClassVariants, VariantDef } from "../plume-utils";
|
|
3
|
-
export interface BaseTextInputProps extends Omit<React.ComponentProps<"input">, "type" | "disabled"> {
|
|
4
|
-
showStartIcon?: boolean;
|
|
5
|
-
showEndIcon?: boolean;
|
|
6
|
-
startIcon?: React.ReactNode;
|
|
7
|
-
endIcon?: React.ReactNode;
|
|
8
|
-
isDisabled?: boolean;
|
|
9
|
-
type?: "text" | "password" | "email" | "url" | string;
|
|
10
|
-
inputClassName?: string;
|
|
11
|
-
inputStyle?: React.CSSProperties;
|
|
12
|
-
}
|
|
13
|
-
export interface TextInputRefValue {
|
|
14
|
-
focus: () => void;
|
|
15
|
-
blur: () => void;
|
|
16
|
-
getRoot: () => HTMLElement | null;
|
|
17
|
-
getInput: () => HTMLInputElement | null;
|
|
18
|
-
}
|
|
19
|
-
export type TextInputRef = React.Ref<TextInputRefValue>;
|
|
20
|
-
interface TextInputConfig<C extends AnyPlasmicClass> {
|
|
21
|
-
showStartIconVariant: VariantDef<PlasmicClassVariants<C>>;
|
|
22
|
-
showEndIconVariant?: VariantDef<PlasmicClassVariants<C>>;
|
|
23
|
-
isDisabledVariant?: VariantDef<PlasmicClassVariants<C>>;
|
|
24
|
-
startIconSlot?: keyof PlasmicClassArgs<C>;
|
|
25
|
-
endIconSlot?: keyof PlasmicClassArgs<C>;
|
|
26
|
-
root: keyof PlasmicClassOverrides<C>;
|
|
27
|
-
input: keyof PlasmicClassOverrides<C>;
|
|
28
|
-
}
|
|
29
|
-
export declare function useTextInput<P extends BaseTextInputProps, C extends AnyPlasmicClass>(plasmicClass: C, props: P, config: TextInputConfig<C>, ref?: TextInputRef): {
|
|
30
|
-
plasmicProps: {
|
|
31
|
-
variants: PlasmicClassVariants<C>;
|
|
32
|
-
args: PlasmicClassArgs<C>;
|
|
33
|
-
overrides: PlasmicClassOverrides<C>;
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export {};
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { AnyPlasmicClass, PlasmicClassArgs, PlasmicClassOverrides, PlasmicClassVariants, VariantDef } from "../plume-utils";
|
|
3
|
+
export interface BaseTextInputProps extends Omit<React.ComponentProps<"input">, "type" | "disabled"> {
|
|
4
|
+
showStartIcon?: boolean;
|
|
5
|
+
showEndIcon?: boolean;
|
|
6
|
+
startIcon?: React.ReactNode;
|
|
7
|
+
endIcon?: React.ReactNode;
|
|
8
|
+
isDisabled?: boolean;
|
|
9
|
+
type?: "text" | "password" | "email" | "url" | string;
|
|
10
|
+
inputClassName?: string;
|
|
11
|
+
inputStyle?: React.CSSProperties;
|
|
12
|
+
}
|
|
13
|
+
export interface TextInputRefValue {
|
|
14
|
+
focus: () => void;
|
|
15
|
+
blur: () => void;
|
|
16
|
+
getRoot: () => HTMLElement | null;
|
|
17
|
+
getInput: () => HTMLInputElement | null;
|
|
18
|
+
}
|
|
19
|
+
export type TextInputRef = React.Ref<TextInputRefValue>;
|
|
20
|
+
interface TextInputConfig<C extends AnyPlasmicClass> {
|
|
21
|
+
showStartIconVariant: VariantDef<PlasmicClassVariants<C>>;
|
|
22
|
+
showEndIconVariant?: VariantDef<PlasmicClassVariants<C>>;
|
|
23
|
+
isDisabledVariant?: VariantDef<PlasmicClassVariants<C>>;
|
|
24
|
+
startIconSlot?: keyof PlasmicClassArgs<C>;
|
|
25
|
+
endIconSlot?: keyof PlasmicClassArgs<C>;
|
|
26
|
+
root: keyof PlasmicClassOverrides<C>;
|
|
27
|
+
input: keyof PlasmicClassOverrides<C>;
|
|
28
|
+
}
|
|
29
|
+
export declare function useTextInput<P extends BaseTextInputProps, C extends AnyPlasmicClass>(plasmicClass: C, props: P, config: TextInputConfig<C>, ref?: TextInputRef): {
|
|
30
|
+
plasmicProps: {
|
|
31
|
+
variants: PlasmicClassVariants<C>;
|
|
32
|
+
args: PlasmicClassArgs<C>;
|
|
33
|
+
overrides: PlasmicClassOverrides<C>;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { c as __rest, b as __assign, p as pick, d as __spreadArray, e as __read, o as omit } from '../../common-
|
|
1
|
+
import { c as __rest, b as __assign, p as pick, d as __spreadArray, e as __read, o as omit } from '../../common-ed411407.js';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { m as mergeVariantToggles } from '../../plume-utils-
|
|
3
|
+
import { m as mergeVariantToggles } from '../../plume-utils-e699cd08.js';
|
|
4
4
|
|
|
5
|
-
function useTextInput(plasmicClass, props, config, ref) {
|
|
6
|
-
var _a, _b, _c;
|
|
7
|
-
if (ref === void 0) { ref = null; }
|
|
8
|
-
var isDisabled = props.isDisabled, startIcon = props.startIcon, endIcon = props.endIcon, showStartIcon = props.showStartIcon, showEndIcon = props.showEndIcon, className = props.className, style = props.style, inputClassName = props.inputClassName, inputStyle = props.inputStyle, rest = __rest(props, ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"]);
|
|
9
|
-
var rootRef = React.useRef(null);
|
|
10
|
-
var inputRef = React.useRef(null);
|
|
11
|
-
React.useImperativeHandle(ref, function () { return ({
|
|
12
|
-
focus: function () {
|
|
13
|
-
var _a;
|
|
14
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
15
|
-
},
|
|
16
|
-
blur: function () {
|
|
17
|
-
var _a;
|
|
18
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
19
|
-
},
|
|
20
|
-
getRoot: function () {
|
|
21
|
-
return rootRef.current;
|
|
22
|
-
},
|
|
23
|
-
getInput: function () {
|
|
24
|
-
return inputRef.current;
|
|
25
|
-
}
|
|
26
|
-
}); }, [rootRef, inputRef]);
|
|
27
|
-
var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.showStartIconVariant, active: showStartIcon }, { def: config.showEndIconVariant, active: showEndIcon }, { def: config.isDisabledVariant, active: isDisabled }));
|
|
28
|
-
var args = __assign(__assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (config.startIconSlot && (_a = {}, _a[config.startIconSlot] = startIcon, _a))), (config.endIconSlot && (_b = {}, _b[config.endIconSlot] = endIcon, _b)));
|
|
29
|
-
var overrides = (_c = {},
|
|
30
|
-
_c[config.root] = {
|
|
31
|
-
props: {
|
|
32
|
-
ref: rootRef,
|
|
33
|
-
className: className,
|
|
34
|
-
style: style
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
_c[config.input] = {
|
|
38
|
-
props: __assign(__assign({}, omit.apply(void 0, __spreadArray(__spreadArray([rest], __read(plasmicClass.internalArgProps.filter(function (prop) { return prop !== "required"; })), false), __read(plasmicClass.internalVariantProps), false))), { disabled: isDisabled, ref: inputRef, className: inputClassName, style: inputStyle })
|
|
39
|
-
},
|
|
40
|
-
_c);
|
|
41
|
-
return {
|
|
42
|
-
plasmicProps: {
|
|
43
|
-
variants: variants,
|
|
44
|
-
args: args,
|
|
45
|
-
overrides: overrides
|
|
46
|
-
}
|
|
47
|
-
};
|
|
5
|
+
function useTextInput(plasmicClass, props, config, ref) {
|
|
6
|
+
var _a, _b, _c;
|
|
7
|
+
if (ref === void 0) { ref = null; }
|
|
8
|
+
var isDisabled = props.isDisabled, startIcon = props.startIcon, endIcon = props.endIcon, showStartIcon = props.showStartIcon, showEndIcon = props.showEndIcon, className = props.className, style = props.style, inputClassName = props.inputClassName, inputStyle = props.inputStyle, rest = __rest(props, ["isDisabled", "startIcon", "endIcon", "showStartIcon", "showEndIcon", "className", "style", "inputClassName", "inputStyle"]);
|
|
9
|
+
var rootRef = React.useRef(null);
|
|
10
|
+
var inputRef = React.useRef(null);
|
|
11
|
+
React.useImperativeHandle(ref, function () { return ({
|
|
12
|
+
focus: function () {
|
|
13
|
+
var _a;
|
|
14
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
15
|
+
},
|
|
16
|
+
blur: function () {
|
|
17
|
+
var _a;
|
|
18
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
19
|
+
},
|
|
20
|
+
getRoot: function () {
|
|
21
|
+
return rootRef.current;
|
|
22
|
+
},
|
|
23
|
+
getInput: function () {
|
|
24
|
+
return inputRef.current;
|
|
25
|
+
},
|
|
26
|
+
}); }, [rootRef, inputRef]);
|
|
27
|
+
var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.showStartIconVariant, active: showStartIcon }, { def: config.showEndIconVariant, active: showEndIcon }, { def: config.isDisabledVariant, active: isDisabled }));
|
|
28
|
+
var args = __assign(__assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (config.startIconSlot && (_a = {}, _a[config.startIconSlot] = startIcon, _a))), (config.endIconSlot && (_b = {}, _b[config.endIconSlot] = endIcon, _b)));
|
|
29
|
+
var overrides = (_c = {},
|
|
30
|
+
_c[config.root] = {
|
|
31
|
+
props: {
|
|
32
|
+
ref: rootRef,
|
|
33
|
+
className: className,
|
|
34
|
+
style: style,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
_c[config.input] = {
|
|
38
|
+
props: __assign(__assign({}, omit.apply(void 0, __spreadArray(__spreadArray([rest], __read(plasmicClass.internalArgProps.filter(function (prop) { return prop !== "required"; })), false), __read(plasmicClass.internalVariantProps), false))), { disabled: isDisabled, ref: inputRef, className: inputClassName, style: inputStyle }),
|
|
39
|
+
},
|
|
40
|
+
_c);
|
|
41
|
+
return {
|
|
42
|
+
plasmicProps: {
|
|
43
|
+
variants: variants,
|
|
44
|
+
args: args,
|
|
45
|
+
overrides: overrides,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export { useTextInput };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { Placement } from "@react-types/overlays";
|
|
2
|
-
import type { FocusStrategy } from "@react-types/shared";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import type { OverlayTriggerState } from "@react-stately/overlays";
|
|
5
|
-
export interface TriggeredOverlayContextValue {
|
|
6
|
-
triggerRef: React.RefObject<HTMLElement>;
|
|
7
|
-
state: OverlayTriggerState;
|
|
8
|
-
autoFocus?: boolean | FocusStrategy;
|
|
9
|
-
placement?: Placement;
|
|
10
|
-
overlayMatchTriggerWidth?: boolean;
|
|
11
|
-
overlayMinTriggerWidth?: boolean;
|
|
12
|
-
overlayWidth?: number;
|
|
13
|
-
}
|
|
14
|
-
export declare const TriggeredOverlayContext: React.Context<TriggeredOverlayContextValue | undefined>;
|
|
1
|
+
import type { Placement } from "@react-types/overlays";
|
|
2
|
+
import type { FocusStrategy } from "@react-types/shared";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import type { OverlayTriggerState } from "@react-stately/overlays";
|
|
5
|
+
export interface TriggeredOverlayContextValue {
|
|
6
|
+
triggerRef: React.RefObject<HTMLElement>;
|
|
7
|
+
state: OverlayTriggerState;
|
|
8
|
+
autoFocus?: boolean | FocusStrategy;
|
|
9
|
+
placement?: Placement;
|
|
10
|
+
overlayMatchTriggerWidth?: boolean;
|
|
11
|
+
overlayMinTriggerWidth?: boolean;
|
|
12
|
+
overlayWidth?: number;
|
|
13
|
+
}
|
|
14
|
+
export declare const TriggeredOverlayContext: React.Context<TriggeredOverlayContextValue | undefined>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { BaseTriggeredOverlayProps, TriggeredOverlayConfig, TriggeredOverlayRef, useTriggeredOverlay, } from "./triggered-overlay";
|
|
2
|
-
export { TriggeredOverlayContext } from "./context";
|
|
1
|
+
export { BaseTriggeredOverlayProps, TriggeredOverlayConfig, TriggeredOverlayRef, useTriggeredOverlay, } from "./triggered-overlay";
|
|
2
|
+
export { TriggeredOverlayContext } from "./context";
|
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
import { e as __read, b as __assign, p as pick, d as __spreadArray } from '../../common-
|
|
1
|
+
import { e as __read, b as __assign, p as pick, d as __spreadArray } from '../../common-ed411407.js';
|
|
2
2
|
import { usePlasmicCanvasContext } from '@plasmicapp/host';
|
|
3
3
|
import { FocusScope } from '@react-aria/focus';
|
|
4
4
|
import { useOverlay, useOverlayPosition, DismissButton } from '@react-aria/overlays';
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import * as ReactDOM from 'react-dom';
|
|
7
|
-
import { d as mergeRefs, u as useIsomorphicLayoutEffect, m as mergeProps } from '../../react-utils-
|
|
8
|
-
import { m as mergeVariantToggles } from '../../plume-utils-
|
|
9
|
-
import { g as getStyleProps } from '../../props-utils-
|
|
7
|
+
import { d as mergeRefs, u as useIsomorphicLayoutEffect, m as mergeProps } from '../../react-utils-5ff031c2.js';
|
|
8
|
+
import { m as mergeVariantToggles } from '../../plume-utils-e699cd08.js';
|
|
9
|
+
import { g as getStyleProps } from '../../props-utils-9d74371f.js';
|
|
10
10
|
import { T as TriggeredOverlayContext } from '../../context-034b8d25.js';
|
|
11
11
|
export { T as TriggeredOverlayContext } from '../../context-034b8d25.js';
|
|
12
12
|
import 'classnames';
|
|
13
13
|
|
|
14
|
-
function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissable) {
|
|
15
|
-
var _a, _b;
|
|
16
|
-
if (outerRef === void 0) { outerRef = null; }
|
|
17
|
-
if (isDismissable === void 0) { isDismissable = true; }
|
|
18
|
-
var overlayRef = React.useRef(null);
|
|
19
|
-
var onOverlayRef = mergeRefs(overlayRef, outerRef);
|
|
20
|
-
var context = React.useContext(TriggeredOverlayContext);
|
|
21
|
-
if (!context) {
|
|
22
|
-
// If no context, then we are not being correctly used. Either complain, or
|
|
23
|
-
// exit early. It's okay to exit early and break the rules of React hooks
|
|
24
|
-
// because we won't suddenly have the appropriate context anyway for this instance.
|
|
25
|
-
{
|
|
26
|
-
throw new Error("You can only use a triggered overlay with a TriggeredOverlayContext");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
var children = props.children;
|
|
30
|
-
var triggerRef = context.triggerRef, placement = context.placement, overlayMatchTriggerWidth = context.overlayMatchTriggerWidth, overlayMinTriggerWidth = context.overlayMinTriggerWidth, overlayWidth = context.overlayWidth, state = context.state;
|
|
31
|
-
// Measure the width of the trigger to inform the width of the menu (below).
|
|
32
|
-
var _c = __read(React.useState(false), 2), isRendered = _c[0], setRendered = _c[1];
|
|
33
|
-
var triggerWidth = triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)
|
|
34
|
-
? triggerRef.current.offsetWidth
|
|
35
|
-
: undefined;
|
|
36
|
-
useIsomorphicLayoutEffect(function () {
|
|
37
|
-
if (!isRendered &&
|
|
38
|
-
triggerRef.current &&
|
|
39
|
-
(overlayMatchTriggerWidth || overlayMinTriggerWidth)) {
|
|
40
|
-
setRendered(true);
|
|
41
|
-
}
|
|
42
|
-
}, [
|
|
43
|
-
triggerRef,
|
|
44
|
-
isRendered,
|
|
45
|
-
overlayMatchTriggerWidth,
|
|
46
|
-
overlayMinTriggerWidth,
|
|
47
|
-
]);
|
|
48
|
-
var overlayAriaProps = useOverlay({
|
|
49
|
-
isOpen: state.isOpen,
|
|
50
|
-
onClose: state.close,
|
|
51
|
-
isDismissable: isDismissable,
|
|
52
|
-
shouldCloseOnBlur: true
|
|
53
|
-
}, overlayRef).overlayProps;
|
|
54
|
-
var _d = useOverlayPosition({
|
|
55
|
-
targetRef: triggerRef,
|
|
56
|
-
overlayRef: overlayRef,
|
|
57
|
-
placement: placement !== null && placement !== void 0 ? placement : "bottom left",
|
|
58
|
-
shouldFlip: true,
|
|
59
|
-
isOpen: state.isOpen,
|
|
60
|
-
onClose: state.close,
|
|
61
|
-
containerPadding: 0
|
|
62
|
-
}), overlayPositionProps = _d.overlayProps, updatePosition = _d.updatePosition, placementAxis = _d.placement;
|
|
63
|
-
useIsomorphicLayoutEffect(function () {
|
|
64
|
-
if (state.isOpen) {
|
|
65
|
-
requestAnimationFrame(function () {
|
|
66
|
-
updatePosition();
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}, [state.isOpen, updatePosition]);
|
|
70
|
-
var overlayProps = mergeProps({
|
|
71
|
-
style: {
|
|
72
|
-
left: "auto",
|
|
73
|
-
right: "auto",
|
|
74
|
-
top: "auto",
|
|
75
|
-
bottom: "auto",
|
|
76
|
-
position: "absolute",
|
|
77
|
-
width: overlayWidth !== null && overlayWidth !== void 0 ? overlayWidth : (overlayMatchTriggerWidth ? triggerWidth : "auto"),
|
|
78
|
-
minWidth: overlayMinTriggerWidth ? triggerWidth : "auto"
|
|
79
|
-
}
|
|
80
|
-
}, overlayAriaProps, overlayPositionProps);
|
|
81
|
-
var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isPlacedTopVariant, active: placementAxis === "top" }, { def: config.isPlacedBottomVariant, active: placementAxis === "bottom" }, { def: config.isPlacedLeftVariant, active: placementAxis === "left" }, { def: config.isPlacedRightVariant, active: placementAxis === "right" }));
|
|
82
|
-
var canvasCtx = usePlasmicCanvasContext();
|
|
83
|
-
var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.contentSlot] = canvasCtx ? (children) : (React.createElement(FocusScope, { restoreFocus: true },
|
|
84
|
-
React.createElement(DismissButton, { onDismiss: state.close }),
|
|
85
|
-
children)), _a));
|
|
86
|
-
var overrides = (_b = {},
|
|
87
|
-
_b[config.root] = {
|
|
88
|
-
props: mergeProps(overlayProps, getStyleProps(props), {
|
|
89
|
-
ref: onOverlayRef
|
|
90
|
-
}),
|
|
91
|
-
wrap: function (root) {
|
|
92
|
-
if (typeof document !== "undefined") {
|
|
93
|
-
return ReactDOM.createPortal(root, document.body);
|
|
94
|
-
}
|
|
95
|
-
else {
|
|
96
|
-
// Possibly being invoked on the server during SSR; no need to
|
|
97
|
-
// bother with a portal in that case.
|
|
98
|
-
return root;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
_b);
|
|
103
|
-
return {
|
|
104
|
-
plasmicProps: {
|
|
105
|
-
variants: variants,
|
|
106
|
-
args: args,
|
|
107
|
-
overrides: overrides
|
|
108
|
-
}
|
|
109
|
-
};
|
|
14
|
+
function useTriggeredOverlay(plasmicClass, props, config, outerRef, isDismissable) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
if (outerRef === void 0) { outerRef = null; }
|
|
17
|
+
if (isDismissable === void 0) { isDismissable = true; }
|
|
18
|
+
var overlayRef = React.useRef(null);
|
|
19
|
+
var onOverlayRef = mergeRefs(overlayRef, outerRef);
|
|
20
|
+
var context = React.useContext(TriggeredOverlayContext);
|
|
21
|
+
if (!context) {
|
|
22
|
+
// If no context, then we are not being correctly used. Either complain, or
|
|
23
|
+
// exit early. It's okay to exit early and break the rules of React hooks
|
|
24
|
+
// because we won't suddenly have the appropriate context anyway for this instance.
|
|
25
|
+
{
|
|
26
|
+
throw new Error("You can only use a triggered overlay with a TriggeredOverlayContext");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
var children = props.children;
|
|
30
|
+
var triggerRef = context.triggerRef, placement = context.placement, overlayMatchTriggerWidth = context.overlayMatchTriggerWidth, overlayMinTriggerWidth = context.overlayMinTriggerWidth, overlayWidth = context.overlayWidth, state = context.state;
|
|
31
|
+
// Measure the width of the trigger to inform the width of the menu (below).
|
|
32
|
+
var _c = __read(React.useState(false), 2), isRendered = _c[0], setRendered = _c[1];
|
|
33
|
+
var triggerWidth = triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)
|
|
34
|
+
? triggerRef.current.offsetWidth
|
|
35
|
+
: undefined;
|
|
36
|
+
useIsomorphicLayoutEffect(function () {
|
|
37
|
+
if (!isRendered &&
|
|
38
|
+
triggerRef.current &&
|
|
39
|
+
(overlayMatchTriggerWidth || overlayMinTriggerWidth)) {
|
|
40
|
+
setRendered(true);
|
|
41
|
+
}
|
|
42
|
+
}, [
|
|
43
|
+
triggerRef,
|
|
44
|
+
isRendered,
|
|
45
|
+
overlayMatchTriggerWidth,
|
|
46
|
+
overlayMinTriggerWidth,
|
|
47
|
+
]);
|
|
48
|
+
var overlayAriaProps = useOverlay({
|
|
49
|
+
isOpen: state.isOpen,
|
|
50
|
+
onClose: state.close,
|
|
51
|
+
isDismissable: isDismissable,
|
|
52
|
+
shouldCloseOnBlur: true,
|
|
53
|
+
}, overlayRef).overlayProps;
|
|
54
|
+
var _d = useOverlayPosition({
|
|
55
|
+
targetRef: triggerRef,
|
|
56
|
+
overlayRef: overlayRef,
|
|
57
|
+
placement: placement !== null && placement !== void 0 ? placement : "bottom left",
|
|
58
|
+
shouldFlip: true,
|
|
59
|
+
isOpen: state.isOpen,
|
|
60
|
+
onClose: state.close,
|
|
61
|
+
containerPadding: 0,
|
|
62
|
+
}), overlayPositionProps = _d.overlayProps, updatePosition = _d.updatePosition, placementAxis = _d.placement;
|
|
63
|
+
useIsomorphicLayoutEffect(function () {
|
|
64
|
+
if (state.isOpen) {
|
|
65
|
+
requestAnimationFrame(function () {
|
|
66
|
+
updatePosition();
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}, [state.isOpen, updatePosition]);
|
|
70
|
+
var overlayProps = mergeProps({
|
|
71
|
+
style: {
|
|
72
|
+
left: "auto",
|
|
73
|
+
right: "auto",
|
|
74
|
+
top: "auto",
|
|
75
|
+
bottom: "auto",
|
|
76
|
+
position: "absolute",
|
|
77
|
+
width: overlayWidth !== null && overlayWidth !== void 0 ? overlayWidth : (overlayMatchTriggerWidth ? triggerWidth : "auto"),
|
|
78
|
+
minWidth: overlayMinTriggerWidth ? triggerWidth : "auto",
|
|
79
|
+
},
|
|
80
|
+
}, overlayAriaProps, overlayPositionProps);
|
|
81
|
+
var variants = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalVariantProps), false))), mergeVariantToggles({ def: config.isPlacedTopVariant, active: placementAxis === "top" }, { def: config.isPlacedBottomVariant, active: placementAxis === "bottom" }, { def: config.isPlacedLeftVariant, active: placementAxis === "left" }, { def: config.isPlacedRightVariant, active: placementAxis === "right" }));
|
|
82
|
+
var canvasCtx = usePlasmicCanvasContext();
|
|
83
|
+
var args = __assign(__assign({}, pick.apply(void 0, __spreadArray([props], __read(plasmicClass.internalArgProps), false))), (_a = {}, _a[config.contentSlot] = canvasCtx && !canvasCtx.interactive ? (children) : (React.createElement(FocusScope, { restoreFocus: true },
|
|
84
|
+
React.createElement(DismissButton, { onDismiss: state.close }),
|
|
85
|
+
children)), _a));
|
|
86
|
+
var overrides = (_b = {},
|
|
87
|
+
_b[config.root] = {
|
|
88
|
+
props: mergeProps(overlayProps, getStyleProps(props), {
|
|
89
|
+
ref: onOverlayRef,
|
|
90
|
+
}),
|
|
91
|
+
wrap: function (root) {
|
|
92
|
+
if (typeof document !== "undefined") {
|
|
93
|
+
return ReactDOM.createPortal(root, document.body);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
// Possibly being invoked on the server during SSR; no need to
|
|
97
|
+
// bother with a portal in that case.
|
|
98
|
+
return root;
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
_b);
|
|
103
|
+
return {
|
|
104
|
+
plasmicProps: {
|
|
105
|
+
variants: variants,
|
|
106
|
+
args: args,
|
|
107
|
+
overrides: overrides,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export { useTriggeredOverlay };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/plume/triggered-overlay/triggered-overlay.tsx"],"sourcesContent":["import { usePlasmicCanvasContext } from \"@plasmicapp/host\";\nimport { FocusScope } from \"@react-aria/focus\";\nimport {\n DismissButton,\n useOverlay,\n useOverlayPosition,\n} from \"@react-aria/overlays\";\nimport { DOMProps } from \"@react-types/shared\";\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { pick } from \"../../common\";\nimport {\n mergeProps,\n mergeRefs,\n useIsomorphicLayoutEffect,\n} from \"../../react-utils\";\nimport { Overrides } from \"../../render/elements\";\nimport {\n AnyPlasmicClass,\n mergeVariantToggles,\n PlasmicClassArgs,\n PlasmicClassOverrides,\n PlasmicClassVariants,\n PLUME_STRICT_MODE,\n VariantDef,\n} from \"../plume-utils\";\nimport {\n getDefaultPlasmicProps,\n getStyleProps,\n StyleProps,\n} from \"../props-utils\";\nimport { TriggeredOverlayContext } from \"./context\";\n\nexport interface BaseTriggeredOverlayProps extends StyleProps, DOMProps {\n children?: React.ReactNode;\n}\n\nexport interface TriggeredOverlayConfig<C extends AnyPlasmicClass> {\n isPlacedTopVariant?: VariantDef<PlasmicClassVariants<C>>;\n isPlacedBottomVariant?: VariantDef<PlasmicClassVariants<C>>;\n isPlacedLeftVariant?: VariantDef<PlasmicClassVariants<C>>;\n isPlacedRightVariant?: VariantDef<PlasmicClassVariants<C>>;\n\n contentSlot: keyof PlasmicClassArgs<C>;\n root: keyof PlasmicClassOverrides<C>;\n contentContainer: keyof PlasmicClassOverrides<C>;\n}\n\nexport type TriggeredOverlayRef = React.Ref<HTMLElement>;\n\nexport function useTriggeredOverlay<\n P extends BaseTriggeredOverlayProps,\n C extends AnyPlasmicClass\n>(\n plasmicClass: C,\n props: P,\n config: TriggeredOverlayConfig<C>,\n outerRef: TriggeredOverlayRef = null,\n isDismissable = true\n) {\n const overlayRef = React.useRef<HTMLElement>(null);\n const onOverlayRef = mergeRefs(overlayRef, outerRef);\n\n const context = React.useContext(TriggeredOverlayContext);\n\n if (!context) {\n // If no context, then we are not being correctly used. Either complain, or\n // exit early. It's okay to exit early and break the rules of React hooks\n // because we won't suddenly have the appropriate context anyway for this instance.\n if (PLUME_STRICT_MODE) {\n throw new Error(\n \"You can only use a triggered overlay with a TriggeredOverlayContext\"\n );\n }\n return getDefaultPlasmicProps(plasmicClass, props);\n }\n\n const { children } = props;\n const {\n triggerRef,\n placement,\n overlayMatchTriggerWidth,\n overlayMinTriggerWidth,\n overlayWidth,\n state,\n } = context;\n\n // Measure the width of the trigger to inform the width of the menu (below).\n const [isRendered, setRendered] = React.useState(false);\n const triggerWidth =\n triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)\n ? triggerRef.current.offsetWidth\n : undefined;\n\n useIsomorphicLayoutEffect(() => {\n if (\n !isRendered &&\n triggerRef.current &&\n (overlayMatchTriggerWidth || overlayMinTriggerWidth)\n ) {\n setRendered(true);\n }\n }, [\n triggerRef,\n isRendered,\n overlayMatchTriggerWidth,\n overlayMinTriggerWidth,\n ]);\n\n const { overlayProps: overlayAriaProps } = useOverlay(\n {\n isOpen: state.isOpen,\n onClose: state.close,\n isDismissable,\n shouldCloseOnBlur: true,\n },\n overlayRef\n );\n\n const {\n overlayProps: overlayPositionProps,\n updatePosition,\n placement: placementAxis,\n } = useOverlayPosition({\n targetRef: triggerRef,\n overlayRef,\n placement: placement ?? \"bottom left\",\n shouldFlip: true,\n isOpen: state.isOpen,\n onClose: state.close,\n containerPadding: 0,\n });\n\n useIsomorphicLayoutEffect(() => {\n if (state.isOpen) {\n requestAnimationFrame(() => {\n updatePosition();\n });\n }\n }, [state.isOpen, updatePosition]);\n\n const overlayProps = mergeProps(\n {\n style: {\n left: \"auto\",\n right: \"auto\",\n top: \"auto\",\n bottom: \"auto\",\n position: \"absolute\",\n width:\n overlayWidth ?? (overlayMatchTriggerWidth ? triggerWidth : \"auto\"),\n minWidth: overlayMinTriggerWidth ? triggerWidth : \"auto\",\n },\n },\n overlayAriaProps,\n overlayPositionProps\n );\n\n const variants = {\n ...pick(props, ...plasmicClass.internalVariantProps),\n ...mergeVariantToggles(\n { def: config.isPlacedTopVariant, active: placementAxis === \"top\" },\n { def: config.isPlacedBottomVariant, active: placementAxis === \"bottom\" },\n { def: config.isPlacedLeftVariant, active: placementAxis === \"left\" },\n { def: config.isPlacedRightVariant, active: placementAxis === \"right\" }\n ),\n };\n\n const canvasCtx = usePlasmicCanvasContext();\n const args = {\n ...pick(props, ...plasmicClass.internalArgProps),\n [config.contentSlot]
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/plume/triggered-overlay/triggered-overlay.tsx"],"sourcesContent":["import { usePlasmicCanvasContext } from \"@plasmicapp/host\";\nimport { FocusScope } from \"@react-aria/focus\";\nimport {\n DismissButton,\n useOverlay,\n useOverlayPosition,\n} from \"@react-aria/overlays\";\nimport { DOMProps } from \"@react-types/shared\";\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { pick } from \"../../common\";\nimport {\n mergeProps,\n mergeRefs,\n useIsomorphicLayoutEffect,\n} from \"../../react-utils\";\nimport { Overrides } from \"../../render/elements\";\nimport {\n AnyPlasmicClass,\n mergeVariantToggles,\n PlasmicClassArgs,\n PlasmicClassOverrides,\n PlasmicClassVariants,\n PLUME_STRICT_MODE,\n VariantDef,\n} from \"../plume-utils\";\nimport {\n getDefaultPlasmicProps,\n getStyleProps,\n StyleProps,\n} from \"../props-utils\";\nimport { TriggeredOverlayContext } from \"./context\";\n\nexport interface BaseTriggeredOverlayProps extends StyleProps, DOMProps {\n children?: React.ReactNode;\n}\n\nexport interface TriggeredOverlayConfig<C extends AnyPlasmicClass> {\n isPlacedTopVariant?: VariantDef<PlasmicClassVariants<C>>;\n isPlacedBottomVariant?: VariantDef<PlasmicClassVariants<C>>;\n isPlacedLeftVariant?: VariantDef<PlasmicClassVariants<C>>;\n isPlacedRightVariant?: VariantDef<PlasmicClassVariants<C>>;\n\n contentSlot: keyof PlasmicClassArgs<C>;\n root: keyof PlasmicClassOverrides<C>;\n contentContainer: keyof PlasmicClassOverrides<C>;\n}\n\nexport type TriggeredOverlayRef = React.Ref<HTMLElement>;\n\nexport function useTriggeredOverlay<\n P extends BaseTriggeredOverlayProps,\n C extends AnyPlasmicClass\n>(\n plasmicClass: C,\n props: P,\n config: TriggeredOverlayConfig<C>,\n outerRef: TriggeredOverlayRef = null,\n isDismissable = true\n) {\n const overlayRef = React.useRef<HTMLElement>(null);\n const onOverlayRef = mergeRefs(overlayRef, outerRef);\n\n const context = React.useContext(TriggeredOverlayContext);\n\n if (!context) {\n // If no context, then we are not being correctly used. Either complain, or\n // exit early. It's okay to exit early and break the rules of React hooks\n // because we won't suddenly have the appropriate context anyway for this instance.\n if (PLUME_STRICT_MODE) {\n throw new Error(\n \"You can only use a triggered overlay with a TriggeredOverlayContext\"\n );\n }\n return getDefaultPlasmicProps(plasmicClass, props);\n }\n\n const { children } = props;\n const {\n triggerRef,\n placement,\n overlayMatchTriggerWidth,\n overlayMinTriggerWidth,\n overlayWidth,\n state,\n } = context;\n\n // Measure the width of the trigger to inform the width of the menu (below).\n const [isRendered, setRendered] = React.useState(false);\n const triggerWidth =\n triggerRef.current && (overlayMatchTriggerWidth || overlayMinTriggerWidth)\n ? triggerRef.current.offsetWidth\n : undefined;\n\n useIsomorphicLayoutEffect(() => {\n if (\n !isRendered &&\n triggerRef.current &&\n (overlayMatchTriggerWidth || overlayMinTriggerWidth)\n ) {\n setRendered(true);\n }\n }, [\n triggerRef,\n isRendered,\n overlayMatchTriggerWidth,\n overlayMinTriggerWidth,\n ]);\n\n const { overlayProps: overlayAriaProps } = useOverlay(\n {\n isOpen: state.isOpen,\n onClose: state.close,\n isDismissable,\n shouldCloseOnBlur: true,\n },\n overlayRef\n );\n\n const {\n overlayProps: overlayPositionProps,\n updatePosition,\n placement: placementAxis,\n } = useOverlayPosition({\n targetRef: triggerRef,\n overlayRef,\n placement: placement ?? \"bottom left\",\n shouldFlip: true,\n isOpen: state.isOpen,\n onClose: state.close,\n containerPadding: 0,\n });\n\n useIsomorphicLayoutEffect(() => {\n if (state.isOpen) {\n requestAnimationFrame(() => {\n updatePosition();\n });\n }\n }, [state.isOpen, updatePosition]);\n\n const overlayProps = mergeProps(\n {\n style: {\n left: \"auto\",\n right: \"auto\",\n top: \"auto\",\n bottom: \"auto\",\n position: \"absolute\",\n width:\n overlayWidth ?? (overlayMatchTriggerWidth ? triggerWidth : \"auto\"),\n minWidth: overlayMinTriggerWidth ? triggerWidth : \"auto\",\n },\n },\n overlayAriaProps,\n overlayPositionProps\n );\n\n const variants = {\n ...pick(props, ...plasmicClass.internalVariantProps),\n ...mergeVariantToggles(\n { def: config.isPlacedTopVariant, active: placementAxis === \"top\" },\n { def: config.isPlacedBottomVariant, active: placementAxis === \"bottom\" },\n { def: config.isPlacedLeftVariant, active: placementAxis === \"left\" },\n { def: config.isPlacedRightVariant, active: placementAxis === \"right\" }\n ),\n };\n\n const canvasCtx = usePlasmicCanvasContext();\n const args = {\n ...pick(props, ...plasmicClass.internalArgProps),\n [config.contentSlot]:\n canvasCtx && !canvasCtx.interactive ? (\n children\n ) : (\n <FocusScope restoreFocus>\n <DismissButton onDismiss={state.close} />\n {children}\n {/* We don't use the DismissButton at the end because it ends up taking up 1px space :-/ */}\n {/* <DismissButton onDismiss={state.close} /> */}\n </FocusScope>\n ),\n };\n\n const overrides: Overrides = {\n [config.root]: {\n props: mergeProps(overlayProps, getStyleProps(props), {\n ref: onOverlayRef,\n }),\n wrap: (root: React.ReactNode) => {\n if (typeof document !== \"undefined\") {\n return ReactDOM.createPortal(root, document.body);\n } else {\n // Possibly being invoked on the server during SSR; no need to\n // bother with a portal in that case.\n return root;\n }\n },\n },\n };\n\n return {\n plasmicProps: {\n variants: variants as PlasmicClassVariants<C>,\n args: args as PlasmicClassArgs<C>,\n overrides: overrides as PlasmicClassOverrides<C>,\n },\n };\n}\n"],"names":[],"mappings":"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"}
|