-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* separate dividers for the toolbar * add toolbar * add layout to stories Authored-by @walaura
- Loading branch information
Showing
14 changed files
with
1,157 additions
and
249 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,9 @@ | ||
import React from 'react'; | ||
|
||
const styles = { | ||
maxWidth: '60em', | ||
margin: '5em auto', | ||
border: '1px solid #eee', | ||
}; | ||
|
||
export const layout = storyFn => <div style={styles}>{storyFn()}</div>; |
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
6 changes: 3 additions & 3 deletions
6
packages/graphiql/src/new-components/List.js → .../graphiql/src/new-components/List/List.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
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'theme-ui'; | ||
|
||
const Content = ({ ...props }) => ( | ||
<div | ||
{...props} | ||
sx={{ | ||
padding: ({ spaces }) => spaces.rowPadding, | ||
}} | ||
/> | ||
); | ||
|
||
export default Content; |
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,48 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'theme-ui'; | ||
import PropTypes from 'prop-types'; | ||
import WithDividers from './support/WithDividers'; | ||
|
||
const Tab = ({ active, ...props }) => ( | ||
<button | ||
sx={{ | ||
padding: ({ spaces }) => spaces.rowPadding, | ||
outline: 'none', | ||
textAlign: 'end', | ||
verticalAlign: 'baseline', | ||
transition: ({ transitions }) => transitions[0], | ||
cursor: 'pointer', | ||
':focus, :hover': { | ||
boxShadow: active ? 'primaryUnderline' : 'underline', | ||
color: active ? 'primary' : 'darkText', | ||
}, | ||
boxShadow: active ? 'primaryUnderline' : 'inset 0 0 0 transparent', | ||
color: active ? 'primary' : 'text', | ||
}} | ||
{...props} | ||
/> | ||
); | ||
Tab.propTypes = { active: PropTypes.bool }; | ||
|
||
const Tabs = ({ tabs, active, onChange }) => { | ||
return ( | ||
<WithDividers> | ||
{tabs.map((tab, index) => ( | ||
<Tab | ||
key={index} | ||
active={active === index} | ||
onClick={() => onChange(index)}> | ||
{tab} | ||
</Tab> | ||
))} | ||
</WithDividers> | ||
); | ||
}; | ||
|
||
Tabs.propTypes = { | ||
tabs: PropTypes.arrayOf(PropTypes.node).isRequired, | ||
active: PropTypes.number.isRequired, | ||
onChange: PropTypes.func.isRequired, | ||
}; | ||
|
||
export default Tabs; |
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,34 @@ | ||
/** @jsx jsx */ | ||
import { jsx } from 'theme-ui'; | ||
import PropTypes from 'prop-types'; | ||
import WithDividers from './support/WithDividers'; | ||
|
||
const Toolbar = ({ children, justifyContent = 'space-between' }) => { | ||
const needsExtraPadding = !justifyContent.includes('space'); | ||
return ( | ||
<div | ||
sx={{ | ||
overflow: 'auto', | ||
display: 'flex', | ||
alignItems: 'stretch', | ||
justifyContent, | ||
}}> | ||
{needsExtraPadding ? ( | ||
<WithDividers padding>{children}</WithDividers> | ||
) : ( | ||
children | ||
)} | ||
</div> | ||
); | ||
}; | ||
Toolbar.propTypes = { | ||
justifyContent: PropTypes.oneOf([ | ||
'space-between', | ||
'space-around', | ||
'flex-start', | ||
'flex-end', | ||
'center', | ||
]), | ||
}; | ||
|
||
export default Toolbar; |
80 changes: 80 additions & 0 deletions
80
packages/graphiql/src/new-components/Toolbar/Toolbar.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import List, { ListRow } from '../List/List'; | ||
import Tabs from './Tabs'; | ||
import React from 'react'; | ||
import Toolbar from './Toolbar'; | ||
import Content from './Content'; | ||
import { layout } from '../../../.storybook/decorators'; | ||
|
||
export default { title: 'Toolbar', decorators: [layout] }; | ||
|
||
export const Basic = () => ( | ||
<List> | ||
<ListRow padding> | ||
<p>{`Toolbars group together widgets in a flexbox. You can cutomize what type of | ||
justification to use and if elements go together it'll add dividers | ||
between them`}</p> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="center"> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
</Toolbar> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="flex-start"> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
</Toolbar> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="flex-end"> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
</Toolbar> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="space-between"> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
<Content>{'Some text'}</Content> | ||
</Toolbar> | ||
</ListRow> | ||
</List> | ||
); | ||
|
||
export const ToolbarWithTabs = () => ( | ||
<List> | ||
<ListRow padding> | ||
<p> | ||
{`The dividers don't nest so if you have tabs inside a toolbar the tabs won't get dividers`} | ||
</p> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="center"> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
</Toolbar> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="flex-start"> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
</Toolbar> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="flex-end"> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
</Toolbar> | ||
</ListRow> | ||
<ListRow> | ||
<Toolbar justifyContent="space-between"> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
<Tabs active={2} tabs={['First', 'Second', 'Third']} /> | ||
</Toolbar> | ||
</ListRow> | ||
</List> | ||
); |
Oops, something went wrong.