forked from decred/decrediton
-
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
4cf589d
commit a18a49e
Showing
22 changed files
with
308 additions
and
422 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,51 @@ | ||
import { createElement as h } from "react"; | ||
import { spring, TransitionMotion } from "react-motion"; | ||
import { object, string, func, bool } from "prop-types"; | ||
|
||
const ensureSpring = (styles, options) => ( | ||
Object.keys(styles).reduce((acc, key) => { | ||
const value = styles[key]; | ||
acc[key] = typeof value === "number" ? spring(value, options) : value; | ||
return acc; | ||
}, {}) | ||
); | ||
|
||
const RouteTransition = props => { | ||
const base = { data: props.children, key: props.pathname }; | ||
const defaultStyles = | ||
!props.runOnMount ? null : | ||
!props.children ? [] : | ||
[{...base, style: props.atEnter }]; | ||
|
||
const styles = | ||
!props.children ? [] : | ||
[{...base, style: ensureSpring(props.atActive, props.opts) }]; | ||
|
||
const willEnter = () => props.atEnter; | ||
const willLeave = () => ensureSpring(props.atLeave, props.opts); | ||
const tmProps = { willEnter, willLeave, defaultStyles, styles }; | ||
const route = ({ key, style, data }) => { | ||
const routeProps = {...{key}, style: props.mapStyles(style) }; | ||
return h("div", routeProps, data); | ||
}; | ||
const routes = routes => h("div", null, routes.map(route)); | ||
return h(TransitionMotion, tmProps, routes); | ||
}; | ||
|
||
RouteTransition.defaultProps = { | ||
runOnMount: true, | ||
mapStyles: val => val, | ||
opts: { stiffness: 40, damping: 26 } | ||
}; | ||
|
||
RouteTransition.propTypes = { | ||
atEnter: object.isRequired, | ||
atActive: object.isRequired, | ||
atLeave: object.isRequired, | ||
pathname: string.isRequired, | ||
mapStyles: func, | ||
runOnMount: bool, | ||
opts: object | ||
}; | ||
|
||
export default RouteTransition; |
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 +1,2 @@ | ||
export { default as RouteTransition } from "./RouteTransition"; | ||
export { default as Tooltip } from "./Tooltip"; |
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,94 @@ | ||
import { spring, Motion } from "react-motion"; | ||
import { Link } from "react-router"; | ||
import { injectIntl, defineMessages, intlShape } from "react-intl"; | ||
import "style/Header.less"; | ||
import headerConnector from "connectors/header"; | ||
|
||
const opts = { stiffness: 150, damping: 20 }; | ||
|
||
const messages = defineMessages({ | ||
"transactions.title": { id: "transactions.title", defaultMessage: "Transactions" }, | ||
"transactions.description.testnet": { id: "transactions.description.testnet", defaultMessage: "Testnet Decred addresses always begin with letter T and contain 26-35 alphanumeric characters (e.g. TxxXXXXXxXXXxXXXXxxx0XxXXXxxXxXxX0)." }, | ||
"transactions.description.mainnet": { id: "transactions.description.mainnet", defaultMessage: "Mainnet Decred addresses always begin with letter D and contain 26-35 alphanumeric characters (e.g. DxxXXXXXxXXXxXXXXxxx0XxXXXxxXxXxX0X)." }, | ||
"transactions.tab.send": { id: "transactions.tab.send", defaultMessage: "Send" }, | ||
"transactions.tab.receive": { id: "transactions.tab.receive", defaultMessage: "Receive" }, | ||
}); | ||
|
||
@autobind | ||
class Header extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this._nodes = new Map(); | ||
this.state = { caretLeft: null, caretWidth: null, selectedTab: null }; | ||
} | ||
componentDidMount() { | ||
this.updateCaretPosition(this.props.pathname); | ||
} | ||
|
||
componentDidUpdate() { | ||
if (this.state.selectedTab != this.props.pathname) { | ||
const caretPosition = this.neededCaretPosition(this.props.pathname); | ||
this.setState({ selectedTab: this.props.pathname, ...caretPosition }); | ||
} | ||
} | ||
|
||
updateCaretPosition(tab) { | ||
const caretPosition = this.neededCaretPosition(tab); | ||
if (caretPosition) this.setState(caretPosition); | ||
} | ||
neededCaretPosition(tab) { | ||
const tabForRoute = this._nodes.get(tab); | ||
if (!tabForRoute) return null; | ||
const tabRect = tabForRoute.getBoundingClientRect(); | ||
const caretLeft = tabForRoute.offsetLeft; | ||
const caretWidth = tabRect.width; | ||
return {caretLeft, caretWidth}; | ||
} | ||
render () { | ||
const { isTestNet, page, tabs, intl } = this.props; | ||
const { caretLeft, caretWidth } = this.state; | ||
const description = [page, "description", isTestNet ? "testnet" : "mainnet"].join("."); | ||
const headerIcon = ["header-icon", page].join("-"); | ||
const title = [page, "title"].join("."); | ||
return ( | ||
<div className="header"> | ||
<div className="header-top"></div> | ||
|
||
<div className="tabbedheader-title"> | ||
<span className={ "tabbedheader-icon " + headerIcon } /> | ||
{ intl.formatMessage(messages[title]) } | ||
</div> | ||
|
||
<div className="tabbedheader-description"> | ||
{ intl.formatMessage(messages[description]) } | ||
</div> | ||
|
||
<div className="tabbedheader-tabs"> | ||
{ tabs.map((tab) => { | ||
const title = [page, "tab", tab].join("."); | ||
const route = ["", page, tab].join("/"); | ||
return ( | ||
<div className="tabbedheader-ref" ref={ ref => this._nodes.set(tab, ref) } key={ tab }> | ||
<Link to={ route } onClick={() => this.updateCaretPosition(tab) } className="tabbedheader-tab" > | ||
{ intl.formatMessage(messages[title]) } | ||
</Link> | ||
</div> | ||
); | ||
})} | ||
<Motion style={{ left: spring(caretLeft, opts), width: spring(caretWidth, opts) }}> | ||
{ style => <div className="tabbedheader-active-tab-caret" style={ style }/> } | ||
</Motion> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
Header.propTypes = { | ||
isTestNet: PropTypes.bool, | ||
page: PropTypes.string.isRequired, | ||
tabs: PropTypes.arrayOf(PropTypes.string), | ||
intl: intlShape | ||
}; | ||
|
||
export default injectIntl(headerConnector(Header)); |
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
Oops, something went wrong.