@qyu/reactcmp-dropdown 2.0.0 → 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 +44 -20
- 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,25 +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;
|
|
509
|
+
const spacereq = list_size_normalized / 2;
|
|
488
510
|
const freespace_reverse = point;
|
|
489
511
|
const freespace_direct = axis_main.screen_size - point;
|
|
490
|
-
if (
|
|
512
|
+
if (spacereq >= freespace_reverse) {
|
|
491
513
|
params.reverse_set(false);
|
|
492
514
|
axis_main.flow_direct.position_set(0);
|
|
493
515
|
axis_main.flow_reverse.position_set(null);
|
|
494
|
-
axis_main.size_set(
|
|
516
|
+
axis_main.size_set(list_size_normalized);
|
|
495
517
|
}
|
|
496
|
-
else if (
|
|
518
|
+
else if (spacereq >= freespace_direct) {
|
|
497
519
|
params.reverse_set(true);
|
|
498
520
|
axis_main.flow_reverse.position_set(0);
|
|
499
521
|
axis_main.flow_direct.position_set(null);
|
|
500
|
-
axis_main.size_set(
|
|
522
|
+
axis_main.size_set(list_size_normalized);
|
|
501
523
|
}
|
|
502
524
|
else {
|
|
503
525
|
params.reverse_set(false);
|
|
504
|
-
axis_main.flow_direct.position_set(point -
|
|
526
|
+
axis_main.flow_direct.position_set(point - spacereq);
|
|
505
527
|
axis_main.flow_reverse.position_set(null);
|
|
506
|
-
axis_main.size_set(
|
|
528
|
+
axis_main.size_set(list_size_normalized);
|
|
507
529
|
}
|
|
508
530
|
}
|
|
509
531
|
break;
|
|
@@ -514,18 +536,18 @@ const normalize_align$1 = function (params) {
|
|
|
514
536
|
const flow_direct = axis_main.flow_direct;
|
|
515
537
|
const flow_reverse = axis_main.flow_reverse;
|
|
516
538
|
const position_direct = Math.max(0, (+axis_main.container_pos
|
|
517
|
-
- Math.max(0,
|
|
539
|
+
- Math.max(0, list_size_normalized - freespace_direct)));
|
|
518
540
|
const position_reverse = Math.max(0, (+axis_main.screen_size
|
|
519
541
|
- (axis_main.container_pos + axis_main.container_size)
|
|
520
|
-
- Math.max(0,
|
|
521
|
-
if (freespace_direct >=
|
|
542
|
+
- Math.max(0, list_size_normalized - freespace_reverse)));
|
|
543
|
+
if (freespace_direct >= list_size_normalized || freespace_direct >= freespace_reverse) {
|
|
522
544
|
params.reverse_set(false);
|
|
523
|
-
axis_main.size_set(Math.min(freespace_direct,
|
|
545
|
+
axis_main.size_set(Math.min(freespace_direct, list_size_normalized));
|
|
524
546
|
flow_direct.position_set(position_direct);
|
|
525
547
|
}
|
|
526
548
|
else {
|
|
527
549
|
params.reverse_set(true);
|
|
528
|
-
axis_main.size_set(Math.min(freespace_reverse,
|
|
550
|
+
axis_main.size_set(Math.min(freespace_reverse, list_size_normalized));
|
|
529
551
|
flow_direct.position_set(null);
|
|
530
552
|
flow_reverse.position_set(position_reverse);
|
|
531
553
|
}
|
|
@@ -538,18 +560,18 @@ const normalize_align$1 = function (params) {
|
|
|
538
560
|
const flow_reverse = axis_main.flow_direct;
|
|
539
561
|
const position_direct = Math.max(0, (+axis_main.screen_size
|
|
540
562
|
- (axis_main.container_pos + axis_main.container_size)
|
|
541
|
-
- Math.max(0,
|
|
563
|
+
- Math.max(0, list_size_normalized - freespace_direct)));
|
|
542
564
|
const position_reverse = Math.max(0, (+axis_main.container_pos
|
|
543
|
-
- Math.max(0,
|
|
544
|
-
if (freespace_direct >=
|
|
565
|
+
- Math.max(0, list_size_normalized - freespace_reverse)));
|
|
566
|
+
if (freespace_direct >= list_size_normalized || freespace_direct >= freespace_reverse) {
|
|
545
567
|
params.reverse_set(false);
|
|
546
|
-
axis_main.size_set(Math.min(freespace_direct,
|
|
568
|
+
axis_main.size_set(Math.min(freespace_direct, list_size_normalized));
|
|
547
569
|
flow_reverse.position_set(null);
|
|
548
570
|
flow_direct.position_set(position_direct);
|
|
549
571
|
}
|
|
550
572
|
else {
|
|
551
573
|
params.reverse_set(true);
|
|
552
|
-
axis_main.size_set(Math.min(freespace_reverse,
|
|
574
|
+
axis_main.size_set(Math.min(freespace_reverse, list_size_normalized));
|
|
553
575
|
flow_direct.position_set(null);
|
|
554
576
|
flow_reverse.position_set(position_reverse);
|
|
555
577
|
}
|
|
@@ -558,6 +580,7 @@ const normalize_align$1 = function (params) {
|
|
|
558
580
|
}
|
|
559
581
|
};
|
|
560
582
|
const useListPosApiFixed = function (params) {
|
|
583
|
+
const nprop_stretch = prop_stretch_new(params.stretch);
|
|
561
584
|
const ctxstate_refs = useCtxStateRefs();
|
|
562
585
|
const [align_reverse, align_reverse_set] = r.useState(false);
|
|
563
586
|
const [justify_reverse, justify_reverse_set] = r.useState(false);
|
|
@@ -638,6 +661,7 @@ const useListPosApiFixed = function (params) {
|
|
|
638
661
|
axis_main,
|
|
639
662
|
axis_cross,
|
|
640
663
|
align: config.align,
|
|
664
|
+
stretch: nprop_stretch,
|
|
641
665
|
direction: config.direction,
|
|
642
666
|
reverse_set: align_reverse_set,
|
|
643
667
|
});
|
|
@@ -646,7 +670,7 @@ const useListPosApiFixed = function (params) {
|
|
|
646
670
|
}
|
|
647
671
|
}
|
|
648
672
|
},
|
|
649
|
-
}), [ctxstate_refs.rootref, params.ref_list, params.ref_content])
|
|
673
|
+
}), [ctxstate_refs.rootref, params.ref_list, params.ref_content, nprop_stretch])
|
|
650
674
|
};
|
|
651
675
|
};
|
|
652
676
|
|
|
@@ -898,7 +922,7 @@ const CmpListFix = r.memo(r.forwardRef((props, f_ref) => {
|
|
|
898
922
|
const ref_content = useRefO(l_ref_content);
|
|
899
923
|
const open = useOpenInfer({});
|
|
900
924
|
const [visible, visible_set] = r.useState(false);
|
|
901
|
-
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, });
|
|
902
926
|
const ctxstate_content = useCtxStateInitContent({
|
|
903
927
|
ref_content: l_ref_content,
|
|
904
928
|
});
|
|
@@ -1247,7 +1271,7 @@ const CmpListPortal = r.memo(r.forwardRef((props, f_ref) => {
|
|
|
1247
1271
|
const ref_content = useRefO(l_ref_content);
|
|
1248
1272
|
const open = useOpenInfer({});
|
|
1249
1273
|
const [visible, visible_set] = r.useState(false);
|
|
1250
|
-
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 });
|
|
1251
1275
|
const ctxstate_content = useCtxStateInitContent({
|
|
1252
1276
|
ref_content: l_ref_content,
|
|
1253
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;
|