mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
site: update code preview, except animation
This commit is contained in:
parent
e378b1f695
commit
6c2115c8a8
@ -76,49 +76,25 @@
|
||||
|
||||
.code-box-meta {
|
||||
position: relative;
|
||||
padding: 10px 15px;
|
||||
border-radius: 0 0 6px 6px;
|
||||
transition: background-color 0.4s ease;
|
||||
width: 100%;
|
||||
font-size: 12px;
|
||||
|
||||
.ant-collapse,
|
||||
.ant-collapse-content,
|
||||
.ant-collapse-content-box {
|
||||
background-color: transparent;
|
||||
border: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.ant-collapse-item > .ant-collapse-header {
|
||||
height: auto;
|
||||
line-height: 1.8;
|
||||
padding: 9px 15px 10px 32px;
|
||||
}
|
||||
|
||||
h4,
|
||||
p {
|
||||
.code-box-meta h4,
|
||||
.code-box-meta p {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
> p {
|
||||
font-size: 12px;
|
||||
margin: .5em 0;
|
||||
padding-right: 25px;
|
||||
width: 100%;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
}
|
||||
|
||||
.code-box-title {
|
||||
position: absolute;
|
||||
top: -14px;
|
||||
left: 14px;
|
||||
padding: 1px 1.1em;
|
||||
color: #777;
|
||||
border-radius: 6px;
|
||||
background: #fff;
|
||||
transition: all 0.4s ease;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.code-box-title:before {
|
||||
@ -129,7 +105,7 @@
|
||||
line-height: 22px;
|
||||
position: relative;
|
||||
margin-right: 8px;
|
||||
top: -1px;
|
||||
top: -2px;
|
||||
color: #ccc;
|
||||
-webkit-transform: rotate(-45deg);
|
||||
transform: rotate(-45deg);
|
||||
@ -155,6 +131,7 @@
|
||||
line-height: 18px;
|
||||
opacity: 0.5;
|
||||
text-align: center;
|
||||
-webkit-transform: rotate(90deg);
|
||||
transform: rotate(90deg);
|
||||
transition: all 0.3s ease;
|
||||
color: #999;
|
||||
@ -173,6 +150,7 @@
|
||||
|
||||
.code-box .highlight {
|
||||
overflow: hidden;
|
||||
padding: 5px;
|
||||
border-top: 1px dashed #e9e9e9;
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
import React from 'react';
|
||||
import { Link } from 'react-router';
|
||||
import { Collapse } from '../../../';
|
||||
import classNames from 'classnames';
|
||||
import Animate from 'rc-animate';
|
||||
import * as utils from '../utils';
|
||||
|
||||
export default class Demo extends React.Component {
|
||||
@ -8,24 +9,35 @@ export default class Demo extends React.Component {
|
||||
super(props);
|
||||
|
||||
this.state = {
|
||||
activeKey: '',
|
||||
codeExpand: false,
|
||||
};
|
||||
}
|
||||
|
||||
handleChange(activeKey) {
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.expand === undefined) return;
|
||||
|
||||
this.setState({
|
||||
activeKey: this.state.activeKey === activeKey ?
|
||||
'' : activeKey
|
||||
codeExpand: nextProps.expand,
|
||||
});
|
||||
}
|
||||
|
||||
handleCodeExapnd() {
|
||||
this.setState({ codeExpand: !this.state.codeExpand });
|
||||
}
|
||||
|
||||
render() {
|
||||
const { id, className, meta, intro, preview, style, src,
|
||||
highlightedCode, highlightedStyle, expand, pathname } = this.props;
|
||||
highlightedCode, highlightedStyle, pathname } = this.props;
|
||||
const codeExpand = this.state.codeExpand;
|
||||
const codeBoxClass = classNames({
|
||||
'code-box': true,
|
||||
[className]: className,
|
||||
expand: codeExpand,
|
||||
});
|
||||
const introChildren = intro.map(utils.objectToComponent.bind(null, pathname));
|
||||
|
||||
return (
|
||||
<section className={`code-box ${className}`} id={id}>
|
||||
<section className={codeBoxClass} id={id}>
|
||||
<section className="code-box-demo">
|
||||
{
|
||||
meta.iframe === 'true' ?
|
||||
@ -44,9 +56,16 @@ export default class Demo extends React.Component {
|
||||
{ meta.chinese || meta.english }
|
||||
</Link>
|
||||
</div>
|
||||
<Collapse activeKey={expand ? `${id}-code` : this.state.activeKey}
|
||||
onChange={this.handleChange.bind(this)}>
|
||||
<Collapse.Panel key={`${id}-code`} header={introChildren}>
|
||||
{ introChildren }
|
||||
<span className="collapse anticon anticon-circle-o-right"
|
||||
onClick={this.handleCodeExapnd.bind(this)}
|
||||
unselectable="none" />
|
||||
</section>
|
||||
<Animate
|
||||
transitionEnter transitionLeave>
|
||||
{
|
||||
codeExpand ?
|
||||
<section key="code">
|
||||
<div className="highlight">
|
||||
<pre>
|
||||
<code className="javascript" dangerouslySetInnerHTML={{
|
||||
@ -55,8 +74,8 @@ export default class Demo extends React.Component {
|
||||
</pre>
|
||||
</div>
|
||||
{
|
||||
!!style ?
|
||||
<div className="highlight">
|
||||
style ?
|
||||
<div key="style" className="highlight">
|
||||
<pre>
|
||||
<code className="css" dangerouslySetInnerHTML={{
|
||||
__html: highlightedStyle,
|
||||
@ -65,9 +84,9 @@ export default class Demo extends React.Component {
|
||||
</div> :
|
||||
null
|
||||
}
|
||||
</Collapse.Panel>
|
||||
</Collapse>
|
||||
</section>
|
||||
</section> : <div key="nothing" />
|
||||
}
|
||||
</Animate>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user