|
1 | 1 | import {clsx} from 'clsx'
|
2 | 2 | import type {To} from 'history'
|
3 | 3 | import React from 'react'
|
4 |
| -import type {ComponentProps} from '../utils/types' |
5 | 4 |
|
6 | 5 | import styles from './SubNav.module.css'
|
7 |
| -import type {SxProp} from '../sx' |
8 |
| -import {BoxWithFallback} from '../internal/components/BoxWithFallback' |
9 | 6 |
|
10 |
| -type StyledSubNavProps = React.ComponentProps<'nav'> & { |
| 7 | +export type SubNavProps = React.ComponentProps<'nav'> & { |
11 | 8 | actions?: React.ReactNode
|
12 | 9 | align?: 'right'
|
13 | 10 | full?: boolean
|
14 | 11 | label?: string
|
15 |
| -} & SxProp |
16 |
| -type StyledSubNavLinksProps = React.ComponentProps<'div'> & SxProp |
17 |
| -type StyledSubNavLinkProps = React.ComponentProps<'a'> & {to?: To; selected?: boolean} & SxProp |
| 12 | +} |
| 13 | +export type SubNavLinksProps = React.ComponentProps<'div'> |
| 14 | +export type SubNavLinkProps = React.ComponentProps<'a'> & {to?: To; selected?: boolean} |
18 | 15 |
|
19 |
| -const SubNav = React.forwardRef<HTMLElement, StyledSubNavProps>(function SubNav( |
| 16 | +const SubNav = React.forwardRef<HTMLElement, SubNavProps>(function SubNav( |
20 | 17 | {actions, className, children, label, ...rest},
|
21 | 18 | forwardRef,
|
22 | 19 | ) {
|
23 | 20 | return (
|
24 |
| - <BoxWithFallback |
25 |
| - as="nav" |
26 |
| - ref={forwardRef} |
27 |
| - className={clsx(className, 'SubNav', styles.SubNav)} |
28 |
| - aria-label={label} |
29 |
| - {...rest} |
30 |
| - > |
| 21 | + <nav ref={forwardRef} className={clsx(className, 'SubNav', styles.SubNav)} aria-label={label} {...rest}> |
31 | 22 | <div className={clsx('SubNav-body', styles.Body)}>{children}</div>
|
32 | 23 | {actions && <div className={clsx('SubNav-actions', styles.Actions)}>{actions}</div>}
|
33 |
| - </BoxWithFallback> |
| 24 | + </nav> |
34 | 25 | )
|
35 | 26 | })
|
36 | 27 | SubNav.displayName = 'SubNav'
|
37 | 28 |
|
38 | 29 | // SubNav.Links
|
39 | 30 |
|
40 |
| -const SubNavLinks = React.forwardRef<HTMLDivElement, StyledSubNavLinksProps>( |
41 |
| - ({children, className, ...rest}, forwardRef) => { |
42 |
| - return ( |
43 |
| - <BoxWithFallback ref={forwardRef} className={clsx(className, styles.Links)} {...rest}> |
44 |
| - {children} |
45 |
| - </BoxWithFallback> |
46 |
| - ) |
47 |
| - }, |
48 |
| -) |
| 31 | +const SubNavLinks = React.forwardRef<HTMLDivElement, SubNavLinksProps>(({children, className, ...rest}, forwardRef) => { |
| 32 | + return ( |
| 33 | + <div ref={forwardRef} className={clsx(className, styles.Links)} {...rest}> |
| 34 | + {children} |
| 35 | + </div> |
| 36 | + ) |
| 37 | +}) |
49 | 38 | SubNavLinks.displayName = 'SubNav.Links'
|
50 | 39 |
|
51 | 40 | // SubNav.Link
|
52 | 41 |
|
53 |
| -const SubNavLink = React.forwardRef<HTMLAnchorElement, StyledSubNavLinkProps>( |
| 42 | +const SubNavLink = React.forwardRef<HTMLAnchorElement, SubNavLinkProps>( |
54 | 43 | ({children, className, ...rest}, forwardRef) => {
|
55 | 44 | return (
|
56 |
| - <BoxWithFallback |
57 |
| - as="a" |
| 45 | + <a |
58 | 46 | ref={forwardRef}
|
59 | 47 | className={clsx(className, styles.Link)}
|
60 | 48 | data-selected={rest.selected}
|
61 | 49 | aria-current={rest.selected}
|
62 | 50 | {...rest}
|
63 | 51 | >
|
64 | 52 | {children}
|
65 |
| - </BoxWithFallback> |
| 53 | + </a> |
66 | 54 | )
|
67 | 55 | },
|
68 | 56 | )
|
69 | 57 |
|
70 | 58 | SubNavLink.displayName = 'SubNav.Link'
|
71 | 59 |
|
72 |
| -export type SubNavProps = ComponentProps<typeof SubNav> |
73 |
| -export type SubNavLinksProps = ComponentProps<typeof SubNavLinks> |
74 |
| -export type SubNavLinkProps = ComponentProps<typeof SubNavLink> |
75 | 60 | export default Object.assign(SubNav, {Link: SubNavLink, Links: SubNavLinks})
|
0 commit comments