@julseb-lib/react 0.0.87 → 0.0.89

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
@@ -40,81 +40,85 @@ import type { ILibImage } from "./types"
40
40
  * />
41
41
  */
42
42
  export const Image: FC<ILibImage> = ({
43
- "data-testid": testid,
44
- ref,
45
- className,
46
- src,
47
- alt,
48
- caption,
49
- width = "100%",
50
- height = "auto",
51
- aspectRatio,
52
- borderRadius,
53
- fit,
54
- fallback = (
55
- <Fallback
56
- $aspectRatio={aspectRatio}
57
- $width={width}
58
- $height={height}
59
- $borderRadius={borderRadius}
60
- />
61
- ),
62
- containerStyle,
63
- containerAs,
64
- ...rest
43
+ "data-testid": testid,
44
+ ref,
45
+ role = "img",
46
+ className,
47
+ src,
48
+ alt,
49
+ caption,
50
+ width = "100%",
51
+ height = "auto",
52
+ aspectRatio,
53
+ borderRadius,
54
+ fit,
55
+ fallback = (
56
+ <Fallback
57
+ $aspectRatio={aspectRatio}
58
+ $width={width}
59
+ $height={height}
60
+ $borderRadius={borderRadius}
61
+ />
62
+ ),
63
+ containerStyle,
64
+ containerAs,
65
+ ...rest
65
66
  }) => {
66
- const imageProps = {
67
- "data-testid": testid,
68
- ref,
69
- fallback,
70
- caption,
71
- className,
72
- src,
73
- alt,
74
- aspectRatio,
75
- width,
76
- height,
77
- borderRadius,
78
- fit,
79
- ...rest,
80
- }
67
+ const imageProps = {
68
+ "data-testid": testid,
69
+ ref,
70
+ role,
71
+ fallback,
72
+ caption,
73
+ className,
74
+ src,
75
+ alt,
76
+ aspectRatio,
77
+ width,
78
+ height,
79
+ borderRadius,
80
+ fit,
81
+ ...rest,
82
+ }
81
83
 
82
- if (caption)
83
- return (
84
- <ImgContainer
85
- data-testid={testid}
86
- className={className}
87
- style={containerStyle}
88
- as={containerAs}
89
- $width={width}
90
- $height={height}
91
- $borderRadius={borderRadius}
92
- >
93
- <ImageFunction {...imageProps} />
84
+ if (caption)
85
+ return (
86
+ <ImgContainer
87
+ data-testid={testid}
88
+ className={className}
89
+ style={containerStyle}
90
+ as={containerAs}
91
+ role="figure"
92
+ $width={width}
93
+ $height={height}
94
+ $borderRadius={borderRadius}
95
+ >
96
+ <ImageFunction {...imageProps} />
94
97
 
95
- <Caption
96
- data-testid={testid && `${testid}.Caption`}
97
- className={className && "Caption"}
98
- as={
99
- typeof caption === "object" && caption.as
100
- ? caption.as
101
- : "figcaption"
102
- }
103
- $backgroundColor={
104
- typeof caption === "object" && caption.background
105
- ? caption?.background
106
- : "black-50"
107
- }
108
- $textColor={
109
- typeof caption === "object" && caption.textColor
110
- ? caption.textColor
111
- : "white"
112
- }
113
- >
114
- {typeof caption === "object" ? caption.text : caption}
115
- </Caption>
116
- </ImgContainer>
117
- )
98
+ <Caption
99
+ data-testid={testid && `${testid}.Caption`}
100
+ className={className && "Caption"}
101
+ role="contentinfo"
102
+ as={
103
+ typeof caption === "object" && caption.as
104
+ ? caption.as
105
+ : "figcaption"
106
+ }
107
+ $backgroundColor={
108
+ typeof caption === "object" && caption.background
109
+ ? caption?.background
110
+ : "black-50"
111
+ }
112
+ $textColor={
113
+ typeof caption === "object" && caption.textColor
114
+ ? caption.textColor
115
+ : "white"
116
+ }
117
+ >
118
+ {typeof caption === "object" ? caption.text : caption}
119
+ </Caption>
120
+ </ImgContainer>
121
+ )
118
122
 
119
- return <ImageFunction {...imageProps} />
123
+ return <ImageFunction {...imageProps} />
120
124
  }
@@ -4,42 +4,44 @@ import type { ILibImage } from "./types"
4
4
  const StyledImage = lazy(() => import("./styles"))
5
5
 
6
6
  export const ImageFunction: FC<ILibImage> = ({
7
- "data-testid": testid,
8
- ref,
9
- fallback,
10
- caption,
11
- className,
12
- src,
13
- alt,
14
- aspectRatio,
15
- width = "100%",
16
- height = "auto",
17
- borderRadius,
18
- fit,
19
- loading = "lazy",
20
- imgFallback,
21
- ...rest
7
+ "data-testid": testid,
8
+ ref,
9
+ role = "img",
10
+ fallback,
11
+ caption,
12
+ className,
13
+ src,
14
+ alt,
15
+ aspectRatio,
16
+ width = "100%",
17
+ height = "auto",
18
+ borderRadius,
19
+ fit,
20
+ loading = "lazy",
21
+ imgFallback,
22
+ ...rest
22
23
  }) => {
23
- return (
24
- <Suspense fallback={fallback}>
25
- <StyledImage
26
- data-testid={!caption ? testid : testid && `${testid}.Image`}
27
- className={!caption ? className : className && "Image"}
28
- ref={ref}
29
- src={src}
30
- alt={alt}
31
- loading={loading}
32
- data-fallback={imgFallback?.text}
33
- $aspectRatio={aspectRatio}
34
- $width={width}
35
- $height={height}
36
- $borderRadius={borderRadius}
37
- $fit={fit}
38
- $fallbackBackground={imgFallback?.background ?? "primary"}
39
- $fallbackTextColor={imgFallback?.textColor ?? "background"}
40
- $fallbackFontSize={imgFallback?.fontSize ?? "body"}
41
- {...rest}
42
- />
43
- </Suspense>
44
- )
24
+ return (
25
+ <Suspense fallback={fallback}>
26
+ <StyledImage
27
+ data-testid={!caption ? testid : testid && `${testid}.Image`}
28
+ className={!caption ? className : className && "Image"}
29
+ role={role}
30
+ ref={ref}
31
+ src={src}
32
+ alt={alt}
33
+ loading={loading}
34
+ data-fallback={imgFallback?.text}
35
+ $aspectRatio={aspectRatio}
36
+ $width={width}
37
+ $height={height}
38
+ $borderRadius={borderRadius}
39
+ $fit={fit}
40
+ $fallbackBackground={imgFallback?.background ?? "primary"}
41
+ $fallbackTextColor={imgFallback?.textColor ?? "background"}
42
+ $fallbackFontSize={imgFallback?.fontSize ?? "body"}
43
+ {...rest}
44
+ />
45
+ </Suspense>
46
+ )
45
47
  }
@@ -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
  }