@qyu/reactcmp-dropdown 1.1.0 → 1.2.0

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/README.md CHANGED
@@ -50,6 +50,7 @@ function App() {
50
50
  </ddn.CmpButton>
51
51
 
52
52
  <ddn.CmpListAbs
53
+ tabIndex={0}
53
54
  className={""}
54
55
  stylemodule={stylemodule}
55
56
 
@@ -79,6 +80,7 @@ function App() {
79
80
 
80
81
  {/* Same as CmpListAbs, but uses fixed positioning */}
81
82
  <ddn.CmpListFix
83
+ tabIndex={0}
82
84
  className={""}
83
85
  stylemodule={stylemodule}
84
86
 
@@ -102,6 +104,10 @@ function App() {
102
104
  justify
103
105
  // set justify directly
104
106
  jystify={"end" || "start"}
107
+
108
+ // when string - finds portal by id
109
+ // when HTMLElement - uses element for portal
110
+ portal={"dropdowns" || document.getElementById("dropdowns")}
105
111
  >
106
112
  Your Content Here
107
113
  </ddn.CmpListFix>
@@ -1,5 +1,6 @@
1
1
  import * as r from 'react';
2
2
  import { jsx } from 'react/jsx-runtime';
3
+ import * as rdom from 'react-dom';
3
4
 
4
5
  const CmpCtxState_Open = r.createContext(null);
5
6
 
@@ -169,6 +170,15 @@ const nprop_direction_new = function (raw) {
169
170
  }
170
171
  return raw;
171
172
  };
173
+ const nprop_portal_new = function (portal) {
174
+ if (typeof portal === "string") {
175
+ return document.getElementById(portal) ?? null;
176
+ }
177
+ if (portal) {
178
+ return portal;
179
+ }
180
+ return null;
181
+ };
172
182
 
173
183
  const stylemap$1 = {
174
184
  listfix: "listfix",
@@ -315,6 +325,7 @@ const CmpListFix = r.memo(r.forwardRef((props, ref) => {
315
325
  const nprop_gap = props.gap ?? 0;
316
326
  const nprop_lazy = props.lazy ?? false;
317
327
  const nprop_align = nprop_align_new(props.align);
328
+ const nprop_portal = nprop_portal_new(props.portal);
318
329
  const nprop_justify = nprop_justify_new(props.justify);
319
330
  const nprop_direction = nprop_direction_new(props.direction);
320
331
  const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap$1, props.stylemodule) : stylemap$1), [props.stylemodule]);
@@ -404,7 +415,7 @@ const CmpListFix = r.memo(r.forwardRef((props, ref) => {
404
415
  }
405
416
  return null;
406
417
  }, [nprop_lazy, visible, ctxstate.open, props.children]);
407
- return jsx("div", { ref: mref, tabIndex: props.tabIndex, className: cl("__qyuddn", props.className, nprop_style.listfix, ctxstate.open && nprop_style.listfix_open, ((nprop_align === "end" && !revalign) || (nprop_align === "start" && revalign)) && nprop_style.listfix_align_end, ((nprop_align === "start" && !revalign) || (nprop_align === "end" && revalign)) && nprop_style.listfix_align_start, nprop_align === "center" && nprop_style.listfix_align_center, ((nprop_justify === "end") !== revjustify) && nprop_style.listfix_justify_end, ((nprop_justify === "start") !== revjustify) && nprop_style.listfix_justify_start, nprop_direction === "hor" && nprop_style.listfix_horizontal, nprop_direction === "ver" && nprop_style.listfix_vertical), style: {
418
+ const element = jsx("div", { ref: mref, tabIndex: props.tabIndex, className: cl("__qyuddn", props.className, nprop_style.listfix, ctxstate.open && nprop_style.listfix_open, ((nprop_align === "end" && !revalign) || (nprop_align === "start" && revalign)) && nprop_style.listfix_align_end, ((nprop_align === "start" && !revalign) || (nprop_align === "end" && revalign)) && nprop_style.listfix_align_start, nprop_align === "center" && nprop_style.listfix_align_center, ((nprop_justify === "end") !== revjustify) && nprop_style.listfix_justify_end, ((nprop_justify === "start") !== revjustify) && nprop_style.listfix_justify_start, nprop_direction === "hor" && nprop_style.listfix_horizontal, nprop_direction === "ver" && nprop_style.listfix_vertical), style: {
408
419
  ["--gap"]: `${nprop_gap}px`,
409
420
  top: top !== null ? `${top}px` : null,
410
421
  left: left !== null ? `${left}px` : null,
@@ -429,6 +440,10 @@ const CmpListFix = r.memo(r.forwardRef((props, ref) => {
429
440
  right_set(null);
430
441
  }
431
442
  }, children: children });
443
+ if (nprop_portal) {
444
+ return rdom.createPortal(element, nprop_portal);
445
+ }
446
+ return element;
432
447
  }));
433
448
 
434
449
  const stylemap = {
@@ -21,6 +21,7 @@ export type CmpListFix_Props = Readonly<{
21
21
  tabIndex?: number;
22
22
  justify?: JustifyRaw;
23
23
  direction?: DirectionRaw;
24
+ portal?: string | HTMLElement;
24
25
  className?: string;
25
26
  stylemodule?: CmpListFix_StyleModule;
26
27
  children?: r.ReactNode | (() => r.ReactNode);
@@ -32,6 +33,7 @@ export declare const CmpListFix: r.NamedExoticComponent<Readonly<{
32
33
  tabIndex?: number;
33
34
  justify?: JustifyRaw;
34
35
  direction?: DirectionRaw;
36
+ portal?: string | HTMLElement;
35
37
  className?: string;
36
38
  stylemodule?: CmpListFix_StyleModule;
37
39
  children?: r.ReactNode | (() => r.ReactNode);
@@ -2,3 +2,4 @@ import type { Align, AlignRaw, Direction, DirectionRaw, Justify, JustifyRaw } fr
2
2
  export declare const nprop_align_new: (raw: AlignRaw) => Align;
3
3
  export declare const nprop_justify_new: (raw: JustifyRaw) => Justify;
4
4
  export declare const nprop_direction_new: (raw: DirectionRaw) => Direction;
5
+ export declare const nprop_portal_new: (portal: string | HTMLElement | undefined | null) => HTMLElement | null;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@qyu/reactcmp-dropdown",
3
3
  "type": "module",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "main": "./build/bundle/entry/index.js",
6
6
  "description": "React Components for Dropdown Positioning",
7
7
  "keywords": [