@colisweb/rescript-toolkit 2.63.1 → 2.64.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/package.json +1 -1
- package/src/router/Toolkit__Router.res +72 -10
package/package.json
CHANGED
|
@@ -86,6 +86,40 @@ module Make = (Config: RouterConfig) => {
|
|
|
86
86
|
|
|
87
87
|
let toString = Config.toString
|
|
88
88
|
|
|
89
|
+
module Breadcrumb = {
|
|
90
|
+
type link = {
|
|
91
|
+
route: Config.t,
|
|
92
|
+
text: React.element,
|
|
93
|
+
}
|
|
94
|
+
type state = {links: option<array<link>>}
|
|
95
|
+
|
|
96
|
+
type action =
|
|
97
|
+
| Reset
|
|
98
|
+
| Update(array<link>)
|
|
99
|
+
|
|
100
|
+
let store = Restorative.createStore({links: None}, (_state, action) =>
|
|
101
|
+
switch action {
|
|
102
|
+
| Reset => {links: None}
|
|
103
|
+
| Update(links) => {links: Some(links)}
|
|
104
|
+
}
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
let use = (routes: array<link>) => {
|
|
108
|
+
React.useLayoutEffect0(() => {
|
|
109
|
+
store.dispatch(Update(routes))
|
|
110
|
+
|
|
111
|
+
Some(() => store.dispatch(Reset))
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
let usePreviousLinkWithDefault = (defaultRoute, cb) => {
|
|
117
|
+
let {previousRoute} = React.useContext(routerContext)
|
|
118
|
+
previousRoute->Option.mapWithDefault(defaultRoute, route => {
|
|
119
|
+
cb(route) ? route : defaultRoute
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
|
|
89
123
|
module Link = {
|
|
90
124
|
@react.component
|
|
91
125
|
let make = (
|
|
@@ -185,7 +219,13 @@ module Make = (Config: RouterConfig) => {
|
|
|
185
219
|
|
|
186
220
|
module SingleLink = {
|
|
187
221
|
@react.component
|
|
188
|
-
let make = (
|
|
222
|
+
let make = (
|
|
223
|
+
~link: link,
|
|
224
|
+
~isNavOpen: bool,
|
|
225
|
+
~isSubLink=false,
|
|
226
|
+
~isActive=false,
|
|
227
|
+
~onLinkClick=() => (),
|
|
228
|
+
) =>
|
|
189
229
|
switch link {
|
|
190
230
|
| Legacy({icon, label, url}) =>
|
|
191
231
|
<a
|
|
@@ -213,7 +253,12 @@ module Make = (Config: RouterConfig) => {
|
|
|
213
253
|
| App({icon, label, route}) =>
|
|
214
254
|
<Link
|
|
215
255
|
route
|
|
216
|
-
className={cx([
|
|
256
|
+
className={cx([
|
|
257
|
+
commonClassName,
|
|
258
|
+
isSubLink ? "ml-3" : "",
|
|
259
|
+
"sidenav-link",
|
|
260
|
+
isActive ? "bg-primary-100/75 text-neutral-700" : "",
|
|
261
|
+
])}
|
|
217
262
|
activeClassName="bg-primary-100/75 text-neutral-700"
|
|
218
263
|
onClick={_ => onLinkClick()}>
|
|
219
264
|
<span className="overflow-hidden flex">
|
|
@@ -255,6 +300,17 @@ module Make = (Config: RouterConfig) => {
|
|
|
255
300
|
| App({route}) => isRouteEqual(currentRoute, route)
|
|
256
301
|
}
|
|
257
302
|
})
|
|
303
|
+
let breadcrumb = Breadcrumb.store.useStore()
|
|
304
|
+
|
|
305
|
+
let relativeRoute = breadcrumb.links->Option.mapWithDefault(None, breadcrumbLinks => {
|
|
306
|
+
links->Array.getBy(link => {
|
|
307
|
+
switch link {
|
|
308
|
+
| Legacy(_) => false
|
|
309
|
+
| App({route}) =>
|
|
310
|
+
breadcrumbLinks->Array.some(breadcrumbLink => breadcrumbLink.route->isRouteEqual(route))
|
|
311
|
+
}
|
|
312
|
+
})
|
|
313
|
+
})
|
|
258
314
|
|
|
259
315
|
React.useEffect1(() => {
|
|
260
316
|
if !isNavOpen {
|
|
@@ -272,11 +328,7 @@ module Make = (Config: RouterConfig) => {
|
|
|
272
328
|
className={cx([
|
|
273
329
|
commonClassName,
|
|
274
330
|
"flex items-center w-full sidenav-link",
|
|
275
|
-
|
|
276
|
-
| (true, true) => "bg-primary-100/50"
|
|
277
|
-
| (true, false) => "bg-primary-100/75"
|
|
278
|
-
| (false, _) => ""
|
|
279
|
-
},
|
|
331
|
+
hasActiveSubRoute || relativeRoute->Option.isSome ? "bg-primary-100/75" : "",
|
|
280
332
|
])}>
|
|
281
333
|
<span className={cx(["mr-2 text-neutral-800", isNavOpen ? "pl-2" : "px-2"])}>
|
|
282
334
|
groupInfo.icon
|
|
@@ -310,11 +362,21 @@ module Make = (Config: RouterConfig) => {
|
|
|
310
362
|
isOpen ? "h-auto" : "h-0 overflow-hidden",
|
|
311
363
|
])}>
|
|
312
364
|
{links
|
|
313
|
-
->Array.mapWithIndex((i, link) =>
|
|
365
|
+
->Array.mapWithIndex((i, link) => {
|
|
366
|
+
let isActive = switch (relativeRoute, link) {
|
|
367
|
+
| (Some(App({route: relativeRoute})), App({route})) =>
|
|
368
|
+
relativeRoute->isRouteEqual(route)
|
|
369
|
+
| _ => false
|
|
370
|
+
}
|
|
314
371
|
<SingleLink
|
|
315
|
-
key={"sidenav-grouped-" ++ i->Int.toString}
|
|
372
|
+
key={"sidenav-grouped-" ++ i->Int.toString}
|
|
373
|
+
link
|
|
374
|
+
isNavOpen
|
|
375
|
+
isSubLink=true
|
|
376
|
+
onLinkClick
|
|
377
|
+
isActive
|
|
316
378
|
/>
|
|
317
|
-
)
|
|
379
|
+
})
|
|
318
380
|
->React.array}
|
|
319
381
|
</div>
|
|
320
382
|
</>
|