| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import React from 'react';
- import ClipboardButton from 'react-clipboard.js';
- export default class PagePath extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- pages: [],
- isListPage: false,
- };
- }
- componentWillMount() {
- // whether list page or not
- const isListPage = this.props.pagePath.match(/\/$/);
- this.setState({ isListPage });
- // generate pages obj
- let splitted = this.props.pagePath.split(/\//);
- splitted.shift(); // omit first element with shift()
- if (splitted[splitted.length-1] === '') {
- splitted.pop(); // omit last element with unshift()
- }
- let pages = [];
- let parentPath = '/';
- splitted.forEach((pageName) => {
- pages.push({
- pagePath: parentPath + pageName,
- pageName: pageName,
- });
- parentPath += pageName + '/';
- });
- this.setState({ pages });
- }
- showTooltip() {
- // TODO implements
- }
- render() {
- const pageLength = this.state.pages.length;
- const afterElements = [];
- this.state.pages.forEach((page, index) => {
- const isLastElement = (index == pageLength-1);
- // add elements
- afterElements.push(
- <span key={page.pagePath} className="path-segment">
- <a href={page.pagePath}>{page.pageName}</a>
- </span>);
- afterElements.push(
- <span key={page.pagePath+'/'} className="separator">
- <a href={page.pagePath+'/'} className={(isLastElement && !this.state.isListPage) ? 'last-path' : ''}>/</a>
- </span>
- );
- });
- return (
- <span className="page-path">
- <span className="separator">
- <a href="/">/</a>
- </span>
- {afterElements}
- <ClipboardButton className="btn btn-default"
- data-clipboard-text={this.props.pagePath} onSuccess={this.showTooltip}>
- <i className="fa fa-clone text-muted"></i>
- </ClipboardButton>
- </span>
- );
- }
- }
- PagePath.propTypes = {
- pagePath: React.PropTypes.string.isRequired,
- };
|