@julseb-lib/react 0.0.87 → 0.0.88

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.
@@ -1,4 +1,4 @@
1
- import { useRef, type FC, type ReactNode } from "react"
1
+ import { useRef, type FC, type ReactNode, type ReactElement } from "react"
2
2
  import classNames from "classnames"
3
3
  import { uuid } from "@julseb-lib/utils"
4
4
  import { useMaxWidth, useClickOutside } from "../../"
@@ -9,72 +9,81 @@ import type { ILibHeaderNav } from "./subtypes"
9
9
  import type { LibHeaderLink } from "../../types"
10
10
 
11
11
  export const HeaderNav: FC<ILibHeaderNav> = ({
12
- "data-testid": testid,
13
- className,
14
- search,
15
- isOpen,
16
- children,
17
- links,
18
- headerHeight,
19
- variant,
20
- navMobileVariant,
21
- burgerPosition,
22
- burgerRef,
23
- handleClose,
24
- nav,
12
+ "data-testid": testid,
13
+ role = "navigation",
14
+ className,
15
+ search,
16
+ isOpen,
17
+ children,
18
+ links,
19
+ headerHeight,
20
+ variant,
21
+ navMobileVariant,
22
+ burgerPosition,
23
+ burgerRef,
24
+ handleClose,
25
+ nav,
25
26
  }) => {
26
- const isMobile = useMaxWidth(600)
27
+ const isMobile = useMaxWidth(600)
27
28
 
28
- const el = useRef<HTMLDivElement>(null as any)
29
- useClickOutside(el, e => {
30
- if (!burgerRef?.current?.contains(e.target as any)) {
31
- handleClose()
32
- }
33
- })
29
+ const el = useRef<HTMLDivElement>(null as any)
30
+ useClickOutside(el, e => {
31
+ if (
32
+ !(
33
+ typeof burgerRef === "object" &&
34
+ burgerRef !== null &&
35
+ "current" in burgerRef &&
36
+ burgerRef.current?.contains(e.target as any)
37
+ )
38
+ ) {
39
+ handleClose()
40
+ }
41
+ })
34
42
 
35
- const valueArr = links ? links : (children as Array<ReactNode>)
43
+ const valueArr = links ? links : (children as Array<ReactNode>)
36
44
 
37
- const searchHeight = isMobile && !!search ? 32 : 0
45
+ const searchHeight = isMobile && !!search ? 32 : 0
38
46
 
39
- const linksHeight = links
40
- ? links.length * 24 + ([...valueArr, searchHeight].length - 1) * 12
41
- : 56
47
+ const linksHeight = links
48
+ ? links.length * 24 + ([...valueArr, searchHeight].length - 1) * 12
49
+ : 56
42
50
 
43
- const navHeight = searchHeight + linksHeight
51
+ const navHeight = searchHeight + linksHeight
44
52
 
45
- return (
46
- <Nav
47
- data-testid={testid && `${testid}.HeaderNav`}
48
- ref={el}
49
- className={classNames({ HeaderNav: className }, { Open: isOpen })}
50
- $headerHeight={headerHeight}
51
- $variant={variant}
52
- $burgerPosition={burgerPosition}
53
- $navMobileVariant={navMobileVariant}
54
- $navHeight={navHeight}
55
- >
56
- {isMobile && search && (
57
- <HeaderSearch
58
- {...search}
59
- data-testid={testid}
60
- className={className}
61
- handleClose={handleClose}
62
- />
63
- )}
53
+ return (
54
+ <Nav
55
+ data-testid={testid && `${testid}.HeaderNav`}
56
+ ref={el}
57
+ className={classNames({ HeaderNav: className }, { Open: isOpen })}
58
+ role={role}
59
+ $headerHeight={headerHeight}
60
+ $variant={variant}
61
+ $burgerPosition={burgerPosition}
62
+ $navMobileVariant={navMobileVariant}
63
+ $navHeight={navHeight}
64
+ >
65
+ {isMobile && search && (
66
+ <HeaderSearch
67
+ {...search}
68
+ data-testid={testid}
69
+ className={className}
70
+ handleClose={handleClose}
71
+ />
72
+ )}
64
73
 
65
- {links &&
66
- links.map(link => (
67
- <HeaderNavLink
68
- data-testid={testid}
69
- className={className}
70
- link={link as LibHeaderLink | JSX.Element}
71
- key={uuid()}
72
- />
73
- ))}
74
+ {links &&
75
+ links.map(link => (
76
+ <HeaderNavLink
77
+ data-testid={testid}
78
+ className={className}
79
+ link={link as LibHeaderLink | ReactElement}
80
+ key={uuid()}
81
+ />
82
+ ))}
74
83
 
75
- {children && children}
84
+ {children && children}
76
85
 
77
- {nav && nav}
78
- </Nav>
79
- )
86
+ {nav && nav}
87
+ </Nav>
88
+ )
80
89
  }
@@ -1,78 +1,79 @@
1
- import type { FC, Ref } from "react"
1
+ import type { FC, ReactElement, Ref } from "react"
2
2
  import type { LibHeaderLink, LibLink } from "../../types"
3
3
  import type { ILibHeader } from "./types"
4
4
 
5
5
  // ! DO NOT EXPORT THOSE TYPES, ONLY USE THEM IN THOSE COMPONENTS
6
6
 
7
7
  export interface ILibHeaderNav
8
- extends Pick<
9
- ILibHeader,
10
- | "data-testid"
11
- | "className"
12
- | "search"
13
- | "children"
14
- | "links"
15
- | "variant"
16
- | "navMobileVariant"
17
- | "burgerPosition"
18
- | "nav"
19
- > {
20
- burgerRef: Ref<HTMLButtonElement>
21
- isOpen: boolean
22
- headerHeight: number
23
- handleClose: () => void
8
+ extends Pick<
9
+ ILibHeader,
10
+ | "data-testid"
11
+ | "className"
12
+ | "search"
13
+ | "children"
14
+ | "links"
15
+ | "variant"
16
+ | "navMobileVariant"
17
+ | "burgerPosition"
18
+ | "nav"
19
+ | "role"
20
+ > {
21
+ burgerRef: Ref<HTMLButtonElement>
22
+ isOpen: boolean
23
+ headerHeight: number
24
+ handleClose: () => void
24
25
  }
25
26
 
26
27
  export interface ILibHeaderBurger
27
- extends Pick<
28
- ILibHeader,
29
- | "data-testid"
30
- | "className"
31
- | "navMobileVariant"
32
- | "variant"
33
- | "burgerColor"
34
- > {
35
- isOpen: boolean
36
- handleOpen: () => void
37
- handleClose: () => void
38
- ref?: Ref<HTMLButtonElement>
28
+ extends Pick<
29
+ ILibHeader,
30
+ | "data-testid"
31
+ | "className"
32
+ | "navMobileVariant"
33
+ | "variant"
34
+ | "burgerColor"
35
+ > {
36
+ isOpen: boolean
37
+ handleOpen: () => void
38
+ handleClose: () => void
39
+ ref?: Ref<HTMLButtonElement>
39
40
  }
40
41
 
41
42
  export interface ILibHeaderLogo
42
- extends Pick<
43
- ILibHeader,
44
- "data-testid" | "className" | "logo" | "children"
45
- > {
46
- isOpen: boolean
43
+ extends Pick<
44
+ ILibHeader,
45
+ "data-testid" | "className" | "logo" | "children"
46
+ > {
47
+ isOpen: boolean
47
48
  }
48
49
 
49
50
  export interface ILibHeaderNavLink {
50
- "data-testid": string | undefined
51
- className: string | undefined
52
- link: LibHeaderLink | JSX.Element | FC
51
+ "data-testid": string | undefined
52
+ className: string | undefined
53
+ link: LibHeaderLink | ReactElement | FC
53
54
  }
54
55
 
55
56
  export interface ILibHeaderSearch
56
- extends Pick<ILibHeader, "data-testid" | "className" | "search"> {
57
- handleClose: () => void
57
+ extends Pick<ILibHeader, "data-testid" | "className" | "search"> {
58
+ handleClose: () => void
58
59
  }
59
60
 
60
61
  type HeaderLogoWithText = LibLink & {
61
- text: string
62
- img?: never
63
- imgOpen?: never
64
- alt?: never
65
- width?: never
66
- height?: never
62
+ text: string
63
+ img?: never
64
+ imgOpen?: never
65
+ alt?: never
66
+ width?: never
67
+ height?: never
67
68
  }
68
69
 
69
70
  type HeaderLogoWithImg = LibLink & {
70
- text?: never
71
- img: string
72
- imgOpen?: string
73
- alt?: string
74
- width?: number
75
- height?: number
71
+ text?: never
72
+ img: string
73
+ imgOpen?: string
74
+ alt?: string
75
+ width?: number
76
+ height?: number
76
77
  }
77
78
 
78
79
  export type LibHeaderLogo = string | HeaderLogoWithText | HeaderLogoWithImg
@@ -25,24 +25,24 @@ import type { ILibMain } from "./types"
25
25
  * </Main>
26
26
  */
27
27
  export const Main: FC<ILibMain> = ({
28
- "data-testid": testid,
29
- as,
30
- ref,
31
- children,
32
- size,
33
- contentSize,
34
- ...rest
28
+ "data-testid": testid,
29
+ as,
30
+ ref,
31
+ children,
32
+ size = "default",
33
+ contentSize = "default",
34
+ ...rest
35
35
  }) => {
36
- return (
37
- <StyledMain
38
- data-testid={testid}
39
- ref={ref}
40
- as={as}
41
- $size={size}
42
- $contentSize={contentSize}
43
- {...rest}
44
- >
45
- {children}
46
- </StyledMain>
47
- )
36
+ return (
37
+ <StyledMain
38
+ data-testid={testid}
39
+ ref={ref}
40
+ as={as}
41
+ $size={size}
42
+ $contentSize={contentSize}
43
+ {...rest}
44
+ >
45
+ {children}
46
+ </StyledMain>
47
+ )
48
48
  }
@@ -36,65 +36,65 @@ import type { ILibTextIcon } from "./types"
36
36
  * <TextIcon icon="star" tag="h2" color="primary">Featured</TextIcon>
37
37
  */
38
38
  export const TextIcon: FC<ILibTextIcon> = ({
39
- "data-testid": testid,
40
- as,
41
- ref,
42
- textAs,
43
- className,
44
- children,
45
- icon,
46
- iconColor,
47
- iconSize,
48
- iconBaseUrl,
49
- tag = "p",
50
- display,
51
- gap,
52
- containerStyle,
53
- ...rest
39
+ "data-testid": testid,
40
+ as,
41
+ ref,
42
+ textAs,
43
+ className,
44
+ children,
45
+ icon,
46
+ iconColor,
47
+ iconSize,
48
+ iconBaseUrl,
49
+ tag = "p",
50
+ display,
51
+ gap = "xs",
52
+ containerStyle,
53
+ ...rest
54
54
  }) => {
55
- const textProps: Partial<Omit<ILibTextIcon, "tag" | "display">> = {
56
- "data-testid": testid && `${testid}.Text`,
57
- as: textAs,
58
- className: "Text",
59
- children,
60
- ...rest,
61
- }
55
+ const textProps: Partial<Omit<ILibTextIcon, "tag" | "display">> = {
56
+ "data-testid": testid && `${testid}.Text`,
57
+ as: textAs,
58
+ className: "Text",
59
+ children,
60
+ ...rest,
61
+ }
62
62
 
63
- return (
64
- <StyledTextIcon
65
- data-testid={testid}
66
- ref={ref}
67
- as={as}
68
- className={className}
69
- style={containerStyle}
70
- $gap={gap}
71
- >
72
- <IconContainer
73
- data-testid={testid && `${testid}.IconContainer`}
74
- className={className && "IconContainer"}
75
- $tag={tag}
76
- $display={display}
77
- $iconSize={iconSize}
78
- >
79
- <LibIcon
80
- data-testid={testid && `${testid}.IconContainer.Icon`}
81
- className={className && "Icon"}
82
- icon={icon}
83
- size={iconSize || getIconHeight(tag, display)}
84
- color={iconColor}
85
- baseUrl={iconBaseUrl}
86
- />
87
- </IconContainer>
63
+ return (
64
+ <StyledTextIcon
65
+ data-testid={testid}
66
+ ref={ref}
67
+ as={as}
68
+ className={className}
69
+ style={containerStyle}
70
+ $gap={gap}
71
+ >
72
+ <IconContainer
73
+ data-testid={testid && `${testid}.IconContainer`}
74
+ className={className && "IconContainer"}
75
+ $tag={tag}
76
+ $display={display}
77
+ $iconSize={iconSize}
78
+ >
79
+ <LibIcon
80
+ data-testid={testid && `${testid}.IconContainer.Icon`}
81
+ className={className && "Icon"}
82
+ icon={icon}
83
+ size={iconSize || getIconHeight(tag, display)}
84
+ color={iconColor}
85
+ baseUrl={iconBaseUrl}
86
+ />
87
+ </IconContainer>
88
88
 
89
- {tag === "h1" ||
90
- tag === "h2" ||
91
- tag === "h3" ||
92
- tag === "h4" ||
93
- tag === "h5" ? (
94
- <Text display={display} tag={tag} {...textProps} />
95
- ) : (
96
- <Text tag={tag} {...textProps} />
97
- )}
98
- </StyledTextIcon>
99
- )
89
+ {tag === "h1" ||
90
+ tag === "h2" ||
91
+ tag === "h3" ||
92
+ tag === "h4" ||
93
+ tag === "h5" ? (
94
+ <Text display={display} tag={tag} {...textProps} />
95
+ ) : (
96
+ <Text tag={tag} {...textProps} />
97
+ )}
98
+ </StyledTextIcon>
99
+ )
100
100
  }
@@ -1,20 +1,21 @@
1
1
  import type { CSSProperties } from "react"
2
2
  import type {
3
- LibComponentBase,
4
- LibAllColorsAndOverlays,
5
- LibAllColors,
6
- LibTooltipPosition,
7
- LibSpacers,
8
- LibTooltipTrigger,
3
+ LibComponentBase,
4
+ LibAllColorsAndOverlays,
5
+ LibAllColors,
6
+ LibTooltipPosition,
7
+ LibSpacers,
8
+ LibTooltipTrigger,
9
+ ReactChildren,
9
10
  } from "../../types"
10
11
 
11
12
  export interface ILibTooltip extends LibComponentBase<HTMLDivElement> {
12
- tooltip: string | JSX.Element
13
- position?: LibTooltipPosition
14
- hideArrow?: boolean
15
- trigger?: LibTooltipTrigger
16
- backgroundColor?: LibAllColorsAndOverlays
17
- textColor?: LibAllColors
18
- offset?: LibSpacers
19
- tooltipStyles?: CSSProperties
13
+ tooltip: string | ReactChildren
14
+ position?: LibTooltipPosition
15
+ hideArrow?: boolean
16
+ trigger?: LibTooltipTrigger
17
+ backgroundColor?: LibAllColorsAndOverlays
18
+ textColor?: LibAllColors
19
+ offset?: LibSpacers
20
+ tooltipStyles?: CSSProperties
20
21
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@julseb-lib/react",
3
- "version": "0.0.87",
3
+ "version": "0.0.88",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "scripts": {