Skip to content

Commit

Permalink
Typescript for Table of Contents (#714)
Browse files Browse the repository at this point in the history
* Convert to typescript

* Change suffix
  • Loading branch information
wenche authored and vnys committed Nov 13, 2020
1 parent 7712fd8 commit 6136281
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// @ts-nocheck
import React, { forwardRef } from 'react'
import React, { forwardRef, HTMLAttributes } from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { tableOfContents as tokens } from './TableOfContents.tokens'
Expand All @@ -14,9 +13,9 @@ const StyledLinkItem = styled.li`
a {
text-decoration: none;
font-size: ${links.fontSize};
line-height: ${links.lineHeight};
line-height: ${links.fontLineHeight};
padding: 10px 18px;
height: ${links.lineHeight};
height: ${links.fontLineHeight};
width: calc(189px - 36px);
display: block;
position: relative;
Expand Down Expand Up @@ -57,7 +56,12 @@ const StyledLinkItem = styled.li`
}
}
`
const LinkItem = forwardRef(function EdsLinkItem({ children, ...props }, ref) {
type Props = HTMLAttributes<HTMLLIElement>

const LinkItem = forwardRef<HTMLLIElement, Props>(function EdsLinkItem(
{ children, ...props },
ref,
) {
return (
<StyledLinkItem {...props} ref={ref}>
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// @ts-nocheck
import { tokens } from '@equinor/eds-tokens'

const {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
// @ts-nocheck
import React, { forwardRef } from 'react'
import PropTypes from 'prop-types'
import React, { forwardRef, HTMLAttributes } from 'react'
import styled, { css } from 'styled-components'
import { List, Typography } from '..'
import { List } from '../List'
import { Typography } from '../Typography'

import { tableOfContents as tokens } from './TableOfContents.tokens'

const { labelText } = tokens

const StyledTableOfContents = styled.nav`
type Props = {
/** Sticky functionality */
sticky?: boolean
/** Label or title for the ToC */
label?: string
} & HTMLAttributes<HTMLElement>

const StyledTableOfContents = styled.nav<Props>`
margin: 48px 0 32px 0;
${({ sticky }) =>
Expand All @@ -19,17 +26,17 @@ const StyledTableOfContents = styled.nav`
`}
`

const TocList = styled((props) => <List {...props} />)`
const TocList = styled(List)`
margin: 0;
padding: 0;
`

const TocLabel = styled((props) => <Typography {...props} />)`
const TocLabel = styled(Typography)`
color: ${labelText.color};
`

const TableOfContents = forwardRef(function TableOfContents(
{ children, sticky, label, className, ...rest },
const TableOfContents = forwardRef<HTMLElement, Props>(function TableOfContents(
{ children, sticky = false, label = '', className, ...rest },
ref,
) {
return (
Expand All @@ -48,21 +55,4 @@ const TableOfContents = forwardRef(function TableOfContents(

TableOfContents.displayName = 'eds-toc'

TableOfContents.propTypes = {
/** @ignore */
children: PropTypes.node.isRequired,
/** @ignore */
className: PropTypes.string,
/** Sticky function */
sticky: PropTypes.bool,
/** Label or title for the ToC */
label: PropTypes.string,
}

TableOfContents.defaultProps = {
className: '',
sticky: false,
label: '',
}

export { TableOfContents }
7 changes: 0 additions & 7 deletions libraries/core-react/src/TableOfContents/index.js

This file was deleted.

12 changes: 12 additions & 0 deletions libraries/core-react/src/TableOfContents/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { TableOfContents as BaseComponent } from './TableOfContents'
import { LinkItem } from './LinkItem'

type TableOfContentsTypes = typeof BaseComponent & {
LinkItem: typeof LinkItem
}

const TableOfContents = BaseComponent as TableOfContentsTypes

TableOfContents.LinkItem = LinkItem

export { TableOfContents }

0 comments on commit 6136281

Please sign in to comment.