Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: a demo use typescript #21045

Merged
merged 3 commits into from Jan 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions components/affix/demo/basic.md
Expand Up @@ -14,12 +14,11 @@ title:
The simplest usage.

```tsx
import React, { useState, FC } from 'react';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

尽量保留这个引用,这样和真实场景更接近。

import { Affix, Button } from 'antd';

const Demo: FC = () => {
const [top, setTop] = useState(10);
const [bottom, setBottom] = useState(10);
const Demo: React.FC = () => {
const [top, setTop] = React.useState(10);
const [bottom, setBottom] = React.useState(10);

return (
<div>
Expand Down
5 changes: 2 additions & 3 deletions components/affix/demo/debug.md
Expand Up @@ -15,11 +15,10 @@ DEBUG
DEBUG

```tsx
import React, { useState, FC } from 'react';
import { Affix, Button } from 'antd';

const Demo: FC = () => {
const [top, setTop] = useState(10);
const Demo: React.FC = () => {
const [top, setTop] = React.useState(10);
return (
<div style={{ height: 10000 }}>
<div>Top</div>
Expand Down
2 changes: 1 addition & 1 deletion components/affix/demo/on-change.md
Expand Up @@ -13,7 +13,7 @@ title:

Callback with affixed state.

```jsx
```tsx
import { Affix, Button } from 'antd';

ReactDOM.render(
Expand Down
5 changes: 2 additions & 3 deletions components/affix/demo/target.md
Expand Up @@ -14,11 +14,10 @@ title:
Set a `target` for 'Affix', which is listen to scroll event of target element (default is `window`).

```tsx
import React, { useState, FC } from 'react';
import { Affix, Button } from 'antd';

const Demo: FC = () => {
const [container, setContainer] = useState(null);
const Demo: React.FC = () => {
const [container, setContainer] = React.useState(null);
return (
<div className="scrollable-container" ref={setContainer}>
<div className="background">
Expand Down
2 changes: 1 addition & 1 deletion components/alert/demo/banner.md
Expand Up @@ -14,7 +14,7 @@ title:

Display Alert as a banner at top of page.

```jsx
```tsx
import { Alert } from 'antd';

ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion components/alert/demo/basic.md
Expand Up @@ -13,7 +13,7 @@ title:

The simplest usage for short messages.

```jsx
```tsx
import { Alert } from 'antd';

ReactDOM.render(<Alert message="Success Text" type="success" />, mountNode);
Expand Down
4 changes: 2 additions & 2 deletions components/alert/demo/closable.md
Expand Up @@ -13,10 +13,10 @@ title:

To show close button.

```jsx
```tsx
import { Alert } from 'antd';

const onClose = e => {
const onClose = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
console.log(e, 'I was closed.');
};

Expand Down
2 changes: 1 addition & 1 deletion components/alert/demo/close-text.md
Expand Up @@ -13,7 +13,7 @@ title:

Replace the default icon with customized text.

```jsx
```tsx
import { Alert } from 'antd';

ReactDOM.render(<Alert message="Info Text" type="info" closeText="Close Now" />, mountNode);
Expand Down
2 changes: 1 addition & 1 deletion components/alert/demo/custom-icon.md
Expand Up @@ -14,7 +14,7 @@ title:

A relevant icon makes information clearer and more friendly.

```jsx
```tsx
import { Alert } from 'antd';
import { SmileOutlined } from '@ant-design/icons';

Expand Down
2 changes: 1 addition & 1 deletion components/alert/demo/description.md
Expand Up @@ -13,7 +13,7 @@ title:

Additional description for alert message.

```jsx
```tsx
import { Alert } from 'antd';

ReactDOM.render(
Expand Down
35 changes: 13 additions & 22 deletions components/alert/demo/error-boundary.md
Expand Up @@ -13,34 +13,25 @@ title:

ErrorBoundary Component for making error handling easier in [React](https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html).

```jsx
```tsx
import { Button, Alert } from 'antd';

const { ErrorBoundary } = Alert;

class ThrowError extends React.Component {
state = {
error: null,
};

onClick = () => {
this.setState({
error: new Error('An Uncaught Error'),
});
const ThrowError: React.FC = () => {
const [error, setError] = React.useState<Error>();
const onClick = () => {
setError(new Error('An Uncaught Error'));
};

render() {
const { error } = this.state;
if (error) {
throw error;
}
return (
<Button type="danger" onClick={this.onClick}>
Click me to throw a error
</Button>
);
if (error) {
throw error;
}
}
return (
<Button type="danger" onClick={onClick}>
Click me to throw a error
</Button>
);
};

ReactDOM.render(
<ErrorBoundary>
Expand Down
2 changes: 1 addition & 1 deletion components/alert/demo/icon.md
Expand Up @@ -13,7 +13,7 @@ title:

A relevant icon will make information clearer and more friendly.

```jsx
```tsx
import { Alert } from 'antd';

ReactDOM.render(
Expand Down
39 changes: 14 additions & 25 deletions components/alert/demo/smooth-closed.md
Expand Up @@ -13,34 +13,23 @@ title:

Smoothly unmount Alert upon close.

```jsx
```tsx
import { Alert } from 'antd';

class App extends React.Component {
state = {
visible: true,
const App: React.FC = () => {
const [visible, setVisible] = React.useState(true);
const handleClose = () => {
setVisible(false);
};

handleClose = () => {
this.setState({ visible: false });
};

render() {
return (
<div>
{this.state.visible ? (
<Alert
message="Alert Message Text"
type="success"
closable
afterClose={this.handleClose}
/>
) : null}
<p>placeholder text here</p>
</div>
);
}
}
return (
<div>
{visible ? (
<Alert message="Alert Message Text" type="success" closable afterClose={handleClose} />
) : null}
<p>placeholder text here</p>
</div>
);
};

ReactDOM.render(<App />, mountNode);
```
2 changes: 1 addition & 1 deletion components/alert/demo/style.md
Expand Up @@ -13,7 +13,7 @@ title:

There are 4 types of Alert: `success`, `info`, `warning`, `error`.

```jsx
```tsx
import { Alert } from 'antd';

ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion components/anchor/demo/basic.md
Expand Up @@ -13,7 +13,7 @@ title:

The simplest usage.

```jsx
```tsx
import { Anchor } from 'antd';

const { Link } = Anchor;
Expand Down
2 changes: 1 addition & 1 deletion components/anchor/demo/customizeHighlight.md
Expand Up @@ -13,7 +13,7 @@ title:

Customize the anchor highlight.

```jsx
```tsx
import { Anchor } from 'antd';

const { Link } = Anchor;
Expand Down
4 changes: 2 additions & 2 deletions components/anchor/demo/onChange.md
Expand Up @@ -13,12 +13,12 @@ title:

Listening for anchor link change.

```jsx
```tsx
import { Anchor } from 'antd';

const { Link } = Anchor;

const onChange = link => {
const onChange = (link: string) => {
console.log('Anchor:OnChange', link);
};

Expand Down
14 changes: 10 additions & 4 deletions components/anchor/demo/onClick.md
Expand Up @@ -13,14 +13,20 @@ title:

Clicking on an anchor does not record history.

```jsx
```tsx
import { Anchor } from 'antd';

const { Link } = Anchor;

const handleClick = (e, link) => {
e.preventDefault();
console.log(link);
const handleClick = (
e: React.MouseEvent<HTMLElement>,
link: {
title: React.ReactNode;
href: string;
},
) => {
e.preventDefault();
console.log(link);
};

ReactDOM.render(
Expand Down
2 changes: 1 addition & 1 deletion components/anchor/demo/static.md
Expand Up @@ -13,7 +13,7 @@ title:

Do not change state when page is scrolling.

```jsx
```tsx
import { Anchor } from 'antd';

const { Link } = Anchor;
Expand Down
42 changes: 17 additions & 25 deletions components/anchor/demo/targetOffset.md
Expand Up @@ -13,35 +13,27 @@ title:

Anchor target scroll to screen center.

```jsx
```tsx
import { Anchor } from 'antd';

const { Link } = Anchor;

class AnchorExample extends React.Component {
state = {
targetOffset: undefined,
};

componentDidMount() {
this.setState({
targetOffset: window.innerHeight / 2,
});
}

render() {
return (
<Anchor targetOffset={this.state.targetOffset}>
<Link href="#components-anchor-demo-basic" title="Basic demo" />
<Link href="#components-anchor-demo-static" title="Static demo" />
<Link href="#API" title="API">
<Link href="#Anchor-Props" title="Anchor Props" />
<Link href="#Link-Props" title="Link Props" />
</Link>
</Anchor>
);
}
}
const AnchorExample: React.FC = () => {
const [targetOffset, setTargetOffset] = React.useState<number | undefined>(undefined);
React.useEffect(() => {
setTargetOffset(window.innerHeight / 2);
}, []);
return (
<Anchor targetOffset={targetOffset}>
<Link href="#components-anchor-demo-basic" title="Basic demo" />
<Link href="#components-anchor-demo-static" title="Static demo" />
<Link href="#API" title="API">
<Link href="#Anchor-Props" title="Anchor Props" />
<Link href="#Link-Props" title="Link Props" />
</Link>
</Anchor>
);
};

ReactDOM.render(<AnchorExample />, mountNode);
```