-
Notifications
You must be signed in to change notification settings - Fork 832
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a737a38
commit 1b246ac
Showing
4 changed files
with
209 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,70 @@ | ||
import React, { PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Icon } from '../../icon' | ||
import Text from './Text' | ||
|
||
export default class ListItem extends PureComponent { | ||
static propTypes = { | ||
...Text.propTypes | ||
...Text.propTypes, | ||
|
||
/** | ||
* When passed, adds a icon before the list item. | ||
* See Evergreen `Icon` for documentation. | ||
*/ | ||
icon: PropTypes.string, | ||
|
||
/** | ||
* The color of the icon. | ||
*/ | ||
iconColor: PropTypes.string | ||
} | ||
|
||
render() { | ||
return <Text is="li" marginY="0.5em" {...this.props} /> | ||
const { children, size, icon, iconColor, ...props } = this.props | ||
|
||
let paddingLeft | ||
if (size === 300) paddingLeft = 4 | ||
if (size === 400) paddingLeft = 8 | ||
if (size === 500) paddingLeft = 8 | ||
if (size === 600) paddingLeft = 12 | ||
|
||
let iconTop | ||
if (size === 300) iconTop = 1 | ||
if (size === 400) iconTop = 3 | ||
if (size === 500) iconTop = 3 | ||
if (size === 600) iconTop = 4 | ||
|
||
let iconSize | ||
if (size === 300) iconSize = 12 | ||
if (size === 400) iconSize = 14 | ||
if (size === 500) iconSize = 14 | ||
if (size === 600) iconSize = 16 | ||
|
||
let iconLeft = -iconSize - 4 | ||
if (size === 600) iconLeft = -iconSize | ||
|
||
return ( | ||
<Text | ||
is="li" | ||
position="relative" | ||
marginY="0.5em" | ||
size={size} | ||
listStyleType={icon ? 'none' : null} | ||
paddingLeft={icon ? paddingLeft : null} | ||
{...props} | ||
> | ||
{icon && ( | ||
<Icon | ||
icon={icon} | ||
color={iconColor} | ||
position="absolute" | ||
size={iconSize} | ||
left={iconLeft} | ||
top={iconTop} | ||
/> | ||
)} | ||
{children} | ||
</Text> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters