Skip to content

Commit

Permalink
✨ Types for List equinor#575
Browse files Browse the repository at this point in the history
  • Loading branch information
wenche committed Oct 8, 2020
1 parent 6493d35 commit fb0951f
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 110 deletions.
77 changes: 0 additions & 77 deletions libraries/core-react/src/List/List.jsx

This file was deleted.

File renamed without changes.
11 changes: 11 additions & 0 deletions libraries/core-react/src/List/List.tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { tokens } from '@equinor/eds-tokens'

const { colors } = tokens

export const list = {
color: colors.text.static_icons__default.hex,
typography: {
lineHeight: '1.5em',
fontSize: '1rem',
},
}
46 changes: 46 additions & 0 deletions libraries/core-react/src/List/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { forwardRef, HTMLAttributes, ElementType } from 'react'
import styled, { css } from 'styled-components'
import { list as tokens } from './List.tokens'

const { color, typography } = tokens

type StyledListProps = {
as: ElementType
}

const StyledList = styled.div<StyledListProps>(
({ as }) =>
as === 'ol' &&
css`
& ol {
list-style-type: lower-alpha;
}
`,
`
line-height: ${typography.lineHeight};
font-size: ${typography.fontSize};
color: ${color};
`,
)

type Props = {
/** Is the list an ordered or unordered list */
variant?: 'bullet' | 'numbered'
start?: string
} & HTMLAttributes<HTMLUListElement | HTMLOListElement>

const List = forwardRef<HTMLUListElement | HTMLOListElement, Props>(
function List({ children, variant = 'bullet', ...props }, ref) {
const as: ElementType = variant === 'numbered' ? 'ol' : 'ul'

return (
<StyledList as={as} ref={ref} {...props}>
{children}
</StyledList>
)
},
)

List.displayName = 'eds-list'

export { List }
26 changes: 0 additions & 26 deletions libraries/core-react/src/List/ListItem.jsx

This file was deleted.

19 changes: 19 additions & 0 deletions libraries/core-react/src/List/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { forwardRef } from 'react'
import PropTypes from 'prop-types'

type Props = React.HTMLAttributes<HTMLElement>

const ListItem = forwardRef<HTMLLIElement, Props>(function ListItem(
{ children, ...props },
ref,
) {
return (
<li {...props} ref={ref}>
{children}
</li>
)
})

ListItem.displayName = 'eds-listitem'

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

This file was deleted.

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

type ListTypes = typeof BaseComponent & {
ListItem: typeof ListItem
}

const List = BaseComponent as ListTypes

List.ListItem = ListItem

export { List }

0 comments on commit fb0951f

Please sign in to comment.