@julseb-lib/react 0.0.43 → 0.0.45

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.
@@ -107,16 +107,22 @@ const StyledDropdownItem = styled.button<{
107
107
  $gap,
108
108
  })}
109
109
 
110
+ &:disabled {
111
+ color: ${({ theme }) => theme.GRAY_500};
112
+ }
113
+
110
114
  @media ${MEDIA.HOVER} {
111
- &:hover {
112
- background-color: ${({ theme, $accentColor }) =>
113
- Mixins.ColorsHoverHover($accentColor, theme)};
114
- color: ${({ theme }) => theme.BACKGROUND};
115
- }
115
+ &:not(:disabled) {
116
+ &:hover {
117
+ background-color: ${({ theme, $accentColor }) =>
118
+ Mixins.ColorsHoverHover($accentColor, theme)};
119
+ color: ${({ theme }) => theme.BACKGROUND};
120
+ }
116
121
 
117
- &:active {
118
- background-color: ${({ theme, $accentColor }) =>
119
- Mixins.ColorsHoverActive($accentColor, theme)};
122
+ &:active {
123
+ background-color: ${({ theme, $accentColor }) =>
124
+ Mixins.ColorsHoverActive($accentColor, theme)};
125
+ }
120
126
  }
121
127
  }
122
128
  `
@@ -2,7 +2,7 @@
2
2
  /*=============================================== HeaderNavLink ===============================================*/
3
3
 
4
4
  import { isValidElement } from "react"
5
- import { NavLink } from "react-router-dom"
5
+ import { Link } from "../../"
6
6
  import type { ILibHeaderNavLink } from "./subtypes"
7
7
 
8
8
  export const HeaderNavLink = ({
@@ -12,56 +12,21 @@ export const HeaderNavLink = ({
12
12
  }: ILibHeaderNavLink) => {
13
13
  if (isValidElement(link)) return link
14
14
 
15
- if (link.to)
16
- return (
17
- <NavLink
18
- data-testid={
19
- link["data-testid"] || (testid && `${testid}.NavLink`)
20
- }
21
- className={link.className || (className && "NavLink")}
22
- id={link.id}
23
- ref={link.ref}
24
- to={link.to}
25
- end={link.end}
26
- target={link.blank ? "_blank" : undefined}
27
- rel={link.blank ? "noreferrer noopener" : undefined}
28
- >
29
- {link.text}
30
- </NavLink>
31
- )
32
-
33
- if (link.href)
34
- return (
35
- <a
36
- data-testid={
37
- link["data-testid"] || (testid && `${testid}.NavLink`)
38
- }
39
- className={link.className || (className && "NavLink")}
40
- id={link.id}
41
- ref={link.ref}
42
- href={link.href}
43
- target={link.blank ? "_blank" : undefined}
44
- rel={link.blank ? "noreferrer noopener" : undefined}
45
- >
46
- {link.text}
47
- </a>
48
- )
49
-
50
- if (link.onClick)
51
- return (
52
- <button
53
- data-testid={
54
- link["data-testid"] || (testid && `${testid}.NavButton`)
55
- }
56
- className={link.className || (className && "NavButton")}
57
- id={link.id}
58
- ref={link.ref}
59
- onClick={link.onClick}
60
- disabled={link.disabled}
61
- >
62
- {link.text}
63
- </button>
64
- )
65
-
66
- return null
15
+ return (
16
+ <Link
17
+ data-testid={link["data-testid"] || (testid && `${testid}.NavLink`)}
18
+ className={link.className || (className && "NavLink")}
19
+ id={link.id}
20
+ ref={link.ref}
21
+ end={link.end}
22
+ blank={link.blank}
23
+ to={link.to}
24
+ href={link.href}
25
+ onClick={link.onClick}
26
+ disabled={link.disabled}
27
+ isNavLink
28
+ >
29
+ {link.text}
30
+ </Link>
31
+ )
67
32
  }
@@ -0,0 +1,68 @@
1
+ /*=============================================== Link component ===============================================*/
2
+
3
+ import { forwardRef, type RefObject } from "react"
4
+ import { Link as RouterLink, NavLink } from "react-router-dom"
5
+ import type { ILibLink } from "./types"
6
+
7
+ /**
8
+ * @description Returns a Link component
9
+ * @link https://documentation-components-react.vercel.app/components/link
10
+ * @extends HTMLDivElement
11
+ * @prop data-testid?: string
12
+ * @prop ref?: ForwardedRef<HTMLDivElement>
13
+ */
14
+ export const Link = forwardRef<HTMLAnchorElement | HTMLButtonElement, ILibLink>(
15
+ (
16
+ { "data-testid": testid, isNavLink, to, href, onClick, blank, end, ...rest },
17
+ ref
18
+ ) => {
19
+ if (onClick)
20
+ return (
21
+ <button
22
+ data-testid={testid}
23
+ ref={ref as RefObject<HTMLButtonElement>}
24
+ onClick={onClick}
25
+ {...rest}
26
+ />
27
+ )
28
+
29
+ if (href)
30
+ return (
31
+ <a
32
+ data-testid={testid}
33
+ ref={ref as RefObject<HTMLAnchorElement>}
34
+ href={href}
35
+ target={blank ? "_blank" : undefined}
36
+ rel={blank ? "noreferrer noopener" : undefined}
37
+ {...rest}
38
+ />
39
+ )
40
+
41
+ if (isNavLink && to)
42
+ return (
43
+ <NavLink
44
+ data-testid={testid}
45
+ ref={ref as RefObject<HTMLAnchorElement>}
46
+ to={to}
47
+ target={blank ? "_blank" : undefined}
48
+ rel={blank ? "noreferrer noopener" : undefined}
49
+ end={end}
50
+ {...rest}
51
+ />
52
+ )
53
+
54
+ if (to)
55
+ return (
56
+ <RouterLink
57
+ data-testid={testid}
58
+ ref={ref as RefObject<HTMLAnchorElement>}
59
+ to={to}
60
+ target={blank ? "_blank" : undefined}
61
+ rel={blank ? "noreferrer noopener" : undefined}
62
+ {...rest}
63
+ />
64
+ )
65
+
66
+ return null
67
+ }
68
+ )
@@ -0,0 +1,3 @@
1
+ /*=============================================== Link exports ===============================================*/
2
+
3
+ export * from "./Link"
@@ -0,0 +1,9 @@
1
+ /*=============================================== Link types ===============================================*/
2
+
3
+ import type { LibComponentBase, LibButtonLinkBlank } from "../../types"
4
+
5
+ export type ILibLink = LibComponentBase<HTMLAnchorElement | HTMLButtonElement> &
6
+ LibButtonLinkBlank & {
7
+ isNavLink?: boolean
8
+ end?: boolean
9
+ }
package/dist/lib/index.ts CHANGED
@@ -85,6 +85,7 @@ export * from "./components/Section"
85
85
  export * from "./components/Grid"
86
86
  export * from "./components/Flexbox"
87
87
  export * from "./components/Icon"
88
+ export * from "./components/Link"
88
89
  export * from "./components/Key"
89
90
  export * from "./components/TextIcon"
90
91
  export * from "./components/Highlight"
@@ -78,4 +78,5 @@ export * from "../components/DragList/types"
78
78
  export * from "../components/Fieldset/types"
79
79
  export * from "../components/Datepicker/types"
80
80
  export * from "../components/Timepicker/types"
81
+ export * from "../components/Link/types"
81
82
  // prependHere
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@julseb-lib/react",
3
- "version": "0.0.43",
3
+ "version": "0.0.45",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "scripts": {