Skip to content

Commit

Permalink
✨ Types for List (#658)
Browse files Browse the repository at this point in the history
* ✨ Types for List #575

* Add body_short as typography token

* Some cleanup
  • Loading branch information
wenche authored and vnys committed Nov 13, 2020
1 parent 19bbed9 commit c931962
Show file tree
Hide file tree
Showing 8 changed files with 85 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.
9 changes: 9 additions & 0 deletions libraries/core-react/src/List/List.tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { tokens } from '@equinor/eds-tokens'

const {
typography: { paragraph },
} = tokens

export const list = {
typography: paragraph.body_short,
}
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'
import { typographyTemplate } from '../_common/templates'

const { typography } = tokens

type StyledListProps = {
as: ElementType
}

const StyledList = styled.div<StyledListProps>(
({ as }) =>
as === 'ol' &&
css`
& ol {
list-style-type: lower-alpha;
}
`,
`
${typographyTemplate(typography)}
`,
)

type Props = {
/** Is the list an ordered or unordered list */
variant?: 'bullet' | 'numbered'
/** Start number if other than 1 for ordered lists */
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 = 'List'

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

This file was deleted.

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

export type ListItemProps = React.HTMLAttributes<HTMLLIElement>

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

ListItem.displayName = '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 c931962

Please sign in to comment.