@dvrd/dvr-controls 1.0.2 → 1.0.5

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": "@dvrd/dvr-controls",
3
- "version": "1.0.2",
3
+ "version": "1.0.5",
4
4
  "description": "Custom web controls",
5
5
  "main": "index.ts",
6
6
  "scripts": {},
@@ -13,24 +13,25 @@ interface Props {
13
13
  className?: string;
14
14
  disabled?: boolean;
15
15
  underline?: boolean;
16
+ target?: string;
16
17
  }
17
18
 
18
19
  export default function Link(props: React.PropsWithChildren<Props>) {
19
- const onClick = (evt: React.MouseEvent) => {
20
+ const {className, disabled, route, children, underline, target, onClick} = props;
21
+
22
+ function _onClick(evt: React.MouseEvent) {
20
23
  evt.preventDefault();
21
- const {disabled, route, onClick} = props;
22
24
  if (!disabled) {
23
25
  if (route) {
24
- if (route.startsWith('http')) window.open(route);
26
+ if (/^(www|http).+/.test(route)) window.open(route, target);
25
27
  else navigate(route);
26
28
  }
27
29
  if (onClick) onClick(evt);
28
30
  }
29
- };
31
+ }
30
32
 
31
- const {className, disabled, route, children, underline} = props;
32
33
  return (
33
- <a href={route} onClick={onClick}
34
+ <a href={route} onClick={_onClick} target={target}
34
35
  className={classNames('app-link', className, disabled && 'disabled',
35
36
  underline && 'underline')}>{children}</a>
36
37
  );
@@ -7,7 +7,7 @@ import React, {MouseEventHandler, ReactNode, useContext, useEffect, useRef, useS
7
7
  import {useLocation} from 'react-router';
8
8
  import {SidebarItem, SideMenuMode} from "../util/interfaces";
9
9
  import classNames from 'classnames';
10
- import {AwesomeIcon, generateComponentId} from "../../../index";
10
+ import {AwesomeIcon, generateComponentId, isAbsoluteLink} from "../../../index";
11
11
  import {ControlContext} from "../util/controlContext";
12
12
  import {defer} from 'lodash';
13
13
 
@@ -67,7 +67,14 @@ export default function SidebarMenu(props: Props) {
67
67
  function _onClickItem(item: SidebarItem) {
68
68
  return function (evt: React.MouseEvent) {
69
69
  evt.stopPropagation();
70
- setActiveItem(item.id);
70
+ const {route} = item;
71
+ let _route: string | null = null;
72
+ if (route) {
73
+ if (Array.isArray(route) && route.length) _route = route[0];
74
+ else _route = route as string;
75
+ }
76
+ if (_route && !isAbsoluteLink(_route))
77
+ setActiveItem(item.id);
71
78
  onClickItem(item)(evt);
72
79
  }
73
80
  }
@@ -163,4 +163,8 @@ export function webpSupported(): boolean {
163
163
  } catch {
164
164
  return false;
165
165
  }
166
+ }
167
+
168
+ export function isAbsoluteLink(link: string): boolean {
169
+ return /^(https?|www).*/.test(link);
166
170
  }