Skip to content

Commit

Permalink
Migrate TabNav component to TSX
Browse files Browse the repository at this point in the history
  • Loading branch information
VanAnderson committed Feb 8, 2021
1 parent 7a73fe5 commit 8a22e6e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/TabNav.js → src/TabNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,34 @@ import React from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import styled from 'styled-components'
import {COMMON, get} from './constants'
import {COMMON, SystemCommonProps, SystemTypographyProps, get} from './constants'
import {ComponentProps} from './utils/types'
import theme from './theme'
import sx from './sx'
import sx, {SxProp} from './sx'
import * as History from 'history'

const ITEM_CLASS = 'TabNav-item'
const SELECTED_CLASS = 'selected'

function TabNavBase({actions, className, align, children, full, theme, ...rest}) {
const TabNavParent = styled.nav`
${COMMON}
${sx}
`

type TabNavBaseProps = {
actions?: Array<any>
full?: boolean
align?: string
} & ComponentProps<typeof TabNavParent> &
SystemCommonProps &
SxProp

function TabNavBase({actions, className, align, children, full, theme, ...rest}: TabNavBaseProps) {
const classes = classnames(className, 'TabNav')
return (
<nav className={classes} {...rest}>
<TabNavParent className={classes} {...rest}>
<div className="TabNav-body">{children}</div>
</nav>
</TabNavParent>
)
}

Expand All @@ -30,11 +45,14 @@ const TabNav = styled(TabNavBase)`
${COMMON};
${sx};
`
type StyledTabNavLinkProps = {to?: History.LocationDescriptor; selected?: boolean} & SystemCommonProps &
SxProp &
SystemTypographyProps

TabNav.Link = styled.a.attrs(props => ({
const TabNavLink = styled.a.attrs<StyledTabNavLinkProps>(props => ({
activeClassName: typeof props.to === 'string' ? 'selected' : '',
className: classnames(ITEM_CLASS, props.selected && SELECTED_CLASS, props.className)
}))`
}))<StyledTabNavLinkProps>`
padding: 8px 12px;
font-size: ${get('fontSizes.1')};
line-height: 20px;
Expand Down Expand Up @@ -73,18 +91,19 @@ TabNav.propTypes = {
...sx.propTypes
}

TabNav.Link.defaultProps = {
TabNavLink.defaultProps = {
theme
}

TabNav.Link.propTypes = {
as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
TabNavLink.propTypes = {
href: PropTypes.string,
selected: PropTypes.bool,
...COMMON.propTypes,
...sx.propTypes
}

TabNav.Link.displayName = 'TabNav.Link'
TabNavLink.displayName = 'TabNav.Link'

export default TabNav
export type TabNavProps = ComponentProps<typeof TabNav>
export type TabNavLinkProps = ComponentProps<typeof TabNavLink>
export default Object.assign(TabNav, {Link: TabNavLink})
File renamed without changes.
File renamed without changes.

0 comments on commit 8a22e6e

Please # to comment.