Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Types for List #658

Merged
merged 3 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions libraries/core-react/src/List/List.jsx

This file was deleted.

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 }