Skip to content

Commit

Permalink
feat(TopBar): initial
Browse files Browse the repository at this point in the history
  • Loading branch information
zouxuoz committed Jun 13, 2019
1 parent 53b6089 commit 266242c
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 0 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions e2e/__tests__/top-bar-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { baisy } from '../setup/TestSuiter';

const SUITES = [
baisy.suite('Components/TopBar', 'common'),
];

SUITES.map(suite => {
it(suite.getTestName(), suite.testStory, 20000);
});

39 changes: 39 additions & 0 deletions src/components/TopBar/TopBar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// @flow

import React from 'react';
import { theme, TopBarTag, TopBarCloseTag } from './TopBar.theme';

import { Row } from '../FlexLayout';
import { Icon } from '../Icon';

type TopBarProps = {
isOpen?: boolean,
onClose?: Function,
children: React$Node,
color: string,
};

const TopBar = ({ children, isOpen, onClose, ...rest }: TopBarProps) => {
let rendered = null;

if (isOpen) {
rendered = (
<TopBarTag tagName={ Row } alignItems="center" justifyContent="center" gap="lg" { ...rest }>
<If condition={ typeof onClose === 'function' }>
<TopBarCloseTag onClick={ onClose }>
<Icon name="Delete" color="WHITE" />
</TopBarCloseTag>
</If>
{ children }
</TopBarTag>
);
}

return rendered;
};

TopBar.defaultProps = {
isOpen: true,
};

export { TopBar, theme };
34 changes: 34 additions & 0 deletions src/components/TopBar/TopBar.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* eslint-disable no-alert */

import React, { useState } from 'react';

export default (asStory) => {
asStory('Components/TopBar', module, (story, { TopBar, Column, Icon, Text, Button }) => {

const TopBarWithState = (props) => {
const [isOpen, setIsOpen] = useState(true);

return <TopBar isOpen={ isOpen } onClose={ () => setIsOpen(false) } { ...props } />;
};

story
.add('common', () => (
<Column gap="lg">
<TopBar color="DSM_HOME_SELECTED">
<Text color="WHITE" weight="semibold">You have 7 days until your FREE TRIAL ends.</Text>
<Button color="white" variant="ghost" size="sm">Update</Button>
</TopBar>
<TopBarWithState color="RED">
<Icon color="YELLOW" name="Alert" />
<Text color="WHITE" weight="semibold">Oh no! Your FREE TRIAL has ended, please update your payment details.</Text>
<Button color="white" variant="ghost" size="sm">Update</Button>
</TopBarWithState>
<TopBar color="RED">
<Icon color="YELLOW" name="Alert" />
<Text color="WHITE" weight="semibold">Oh no! Your FREE TRIAL has ended, please update your payment details.</Text>
<Button color="white" variant="ghost" size="sm">Update</Button>
</TopBar>
</Column>
));
});
};
34 changes: 34 additions & 0 deletions src/components/TopBar/TopBar.theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//@flow

import { createThemeTag } from '../../theme/createThemeTag';

const name = 'topBar';

const [TopBarTag, themeTopBar] = createThemeTag(name, ({ COLORS }: *) => ({
root: (props) => ({
width: '100%',
height: '52px',
backgroundColor: COLORS[props.color],
position: 'relative',
}),
}));

const [TopBarCloseTag, themeTopBarClose] = createThemeTag(`${name}Close`, () => ({
root: {
position: 'absolute',
right: 24,
height: '100%',
display: 'flex',
alignItems: 'center',
cursor: 'pointer',
marginRight: '0 !important',
},
}));

const theme = {
...themeTopBar,
...themeTopBarClose,
};

export { theme, TopBarTag, TopBarCloseTag };

1 change: 1 addition & 0 deletions src/components/TopBar/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './TopBar';
1 change: 1 addition & 0 deletions src/components/components.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export { TextAreaField } from './TextAreaField';
export { TreeSelect } from './TreeSelect';
export { TreeSelectField } from './TreeSelectField';
export { Tooltip } from './Tooltip';
export { TopBar } from './TopBar';
export { NoData } from './NoData';
export { Pagination } from './Pagination';
export { Indicator } from './Indicator';
Expand Down
2 changes: 2 additions & 0 deletions src/components/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { theme as tagTheme } from './Tag';
import { theme as textAreaTheme } from './TextArea';
import { theme as textTheme } from './Text';
import { theme as tooltipTheme } from './Tooltip';
import { theme as topBarTheme } from './TopBar';
import { theme as treeSelectTheme } from './TreeSelect';
import { theme as menuTheme } from './Menu';
import { theme as dateInputTheme } from './DateInput';
Expand Down Expand Up @@ -77,6 +78,7 @@ export const theme = {
...textAreaTheme,
...textTheme,
...tooltipTheme,
...topBarTheme,
...treeSelectTheme,
...menuTheme,
...dateInputTheme,
Expand Down

0 comments on commit 266242c

Please sign in to comment.