@qyu/reactcmp-dropdown 1.2.0 → 2.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/README.md +173 -75
- package/build/bundle/entry/index.js +1266 -398
- package/build/declaration/component/button/element/view.d.ts +8 -5
- package/build/declaration/component/button/element/virtual.d.ts +9 -0
- package/build/declaration/component/container/element/view.d.ts +14 -23
- package/build/declaration/component/container/element/virtual.d.ts +13 -0
- package/build/declaration/component/content/element/view.d.ts +11 -0
- package/build/declaration/component/ctx-state/element/config.d.ts +3 -0
- package/build/declaration/component/ctx-state/element/content.d.ts +3 -0
- package/build/declaration/component/ctx-state/element/open.d.ts +2 -5
- package/build/declaration/component/ctx-state/element/refs.d.ts +3 -0
- package/build/declaration/component/ctx-state/hook/init/config.d.ts +8 -0
- package/build/declaration/component/ctx-state/hook/init/content.d.ts +6 -0
- package/build/declaration/component/ctx-state/hook/init/open.d.ts +7 -0
- package/build/declaration/component/ctx-state/hook/init/refs.d.ts +5 -0
- package/build/declaration/component/ctx-state/hook/view/config.d.ts +1 -0
- package/build/declaration/component/ctx-state/hook/view/content.d.ts +1 -0
- package/build/declaration/component/ctx-state/hook/view/open.d.ts +1 -0
- package/build/declaration/component/ctx-state/hook/view/refs.d.ts +1 -0
- package/build/declaration/component/ctx-state/type/state.d.ts +40 -6
- package/build/declaration/component/list-abs/element/view.d.ts +23 -36
- package/build/declaration/component/list-fix/element/view.d.ts +24 -38
- package/build/declaration/component/list-portal/element/view.d.ts +29 -0
- package/build/declaration/hook/closeevt/root.d.ts +8 -0
- package/build/declaration/hook/closeevt/root_infer.d.ts +3 -0
- package/build/declaration/hook/closeevt/shard.d.ts +9 -0
- package/build/declaration/hook/closeevt/shard_infer.d.ts +3 -0
- package/build/declaration/hook/ddnparts/list.d.ts +6 -0
- package/build/declaration/hook/ddnparts/list_infer.d.ts +3 -0
- package/build/declaration/hook/ddnparts/root.d.ts +8 -0
- package/build/declaration/hook/ddnparts/root_infer.d.ts +3 -0
- package/build/declaration/hook/ddnparts/shard.d.ts +9 -0
- package/build/declaration/hook/ddnparts/shard_infer.d.ts +3 -0
- package/build/declaration/hook/focus/capture.d.ts +16 -0
- package/build/declaration/hook/focus/capture_infer.d.ts +3 -0
- package/build/declaration/hook/listpos/api/absolute.d.ts +15 -0
- package/build/declaration/hook/listpos/api/fixed.d.ts +18 -0
- package/build/declaration/hook/listpos/api/type/api.d.ts +13 -0
- package/build/declaration/hook/listpos/api/type/position.d.ts +6 -0
- package/build/declaration/hook/listpos/api/type/reverse.d.ts +4 -0
- package/build/declaration/hook/listpos/api/type/size.d.ts +4 -0
- package/build/declaration/hook/listpos/rearrange/index.d.ts +10 -0
- package/build/declaration/hook/listpos/rearrange/type/config.d.ts +7 -0
- package/build/declaration/hook/open/view.d.ts +6 -0
- package/build/declaration/hook/open/view_infer.d.ts +3 -0
- package/build/declaration/hook/ref/merge.d.ts +2 -0
- package/build/declaration/hook/ref/o.d.ts +3 -0
- package/build/declaration/index.d.ts +58 -3
- package/build/declaration/type/fnref.d.ts +4 -0
- package/build/declaration/util/clname/merge.d.ts +1 -0
- package/build/declaration/util/closeevt/type/config.d.ts +11 -0
- package/build/declaration/util/cssprops/new/position.d.ts +3 -0
- package/build/declaration/util/cssprops/new/size.d.ts +9 -0
- package/build/declaration/util/focus/config/type/config.d.ts +6 -0
- package/build/declaration/util/prop/align/new/index.d.ts +2 -0
- package/build/declaration/util/prop/align/new/reversed.d.ts +2 -0
- package/build/declaration/util/prop/align/type/prop.d.ts +2 -0
- package/build/declaration/util/prop/clmap/def/container.d.ts +6 -0
- package/build/declaration/util/prop/clmap/def/content.d.ts +8 -0
- package/build/declaration/util/prop/clmap/def/listabs.d.ts +15 -0
- package/build/declaration/util/prop/clmap/def/listfix.d.ts +16 -0
- package/build/declaration/util/prop/clmap/new/index.d.ts +2 -0
- package/build/declaration/util/prop/clmap/type/prop.d.ts +4 -0
- package/build/declaration/util/prop/direction/new/index.d.ts +2 -0
- package/build/declaration/util/prop/direction/type/prop.d.ts +2 -0
- package/build/declaration/util/prop/justify/new/index.d.ts +2 -0
- package/build/declaration/util/prop/justify/new/reversed.d.ts +2 -0
- package/build/declaration/util/prop/justify/type/prop.d.ts +2 -0
- package/build/declaration/util/prop/portal/new/index.d.ts +2 -0
- package/build/declaration/util/prop/portal/type/prop.d.ts +2 -0
- package/build/declaration/util/ref/use.d.ts +2 -0
- package/build/style/index.css +132 -0
- package/build/style/index.css.d.ts +21 -0
- package/package.json +6 -9
- package/build/declaration/component/container/hook/useDropdownCloseEvents.d.ts +0 -15
- package/build/declaration/type/params.d.ts +0 -6
- package/build/declaration/util/cl.d.ts +0 -1
- package/build/declaration/util/nprop/index.d.ts +0 -5
- package/build/declaration/util/stylemap/new/remap.d.ts +0 -2
- package/build/declaration/util/stylemap/type/StyleMap.d.ts +0 -3
- package/build/style/index.global.css +0 -110
- package/build/style/index.global.css.d.ts +0 -21
- package/build/style/index.module.css +0 -110
- package/build/style/index.module.css.d.ts +0 -20
package/README.md
CHANGED
|
@@ -2,34 +2,123 @@
|
|
|
2
2
|
|
|
3
3
|
React Component Library for solving dropdown positioning problems
|
|
4
4
|
|
|
5
|
+
## Purpose
|
|
6
|
+
|
|
7
|
+
Library is intended as minimalistic solution for dropdown rendering
|
|
8
|
+
|
|
9
|
+
It supportas:
|
|
10
|
+
- Nested Dropdpowns
|
|
11
|
+
- List is rendered in Portal (no issues with overflow)
|
|
12
|
+
- Basic focus management (for complex cases you would need external library)
|
|
13
|
+
- Basic animations with css transitions (for complex animations you would need external library)
|
|
14
|
+
|
|
5
15
|
## First include styles
|
|
6
16
|
|
|
7
17
|
```typescript
|
|
8
18
|
// import styles with your bundler or copy them by hand and reference in your html
|
|
9
|
-
import "@qyu/reactcmp-dropdown/style/index
|
|
19
|
+
import "@qyu/reactcmp-dropdown/style/index"
|
|
10
20
|
// or import module and insert them directly to the component
|
|
11
|
-
import
|
|
21
|
+
import clmap from "@qyu/reactcmp-dropdown/stlye/index"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Basic usage
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import * as ddn from "qyu/reactcmp-dropdown"
|
|
28
|
+
|
|
29
|
+
// will render dropdown
|
|
30
|
+
function DDN(props: { children: r.Children }) {
|
|
31
|
+
// virtual container will not render any dom element, only create necessary contexts
|
|
32
|
+
// there also a Component that renders a real one
|
|
33
|
+
return <ddn.CmpContainerVirtual>
|
|
34
|
+
<ddn.CmpButton>
|
|
35
|
+
Press
|
|
36
|
+
</ddn.CmpButton>
|
|
37
|
+
|
|
38
|
+
<ddn.CmpListPortal
|
|
39
|
+
gap={5}
|
|
40
|
+
// find by id, you can pass HTLMElement directly alternatively
|
|
41
|
+
portal={"ddnportal"}
|
|
42
|
+
|
|
43
|
+
// optional
|
|
44
|
+
direction={"ver"}
|
|
45
|
+
// optional
|
|
46
|
+
align={"start"}
|
|
47
|
+
// optional
|
|
48
|
+
justify={"end"}
|
|
49
|
+
>
|
|
50
|
+
{/* Used to measure content. Required for any list */}
|
|
51
|
+
<ddn.Content>
|
|
52
|
+
{props.children}
|
|
53
|
+
</ddn.Content>
|
|
54
|
+
</ddn.CmpListPortal>
|
|
55
|
+
</ddn.CmpContainer>
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// nested dropdowns
|
|
59
|
+
function App() {
|
|
60
|
+
// if you want to render nested dropdown
|
|
61
|
+
// - it will need its own context with <ddn.CmpContainerVirtual>
|
|
62
|
+
// therefore - this works
|
|
63
|
+
return <DDN>
|
|
64
|
+
<DDN>
|
|
65
|
+
List Content
|
|
66
|
+
</DDN>
|
|
67
|
+
</DDN>
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Change Transition time and z-index
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
:root {
|
|
75
|
+
--qyuddn-z-index: 3;
|
|
76
|
+
--qyuddn-trtime: 0.2s;
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Making your custom button
|
|
81
|
+
|
|
82
|
+
```tsx
|
|
83
|
+
const CustomButton = function () {
|
|
84
|
+
const ref = r.useRef<HTMLButtonElement | null>(null)
|
|
85
|
+
const ctxstate_open = ddn.useCtxStateOpen()
|
|
86
|
+
|
|
87
|
+
// this will give you calculated value of wether your dropdown is open or not
|
|
88
|
+
const open = ddn.useOpenInfer({})
|
|
89
|
+
|
|
90
|
+
// this wrapper is required, it necessary events and stuff
|
|
91
|
+
return <ddn.ButtonVirtual target={ref}>
|
|
92
|
+
<button
|
|
93
|
+
ref={ref}
|
|
94
|
+
onClick={() => ctxstate_open.open_set(o => !o)}
|
|
95
|
+
>
|
|
96
|
+
MyButton
|
|
97
|
+
</button>
|
|
98
|
+
</ddn.ButtonVirtual>
|
|
99
|
+
}
|
|
12
100
|
```
|
|
13
101
|
|
|
14
|
-
##
|
|
102
|
+
## Usage with all properties
|
|
15
103
|
|
|
16
104
|
```tsx
|
|
17
105
|
import * as ddn from "qyu/reactcmp-dropdown"
|
|
18
106
|
|
|
19
107
|
function App() {
|
|
108
|
+
// it is generally recomended to use local state instead of declaring it here
|
|
20
109
|
const [open, open_set] = r.useState(false)
|
|
21
110
|
|
|
22
111
|
return <ddn.CmpContainer
|
|
23
112
|
// optional, will be added to other styles
|
|
24
113
|
className={""}
|
|
25
114
|
// here you can insert styles in modular form
|
|
26
|
-
|
|
115
|
+
clmap={clmap}
|
|
27
116
|
|
|
28
117
|
// optional, will use local state if not provided
|
|
29
118
|
open={open}
|
|
30
119
|
open_set={open_set}
|
|
31
120
|
|
|
32
|
-
// on which events should close the dropdown
|
|
121
|
+
// on which events should close the dropdown {CloseEvt_ConfigFull}
|
|
33
122
|
// optional, all true by default
|
|
34
123
|
closeevents={{
|
|
35
124
|
// focus going outside the container
|
|
@@ -43,49 +132,53 @@ function App() {
|
|
|
43
132
|
// press escape
|
|
44
133
|
escape: true,
|
|
45
134
|
}}
|
|
135
|
+
|
|
136
|
+
// focus controls {Focus_Config}
|
|
137
|
+
// optional, default values below
|
|
138
|
+
focus={{
|
|
139
|
+
// should capture focus
|
|
140
|
+
capture: true,
|
|
141
|
+
// focus options
|
|
142
|
+
capture_options: { preventScroll: true },
|
|
143
|
+
// should restore focus
|
|
144
|
+
restore: true,
|
|
145
|
+
// focus options
|
|
146
|
+
restore_options: { preventScroll: true },
|
|
147
|
+
}}
|
|
148
|
+
|
|
149
|
+
// customize rendered element
|
|
150
|
+
render_view={props => <div {...props} />}
|
|
46
151
|
>
|
|
47
|
-
|
|
48
|
-
|
|
152
|
+
<ddn.CmpButton
|
|
153
|
+
className={""}
|
|
154
|
+
disabled={false}
|
|
155
|
+
render_view={props => <button {...props} />}
|
|
156
|
+
|
|
157
|
+
// if it should be the element list position is based around
|
|
158
|
+
// if unset - applies automatically depending on the context (true for virtual container, false otherwise)
|
|
159
|
+
isroot={false}
|
|
160
|
+
>
|
|
49
161
|
Press
|
|
50
162
|
</ddn.CmpButton>
|
|
51
163
|
|
|
52
|
-
|
|
53
|
-
|
|
164
|
+
{/* ListPortal renders inside a portal with position: fixed */}
|
|
165
|
+
{/* There also ListAbs and ListFix. They share most of the properties. */}
|
|
166
|
+
<ddn.CmpListPortal
|
|
54
167
|
className={""}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
lazy
|
|
59
|
-
|
|
60
|
-
// add gap between button and list, in pixels
|
|
61
|
-
gap={5}
|
|
62
|
-
|
|
63
|
-
// inverse direction default if "ver"
|
|
64
|
-
direction
|
|
65
|
-
// set direction directly
|
|
66
|
-
direction={"hor" || "ver"}
|
|
168
|
+
clmap={clmap}
|
|
169
|
+
clmap_content={clmap}
|
|
170
|
+
render_view={props => <div {...props} />}
|
|
67
171
|
|
|
68
|
-
//
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
align={"start" || "end" || "center"}
|
|
72
|
-
|
|
73
|
-
// inverse justify default is "end"
|
|
74
|
-
justify
|
|
75
|
-
// set justify directly
|
|
76
|
-
jystify={"end" || "start"}
|
|
77
|
-
>
|
|
78
|
-
Your Content Here
|
|
79
|
-
</ddn.CmpListAbs>
|
|
172
|
+
// specify the portal
|
|
173
|
+
portal={"domid"}
|
|
174
|
+
portal={document.getElementById("domid")}
|
|
80
175
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
className={""}
|
|
85
|
-
stylemodule={stylemodule}
|
|
176
|
+
// disable types of transitions, default is false
|
|
177
|
+
transition_nopos={false}
|
|
178
|
+
transition_nosize={false}
|
|
86
179
|
|
|
87
|
-
// do not render children when hidden, default
|
|
88
|
-
lazy
|
|
180
|
+
// do not render children when hidden, default is true
|
|
181
|
+
lazy={true}
|
|
89
182
|
|
|
90
183
|
// add gap between button and list, in pixels
|
|
91
184
|
gap={5}
|
|
@@ -103,42 +196,47 @@ function App() {
|
|
|
103
196
|
// inverse justify default is "end"
|
|
104
197
|
justify
|
|
105
198
|
// set justify directly
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
//
|
|
109
|
-
//
|
|
110
|
-
|
|
199
|
+
justify={"end" || "start"}
|
|
200
|
+
|
|
201
|
+
// recalculate position on, optional
|
|
202
|
+
// default values shown below
|
|
203
|
+
rearrange={{
|
|
204
|
+
// {any[] | undefined}
|
|
205
|
+
deps: undefined,
|
|
206
|
+
// rearrange when list is opened
|
|
207
|
+
open: true,
|
|
208
|
+
// rearrange on scroll
|
|
209
|
+
scroll: true,
|
|
210
|
+
// rearrange on window resize
|
|
211
|
+
resize: true,
|
|
212
|
+
// rearrange every animation frame
|
|
213
|
+
// if you need to use it - you are probably doing something wrong
|
|
214
|
+
polling: false,
|
|
215
|
+
}}
|
|
216
|
+
|
|
217
|
+
// when visibility changes
|
|
218
|
+
event_visibility_chage={(visible: boolean) => {}}
|
|
219
|
+
// when transition status changes
|
|
220
|
+
event_transition_change={(property: string, active: true) => {}}
|
|
111
221
|
>
|
|
112
|
-
|
|
113
|
-
|
|
222
|
+
{/* Used to measure content. Required for any list */}
|
|
223
|
+
<ddn.Content
|
|
224
|
+
clmap={clmap}
|
|
225
|
+
className={""}
|
|
226
|
+
render_view={props => <div {...props} />}
|
|
227
|
+
|
|
228
|
+
// dont render focusguards, false by default
|
|
229
|
+
focus_noguards={false}
|
|
230
|
+
>
|
|
231
|
+
Your Content Here
|
|
232
|
+
</ddn.Content>
|
|
233
|
+
|
|
234
|
+
{() => {
|
|
235
|
+
return <ddn.Content>
|
|
236
|
+
Your Content Here
|
|
237
|
+
</ddn.Content>
|
|
238
|
+
}}
|
|
239
|
+
</ddn.CmpListPortal>
|
|
114
240
|
</ddn.CmpContainer>
|
|
115
241
|
}
|
|
116
242
|
```
|
|
117
|
-
|
|
118
|
-
## Making your custom button
|
|
119
|
-
|
|
120
|
-
```tsx
|
|
121
|
-
export const CmpButton = () => {
|
|
122
|
-
// just listen to the context state
|
|
123
|
-
const ctxstate = r.useContext(CmpCtxState_Open)
|
|
124
|
-
|
|
125
|
-
if (!ctxstate) { throw new Error(`Using DropdownStateOpen dependend component outside of DropdownStateOpen Context`) }
|
|
126
|
-
|
|
127
|
-
return <button
|
|
128
|
-
onClick={() => {
|
|
129
|
-
ctxstate.open_set(t => !t)
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
132
|
-
Press
|
|
133
|
-
</button>
|
|
134
|
-
}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## Change Transition time and z-index
|
|
138
|
-
|
|
139
|
-
```css
|
|
140
|
-
:root {
|
|
141
|
-
--qyuddn-z-index: 3;
|
|
142
|
-
--qyuddn-trtime: 0.2s;
|
|
143
|
-
}
|
|
144
|
-
```
|