Skip to content

Commit

Permalink
[Component] Well + List (#84)
Browse files Browse the repository at this point in the history
* feat: List component

* feat: Well component

* fix: Cleanup unused Well.less
  • Loading branch information
meissadia committed Jun 21, 2023
1 parent c62c913 commit 1341996
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/components/List/List.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import type { Meta, StoryObj } from '@storybook/react';
import List from './List';
import ListItem from './ListItem';

const meta: Meta<typeof List> = {
component: List,
argTypes: {}
};

export default meta;

type Story = StoryObj<typeof meta>;

export const Unordered: Story = {
args: {
children: (
<>
<ListItem>First</ListItem>
<ListItem>Second</ListItem>
<ListItem>Third</ListItem>
</>
)
}
};

export const Ordered: Story = {
args: {
...Unordered.args,
isOrdered: true
}
};

export const Unstyled: Story = {
args: {
...Unordered.args,
isUnstyled: true
}
};

export const Horizontal: Story = {
args: {
...Unordered.args,
isHorizontal: true
}
};

export const Spaced: Story = {
args: {
...Unordered.args,
isSpaced: true
}
};

export const Links: Story = {
args: {
isLinks: true,
children: (
<>
<ListItem>
<a href='#'>First Link</a>
</ListItem>
<ListItem>
<a href='#'>Second Link</a>
</ListItem>
<ListItem>
<a href='#'>Third Link</a>
</ListItem>
</>
)
}
};
28 changes: 28 additions & 0 deletions src/components/List/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import classnames from 'classnames';

interface ListProperties {
isHorizontal?: boolean;
isLinks?: boolean;
isOrdered?: boolean;
isUnstyled?: boolean;
isSpaced?: boolean;
children: JSX.Element | JSX.Element[];
}

export default function List({
children,
isHorizontal,
isLinks = false,
isOrdered,
isSpaced,
isUnstyled
}: ListProperties): JSX.Element {
const cnames = ['m-list'];
if (isHorizontal) cnames.push('m-list__horizontal');
if (isLinks) cnames.push('m-list__links');
if (isSpaced) cnames.push('m-list__spaced');
if (isUnstyled) cnames.push('m-list__unstyled');

if (isOrdered) return <ol className={classnames(cnames)}>{children}</ol>;
return <ul className={classnames(cnames)}>{children}</ul>;
}
9 changes: 9 additions & 0 deletions src/components/List/ListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
interface ListItemProperties {
children: JSX.Element | string;
}

export default function ListItem({
children
}: ListItemProperties): JSX.Element {
return <li className='m-list_item'>{children}</li>;
}
44 changes: 44 additions & 0 deletions src/components/Well/Well.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Meta, StoryObj } from '@storybook/react';
import Well from './Well';

const meta: Meta<typeof Well> = {
component: Well,
argTypes: {}
};

export default meta;

type Story = StoryObj<typeof meta>;

export const Standard: Story = {
args: {
heading: 'Well title',
text: (
<>
Lorem ipsum dolor sit amet consectetur adipisicing elit. At quae dolor
distinctio tenetur quibusdam rem debitis, voluptate nesciunt culpa
officiis quos perspiciatis nostrum illo libero autem beatae temporibus
ratione reprehenderit? <a href='#'>Example link</a>.
</>
)
}
};

export const CallToAction: Story = {
args: {
heading: 'Well title',
text: (
<>
Lorem ipsum dolor sit amet consectetur adipisicing elit. At quae dolor
distinctio tenetur quibusdam rem debitis, voluptate nesciunt culpa
officiis quos perspiciatis nostrum illo libero autem beatae temporibus
ratione reprehenderit?
</>
),
links: [
<a href='#' key='example1'>
Example link
</a>
]
}
};
31 changes: 31 additions & 0 deletions src/components/Well/Well.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { HeadingLevel } from '../../types/headingLevel';
import List from '../List/List';
import ListItem from '../List/ListItem';

interface WellProperties {
heading: string;
text: JSX.Element | string;
links?: JSX.Element[];
headingLevel: HeadingLevel;
}

export default function Well({
heading,
headingLevel = 'h4',
links,
text
}: WellProperties): JSX.Element {
const callsToAction = [];
if (links)
for (const link of links) {
callsToAction.push(<ListItem>{link}</ListItem>);
}

return (
<div className='o-well'>
<p className={headingLevel}>{heading}</p>
<p className='text'>{text}</p>
{callsToAction.length > 0 ? <List isLinks>{callsToAction}</List> : null}
</div>
);
}

0 comments on commit 1341996

Please sign in to comment.