@qyu/reactcmp-dropdown 2.0.1 → 2.1.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 +10 -1
- package/build/bundle/entry/index.js +41 -18
- package/build/declaration/component/list-fix/element/view.d.ts +2 -0
- package/build/declaration/component/list-portal/element/view.d.ts +2 -0
- package/build/declaration/hook/listpos/api/fixed.d.ts +2 -0
- package/build/declaration/util/prop/stretch/new/index.d.ts +2 -0
- package/build/declaration/util/prop/stretch/type/prop.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -46,6 +46,8 @@ function DDN(props: { children: r.Children }) {
|
|
|
46
46
|
align={"start"}
|
|
47
47
|
// optional
|
|
48
48
|
justify={"end"}
|
|
49
|
+
// optional
|
|
50
|
+
stretch={"min"}
|
|
49
51
|
>
|
|
50
52
|
{/* Used to measure content. Required for any list */}
|
|
51
53
|
<ddn.Content>
|
|
@@ -87,7 +89,7 @@ const CustomButton = function () {
|
|
|
87
89
|
// this will give you calculated value of wether your dropdown is open or not
|
|
88
90
|
const open = ddn.useOpenInfer({})
|
|
89
91
|
|
|
90
|
-
// this wrapper is required, it necessary events and stuff
|
|
92
|
+
// this wrapper is required, it registers necessary events and stuff
|
|
91
93
|
return <ddn.ButtonVirtual target={ref}>
|
|
92
94
|
<button
|
|
93
95
|
ref={ref}
|
|
@@ -198,6 +200,13 @@ function App() {
|
|
|
198
200
|
// set justify directly
|
|
199
201
|
justify={"end" || "start"}
|
|
200
202
|
|
|
203
|
+
// stretch to min default is "none"
|
|
204
|
+
stretch
|
|
205
|
+
// set stretch directly
|
|
206
|
+
// "min" stretches it to the size of the root if list is smaller
|
|
207
|
+
// "strict" sets the size of the root to the list
|
|
208
|
+
stretch={"none" | "min" | "strict"}
|
|
209
|
+
|
|
201
210
|
// recalculate position on, optional
|
|
202
211
|
// default values shown below
|
|
203
212
|
rearrange={{
|
|
@@ -412,6 +412,26 @@ const useFocusCaptureInfer = function (params) {
|
|
|
412
412
|
});
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
+
const prop_stretch_new = function (raw) {
|
|
416
|
+
if (!raw) {
|
|
417
|
+
return "none";
|
|
418
|
+
}
|
|
419
|
+
if (raw === true) {
|
|
420
|
+
return "min";
|
|
421
|
+
}
|
|
422
|
+
return raw;
|
|
423
|
+
};
|
|
424
|
+
|
|
425
|
+
const stretch_apply = function (stretch, target, container) {
|
|
426
|
+
switch (stretch) {
|
|
427
|
+
case "none":
|
|
428
|
+
return target;
|
|
429
|
+
case "min":
|
|
430
|
+
return Math.max(target, container);
|
|
431
|
+
case "strict":
|
|
432
|
+
return container;
|
|
433
|
+
}
|
|
434
|
+
};
|
|
415
435
|
const normalize_justify$1 = function (params) {
|
|
416
436
|
let axis_main;
|
|
417
437
|
switch (params.direction) {
|
|
@@ -475,9 +495,10 @@ const normalize_align$1 = function (params) {
|
|
|
475
495
|
break;
|
|
476
496
|
}
|
|
477
497
|
}
|
|
498
|
+
const list_size_normalized = stretch_apply(params.stretch, axis_main.list_size, axis_main.container_size);
|
|
478
499
|
switch (params.align) {
|
|
479
500
|
case "center": {
|
|
480
|
-
if (
|
|
501
|
+
if (list_size_normalized >= axis_main.screen_size) {
|
|
481
502
|
params.reverse_set(false);
|
|
482
503
|
axis_main.size_set(axis_main.screen_size);
|
|
483
504
|
axis_main.flow_direct.position_set(0);
|
|
@@ -485,26 +506,26 @@ const normalize_align$1 = function (params) {
|
|
|
485
506
|
}
|
|
486
507
|
else {
|
|
487
508
|
const point = axis_main.container_pos + axis_main.container_size / 2;
|
|
488
|
-
const spacereq =
|
|
509
|
+
const spacereq = list_size_normalized / 2;
|
|
489
510
|
const freespace_reverse = point;
|
|
490
511
|
const freespace_direct = axis_main.screen_size - point;
|
|
491
512
|
if (spacereq >= freespace_reverse) {
|
|
492
513
|
params.reverse_set(false);
|
|
493
514
|
axis_main.flow_direct.position_set(0);
|
|
494
515
|
axis_main.flow_reverse.position_set(null);
|
|
495
|
-
axis_main.size_set(
|
|
516
|
+
axis_main.size_set(list_size_normalized);
|
|
496
517
|
}
|
|
497
518
|
else if (spacereq >= freespace_direct) {
|
|
498
519
|
params.reverse_set(true);
|
|
499
520
|
axis_main.flow_reverse.position_set(0);
|
|
500
521
|
axis_main.flow_direct.position_set(null);
|
|
501
|
-
axis_main.size_set(
|
|
522
|
+
axis_main.size_set(list_size_normalized);
|
|
502
523
|
}
|
|
503
524
|
else {
|
|
504
525
|
params.reverse_set(false);
|
|
505
526
|
axis_main.flow_direct.position_set(point - spacereq);
|
|
506
527
|
axis_main.flow_reverse.position_set(null);
|
|
507
|
-
axis_main.size_set(
|
|
528
|
+
axis_main.size_set(list_size_normalized);
|
|
508
529
|
}
|
|
509
530
|
}
|
|
510
531
|
break;
|
|
@@ -515,18 +536,18 @@ const normalize_align$1 = function (params) {
|
|
|
515
536
|
const flow_direct = axis_main.flow_direct;
|
|
516
537
|
const flow_reverse = axis_main.flow_reverse;
|
|
517
538
|
const position_direct = Math.max(0, (+axis_main.container_pos
|
|
518
|
-
- Math.max(0,
|
|
539
|
+
- Math.max(0, list_size_normalized - freespace_direct)));
|
|
519
540
|
const position_reverse = Math.max(0, (+axis_main.screen_size
|
|
520
541
|
- (axis_main.container_pos + axis_main.container_size)
|
|
521
|
-
- Math.max(0,
|
|
522
|
-
if (freespace_direct >=
|
|
542
|
+
- Math.max(0, list_size_normalized - freespace_reverse)));
|
|
543
|
+
if (freespace_direct >= list_size_normalized || freespace_direct >= freespace_reverse) {
|
|
523
544
|
params.reverse_set(false);
|
|
524
|
-
axis_main.size_set(Math.min(freespace_direct,
|
|
545
|
+
axis_main.size_set(Math.min(freespace_direct, list_size_normalized));
|
|
525
546
|
flow_direct.position_set(position_direct);
|
|
526
547
|
}
|
|
527
548
|
else {
|
|
528
549
|
params.reverse_set(true);
|
|
529
|
-
axis_main.size_set(Math.min(freespace_reverse,
|
|
550
|
+
axis_main.size_set(Math.min(freespace_reverse, list_size_normalized));
|
|
530
551
|
flow_direct.position_set(null);
|
|
531
552
|
flow_reverse.position_set(position_reverse);
|
|
532
553
|
}
|
|
@@ -539,18 +560,18 @@ const normalize_align$1 = function (params) {
|
|
|
539
560
|
const flow_reverse = axis_main.flow_direct;
|
|
540
561
|
const position_direct = Math.max(0, (+axis_main.screen_size
|
|
541
562
|
- (axis_main.container_pos + axis_main.container_size)
|
|
542
|
-
- Math.max(0,
|
|
563
|
+
- Math.max(0, list_size_normalized - freespace_direct)));
|
|
543
564
|
const position_reverse = Math.max(0, (+axis_main.container_pos
|
|
544
|
-
- Math.max(0,
|
|
545
|
-
if (freespace_direct >=
|
|
565
|
+
- Math.max(0, list_size_normalized - freespace_reverse)));
|
|
566
|
+
if (freespace_direct >= list_size_normalized || freespace_direct >= freespace_reverse) {
|
|
546
567
|
params.reverse_set(false);
|
|
547
|
-
axis_main.size_set(Math.min(freespace_direct,
|
|
568
|
+
axis_main.size_set(Math.min(freespace_direct, list_size_normalized));
|
|
548
569
|
flow_reverse.position_set(null);
|
|
549
570
|
flow_direct.position_set(position_direct);
|
|
550
571
|
}
|
|
551
572
|
else {
|
|
552
573
|
params.reverse_set(true);
|
|
553
|
-
axis_main.size_set(Math.min(freespace_reverse,
|
|
574
|
+
axis_main.size_set(Math.min(freespace_reverse, list_size_normalized));
|
|
554
575
|
flow_direct.position_set(null);
|
|
555
576
|
flow_reverse.position_set(position_reverse);
|
|
556
577
|
}
|
|
@@ -559,6 +580,7 @@ const normalize_align$1 = function (params) {
|
|
|
559
580
|
}
|
|
560
581
|
};
|
|
561
582
|
const useListPosApiFixed = function (params) {
|
|
583
|
+
const nprop_stretch = prop_stretch_new(params.stretch);
|
|
562
584
|
const ctxstate_refs = useCtxStateRefs();
|
|
563
585
|
const [align_reverse, align_reverse_set] = r.useState(false);
|
|
564
586
|
const [justify_reverse, justify_reverse_set] = r.useState(false);
|
|
@@ -639,6 +661,7 @@ const useListPosApiFixed = function (params) {
|
|
|
639
661
|
axis_main,
|
|
640
662
|
axis_cross,
|
|
641
663
|
align: config.align,
|
|
664
|
+
stretch: nprop_stretch,
|
|
642
665
|
direction: config.direction,
|
|
643
666
|
reverse_set: align_reverse_set,
|
|
644
667
|
});
|
|
@@ -647,7 +670,7 @@ const useListPosApiFixed = function (params) {
|
|
|
647
670
|
}
|
|
648
671
|
}
|
|
649
672
|
},
|
|
650
|
-
}), [ctxstate_refs.rootref, params.ref_list, params.ref_content])
|
|
673
|
+
}), [ctxstate_refs.rootref, params.ref_list, params.ref_content, nprop_stretch])
|
|
651
674
|
};
|
|
652
675
|
};
|
|
653
676
|
|
|
@@ -899,7 +922,7 @@ const CmpListFix = r.memo(r.forwardRef((props, f_ref) => {
|
|
|
899
922
|
const ref_content = useRefO(l_ref_content);
|
|
900
923
|
const open = useOpenInfer({});
|
|
901
924
|
const [visible, visible_set] = r.useState(false);
|
|
902
|
-
const listapi = useListPosApiFixed({ ref_list, ref_content, clmap_content: nprop_clmap_content });
|
|
925
|
+
const listapi = useListPosApiFixed({ ref_list, ref_content, clmap_content: nprop_clmap_content, stretch: props.stretch, });
|
|
903
926
|
const ctxstate_content = useCtxStateInitContent({
|
|
904
927
|
ref_content: l_ref_content,
|
|
905
928
|
});
|
|
@@ -1248,7 +1271,7 @@ const CmpListPortal = r.memo(r.forwardRef((props, f_ref) => {
|
|
|
1248
1271
|
const ref_content = useRefO(l_ref_content);
|
|
1249
1272
|
const open = useOpenInfer({});
|
|
1250
1273
|
const [visible, visible_set] = r.useState(false);
|
|
1251
|
-
const listapi = useListPosApiFixed({ ref_list, ref_content, clmap_content: nprop_clmap_content });
|
|
1274
|
+
const listapi = useListPosApiFixed({ ref_list, ref_content, clmap_content: nprop_clmap_content, stretch: props.stretch });
|
|
1252
1275
|
const ctxstate_content = useCtxStateInitContent({
|
|
1253
1276
|
ref_content: l_ref_content,
|
|
1254
1277
|
});
|
|
@@ -5,12 +5,14 @@ import { prop_clmap_def_listfix } from "../../../util/prop/clmap/def/listfix.js"
|
|
|
5
5
|
import type { PropClMap_Raw } from "../../../util/prop/clmap/type/prop.js";
|
|
6
6
|
import type { PropDirection_Raw } from "../../../util/prop/direction/type/prop.js";
|
|
7
7
|
import type { PropJustify_Raw } from "../../../util/prop/justify/type/prop.js";
|
|
8
|
+
import type { PropStretch_Raw } from "../../../util/prop/stretch/type/prop.js";
|
|
8
9
|
import * as r from "react";
|
|
9
10
|
export type CmpListFix_Props = {
|
|
10
11
|
readonly gap?: number;
|
|
11
12
|
readonly lazy?: boolean;
|
|
12
13
|
readonly align?: PropAlign_Raw;
|
|
13
14
|
readonly justify?: PropJustify_Raw;
|
|
15
|
+
readonly stretch?: PropStretch_Raw;
|
|
14
16
|
readonly direction?: PropDirection_Raw;
|
|
15
17
|
readonly clmap?: PropClMap_Raw<keyof typeof prop_clmap_def_listfix>;
|
|
16
18
|
readonly clmap_content?: PropClMap_Raw<keyof typeof prop_clmap_def_content>;
|
|
@@ -6,11 +6,13 @@ import type { PropClMap_Raw } from "../../../util/prop/clmap/type/prop.js";
|
|
|
6
6
|
import type { PropDirection_Raw } from "../../../util/prop/direction/type/prop.js";
|
|
7
7
|
import type { PropJustify_Raw } from "../../../util/prop/justify/type/prop.js";
|
|
8
8
|
import type { PropPortal_Raw } from "../../../util/prop/portal/type/prop.js";
|
|
9
|
+
import type { PropStretch_Raw } from "../../../util/prop/stretch/type/prop.js";
|
|
9
10
|
import * as r from "react";
|
|
10
11
|
export type CmpListPortal_Props = {
|
|
11
12
|
readonly portal: NonNullable<PropPortal_Raw>;
|
|
12
13
|
readonly gap?: number;
|
|
13
14
|
readonly lazy?: boolean;
|
|
15
|
+
readonly stretch?: PropStretch_Raw;
|
|
14
16
|
readonly align?: PropAlign_Raw;
|
|
15
17
|
readonly justify?: PropJustify_Raw;
|
|
16
18
|
readonly direction?: PropDirection_Raw;
|
|
@@ -4,6 +4,7 @@ import type { ListPosApi_Reverse } from "./type/reverse.js";
|
|
|
4
4
|
import type { ListPosApi_Size } from "./type/size.js";
|
|
5
5
|
import type { FnORefHTML } from "../../../type/fnref.js";
|
|
6
6
|
import type { PropClMap_DefContent } from "../../../util/prop/clmap/def/content.js";
|
|
7
|
+
import type { PropStretch_Raw } from "../../../util/prop/stretch/type/prop.js";
|
|
7
8
|
export type UseListPosFixed_Return = {
|
|
8
9
|
readonly api: ListPosApi_Api;
|
|
9
10
|
readonly size: ListPosApi_Size;
|
|
@@ -14,5 +15,6 @@ export type UseListPosFixed_Params = {
|
|
|
14
15
|
readonly ref_list: FnORefHTML;
|
|
15
16
|
readonly ref_content: FnORefHTML;
|
|
16
17
|
readonly clmap_content: PropClMap_DefContent;
|
|
18
|
+
readonly stretch?: PropStretch_Raw;
|
|
17
19
|
};
|
|
18
20
|
export declare const useListPosApiFixed: (params: UseListPosFixed_Params) => UseListPosFixed_Return;
|