@qyu/reactcmp-dropdown 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 qlwt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,138 @@
1
+ # @qyu/reactcmp-dropdown
2
+
3
+ React Component Library for solving dropdown positioning problems
4
+
5
+ ## First include styles
6
+
7
+ ```typescript
8
+ // import styles with your bundler or copy them by hand and reference in your html
9
+ import "@qyu/reactcmp-dropdown/style/index.global"
10
+ // or import module and insert them directly to the component
11
+ import stylemodule from "@qyu/reactcmp-dropdown/stlye/index.module"
12
+ ```
13
+
14
+ ## Use Dropdown
15
+
16
+ ```tsx
17
+ import * as ddn from "qyu/reactcmp-dropdown"
18
+
19
+ function App() {
20
+ const [open, open_set] = r.useState(false)
21
+
22
+ return <ddn.CmpContainer
23
+ // optional, will be added to other styles
24
+ className={""}
25
+ // here you can insert styles in modular form
26
+ stylemodule={stylemodule}
27
+
28
+ // optional, will use local state if not provided
29
+ open={open}
30
+ open_set={open_set}
31
+
32
+ // on which events should close the dropdown
33
+ // optional, all true by default
34
+ closeevents={{
35
+ // focus going outside the container
36
+ blur: true,
37
+ // click anywhere outside
38
+ click: true,
39
+ // scroll of any parent
40
+ scroll: true,
41
+ // page resize
42
+ resize: true,
43
+ // press escape
44
+ escape: true,
45
+ }}
46
+ >
47
+ {/* You would often want to imlement you own button. See futher */}
48
+ <ddn.CmpButton className={""}>
49
+ Press
50
+ </ddn.CmpButton>
51
+
52
+ <ddn.CmpListAbs
53
+ className={""}
54
+ stylemodule={stylemodule}
55
+
56
+ // do not render children when hidden, default if false
57
+ lazy
58
+
59
+ // add gap between button and list, in pixels
60
+ gap={5}
61
+
62
+ // inverse direction default if "ver"
63
+ direction
64
+ // set direction directly
65
+ direction={"hor" || "ver"}
66
+
67
+ // inverse align default is "start"
68
+ align
69
+ // set align directly
70
+ align={"start" || "end" || "center"}
71
+
72
+ // inverse justify default is "end"
73
+ justify
74
+ // set justify directly
75
+ jystify={"end" || "start"}
76
+ >
77
+ Your Content Here
78
+ </ddn.CmpListAbs>
79
+
80
+ {/* Same as CmpListAbs, but uses fixed positioning */}
81
+ <ddn.CmpListFix
82
+ className={""}
83
+ stylemodule={stylemodule}
84
+
85
+ // do not render children when hidden, default if false
86
+ lazy
87
+
88
+ // add gap between button and list, in pixels
89
+ gap={5}
90
+
91
+ // inverse direction default if "ver"
92
+ direction
93
+ // set direction directly
94
+ direction={"hor" || "ver"}
95
+
96
+ // inverse align default is "start"
97
+ align
98
+ // set align directly
99
+ align={"start" || "end" || "center"}
100
+
101
+ // inverse justify default is "end"
102
+ justify
103
+ // set justify directly
104
+ jystify={"end" || "start"}
105
+ >
106
+ Your Content Here
107
+ </ddn.CmpListFix>
108
+ </ddn.CmpContainer>
109
+ }
110
+ ```
111
+
112
+ ## Making your custom button
113
+
114
+ ```tsx
115
+ export const CmpButton = () => {
116
+ // just listen to the context state
117
+ const ctxstate = r.useContext(CmpCtxState_Open)
118
+
119
+ if (!ctxstate) { throw new Error(`Using DropdownStateOpen dependend component outside of DropdownStateOpen Context`) }
120
+
121
+ return <button
122
+ onClick={() => {
123
+ ctxstate.open_set(t => !t)
124
+ }}
125
+ >
126
+ Press
127
+ </button>
128
+ }
129
+ ```
130
+
131
+ ## Change Transition time and z-index
132
+
133
+ ```css
134
+ :root {
135
+ --qyuddn-z-index: 3;
136
+ --qyuddn-trtime: 0.2s;
137
+ }
138
+ ```
@@ -0,0 +1,632 @@
1
+ import * as r from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ const CmpCtxState_Open = r.createContext(null);
5
+
6
+ const CmpButton = props => {
7
+ const ctxstate = r.useContext(CmpCtxState_Open);
8
+ if (!ctxstate) {
9
+ throw new Error(`Using DropdownStateOpen dependend component outside of DropdownStateOpen Context`);
10
+ }
11
+ const event_click = r.useCallback(() => {
12
+ ctxstate.open_set(t => !t);
13
+ }, []);
14
+ return jsx("button", { onClick: event_click, className: props.className, children: props.children });
15
+ };
16
+
17
+ const useDropdownCloseEvents = function (params) {
18
+ const nconfig_blur = params.config?.blur ?? true;
19
+ const nconfig_click = params.config?.click ?? true;
20
+ const nconfig_scroll = params.config?.scroll ?? true;
21
+ const nconfig_resize = params.config?.resize ?? true;
22
+ const nconfig_escape = params.config?.escape ?? true;
23
+ r.useEffect(() => {
24
+ const container = params.ref();
25
+ if (params.open && container) {
26
+ const controller = new AbortController();
27
+ if (nconfig_blur) {
28
+ container.addEventListener("focusout", ev => {
29
+ if (!(ev.relatedTarget instanceof Element) || !container.contains(ev.relatedTarget)) {
30
+ params.open_set(false);
31
+ }
32
+ }, { signal: controller.signal });
33
+ }
34
+ if (nconfig_click) {
35
+ document.addEventListener("click", ev => {
36
+ const path = ev.composedPath();
37
+ if (!container || !path.includes(container)) {
38
+ params.open_set(false);
39
+ }
40
+ }, { signal: controller.signal });
41
+ }
42
+ if (nconfig_escape) {
43
+ document.addEventListener("keydown", ev => {
44
+ if (!ev.defaultPrevented && ev.key.toLowerCase() === "escape") {
45
+ params.open_set(false);
46
+ ev.preventDefault();
47
+ }
48
+ }, { signal: controller.signal });
49
+ }
50
+ if (nconfig_resize) {
51
+ window.addEventListener("resize", () => {
52
+ params.open_set(false);
53
+ }, { signal: controller.signal });
54
+ }
55
+ if (nconfig_scroll) {
56
+ let parent = container.parentElement;
57
+ while (parent) {
58
+ parent.addEventListener("scroll", () => {
59
+ params.open_set(false);
60
+ }, { signal: controller.signal });
61
+ parent = parent.parentElement;
62
+ }
63
+ document.addEventListener("scroll", () => {
64
+ params.open_set(false);
65
+ }, { signal: controller.signal });
66
+ }
67
+ return () => {
68
+ controller.abort();
69
+ };
70
+ }
71
+ }, [
72
+ params.ref,
73
+ params.open,
74
+ params.open_set,
75
+ nconfig_click,
76
+ nconfig_scroll,
77
+ nconfig_resize,
78
+ nconfig_escape
79
+ ]);
80
+ };
81
+
82
+ const cl = function (...clnames) {
83
+ let result = [];
84
+ for (const clname of clnames) {
85
+ if (clname) {
86
+ result.push(clname);
87
+ }
88
+ }
89
+ return result.join(" ");
90
+ };
91
+
92
+ const stylemap_new_remap = function (def, remap) {
93
+ const result = {};
94
+ for (const clname of Object.keys(def)) {
95
+ const remaped = remap[clname];
96
+ if (remaped !== undefined) {
97
+ result[clname] = remaped;
98
+ continue;
99
+ }
100
+ {
101
+ result[clname] = clname;
102
+ }
103
+ }
104
+ return result;
105
+ };
106
+
107
+ const stylemap$2 = {
108
+ container: "container"
109
+ };
110
+ const CmpContainer = r.memo(r.forwardRef((props, ref) => {
111
+ const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap$2, props.stylemodule) : stylemap$2), [props.stylemodule]);
112
+ const l_ref = r.useRef(null);
113
+ const [open, open_set] = r.useState(false);
114
+ const l_open = props.open ?? open;
115
+ const l_open_set = props.open_set ?? open_set;
116
+ const ctxstate = r.useMemo(() => {
117
+ return {
118
+ open: l_open,
119
+ ref: l_ref,
120
+ open_set: l_open_set,
121
+ };
122
+ }, [l_open, l_open_set]);
123
+ const mref = r.useMemo(() => {
124
+ return (element) => {
125
+ l_ref.current = element;
126
+ if (ref) {
127
+ if (typeof ref === "object") {
128
+ ref.current = element;
129
+ }
130
+ else {
131
+ ref(element);
132
+ }
133
+ }
134
+ };
135
+ }, [ref]);
136
+ useDropdownCloseEvents({
137
+ config: props.closeevents,
138
+ ref: r.useCallback(() => l_ref.current, []),
139
+ open: ctxstate.open,
140
+ open_set: ctxstate.open_set,
141
+ });
142
+ return jsx("div", { ref: mref, className: cl("__qyuddn", props.className, nprop_style.container), children: jsx(CmpCtxState_Open.Provider, { value: ctxstate, children: props.children }) });
143
+ }));
144
+
145
+ const nprop_align_new = function (raw) {
146
+ if (!raw) {
147
+ return "start";
148
+ }
149
+ if (raw === true) {
150
+ return "end";
151
+ }
152
+ return raw;
153
+ };
154
+ const nprop_justify_new = function (raw) {
155
+ if (!raw) {
156
+ return "end";
157
+ }
158
+ if (raw === true) {
159
+ return "start";
160
+ }
161
+ return raw;
162
+ };
163
+ const nprop_direction_new = function (raw) {
164
+ if (!raw) {
165
+ return "ver";
166
+ }
167
+ if (raw === true) {
168
+ return "hor";
169
+ }
170
+ return raw;
171
+ };
172
+
173
+ const stylemap$1 = {
174
+ listfix: "listfix",
175
+ listfix_open: "listfix_open",
176
+ listfix_justify_start: "listfix_justify_start",
177
+ listfix_justify_end: "listfix_justify_end",
178
+ listfix_align_start: "listfix_align_start",
179
+ listfix_align_end: "listfix_align_end",
180
+ listfix_align_center: "listfix_align_center",
181
+ listfix_vertical: "listfix_vertical",
182
+ listfix_horizontal: "listfix_horizontal",
183
+ };
184
+ const normalize_justify$1 = function (params) {
185
+ let axis_main;
186
+ switch (params.direction) {
187
+ case "ver": {
188
+ axis_main = params.axis_main;
189
+ break;
190
+ }
191
+ case "hor": {
192
+ axis_main = params.axis_cross;
193
+ break;
194
+ }
195
+ }
196
+ let flow_direct;
197
+ let flow_reverse;
198
+ let freespace_direct;
199
+ let freespace_reverse;
200
+ let position_direct;
201
+ let position_reverse;
202
+ switch (params.justify) {
203
+ case "start": {
204
+ freespace_reverse = axis_main.screen_size - params.gap - (axis_main.container_pos + axis_main.container_size);
205
+ freespace_direct = axis_main.container_pos - params.gap;
206
+ flow_direct = axis_main.flow_reverse;
207
+ flow_reverse = axis_main.flow_direct;
208
+ position_direct = axis_main.screen_size - axis_main.container_pos + params.gap;
209
+ position_reverse = axis_main.container_pos + axis_main.container_size + params.gap;
210
+ break;
211
+ }
212
+ case "end": {
213
+ freespace_direct = axis_main.screen_size - params.gap - (axis_main.container_pos + axis_main.container_size);
214
+ freespace_reverse = axis_main.container_pos - params.gap;
215
+ flow_direct = axis_main.flow_direct;
216
+ flow_reverse = axis_main.flow_reverse;
217
+ position_direct = axis_main.container_pos + axis_main.container_size + params.gap;
218
+ position_reverse = axis_main.screen_size - axis_main.container_pos + params.gap;
219
+ break;
220
+ }
221
+ }
222
+ if (freespace_direct >= axis_main.list_size) {
223
+ params.reverse_justify_set(false);
224
+ axis_main.space_set(null);
225
+ flow_direct.position_set(position_direct);
226
+ flow_reverse.position_set(null);
227
+ }
228
+ else if (freespace_reverse >= axis_main.list_size) {
229
+ params.reverse_justify_set(true);
230
+ axis_main.space_set(null);
231
+ flow_direct.position_set(null);
232
+ flow_reverse.position_set(position_reverse);
233
+ }
234
+ else if (freespace_direct >= freespace_reverse) {
235
+ params.reverse_justify_set(false);
236
+ axis_main.space_set(freespace_direct);
237
+ flow_direct.position_set(position_direct);
238
+ flow_reverse.position_set(null);
239
+ }
240
+ else {
241
+ params.reverse_justify_set(true);
242
+ axis_main.space_set(freespace_reverse);
243
+ flow_direct.position_set(null);
244
+ flow_reverse.position_set(position_reverse);
245
+ }
246
+ };
247
+ const normalize_align$1 = function (params) {
248
+ let axis_main;
249
+ switch (params.direction) {
250
+ case "hor": {
251
+ axis_main = params.axis_main;
252
+ break;
253
+ }
254
+ case "ver": {
255
+ axis_main = params.axis_cross;
256
+ break;
257
+ }
258
+ }
259
+ axis_main.space_set(null);
260
+ switch (params.align) {
261
+ case "center": {
262
+ const offset = (axis_main.list_size - axis_main.container_size) / 2;
263
+ params.reverse_align_set(false);
264
+ axis_main.flow_reverse.position_set(null);
265
+ axis_main.flow_direct.position_set(Math.max(0, axis_main.container_pos - offset));
266
+ break;
267
+ }
268
+ case "start": {
269
+ const freespace_direct = axis_main.screen_size - axis_main.container_pos;
270
+ const freespace_reverse = axis_main.container_pos + axis_main.container_size;
271
+ const flow_direct = axis_main.flow_direct;
272
+ const flow_reverse = axis_main.flow_reverse;
273
+ const position_direct = Math.max(0, (+axis_main.container_pos
274
+ - Math.max(0, axis_main.list_size - freespace_direct)));
275
+ const position_reverse = Math.max(0, (+axis_main.screen_size
276
+ - (axis_main.container_pos + axis_main.container_size)
277
+ - Math.max(0, axis_main.list_size - freespace_reverse)));
278
+ if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
279
+ params.reverse_align_set(false);
280
+ flow_reverse.position_set(null);
281
+ flow_direct.position_set(position_direct);
282
+ }
283
+ else {
284
+ params.reverse_align_set(true);
285
+ flow_direct.position_set(null);
286
+ flow_reverse.position_set(position_reverse);
287
+ }
288
+ break;
289
+ }
290
+ case "end": {
291
+ const freespace_direct = axis_main.container_pos + axis_main.container_size;
292
+ const freespace_reverse = axis_main.screen_size - axis_main.container_pos;
293
+ const flow_direct = axis_main.flow_reverse;
294
+ const flow_reverse = axis_main.flow_direct;
295
+ const position_direct = Math.max(0, (+axis_main.screen_size
296
+ - (axis_main.container_pos + axis_main.container_size)
297
+ - Math.max(0, axis_main.list_size - freespace_direct)));
298
+ const position_reverse = Math.max(0, (+axis_main.container_pos
299
+ - Math.max(0, axis_main.list_size - freespace_reverse)));
300
+ if (freespace_direct >= axis_main.list_size || freespace_direct >= freespace_reverse) {
301
+ params.reverse_align_set(false);
302
+ flow_reverse.position_set(null);
303
+ flow_direct.position_set(position_direct);
304
+ }
305
+ else {
306
+ params.reverse_align_set(true);
307
+ flow_direct.position_set(null);
308
+ flow_reverse.position_set(position_reverse);
309
+ }
310
+ break;
311
+ }
312
+ }
313
+ };
314
+ const CmpListFix = r.memo(r.forwardRef((props, ref) => {
315
+ const nprop_gap = props.gap ?? 0;
316
+ const nprop_lazy = props.lazy ?? false;
317
+ const nprop_align = nprop_align_new(props.align);
318
+ const nprop_justify = nprop_justify_new(props.justify);
319
+ const nprop_direction = nprop_direction_new(props.direction);
320
+ const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap$1, props.stylemodule) : stylemap$1), [props.stylemodule]);
321
+ const ctxstate = r.useContext(CmpCtxState_Open);
322
+ if (!ctxstate) {
323
+ throw new Error(`Using DDN dependend component outside of DDN Context`);
324
+ }
325
+ const l_ref = r.useRef(null);
326
+ const [visible, visible_set] = r.useState(false);
327
+ const [revalign, revalign_set] = r.useState(false);
328
+ const [revjustify, revjustify_set] = r.useState(false);
329
+ const [maxheight, maxheight_set] = r.useState(null);
330
+ const [maxwidth, maxwidth_set] = r.useState(null);
331
+ const [top, top_set] = r.useState(null);
332
+ const [left, left_set] = r.useState(null);
333
+ const [right, right_set] = r.useState(null);
334
+ const [bottom, bottom_set] = r.useState(null);
335
+ r.useLayoutEffect(() => {
336
+ const list = l_ref.current;
337
+ const container = ctxstate.ref.current;
338
+ if (list && container && ctxstate.open) {
339
+ const container_rect = container.getBoundingClientRect();
340
+ const axis_main = {
341
+ list_size: list.offsetHeight,
342
+ space_set: maxheight_set,
343
+ screen_size: document.documentElement.clientHeight,
344
+ container_pos: container_rect.y,
345
+ container_size: container_rect.height,
346
+ flow_direct: {
347
+ position_set: top_set
348
+ },
349
+ flow_reverse: {
350
+ position_set: bottom_set
351
+ },
352
+ };
353
+ const axis_cross = {
354
+ list_size: list.offsetWidth,
355
+ space_set: maxwidth_set,
356
+ screen_size: document.documentElement.clientWidth,
357
+ container_pos: container_rect.x,
358
+ container_size: container_rect.width,
359
+ flow_direct: {
360
+ position_set: left_set
361
+ },
362
+ flow_reverse: {
363
+ position_set: right_set
364
+ },
365
+ };
366
+ normalize_justify$1({
367
+ axis_main,
368
+ axis_cross,
369
+ gap: nprop_gap,
370
+ justify: nprop_justify,
371
+ direction: nprop_direction,
372
+ reverse_align_set: revalign_set,
373
+ reverse_justify_set: revjustify_set,
374
+ });
375
+ normalize_align$1({
376
+ axis_main,
377
+ axis_cross,
378
+ align: nprop_align,
379
+ direction: nprop_direction,
380
+ reverse_align_set: revalign_set,
381
+ reverse_justify_set: revjustify_set,
382
+ });
383
+ }
384
+ }, [ctxstate.open, ctxstate.ref, nprop_gap, nprop_align, nprop_justify, nprop_direction]);
385
+ const mref = r.useMemo(() => {
386
+ return (element) => {
387
+ l_ref.current = element;
388
+ if (ref) {
389
+ if (typeof ref === "object") {
390
+ ref.current = element;
391
+ }
392
+ else {
393
+ ref(element);
394
+ }
395
+ }
396
+ };
397
+ }, [ref]);
398
+ const children = r.useMemo(() => {
399
+ if (!nprop_lazy || visible || ctxstate.open) {
400
+ if (typeof props.children === "function") {
401
+ return props.children();
402
+ }
403
+ return props.children;
404
+ }
405
+ return null;
406
+ }, [nprop_lazy, visible, ctxstate.open, props.children]);
407
+ return jsx("div", { ref: mref, 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
+ ["--gap"]: `${nprop_gap}px`,
409
+ top: top !== null ? `${top}px` : null,
410
+ left: left !== null ? `${left}px` : null,
411
+ right: right !== null ? `${right}px` : null,
412
+ bottom: bottom !== null ? `${bottom}px` : null,
413
+ maxWidth: maxwidth === null ? undefined : `${maxwidth}px`,
414
+ maxHeight: maxheight === null ? undefined : `${maxheight}px`,
415
+ }, onTransitionStart: ev => {
416
+ if (ev.propertyName === "opacity" && ctxstate.open) {
417
+ visible_set(true);
418
+ }
419
+ }, onTransitionEnd: ev => {
420
+ if (ev.propertyName === "opacity" && !ctxstate.open) {
421
+ revalign_set(false);
422
+ revjustify_set(false);
423
+ maxwidth_set(null);
424
+ maxheight_set(null);
425
+ visible_set(false);
426
+ top_set(null);
427
+ bottom_set(null);
428
+ left_set(null);
429
+ right_set(null);
430
+ }
431
+ }, children: children });
432
+ }));
433
+
434
+ const stylemap = {
435
+ listabs: "listabs",
436
+ listabs_open: "listabs_open",
437
+ listabs_justify_start: "listabs_justify_start",
438
+ listabs_justify_end: "listabs_justify_end",
439
+ listabs_align_start: "listabs_align_start",
440
+ listabs_align_end: "listabs_align_end",
441
+ listabs_align_center: "listabs_align_center",
442
+ listabs_vertical: "listabs_vertical",
443
+ listabs_horizontal: "listabs_horizontal",
444
+ };
445
+ const normalize_justify = function (params) {
446
+ let axis_main;
447
+ switch (params.direction) {
448
+ case "ver": {
449
+ axis_main = params.axis_main;
450
+ break;
451
+ }
452
+ case "hor": {
453
+ axis_main = params.axis_cross;
454
+ break;
455
+ }
456
+ }
457
+ let freespace_direct;
458
+ let freespace_reverse;
459
+ switch (params.justify) {
460
+ case "start": {
461
+ freespace_direct = axis_main.container_pos - params.gap;
462
+ freespace_reverse = axis_main.screen_size - params.gap - (axis_main.container_pos + axis_main.container_size);
463
+ break;
464
+ }
465
+ case "end": {
466
+ freespace_direct = axis_main.screen_size - params.gap - (axis_main.container_pos + axis_main.container_size);
467
+ freespace_reverse = axis_main.container_pos - params.gap;
468
+ break;
469
+ }
470
+ }
471
+ if (freespace_direct >= axis_main.list_size) {
472
+ params.reverse_justify_set(false);
473
+ axis_main.space_set(null);
474
+ }
475
+ else if (freespace_reverse >= axis_main.list_size) {
476
+ params.reverse_justify_set(true);
477
+ axis_main.space_set(null);
478
+ }
479
+ else if (freespace_direct >= freespace_reverse) {
480
+ params.reverse_justify_set(false);
481
+ axis_main.space_set(freespace_direct);
482
+ }
483
+ else {
484
+ params.reverse_justify_set(true);
485
+ axis_main.space_set(freespace_reverse);
486
+ }
487
+ };
488
+ const normalize_align = function (params) {
489
+ let axis_main;
490
+ switch (params.direction) {
491
+ case "hor": {
492
+ axis_main = params.axis_main;
493
+ break;
494
+ }
495
+ case "ver": {
496
+ axis_main = params.axis_cross;
497
+ break;
498
+ }
499
+ }
500
+ let freespace_direct;
501
+ let freespace_reverse;
502
+ switch (params.align) {
503
+ case "center": {
504
+ params.reverse_align_set(false);
505
+ axis_main.space_set(null);
506
+ return;
507
+ }
508
+ case "start": {
509
+ freespace_direct = axis_main.screen_size - axis_main.container_pos;
510
+ freespace_reverse = axis_main.container_pos + axis_main.container_size;
511
+ break;
512
+ }
513
+ case "end": {
514
+ freespace_direct = axis_main.container_pos + axis_main.container_size;
515
+ freespace_reverse = axis_main.screen_size - axis_main.container_pos;
516
+ break;
517
+ }
518
+ }
519
+ if (freespace_direct >= axis_main.list_size) {
520
+ params.reverse_align_set(false);
521
+ axis_main.space_set(null);
522
+ }
523
+ else if (freespace_reverse >= axis_main.list_size) {
524
+ params.reverse_align_set(true);
525
+ axis_main.space_set(null);
526
+ }
527
+ else if (freespace_direct >= freespace_reverse) {
528
+ params.reverse_align_set(false);
529
+ axis_main.space_set(freespace_direct);
530
+ }
531
+ else {
532
+ params.reverse_align_set(true);
533
+ axis_main.space_set(freespace_reverse);
534
+ }
535
+ };
536
+ const CmpListAbs = r.memo(r.forwardRef((props, ref) => {
537
+ const nprop_gap = props.gap ?? 0;
538
+ const nprop_lazy = props.lazy ?? false;
539
+ const nprop_align = nprop_align_new(props.align);
540
+ const nprop_justify = nprop_justify_new(props.justify);
541
+ const nprop_direction = nprop_direction_new(props.direction);
542
+ const nprop_style = r.useMemo(() => (props.stylemodule ? stylemap_new_remap(stylemap, props.stylemodule) : stylemap), [props.stylemodule]);
543
+ const ctxstate = r.useContext(CmpCtxState_Open);
544
+ if (!ctxstate) {
545
+ throw new Error(`Using DDN dependend component outside of DDN Context`);
546
+ }
547
+ const l_ref = r.useRef(null);
548
+ const [visible, visible_set] = r.useState(false);
549
+ const [revalign, revalign_set] = r.useState(false);
550
+ const [revjustify, revjustify_set] = r.useState(false);
551
+ const [maxheight, maxheight_set] = r.useState(null);
552
+ const [maxwidth, maxwidth_set] = r.useState(null);
553
+ r.useLayoutEffect(() => {
554
+ const list = l_ref.current;
555
+ const container = ctxstate.ref.current;
556
+ if (list && container && ctxstate.open) {
557
+ const container_rect = container.getBoundingClientRect();
558
+ const axis_main = {
559
+ list_size: list.offsetHeight,
560
+ space_set: maxheight_set,
561
+ screen_size: document.documentElement.clientHeight,
562
+ container_pos: container_rect.y,
563
+ container_size: container_rect.height,
564
+ };
565
+ const axis_cross = {
566
+ list_size: list.offsetWidth,
567
+ space_set: maxwidth_set,
568
+ screen_size: document.documentElement.clientWidth,
569
+ container_pos: container_rect.x,
570
+ container_size: container_rect.width,
571
+ };
572
+ normalize_justify({
573
+ axis_main,
574
+ axis_cross,
575
+ gap: nprop_gap,
576
+ justify: nprop_justify,
577
+ direction: nprop_direction,
578
+ reverse_align_set: revalign_set,
579
+ reverse_justify_set: revjustify_set,
580
+ });
581
+ normalize_align({
582
+ axis_main,
583
+ axis_cross,
584
+ align: nprop_align,
585
+ direction: nprop_direction,
586
+ reverse_align_set: revalign_set,
587
+ reverse_justify_set: revjustify_set,
588
+ });
589
+ }
590
+ }, [ctxstate.open, ctxstate.ref, nprop_gap, nprop_align, nprop_justify, nprop_direction]);
591
+ const mref = r.useMemo(() => {
592
+ return (element) => {
593
+ l_ref.current = element;
594
+ if (ref) {
595
+ if (typeof ref === "object") {
596
+ ref.current = element;
597
+ }
598
+ else {
599
+ ref(element);
600
+ }
601
+ }
602
+ };
603
+ }, [ref]);
604
+ const children = r.useMemo(() => {
605
+ if (!nprop_lazy || visible || ctxstate.open) {
606
+ if (typeof props.children === "function") {
607
+ return props.children();
608
+ }
609
+ return props.children;
610
+ }
611
+ return null;
612
+ }, [nprop_lazy, visible, ctxstate.open, props.children]);
613
+ return jsx("div", { ref: mref, className: cl("__qyuddn", props.className, nprop_style.listabs, ctxstate.open && nprop_style.listabs_open, ((nprop_align === "end" && !revalign) || (nprop_align === "start" && revalign)) && nprop_style.listabs_align_end, ((nprop_align === "start" && !revalign) || (nprop_align === "end" && revalign)) && nprop_style.listabs_align_start, nprop_align === "center" && nprop_style.listabs_align_center, ((nprop_justify === "end") !== revjustify) && nprop_style.listabs_justify_end, ((nprop_justify === "start") !== revjustify) && nprop_style.listabs_justify_start, nprop_direction === "hor" && nprop_style.listabs_horizontal, nprop_direction === "ver" && nprop_style.listabs_vertical), style: {
614
+ ["--gap"]: `${nprop_gap}px`,
615
+ maxWidth: maxwidth === null ? undefined : `${maxwidth}px`,
616
+ maxHeight: maxheight === null ? undefined : `${maxheight}px`,
617
+ }, onTransitionStart: ev => {
618
+ if (ev.propertyName === "opacity" && ctxstate.open) {
619
+ visible_set(true);
620
+ }
621
+ }, onTransitionEnd: ev => {
622
+ if (ev.propertyName === "opacity" && !ctxstate.open) {
623
+ revalign_set(false);
624
+ revjustify_set(false);
625
+ maxwidth_set(null);
626
+ maxheight_set(null);
627
+ visible_set(false);
628
+ }
629
+ }, children: children });
630
+ }));
631
+
632
+ export { CmpButton, CmpContainer, CmpCtxState_Open, CmpListAbs, CmpListFix, useDropdownCloseEvents };
@@ -0,0 +1,7 @@
1
+ import * as r from "react";
2
+ export type Cmp_Button_Props = Readonly<{
3
+ className?: string;
4
+ children?: r.ReactNode;
5
+ }>;
6
+ export declare const CmpButton: r.FC<Cmp_Button_Props>;
7
+ export default CmpButton;
@@ -0,0 +1,26 @@
1
+ import { type UseDropdownCloseEvents_Config } from "../hook/useDropdownCloseEvents.js";
2
+ import type { FnSetterStateful } from "../../../type/setter.js";
3
+ import * as r from "react";
4
+ declare const stylemap: {
5
+ readonly container: "container";
6
+ };
7
+ export type CmpContainer_StyleModule = {
8
+ [K in keyof typeof stylemap]?: string | null;
9
+ };
10
+ export type CmpContainer_Props = Readonly<{
11
+ open?: boolean;
12
+ open_set?: FnSetterStateful<boolean>;
13
+ className?: string;
14
+ children?: r.ReactNode;
15
+ stylemodule?: CmpContainer_StyleModule;
16
+ closeevents?: UseDropdownCloseEvents_Config;
17
+ }>;
18
+ export declare const CmpContainer: r.NamedExoticComponent<Readonly<{
19
+ open?: boolean;
20
+ open_set?: FnSetterStateful<boolean>;
21
+ className?: string;
22
+ children?: r.ReactNode;
23
+ stylemodule?: CmpContainer_StyleModule;
24
+ closeevents?: UseDropdownCloseEvents_Config;
25
+ }> & r.RefAttributes<HTMLDivElement>>;
26
+ export {};
@@ -0,0 +1,15 @@
1
+ import type { FnSetterStateful } from "../../../type/setter.js";
2
+ export type UseDropdownCloseEvents_Config = Readonly<{
3
+ blur?: boolean;
4
+ click?: boolean;
5
+ scroll?: boolean;
6
+ resize?: boolean;
7
+ escape?: boolean;
8
+ }>;
9
+ export type UseDropdownCloseEvents_Params = Readonly<{
10
+ ref: () => HTMLElement | null;
11
+ open: boolean;
12
+ open_set: FnSetterStateful<boolean>;
13
+ config?: UseDropdownCloseEvents_Config;
14
+ }>;
15
+ export declare const useDropdownCloseEvents: (params: UseDropdownCloseEvents_Params) => void;
@@ -0,0 +1,6 @@
1
+ import * as r from "react";
2
+ export declare const CmpCtxState_Open: r.Context<Readonly<{
3
+ ref: r.RefObject<HTMLDivElement | null>;
4
+ open: boolean;
5
+ open_set: import("../../../index.js").FnSetterStateful<boolean>;
6
+ }> | null>;
@@ -0,0 +1,7 @@
1
+ import type { FnSetterStateful } from "../../../type/setter.js";
2
+ import * as r from "react";
3
+ export type CmpCtxState_StateOpen = Readonly<{
4
+ ref: r.RefObject<HTMLDivElement | null>;
5
+ open: boolean;
6
+ open_set: FnSetterStateful<boolean>;
7
+ }>;
@@ -0,0 +1,37 @@
1
+ import type { AlignRaw, DirectionRaw, JustifyRaw } from "../../../type/params.js";
2
+ import * as r from "react";
3
+ declare const stylemap: {
4
+ readonly listabs: "listabs";
5
+ readonly listabs_open: "listabs_open";
6
+ readonly listabs_justify_start: "listabs_justify_start";
7
+ readonly listabs_justify_end: "listabs_justify_end";
8
+ readonly listabs_align_start: "listabs_align_start";
9
+ readonly listabs_align_end: "listabs_align_end";
10
+ readonly listabs_align_center: "listabs_align_center";
11
+ readonly listabs_vertical: "listabs_vertical";
12
+ readonly listabs_horizontal: "listabs_horizontal";
13
+ };
14
+ export type CmpListAbs_StyleModule = {
15
+ [K in keyof typeof stylemap]?: string | null;
16
+ };
17
+ export type CmpListAbs_Props = Readonly<{
18
+ gap?: number;
19
+ lazy?: boolean;
20
+ align?: AlignRaw;
21
+ justify?: JustifyRaw;
22
+ direction?: DirectionRaw;
23
+ className?: string;
24
+ stylemodule?: CmpListAbs_StyleModule;
25
+ children?: r.ReactNode | (() => r.ReactNode);
26
+ }>;
27
+ export declare const CmpListAbs: r.NamedExoticComponent<Readonly<{
28
+ gap?: number;
29
+ lazy?: boolean;
30
+ align?: AlignRaw;
31
+ justify?: JustifyRaw;
32
+ direction?: DirectionRaw;
33
+ className?: string;
34
+ stylemodule?: CmpListAbs_StyleModule;
35
+ children?: r.ReactNode | (() => r.ReactNode);
36
+ }> & r.RefAttributes<HTMLDivElement>>;
37
+ export default CmpListAbs;
@@ -0,0 +1,37 @@
1
+ import type { AlignRaw, DirectionRaw, JustifyRaw } from "../../../type/params.js";
2
+ import * as r from "react";
3
+ declare const stylemap: {
4
+ readonly listfix: "listfix";
5
+ readonly listfix_open: "listfix_open";
6
+ readonly listfix_justify_start: "listfix_justify_start";
7
+ readonly listfix_justify_end: "listfix_justify_end";
8
+ readonly listfix_align_start: "listfix_align_start";
9
+ readonly listfix_align_end: "listfix_align_end";
10
+ readonly listfix_align_center: "listfix_align_center";
11
+ readonly listfix_vertical: "listfix_vertical";
12
+ readonly listfix_horizontal: "listfix_horizontal";
13
+ };
14
+ export type CmpListFix_StyleModule = {
15
+ [K in keyof typeof stylemap]?: string | null;
16
+ };
17
+ export type CmpListFix_Props = Readonly<{
18
+ gap?: number;
19
+ lazy?: boolean;
20
+ align?: AlignRaw;
21
+ justify?: JustifyRaw;
22
+ direction?: DirectionRaw;
23
+ className?: string;
24
+ stylemodule?: CmpListFix_StyleModule;
25
+ children?: r.ReactNode | (() => r.ReactNode);
26
+ }>;
27
+ export declare const CmpListFix: r.NamedExoticComponent<Readonly<{
28
+ gap?: number;
29
+ lazy?: boolean;
30
+ align?: AlignRaw;
31
+ justify?: JustifyRaw;
32
+ direction?: DirectionRaw;
33
+ className?: string;
34
+ stylemodule?: CmpListFix_StyleModule;
35
+ children?: r.ReactNode | (() => r.ReactNode);
36
+ }> & r.RefAttributes<HTMLDivElement>>;
37
+ export default CmpListFix;
@@ -0,0 +1,9 @@
1
+ export * from "./type/setter.js";
2
+ export * from "./type/params.js";
3
+ export * from "./component/ctx-state/type/state.js";
4
+ export * from "./component/ctx-state/element/open.js";
5
+ export * from "./component/button/element/view.js";
6
+ export * from "./component/container/element/view.js";
7
+ export * from "./component/container/hook/useDropdownCloseEvents.js";
8
+ export * from "./component/list-fix/element/view.js";
9
+ export * from "./component/list-abs/element/view.js";
@@ -0,0 +1,6 @@
1
+ export type Direction = ("hor" | "ver");
2
+ export type Justify = ("start" | "end");
3
+ export type Align = ("start" | "center" | "end");
4
+ export type DirectionRaw = (Direction | null | boolean | undefined);
5
+ export type JustifyRaw = (Justify | null | boolean | undefined);
6
+ export type AlignRaw = (Align | null | boolean | undefined);
@@ -0,0 +1,6 @@
1
+ export type FnSetterStateles<T> = {
2
+ (setter_value: T): void;
3
+ };
4
+ export type FnSetterStateful<T> = {
5
+ (setter_value: T | ((old_setter_value: T) => T)): void;
6
+ };
@@ -0,0 +1 @@
1
+ export declare const cl: (...clnames: (string | false | undefined | null)[]) => string;
@@ -0,0 +1,4 @@
1
+ import type { Align, AlignRaw, Direction, DirectionRaw, Justify, JustifyRaw } from "../../type/params.js";
2
+ export declare const nprop_align_new: (raw: AlignRaw) => Align;
3
+ export declare const nprop_justify_new: (raw: JustifyRaw) => Justify;
4
+ export declare const nprop_direction_new: (raw: DirectionRaw) => Direction;
@@ -0,0 +1,2 @@
1
+ import type { StyleMap } from "../type/StyleMap.js";
2
+ export declare const stylemap_new_remap: <Def extends Readonly<Record<string, string>>>(def: Def, remap: Readonly<Record<string, string | null>>) => StyleMap<keyof Def>;
@@ -0,0 +1,3 @@
1
+ export type StyleMap<ClName extends keyof any> = {
2
+ [K in ClName]: string | null;
3
+ };
@@ -0,0 +1,130 @@
1
+ .__qyuddn.container {
2
+ position: relative;
3
+ }
4
+
5
+ .__qyuddn.listabs {
6
+ --scale: 1;
7
+ position: absolute;
8
+ z-index: var(--qyuddn-z-index, 3);
9
+ transition: transform var(--qyuddn-trtime, 0.2s), opacity var(--qyuddn-trtime, 0.2s);
10
+ }
11
+ .__qyuddn.listabs:not(.listabs_open) {
12
+ --scale: 0;
13
+ opacity: 0;
14
+ user-select: none;
15
+ pointer-events: none;
16
+ }
17
+
18
+ .__qyuddn.listabs_justify_start.listabs_horizontal {
19
+ right: 100%;
20
+ transform-origin: center right;
21
+ }
22
+ .__qyuddn.listabs_justify_start.listabs_horizontal:not(.listabs_align_center) {
23
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px)));
24
+ }
25
+ .__qyuddn.listabs_justify_start.listabs_horizontal.listabs_align_center {
26
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px))) translateY(-50%);
27
+ }
28
+ .__qyuddn.listabs_justify_start.listabs_vertical {
29
+ bottom: 100%;
30
+ transform-origin: bottom center;
31
+ }
32
+ .__qyuddn.listabs_justify_start.listabs_vertical:not(.listabs_align_center) {
33
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px)));
34
+ }
35
+ .__qyuddn.listabs_justify_start.listabs_vertical.listabs_align_center {
36
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px))) translateX(-50%);
37
+ }
38
+
39
+ .__qyuddn.listabs_justify_end.listabs_horizontal {
40
+ left: 100%;
41
+ transform-origin: center left;
42
+ }
43
+ .__qyuddn.listabs_justify_end.listabs_horizontal:not(.listabs_align_center) {
44
+ transform: scaleX(--scale), translateX(var(--gap, 0px));
45
+ }
46
+ .__qyuddn.listabs_justify_end.listabs_horizontal.listabs_align_center {
47
+ transform: scaleX(--scale), translateX(var(--gap, 0px)) translateY(-50%);
48
+ }
49
+ .__qyuddn.listabs_justify_end.listabs_vertical {
50
+ top: 100%;
51
+ transform-origin: top center;
52
+ }
53
+ .__qyuddn.listabs_justify_end.listabs_vertical:not(.listabs_align_center) {
54
+ transform: scaleY(--scale), translateY(var(--gap, 0px));
55
+ }
56
+ .__qyuddn.listabs_justify_end.listabs_vertical.listabs_align_center {
57
+ transform: scaleY(--scale), translateY(var(--gap, 0px)) translateX(-50%);
58
+ }
59
+
60
+ .__qyuddn.listabs_align_start.listabs_horizontal {
61
+ top: 0;
62
+ }
63
+ .__qyuddn.listabs_align_start.listabs_vertical {
64
+ left: 0;
65
+ }
66
+
67
+ .__qyuddn.listabs_align_center.listabs_horizontal {
68
+ top: 50%;
69
+ }
70
+ .__qyuddn.listabs_align_center.listabs_vertical {
71
+ left: 50%;
72
+ }
73
+
74
+ .__qyuddn.listabs_align_end.listabs_horizontal {
75
+ right: 0;
76
+ }
77
+ .__qyuddn.listabs_align_end.listabs_vertical {
78
+ top: 0;
79
+ }
80
+
81
+ .__qyuddn.listfix {
82
+ --scale: 1;
83
+ position: fixed;
84
+ z-index: var(--qyuddn-z-index, 3);
85
+ transition: transform var(--qyuddn-trtime, 0.2s), opacity var(--qyuddn-trtime, 0.2s);
86
+ }
87
+ .__qyuddn.listfix:not(.listfix_open) {
88
+ --scale: 0;
89
+ opacity: 0;
90
+ user-select: none;
91
+ pointer-events: none;
92
+ }
93
+
94
+ .__qyuddn.listfix_justify_start.listfix_horizontal {
95
+ transform-origin: center right;
96
+ }
97
+ .__qyuddn.listfix_justify_start.listfix_horizontal:not(.listfix_align_center) {
98
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px)));
99
+ }
100
+ .__qyuddn.listfix_justify_start.listfix_horizontal.listfix_align_center {
101
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px))) translateY(-50%);
102
+ }
103
+ .__qyuddn.listfix_justify_start.listfix_vertical {
104
+ transform-origin: bottom center;
105
+ }
106
+ .__qyuddn.listfix_justify_start.listfix_vertical:not(.listfix_align_center) {
107
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px)));
108
+ }
109
+ .__qyuddn.listfix_justify_start.listfix_vertical.listfix_align_center {
110
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px))) translateX(-50%);
111
+ }
112
+
113
+ .__qyuddn.listfix_justify_end.listfix_horizontal {
114
+ transform-origin: center left;
115
+ }
116
+ .__qyuddn.listfix_justify_end.listfix_horizontal:not(.listfix_align_center) {
117
+ transform: scaleX(--scale), translateX(var(--gap, 0px));
118
+ }
119
+ .__qyuddn.listfix_justify_end.listfix_horizontal.listfix_align_center {
120
+ transform: scaleX(--scale), translateX(var(--gap, 0px)) translateY(-50%);
121
+ }
122
+ .__qyuddn.listfix_justify_end.listfix_vertical {
123
+ transform-origin: top center;
124
+ }
125
+ .__qyuddn.listfix_justify_end.listfix_vertical:not(.listfix_align_center) {
126
+ transform: scaleY(--scale), translateY(var(--gap, 0px));
127
+ }
128
+ .__qyuddn.listfix_justify_end.listfix_vertical.listfix_align_center {
129
+ transform: scaleY(--scale), translateY(var(--gap, 0px)) translateX(-50%);
130
+ }
@@ -0,0 +1,22 @@
1
+ declare const styles: {
2
+ readonly "__qyuddn": string;
3
+ readonly "container": string;
4
+ readonly "listabs": string;
5
+ readonly "listabs_align_center": string;
6
+ readonly "listabs_align_end": string;
7
+ readonly "listabs_align_start": string;
8
+ readonly "listabs_horizontal": string;
9
+ readonly "listabs_justify_end": string;
10
+ readonly "listabs_justify_start": string;
11
+ readonly "listabs_open": string;
12
+ readonly "listabs_vertical": string;
13
+ readonly "listfix": string;
14
+ readonly "listfix_align_center": string;
15
+ readonly "listfix_horizontal": string;
16
+ readonly "listfix_justify_end": string;
17
+ readonly "listfix_justify_start": string;
18
+ readonly "listfix_open": string;
19
+ readonly "listfix_vertical": string;
20
+ };
21
+ export = styles;
22
+
@@ -0,0 +1,130 @@
1
+ .container {
2
+ position: relative;
3
+ }
4
+
5
+ .listabs {
6
+ --scale: 1;
7
+ position: absolute;
8
+ z-index: var(--qyuddn-z-index, 3);
9
+ transition: transform var(--qyuddn-trtime, 0.2s), opacity var(--qyuddn-trtime, 0.2s);
10
+ }
11
+ .listabs:not(.listabs_open) {
12
+ --scale: 0;
13
+ opacity: 0;
14
+ user-select: none;
15
+ pointer-events: none;
16
+ }
17
+
18
+ .listabs_justify_start.listabs_horizontal {
19
+ right: 100%;
20
+ transform-origin: center right;
21
+ }
22
+ .listabs_justify_start.listabs_horizontal:not(.listabs_align_center) {
23
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px)));
24
+ }
25
+ .listabs_justify_start.listabs_horizontal.listabs_align_center {
26
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px))) translateY(-50%);
27
+ }
28
+ .listabs_justify_start.listabs_vertical {
29
+ bottom: 100%;
30
+ transform-origin: bottom center;
31
+ }
32
+ .listabs_justify_start.listabs_vertical:not(.listabs_align_center) {
33
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px)));
34
+ }
35
+ .listabs_justify_start.listabs_vertical.listabs_align_center {
36
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px))) translateX(-50%);
37
+ }
38
+
39
+ .listabs_justify_end.listabs_horizontal {
40
+ left: 100%;
41
+ transform-origin: center left;
42
+ }
43
+ .listabs_justify_end.listabs_horizontal:not(.listabs_align_center) {
44
+ transform: scaleX(--scale), translateX(var(--gap, 0px));
45
+ }
46
+ .listabs_justify_end.listabs_horizontal.listabs_align_center {
47
+ transform: scaleX(--scale), translateX(var(--gap, 0px)) translateY(-50%);
48
+ }
49
+ .listabs_justify_end.listabs_vertical {
50
+ top: 100%;
51
+ transform-origin: top center;
52
+ }
53
+ .listabs_justify_end.listabs_vertical:not(.listabs_align_center) {
54
+ transform: scaleY(--scale), translateY(var(--gap, 0px));
55
+ }
56
+ .listabs_justify_end.listabs_vertical.listabs_align_center {
57
+ transform: scaleY(--scale), translateY(var(--gap, 0px)) translateX(-50%);
58
+ }
59
+
60
+ .listabs_align_start.listabs_horizontal {
61
+ top: 0;
62
+ }
63
+ .listabs_align_start.listabs_vertical {
64
+ left: 0;
65
+ }
66
+
67
+ .listabs_align_center.listabs_horizontal {
68
+ top: 50%;
69
+ }
70
+ .listabs_align_center.listabs_vertical {
71
+ left: 50%;
72
+ }
73
+
74
+ .listabs_align_end.listabs_horizontal {
75
+ right: 0;
76
+ }
77
+ .listabs_align_end.listabs_vertical {
78
+ top: 0;
79
+ }
80
+
81
+ .listfix {
82
+ --scale: 1;
83
+ position: fixed;
84
+ z-index: var(--qyuddn-z-index, 3);
85
+ transition: transform var(--qyuddn-trtime, 0.2s), opacity var(--qyuddn-trtime, 0.2s);
86
+ }
87
+ .listfix:not(.listfix_open) {
88
+ --scale: 0;
89
+ opacity: 0;
90
+ user-select: none;
91
+ pointer-events: none;
92
+ }
93
+
94
+ .listfix_justify_start.listfix_horizontal {
95
+ transform-origin: center right;
96
+ }
97
+ .listfix_justify_start.listfix_horizontal:not(.listfix_align_center) {
98
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px)));
99
+ }
100
+ .listfix_justify_start.listfix_horizontal.listfix_align_center {
101
+ transform: scaleX(--scale), translateX(calc(-1 * var(--gap, 0px))) translateY(-50%);
102
+ }
103
+ .listfix_justify_start.listfix_vertical {
104
+ transform-origin: bottom center;
105
+ }
106
+ .listfix_justify_start.listfix_vertical:not(.listfix_align_center) {
107
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px)));
108
+ }
109
+ .listfix_justify_start.listfix_vertical.listfix_align_center {
110
+ transform: scaleY(--scale), translateY(calc(-1 * var(--gap, 0px))) translateX(-50%);
111
+ }
112
+
113
+ .listfix_justify_end.listfix_horizontal {
114
+ transform-origin: center left;
115
+ }
116
+ .listfix_justify_end.listfix_horizontal:not(.listfix_align_center) {
117
+ transform: scaleX(--scale), translateX(var(--gap, 0px));
118
+ }
119
+ .listfix_justify_end.listfix_horizontal.listfix_align_center {
120
+ transform: scaleX(--scale), translateX(var(--gap, 0px)) translateY(-50%);
121
+ }
122
+ .listfix_justify_end.listfix_vertical {
123
+ transform-origin: top center;
124
+ }
125
+ .listfix_justify_end.listfix_vertical:not(.listfix_align_center) {
126
+ transform: scaleY(--scale), translateY(var(--gap, 0px));
127
+ }
128
+ .listfix_justify_end.listfix_vertical.listfix_align_center {
129
+ transform: scaleY(--scale), translateY(var(--gap, 0px)) translateX(-50%);
130
+ }
@@ -0,0 +1,21 @@
1
+ declare const styles: {
2
+ readonly "container": string;
3
+ readonly "listabs": string;
4
+ readonly "listabs_align_center": string;
5
+ readonly "listabs_align_end": string;
6
+ readonly "listabs_align_start": string;
7
+ readonly "listabs_horizontal": string;
8
+ readonly "listabs_justify_end": string;
9
+ readonly "listabs_justify_start": string;
10
+ readonly "listabs_open": string;
11
+ readonly "listabs_vertical": string;
12
+ readonly "listfix": string;
13
+ readonly "listfix_align_center": string;
14
+ readonly "listfix_horizontal": string;
15
+ readonly "listfix_justify_end": string;
16
+ readonly "listfix_justify_start": string;
17
+ readonly "listfix_open": string;
18
+ readonly "listfix_vertical": string;
19
+ };
20
+ export = styles;
21
+
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@qyu/reactcmp-dropdown",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "main": "./build/bundle/entry/index.js",
6
+ "description": "React Components for Dropdown Positioning",
7
+ "keywords": [
8
+ "react",
9
+ "dropdown",
10
+ "select"
11
+ ],
12
+ "homepage": "https://github.com/qlwt/reactcmp-dropdown#readme",
13
+ "license": "MIT",
14
+ "files": [
15
+ "./build/**/*"
16
+ ],
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/qlwt/reactcmp-dropdown.git"
20
+ },
21
+ "scripts": {
22
+ "build": "run-s build:clear build:style:module build:style:global build:style:types build:rollup",
23
+ "build:clear": "rimraf ./build",
24
+ "build:rollup": "rollup -c npm/rollup/rollup.config.js",
25
+ "build:style:module": "sass ./src/style/index.module.scss:./build/style/index.module.css --no-source-map",
26
+ "build:style:global": "postcss ./build/style/index.module.css --config ./npm/postcss/ -o ./build/style/index.global.css",
27
+ "build:style:types": "tcm ./build/style"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "types": "./build/declaration/index.d.ts",
32
+ "import": "./build/bundle/entry/index.js"
33
+ },
34
+ "./style/*": {
35
+ "types": "./build/style/*.css.d.ts",
36
+ "import": "./build/style/*.css"
37
+ }
38
+ },
39
+ "devDependencies": {
40
+ "@rollup/plugin-typescript": "^11.1.6",
41
+ "@types/react": "^19.0.0",
42
+ "@types/react-dom": "^19.0.0",
43
+ "npm-run-all": "^4.1.5",
44
+ "postcss": "^8.5.6",
45
+ "postcss-cli": "^11.0.1",
46
+ "postcss-prefix-selector": "^2.1.1",
47
+ "rimraf": "^6.0.1",
48
+ "rollup": "^4.20.0",
49
+ "sass": "^1.94.2",
50
+ "typed-css-modules": "^0.9.1",
51
+ "typescript": "^5.8.2",
52
+ "typescript-transform-paths": "^3.5.5"
53
+ },
54
+ "dependencies": {
55
+ "tslib": "^2.6.3"
56
+ },
57
+ "peerDependencies": {
58
+ "react": ">=19.0.0",
59
+ "react-dom": ">=19.0.0"
60
+ }
61
+ }