This repository was archived by the owner on Jan 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| import Tabs from './tabs' | ||
| import Tab from './tab' | ||
|
|
||
| export { Tabs, Tab } |
This file contains hidden or 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 PropTypes from 'prop-types' | ||
| import { merge } from 'glamor' | ||
|
|
||
| import styles from './tab.styles' | ||
|
|
||
| const Tab = ({ tabKey, title, className, children }) => { | ||
| return ( | ||
| <div className={merge(styles.layout, className)} aria-hidden={tabKey} aria-label={title}> | ||
| {children} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| Tab.propTypes = { | ||
| tabKey: PropTypes.string.isRequired, | ||
| title: PropTypes.string.isRequired, | ||
| className: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
| children: PropTypes.oneOfType([PropTypes.node, PropTypes.array]), | ||
| } | ||
|
|
||
| Tab.defaultProps = { | ||
| children: '', | ||
| className: undefined, | ||
| } | ||
|
|
||
| export default Tab |
This file contains hidden or 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,10 @@ | ||
| import { css } from 'glamor' | ||
|
|
||
| const layout = css({ | ||
| width: '100%', | ||
| height: '100%', | ||
| overflow: 'auto', | ||
| padding: '1em', | ||
| }) | ||
|
|
||
| export default { layout } |
This file contains hidden or 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,58 @@ | ||
| import React, { Component } from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import { merge } from 'glamor' | ||
|
|
||
| import TabsHeader from './tabsHeader' | ||
| import TabsAction from './tabsActions' | ||
| import styles from './tabs.styles' | ||
|
|
||
| class Tabs extends Component { | ||
| state = { | ||
| selected: this.props.defaultKey, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really don't like that pattern.
at least, can't we create a curry version of handleSelectedTab = (key) => () => {
//...
}
// ...
titles={titles.map(title => <li {/* ... */} onClick={handleSelectedTab(title)}>{...}</li>)}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know that you don't like inner state 😇 Otherwise, I give the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
|
|
||
| handleSelectedTab = (key) => { | ||
| this.setState(() => ({ selected: key })) | ||
| } | ||
|
|
||
| render() { | ||
| const { children, actions, className, actionsClassName, headersClassName } = this.props | ||
|
|
||
| const childArray = React.Children.toArray(children) | ||
| const headers = childArray.map(({ props }) => ({ tabKey: props.tabKey, title: props.title })) | ||
| const selected = this.state.selected || headers[0].tabKey | ||
| const tab = childArray.find(c => c.props.tabKey === selected) | ||
|
|
||
| return ( | ||
| <div className={merge(styles.layout, className)}> | ||
| <TabsHeader | ||
| headers={headers} | ||
| selectedTab={selected} | ||
| onSelectTab={this.handleSelectedTab} | ||
| className={headersClassName} | ||
| /> | ||
| <TabsAction actions={actions} className={actionsClassName} /> | ||
| {tab} | ||
| </div> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| Tabs.propTypes = { | ||
| defaultKey: PropTypes.number, | ||
| children: PropTypes.oneOfType([PropTypes.node, PropTypes.array]).isRequired, | ||
| actions: PropTypes.oneOfType([PropTypes.node, PropTypes.object]), | ||
| className: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
| actionsClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
| headersClassName: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
| } | ||
|
|
||
| Tabs.defaultProps = { | ||
| defaultKey: undefined, | ||
| actions: undefined, | ||
| className: undefined, | ||
| actionsClassName: undefined, | ||
| headersClassName: undefined, | ||
| } | ||
|
|
||
| export default Tabs | ||
This file contains hidden or 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,8 @@ | ||
| import { css } from 'glamor' | ||
|
|
||
| const layout = css({ | ||
| position: 'relative', | ||
| border: '.1em solid #ddd', | ||
| }) | ||
|
|
||
| export default { layout } |
This file contains hidden or 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,28 @@ | ||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import { merge } from 'glamor' | ||
|
|
||
| import styles from './tabsActions.styles' | ||
|
|
||
| const TabsActions = ({ actions, className }) => { | ||
| if (!actions) { | ||
| return null | ||
| } | ||
| return ( | ||
| <div className={merge(styles.actions, className)}> | ||
| {actions} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| TabsActions.propTypes = { | ||
| actions: PropTypes.oneOfType([PropTypes.node, PropTypes.object]), | ||
| className: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
| } | ||
|
|
||
| TabsActions.defaultProps = { | ||
| actions: undefined, | ||
| className: undefined, | ||
| } | ||
|
|
||
| export default TabsActions |
This file contains hidden or 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,10 @@ | ||
| import { css } from 'glamor' | ||
|
|
||
| const layout = css({ | ||
| position: 'absolute', | ||
| top: 0, | ||
| right: 0, | ||
| padding: '.9em 1.1em', | ||
| }) | ||
|
|
||
| export default { layout } |
This file contains hidden or 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,43 @@ | ||
| import React, { Component } from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import { merge } from 'glamor' | ||
|
|
||
| import styles from './tabsHeader.styles' | ||
|
|
||
| class TabsHeader extends Component { | ||
|
|
||
| handleSelectedTab = tabKey => () => { | ||
| this.props.onSelectTab(tabKey) | ||
| } | ||
|
|
||
| render() { | ||
| const { headers, selectedTab, className } = this.props | ||
| return ( | ||
| <ul className={merge(styles.layout, className)}> | ||
| {headers.map(({ tabKey, title }) => | ||
| <li | ||
| key={tabKey} | ||
| className={merge(styles.item, selectedTab === tabKey && styles.selected)} | ||
| aria-expanded={selectedTab === tabKey} | ||
| onClick={this.handleSelectedTab(tabKey)} | ||
| > | ||
| {title} | ||
| </li> | ||
| )} | ||
| </ul> | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| TabsHeader.propTypes = { | ||
| headers: PropTypes.arrayOf(PropTypes.object).isRequired, | ||
| selectedTab: PropTypes.string.isRequired, | ||
| onSelectTab: PropTypes.func.isRequired, | ||
| className: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), | ||
| } | ||
|
|
||
| TabsHeader.defaultProps = { | ||
| className: undefined, | ||
| } | ||
|
|
||
| export default TabsHeader |
This file contains hidden or 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,26 @@ | ||
| import { css } from 'glamor' | ||
|
|
||
| const layout = css({ | ||
| display: 'flex', | ||
| margin: 0, | ||
| padding: 0, | ||
| listStyle: 'none', | ||
| borderBottom: '1px solid #ddd', | ||
| }) | ||
|
|
||
| const item = css({ | ||
| cursor: 'pointer', | ||
| marginRight: 0, | ||
| padding: '.9em 1.1em', | ||
| lineHeight: '1.1em', | ||
| color: '#607580', | ||
| fontWeight: 600, | ||
| }) | ||
|
|
||
| const selected = css({ | ||
| cursor: 'default', | ||
| color: '#243641', | ||
| backgroundColor: '#ddd', | ||
| }) | ||
|
|
||
| export default { layout, item, selected } |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we change all those defaultProps ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because in
glamor#merge, falsy values are :false,null,undefinedand{}.''is not considered as falsy.