@colisweb/rescript-toolkit 4.11.2 → 4.12.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colisweb/rescript-toolkit",
3
- "version": "4.11.2",
3
+ "version": "4.12.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "clean": "rescript clean",
@@ -206,15 +206,17 @@ module Make = (Config: RouterConfig) => {
206
206
  and link =
207
207
  | Legacy(legacyLink)
208
208
  | App(appLink)
209
+ | Custom(React.element)
209
210
  and groupInfo = {
210
211
  label: React.element,
211
212
  icon: React.element,
212
- activeForCurrentRoute?: Config.t => bool,
213
+ hideContentWhenClosed?: bool,
213
214
  }
214
215
  and appLink = {
215
216
  route: Config.t,
216
217
  icon?: React.element,
217
218
  label: React.element,
219
+ disabledActiveLink?: bool,
218
220
  }
219
221
  and legacyLink = {
220
222
  url: string,
@@ -239,6 +241,7 @@ module Make = (Config: RouterConfig) => {
239
241
  ~onLinkClick=() => (),
240
242
  ) =>
241
243
  switch link {
244
+ | Custom(element) => element
242
245
  | Legacy(config) =>
243
246
  let {label, url} = config
244
247
  <a
@@ -267,6 +270,9 @@ module Make = (Config: RouterConfig) => {
267
270
  </a>
268
271
  | App(config) =>
269
272
  let {label, route} = config
273
+
274
+ let disabledActiveLink = config.disabledActiveLink->Option.getWithDefault(false)
275
+
270
276
  <Link
271
277
  route
272
278
  className={cx([
@@ -274,7 +280,7 @@ module Make = (Config: RouterConfig) => {
274
280
  isSubLink ? "ml-3" : "",
275
281
  config.icon->Option.isNone ? "py-5" : "",
276
282
  "sidenav-link",
277
- isActive ? "bg-primary-100/75 text-neutral-700" : "",
283
+ isActive && !disabledActiveLink ? "bg-primary-100/75 text-neutral-700" : "",
278
284
  ])}
279
285
  activeClassName="bg-primary-100/75 text-neutral-700"
280
286
  onClick={_ => onLinkClick()}>
@@ -302,6 +308,28 @@ module Make = (Config: RouterConfig) => {
302
308
  }
303
309
 
304
310
  module GroupedLinks = {
311
+ module LinksList = {
312
+ @react.component
313
+ let make = (~links, ~relativeRoute, ~isNavOpen, ~onLinkClick) => {
314
+ links
315
+ ->Array.mapWithIndex((i, link) => {
316
+ let isActive = switch (relativeRoute, link) {
317
+ | (Some(App({route: relativeRoute})), App({route})) => relativeRoute->isRouteEqual(route)
318
+ | _ => false
319
+ }
320
+ <SingleLink
321
+ key={"sidenav-grouped-" ++ i->Int.toString}
322
+ link
323
+ isNavOpen
324
+ isSubLink=true
325
+ onLinkClick
326
+ isActive
327
+ />
328
+ })
329
+ ->React.array
330
+ }
331
+ }
332
+
305
333
  @react.component
306
334
  let make = (
307
335
  ~groupInfo: groupInfo,
@@ -316,6 +344,7 @@ module Make = (Config: RouterConfig) => {
316
344
  let hasActiveSubRoute = links->Array.some(link => {
317
345
  switch link {
318
346
  | Legacy(_) => false
347
+ | Custom(_) => false
319
348
  | App({route}) => isRouteEqual(currentRoute, route)
320
349
  }
321
350
  })
@@ -325,6 +354,7 @@ module Make = (Config: RouterConfig) => {
325
354
  links->Array.getBy(link => {
326
355
  switch link {
327
356
  | Legacy(_) => false
357
+ | Custom(_) => false
328
358
  | App({route}) =>
329
359
  breadcrumbLinks->Array.some(breadcrumbLink => breadcrumbLink.route->isRouteEqual(route))
330
360
  }
@@ -380,23 +410,11 @@ module Make = (Config: RouterConfig) => {
380
410
  "transition ease-linear duration-300",
381
411
  isOpen ? "h-auto" : "h-0 overflow-hidden",
382
412
  ])}>
383
- {links
384
- ->Array.mapWithIndex((i, link) => {
385
- let isActive = switch (relativeRoute, link) {
386
- | (Some(App({route: relativeRoute})), App({route})) =>
387
- relativeRoute->isRouteEqual(route)
388
- | _ => false
389
- }
390
- <SingleLink
391
- key={"sidenav-grouped-" ++ i->Int.toString}
392
- link
393
- isNavOpen
394
- isSubLink=true
395
- onLinkClick
396
- isActive
397
- />
398
- })
399
- ->React.array}
413
+ {switch groupInfo.hideContentWhenClosed {
414
+ | Some(true) =>
415
+ isOpen ? <LinksList links relativeRoute onLinkClick isNavOpen /> : React.null
416
+ | _ => <LinksList links relativeRoute onLinkClick isNavOpen />
417
+ }}
400
418
  </div>
401
419
  </>
402
420
  }