Skip to content

Commit

Permalink
Typescript for list stories (#753)
Browse files Browse the repository at this point in the history
* 🚚 Rename to .tsx

* πŸ“ Update story with args table, ts and 6.0 storybook api

* πŸ› Remove displayName
  • Loading branch information
wenche authored and vnys committed Nov 13, 2020
1 parent 94ebe1b commit 3f20021
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 72 deletions.
66 changes: 0 additions & 66 deletions apps/storybook-react/stories/Lists.stories.jsx

This file was deleted.

77 changes: 77 additions & 0 deletions apps/storybook-react/stories/Lists.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'react'
import { List, ListProps } from '@equinor/eds-core-react'
import { Meta, Story } from '@storybook/react'

const { ListItem } = List

const start = '15'

export default {
title: 'Components/Lists',
component: List,
} as Meta

export const Default: Story<ListProps> = (args) => (
<List {...args}>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>
List item
<List {...args}>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
</List>
</ListItem>
</List>
)

export const Unordered: Story<ListProps> = () => (
<List variant="bullet">
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>
List item
<List>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
</List>
</ListItem>
</List>
)

export const Ordered: Story<ListProps> = () => (
<List variant="numbered">
<ListItem>List item</ListItem>
<ListItem>
List item
<List variant="numbered">
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>
List item
<List variant="numbered">
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
</List>
</ListItem>
</List>
</ListItem>
<ListItem>List item</ListItem>
</List>
)

export const OrderedStartingOn15: Story<ListProps> = () => (
<List variant="numbered" start={start}>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
<ListItem>List item</ListItem>
</List>
)
4 changes: 2 additions & 2 deletions libraries/core-react/src/List/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ const StyledList = styled.div<StyledListProps>(
`,
)

type Props = {
export type ListProps = {
/** 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>(
const List = forwardRef<HTMLUListElement | HTMLOListElement, ListProps>(
function List({ children, variant = 'bullet', ...props }, ref) {
const as: ElementType = variant === 'numbered' ? 'ol' : 'ul'

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

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

const List = BaseComponent as ListTypes
const List = BaseComponent as ListProps

List.ListItem = ListItem

export { List }
export { List, ListProps }
2 changes: 1 addition & 1 deletion libraries/core-react/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export { Table } from './Table'
export * from './Divider'
export { TextField } from './TextField'
export { Icon } from './Icon'
export { List } from './List'
export * from './List'
export { Accordion } from './Accordion'
export { Tabs } from './Tabs'
export * from './TopBar'
Expand Down

0 comments on commit 3f20021

Please sign in to comment.