@qyu/reactcmp-dropdown 1.1.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.
Files changed (84) hide show
  1. package/README.md +173 -69
  2. package/build/bundle/entry/index.js +1268 -385
  3. package/build/declaration/component/button/element/view.d.ts +8 -5
  4. package/build/declaration/component/button/element/virtual.d.ts +9 -0
  5. package/build/declaration/component/container/element/view.d.ts +14 -23
  6. package/build/declaration/component/container/element/virtual.d.ts +13 -0
  7. package/build/declaration/component/content/element/view.d.ts +11 -0
  8. package/build/declaration/component/ctx-state/element/config.d.ts +3 -0
  9. package/build/declaration/component/ctx-state/element/content.d.ts +3 -0
  10. package/build/declaration/component/ctx-state/element/open.d.ts +2 -5
  11. package/build/declaration/component/ctx-state/element/refs.d.ts +3 -0
  12. package/build/declaration/component/ctx-state/hook/init/config.d.ts +8 -0
  13. package/build/declaration/component/ctx-state/hook/init/content.d.ts +6 -0
  14. package/build/declaration/component/ctx-state/hook/init/open.d.ts +7 -0
  15. package/build/declaration/component/ctx-state/hook/init/refs.d.ts +5 -0
  16. package/build/declaration/component/ctx-state/hook/view/config.d.ts +1 -0
  17. package/build/declaration/component/ctx-state/hook/view/content.d.ts +1 -0
  18. package/build/declaration/component/ctx-state/hook/view/open.d.ts +1 -0
  19. package/build/declaration/component/ctx-state/hook/view/refs.d.ts +1 -0
  20. package/build/declaration/component/ctx-state/type/state.d.ts +40 -6
  21. package/build/declaration/component/list-abs/element/view.d.ts +23 -36
  22. package/build/declaration/component/list-fix/element/view.d.ts +24 -36
  23. package/build/declaration/component/list-portal/element/view.d.ts +29 -0
  24. package/build/declaration/hook/closeevt/root.d.ts +8 -0
  25. package/build/declaration/hook/closeevt/root_infer.d.ts +3 -0
  26. package/build/declaration/hook/closeevt/shard.d.ts +9 -0
  27. package/build/declaration/hook/closeevt/shard_infer.d.ts +3 -0
  28. package/build/declaration/hook/ddnparts/list.d.ts +6 -0
  29. package/build/declaration/hook/ddnparts/list_infer.d.ts +3 -0
  30. package/build/declaration/hook/ddnparts/root.d.ts +8 -0
  31. package/build/declaration/hook/ddnparts/root_infer.d.ts +3 -0
  32. package/build/declaration/hook/ddnparts/shard.d.ts +9 -0
  33. package/build/declaration/hook/ddnparts/shard_infer.d.ts +3 -0
  34. package/build/declaration/hook/focus/capture.d.ts +16 -0
  35. package/build/declaration/hook/focus/capture_infer.d.ts +3 -0
  36. package/build/declaration/hook/listpos/api/absolute.d.ts +15 -0
  37. package/build/declaration/hook/listpos/api/fixed.d.ts +18 -0
  38. package/build/declaration/hook/listpos/api/type/api.d.ts +13 -0
  39. package/build/declaration/hook/listpos/api/type/position.d.ts +6 -0
  40. package/build/declaration/hook/listpos/api/type/reverse.d.ts +4 -0
  41. package/build/declaration/hook/listpos/api/type/size.d.ts +4 -0
  42. package/build/declaration/hook/listpos/rearrange/index.d.ts +10 -0
  43. package/build/declaration/hook/listpos/rearrange/type/config.d.ts +7 -0
  44. package/build/declaration/hook/open/view.d.ts +6 -0
  45. package/build/declaration/hook/open/view_infer.d.ts +3 -0
  46. package/build/declaration/hook/ref/merge.d.ts +2 -0
  47. package/build/declaration/hook/ref/o.d.ts +3 -0
  48. package/build/declaration/index.d.ts +58 -3
  49. package/build/declaration/type/fnref.d.ts +4 -0
  50. package/build/declaration/util/clname/merge.d.ts +1 -0
  51. package/build/declaration/util/closeevt/type/config.d.ts +11 -0
  52. package/build/declaration/util/cssprops/new/position.d.ts +3 -0
  53. package/build/declaration/util/cssprops/new/size.d.ts +9 -0
  54. package/build/declaration/util/focus/config/type/config.d.ts +6 -0
  55. package/build/declaration/util/prop/align/new/index.d.ts +2 -0
  56. package/build/declaration/util/prop/align/new/reversed.d.ts +2 -0
  57. package/build/declaration/util/prop/align/type/prop.d.ts +2 -0
  58. package/build/declaration/util/prop/clmap/def/container.d.ts +6 -0
  59. package/build/declaration/util/prop/clmap/def/content.d.ts +8 -0
  60. package/build/declaration/util/prop/clmap/def/listabs.d.ts +15 -0
  61. package/build/declaration/util/prop/clmap/def/listfix.d.ts +16 -0
  62. package/build/declaration/util/prop/clmap/new/index.d.ts +2 -0
  63. package/build/declaration/util/prop/clmap/type/prop.d.ts +4 -0
  64. package/build/declaration/util/prop/direction/new/index.d.ts +2 -0
  65. package/build/declaration/util/prop/direction/type/prop.d.ts +2 -0
  66. package/build/declaration/util/prop/justify/new/index.d.ts +2 -0
  67. package/build/declaration/util/prop/justify/new/reversed.d.ts +2 -0
  68. package/build/declaration/util/prop/justify/type/prop.d.ts +2 -0
  69. package/build/declaration/util/prop/portal/new/index.d.ts +2 -0
  70. package/build/declaration/util/prop/portal/type/prop.d.ts +2 -0
  71. package/build/declaration/util/ref/use.d.ts +2 -0
  72. package/build/style/index.css +132 -0
  73. package/build/style/index.css.d.ts +21 -0
  74. package/package.json +6 -9
  75. package/build/declaration/component/container/hook/useDropdownCloseEvents.d.ts +0 -15
  76. package/build/declaration/type/params.d.ts +0 -6
  77. package/build/declaration/util/cl.d.ts +0 -1
  78. package/build/declaration/util/nprop/index.d.ts +0 -4
  79. package/build/declaration/util/stylemap/new/remap.d.ts +0 -2
  80. package/build/declaration/util/stylemap/type/StyleMap.d.ts +0 -3
  81. package/build/style/index.global.css +0 -110
  82. package/build/style/index.global.css.d.ts +0 -21
  83. package/build/style/index.module.css +0 -110
  84. 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.global"
19
+ import "@qyu/reactcmp-dropdown/style/index"
10
20
  // or import module and insert them directly to the component
11
- import stylemodule from "@qyu/reactcmp-dropdown/stlye/index.module"
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
- ## Use Dropdown
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
- stylemodule={stylemodule}
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,47 +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
- {/* You would often want to imlement you own button. See futher */}
48
- <ddn.CmpButton className={""}>
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
- <ddn.CmpListAbs
164
+ {/* ListPortal renders inside a portal with position: fixed */}
165
+ {/* There also ListAbs and ListFix. They share most of the properties. */}
166
+ <ddn.CmpListPortal
53
167
  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"}
168
+ clmap={clmap}
169
+ clmap_content={clmap}
170
+ render_view={props => <div {...props} />}
66
171
 
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>
172
+ // specify the portal
173
+ portal={"domid"}
174
+ portal={document.getElementById("domid")}
79
175
 
80
- {/* Same as CmpListAbs, but uses fixed positioning */}
81
- <ddn.CmpListFix
82
- className={""}
83
- stylemodule={stylemodule}
176
+ // disable types of transitions, default is false
177
+ transition_nopos={false}
178
+ transition_nosize={false}
84
179
 
85
- // do not render children when hidden, default if false
86
- lazy
180
+ // do not render children when hidden, default is true
181
+ lazy={true}
87
182
 
88
183
  // add gap between button and list, in pixels
89
184
  gap={5}
@@ -101,38 +196,47 @@ function App() {
101
196
  // inverse justify default is "end"
102
197
  justify
103
198
  // set justify directly
104
- jystify={"end" || "start"}
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) => {}}
105
221
  >
106
- Your Content Here
107
- </ddn.CmpListFix>
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>
108
240
  </ddn.CmpContainer>
109
241
  }
110
242
  ```
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
- ```