-
Notifications
You must be signed in to change notification settings - Fork 0
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
489f591
commit dbdf069
Showing
15 changed files
with
258 additions
and
96 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from 'react' | ||
import { Flex, Column } from './components/Structure' | ||
import { Text } from './components/Typography' | ||
import useTheme from './hooks/useTheme' | ||
import theme from './lib/theme' | ||
|
||
export default { | ||
title: 'Colors', | ||
} | ||
|
||
const Color = ({ color }) => { | ||
const bg = useTheme(`colors.${color}`) | ||
return ( | ||
<Flex width="100px" height="100px" bg={bg} borderRadius="3px" m="10px" alignItems="center" justifyContent="center"> | ||
<Text>{bg}</Text> | ||
</Flex> | ||
) | ||
} | ||
|
||
const colors = Object.keys(theme.colors) | ||
|
||
|
||
export const Default = () => ( | ||
<Column> | ||
{colors.map((color) => <Color color={color} key={color} />)} | ||
</Column> | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Base } from './styled' | ||
import { Flex } from '../Structure' | ||
import Overlay from '../Overlay' | ||
import Loading from '../Loading' | ||
import { Text } from '../Typography' | ||
import useTheme from '../../hooks/useTheme' | ||
|
||
const ButtonComponent = ({ | ||
children, | ||
LeftIcon, | ||
RightIcon, | ||
loading, | ||
disabled, | ||
large, | ||
small, | ||
error, | ||
info, | ||
warning, | ||
success, | ||
...props | ||
}) => { | ||
const variants = { | ||
error, | ||
info, | ||
success, | ||
warning, | ||
large, | ||
small, | ||
} | ||
const iconColor = useTheme('colors.icon_inverse', { ignoreTheme: true }) | ||
return ( | ||
<Base {...variants} {...props} disabled={loading || disabled}> | ||
{loading && ( | ||
<Overlay> | ||
<Loading white ignoreTheme /> | ||
</Overlay> | ||
)} | ||
{Boolean(LeftIcon) && ( | ||
<Flex mr={2}> | ||
<LeftIcon color={iconColor} /> | ||
</Flex> | ||
)} | ||
<Text white ignoreTheme> | ||
{children} | ||
</Text> | ||
{Boolean(RightIcon) && ( | ||
<Flex ml={2}> | ||
<RightIcon color={iconColor} /> | ||
</Flex> | ||
)} | ||
</Base> | ||
) | ||
} | ||
|
||
ButtonComponent.propTypes = { | ||
children: PropTypes.bool, | ||
LeftIcon: PropTypes.node, | ||
RightIcon: PropTypes.node, | ||
loading: PropTypes.bool, | ||
disabled: PropTypes.bool, | ||
large: PropTypes.bool, | ||
small: PropTypes.bool, | ||
error: PropTypes.bool, | ||
info: PropTypes.bool, | ||
warning: PropTypes.bool, | ||
success: PropTypes.bool, | ||
} | ||
|
||
export default ButtonComponent |
2 changes: 1 addition & 1 deletion
2
src/components/Button/stories.js → src/components/Button/Button.stories.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { Base } from './styled' | ||
import Overlay from '../Overlay' | ||
import Loading from '../Loading' | ||
import useTheme from '../../hooks/useTheme' | ||
|
||
const ButtonIconComponent = ({ | ||
Icon, | ||
loading, | ||
disabled, | ||
large, | ||
small, | ||
error, | ||
info, | ||
warning, | ||
success, | ||
...props | ||
}) => { | ||
const variants = { | ||
error, | ||
info, | ||
success, | ||
warning, | ||
large, | ||
small, | ||
} | ||
|
||
const iconColor = useTheme('colors.icon_inverse', { ignoreTheme: true }) | ||
|
||
return ( | ||
<Base {...variants} {...props} disabled={loading || disabled} circle> | ||
{loading && ( | ||
<Overlay> | ||
<Loading white ignoreTheme /> | ||
</Overlay> | ||
)} | ||
{Boolean(Icon) && ( | ||
<Icon color={iconColor} /> | ||
)} | ||
</Base> | ||
) | ||
} | ||
|
||
ButtonIconComponent.propTypes = { | ||
Icon: PropTypes.node, | ||
loading: PropTypes.bool, | ||
disabled: PropTypes.bool, | ||
large: PropTypes.bool, | ||
small: PropTypes.bool, | ||
error: PropTypes.bool, | ||
info: PropTypes.bool, | ||
warning: PropTypes.bool, | ||
success: PropTypes.bool, | ||
} | ||
|
||
export default ButtonIconComponent |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react' | ||
import { action } from '@storybook/addon-actions' | ||
import { FiUser } from 'react-icons/fi' | ||
import { ButtonIcon } from '.' | ||
|
||
export default { | ||
title: 'ButtonIcon', | ||
} | ||
|
||
const props = { | ||
onClick: action('onClick'), | ||
Icon: FiUser, | ||
} | ||
|
||
export const Default = () => <ButtonIcon {...props}>ButtonIcon</ButtonIcon> | ||
|
||
export const Warning = () => <ButtonIcon {...props} warning>ButtonIcon</ButtonIcon> | ||
|
||
export const Error = () => <ButtonIcon {...props} error>ButtonIcon</ButtonIcon> | ||
|
||
export const Success = () => <ButtonIcon {...props} success>ButtonIcon</ButtonIcon> | ||
|
||
export const Info = () => <ButtonIcon {...props} info>ButtonIcon</ButtonIcon> | ||
|
||
export const Small = () => <ButtonIcon {...props} small>ButtonIcon</ButtonIcon> | ||
|
||
export const Large = () => <ButtonIcon {...props} large>ButtonIcon</ButtonIcon> | ||
|
||
export const LeftIcon = () => <ButtonIcon {...props}>ButtonIcon</ButtonIcon> | ||
|
||
export const RightIcon = () => <ButtonIcon {...props}>ButtonIcon</ButtonIcon> | ||
|
||
export const Loading = () => <ButtonIcon {...props} loading>ButtonIcon</ButtonIcon> | ||
|
||
export const LoadingSuccess = () => <ButtonIcon {...props} success loading>ButtonIcon</ButtonIcon> |
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,58 +1,2 @@ | ||
import React from 'react' | ||
import { Base } from './styled' | ||
import { Flex } from '../Structure' | ||
import Overlay from '../Overlay' | ||
import Loading from '../Loading' | ||
import { Text } from '../Typography' | ||
import useTheme from '../../hooks/useTheme' | ||
|
||
const ButtonComponent = ({ | ||
children, | ||
leftIcon: LeftIcon, | ||
rightIcon: RightIcon, | ||
loading, | ||
disabled, | ||
large, | ||
small, | ||
error, | ||
info, | ||
warning, | ||
success, | ||
...props | ||
}) => { | ||
const variants = { | ||
error, | ||
info, | ||
success, | ||
warning, | ||
large, | ||
small, | ||
} | ||
const iconColor = useTheme('colors.icon') | ||
return ( | ||
<Base {...variants} {...props} disabled={loading || disabled}> | ||
{loading && ( | ||
<Overlay> | ||
<Loading ignoreTheme /> | ||
</Overlay> | ||
)} | ||
{Boolean(LeftIcon) && ( | ||
<Flex mr={2}> | ||
<LeftIcon color={iconColor} /> | ||
</Flex> | ||
)} | ||
<Text white ignoreTheme> | ||
{children} | ||
</Text> | ||
{Boolean(RightIcon) && ( | ||
<Flex ml={2}> | ||
<RightIcon color={iconColor} /> | ||
</Flex> | ||
)} | ||
</Base> | ||
) | ||
} | ||
|
||
ButtonComponent.propTypes = {} | ||
|
||
export default ButtonComponent | ||
export { default as Button } from './Button' | ||
export { default as ButtonIcon } from './ButtonIcon' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { FiLoader } from 'react-icons/fi' | ||
import Spin from '../Spin' | ||
import useTheme from '../../hooks/useTheme' | ||
|
||
const LoadingComponent = (props) => { | ||
const color = useTheme('colors.icon') | ||
const LoadingComponent = ({ ignoreTheme, white }) => { | ||
const color = useTheme(white ? 'colors.icon_inverse' : 'colors.icon', { ignoreTheme }) | ||
return <Spin><FiLoader color={color} /></Spin> | ||
} | ||
|
||
LoadingComponent.propTypes = {} | ||
LoadingComponent.propTypes = { | ||
ignoreTheme: PropTypes.bool, | ||
white: PropTypes.bool, | ||
} | ||
|
||
export default LoadingComponent |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
import { path } from 'rambda' | ||
import { useTheme as useStyledTheme } from 'styled-components' | ||
import { getValueFromTheme } from '../../lib/mixins' | ||
|
||
export default function useTheme(key) { | ||
export default function useTheme(key, options = {}) { | ||
const { ignoreTheme } = options | ||
const theme = useStyledTheme() | ||
if (path(key, theme)[theme.mode]) { | ||
return path(key, theme)[theme.mode] | ||
} | ||
|
||
return path(key, theme) | ||
return getValueFromTheme(key, { theme, ignoreTheme }) | ||
} |
Oops, something went wrong.