Skip to content

Commit

Permalink
Inline Message (#180)
Browse files Browse the repository at this point in the history
* Add InlineMessage

* Fix issues with dot notation colors

* Bump version
  • Loading branch information
FrederikBolding authored Jan 17, 2022
1 parent 2687321 commit ff2f4e7
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mycrypto/ui",
"version": "1.9.8",
"version": "1.10.0",
"description": "The shared UI component library used across all MyCrypto products.",
"repository": "MyCryptoHQ/ui",
"keywords": [
Expand Down
3 changes: 2 additions & 1 deletion src/atoms/Icon.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FunctionComponent } from 'react';
import InlineSVG from 'react-inlinesvg';
import { useTheme } from 'styled-components';
import { get } from 'styled-system';
import type { Theme } from 'theme';

import type { BoxProps } from '.';
Expand Down Expand Up @@ -96,7 +97,7 @@ export const Icon: FunctionComponent<IconProps & BoxProps> = ({
as={InlineSVG}
src={icons[type]}
width={width}
fill={(theme.colors[fill as keyof Theme['colors']] as string) || fill}
fill={get(theme.colors, (fill as keyof Theme['colors']) as string) || fill}
{...props}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions src/atoms/Spinner.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FunctionComponent } from 'react';
import styled, { keyframes, useTheme } from 'styled-components';
import type { SpaceProps } from 'styled-system';
import { space } from 'styled-system';
import { space, get } from 'styled-system';

import type { Theme } from '../theme';

Expand Down Expand Up @@ -42,7 +42,7 @@ export const Spinner: FunctionComponent<SpinnerProps> = ({
cy="25"
r="20"
fill="none"
stroke={(theme.colors[color as keyof Theme['colors']] as string) || color}
stroke={get(theme.colors, (color as keyof Theme['colors']) as string) || color}
strokeWidth="5"
strokeDasharray="90, 150"
strokeDashoffset={0}
Expand Down
28 changes: 28 additions & 0 deletions src/molecules/InlineMessage.stories.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Meta, Story, Canvas } from '@storybook/addon-docs/blocks';

import { fAddress } from '../../.jest/__fixtures__';
import { InlineMessage } from './InlineMessage';

<Meta
title="molecules/InlineMessage"
component={InlineMessage}
parameters={{ actions: { argTypesRegex: '^on.*' } }}
argTypes={{
type: {
control: {
type: 'select',
options: ['success', 'info', 'action', 'warning', 'error']
}
}
}}
/>

# InlineMessage

InlineMessage!

<Canvas>
<Story name="Default" args={{ type: 'success', children: 'Default' }}>
{(props) => <InlineMessage {...props} />}
</Story>
</Canvas>
8 changes: 8 additions & 0 deletions src/molecules/InlineMessage.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { simpleRender } from '../../.jest/test-utils';
import { InlineMessage } from './InlineMessage';

describe('InlineMessage', () => {
it('renders correctly', () => {
expect(() => simpleRender(<InlineMessage type="error">Foo</InlineMessage>)).not.toThrow();
});
});
33 changes: 33 additions & 0 deletions src/molecules/InlineMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { FunctionComponent } from 'react';
import type { DefaultTheme } from 'styled-components';
import type { SpaceProps } from 'styled-system';

import type { IconType } from '../atoms';
import { Body, Flex, Icon } from '../atoms';

export type InlineMessageType = keyof DefaultTheme['colors']['banner'];

export interface InlineMessageProps extends SpaceProps {
type: InlineMessageType;
}

const icons: { [key in InlineMessageType]: IconType } = {
success: 'checkmark',
info: 'info',
action: 'waiting',
warning: 'info',
error: 'alert'
};

export const InlineMessage: FunctionComponent<InlineMessageProps> = ({
type,
children,
...props
}) => (
<Flex display="inline-flex" {...props}>
<Icon type={icons[type]} fill={`banner.${type}`} mr="1" />
<Body color={`banner.${type}`} as="span" verticalAlign="middle" {...props}>
{children}
</Body>
</Flex>
);
20 changes: 14 additions & 6 deletions src/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,14 @@ export const theme = {
tooltip: {
background: 'white',
border: COLORS.GREY_SECONDARY
},

banner: {
success: '#b4dd88',
info: '#b6c0c8',
action: '#a682ff',
warning: '#fa873f',
error: '#ef4747'
}
},
fontSizes: ['0.625rem', '0.75rem', '1rem', '1.125rem', '1.25rem', '2.5rem'],
Expand Down Expand Up @@ -327,27 +335,27 @@ export const theme = {
banner: {
success: {
background: '#f4faed',
color: '#b4dd88'
color: 'banner.success'
},
info: {
background: '#f4f6f7',
color: '#b6c0c8'
color: 'banner.info'
},
action: {
background: '#f2ecff',
color: '#a682ff'
color: 'banner.action'
},
warning: {
background: '#feede2',
color: '#fa873f'
color: 'banner.warning'
},
error: {
background: '#fde4e4',
color: '#ef4747'
color: 'banner.error'
},
clear: {
background: 'none',
color: '#a682ff'
color: 'banner.action'
}
},
panel: {
Expand Down

0 comments on commit ff2f4e7

Please sign in to comment.