Skip to content

Commit

Permalink
site: fix target demo highlight, close: ant-design#4545
Browse files Browse the repository at this point in the history
  • Loading branch information
benjycui committed Jan 13, 2017
1 parent d013952 commit e459562
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
23 changes: 11 additions & 12 deletions site/theme/template/Content/ComponentDoc.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@ export default class ComponentDoc extends React.Component {
demos.filter(demo => demo.meta.only) : demos.filter(demo => demo.preview);
showedDemo.sort((a, b) => a.meta.order - b.meta.order)
.forEach((demoData, index) => {
const demoElem = (
<Demo
{...demoData}
key={demoData.meta.filename}
utils={props.utils}
expand={expand}
location={location}
/>
);
if (index % 2 === 0 || isSingleCol) {
leftChildren.push(
<Demo {...demoData}
key={demoData.meta.filename} utils={props.utils}
expand={expand} pathname={location.pathname}
/>
);
leftChildren.push(demoElem);
} else {
rightChildren.push(
<Demo {...demoData}
key={demoData.meta.filename} utils={props.utils}
expand={expand} pathname={location.pathname}
/>
);
rightChildren.push(demoElem);
}
});
const expandTriggerClass = classNames({
Expand Down
13 changes: 12 additions & 1 deletion site/theme/template/Content/Demo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,21 @@ export default class Demo extends React.Component {
return (this.state.codeExpand || this.props.expand) !== (nextState.codeExpand || nextProps.expand);
}

componentDidMount() {
const { meta, location } = this.props;
if (meta.id === location.hash.slice(1)) {
this.anchor.click();
}
}

handleCodeExapnd = () => {
this.setState({ codeExpand: !this.state.codeExpand });
}

saveAnchor = (anchor) => {
this.anchor = anchor;
}

render() {
const props = this.props;
const {
Expand Down Expand Up @@ -70,7 +81,7 @@ export default class Demo extends React.Component {
</section>
<section className="code-box-meta markdown">
<div className="code-box-title">
<a href={`#${meta.id}`}>
<a href={`#${meta.id}`} ref={this.saveAnchor}>
{localizedTitle}
</a>
<EditButton title={<FormattedMessage id="app.content.edit-page" />} filename={meta.filename} />
Expand Down

0 comments on commit e459562

Please sign in to comment.