Skip to content

Commit 0febcc3

Browse files
Add TypeScript to ant design example (#38470)
## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [x] Make sure the linting passes by running `pnpm lint` - [x] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Balázs Orbán <[email protected]>
1 parent 147a24e commit 0febcc3

File tree

8 files changed

+133
-135
lines changed

8 files changed

+133
-135
lines changed

examples/with-ant-design/components/DatePicker.js

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/// <reference types="next" />
2+
/// <reference types="next/image-types/global" />
3+
4+
// NOTE: This file should not be edited
5+
// see https://nextjs.org/docs/basic-features/typescript for more information.
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
const withBundleAnalyzer = require('@next/bundle-analyzer')({
2-
enabled: process.env.ANALYZE === 'true',
3-
})
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
reactStrictMode: true,
4+
swcMinify: true,
5+
}
46

5-
module.exports = withBundleAnalyzer()
7+
module.exports = nextConfig

examples/with-ant-design/package.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,23 @@
33
"scripts": {
44
"dev": "next",
55
"build": "next build",
6-
"start": "next start",
7-
"analyze": "cross-env ANALYZE=true next build"
6+
"start": "next start"
87
},
98
"dependencies": {
10-
"@ant-design/icons": "4.2.1",
11-
"@next/bundle-analyzer": "^9.1.4",
12-
"antd": "4.3.0",
13-
"cross-env": "^7.0.2",
14-
"dayjs": "1.8.28",
15-
"esm": "^3.2.25",
9+
"@ant-design/icons": "^4.7.0",
10+
"antd": "^4.21.5",
1611
"next": "latest",
17-
"postcss-preset-env": "^6.7.0",
18-
"react": "^17.0.2",
19-
"react-dom": "^17.0.2"
12+
"react": "18.2.0",
13+
"react-dom": "18.2.0"
2014
},
2115
"browser": {
2216
"fs": false,
2317
"path": false
2418
},
2519
"devDependencies": {
26-
"cross-env": "^7.0.3"
20+
"@types/node": "18.0.3",
21+
"@types/react": "18.0.15",
22+
"@types/react-dom": "18.0.6",
23+
"typescript": "4.7.4"
2724
}
2825
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import type { AppProps } from 'next/app'
12
import 'antd/dist/antd.css'
23
import '../styles/vars.css'
34
import '../styles/global.css'
45

5-
export default function MyApp({ Component, pageProps }) {
6+
function MyApp({ Component, pageProps }: AppProps) {
67
return <Component {...pageProps} />
78
}
9+
10+
export default MyApp

examples/with-ant-design/pages/index.js

Lines changed: 0 additions & 104 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {
2+
Button,
3+
DatePicker,
4+
Form,
5+
InputNumber,
6+
Select,
7+
Slider,
8+
Switch,
9+
} from 'antd'
10+
import type { DatePickerProps } from 'antd'
11+
import { SmileFilled } from '@ant-design/icons'
12+
import Link from 'next/link'
13+
14+
const FormItem = Form.Item
15+
const Option = Select.Option
16+
17+
const content = {
18+
marginTop: '100px',
19+
}
20+
21+
export default function Home() {
22+
const onDatePickerChange: DatePickerProps['onChange'] = (
23+
date,
24+
dateString
25+
) => {
26+
console.log(date, dateString)
27+
}
28+
29+
return (
30+
<div style={content}>
31+
<div className="text-center mb-5">
32+
<Link href="#">
33+
<a className="logo mr-0">
34+
<SmileFilled style={{ fontSize: 48 }} />
35+
</a>
36+
</Link>
37+
38+
<p className="mb-0 mt-3 text-disabled">Welcome to the world !</p>
39+
</div>
40+
<div>
41+
<Form
42+
layout="horizontal"
43+
size={'large'}
44+
labelCol={{ span: 8 }}
45+
wrapperCol={{ span: 8 }}
46+
>
47+
<FormItem label="Input Number">
48+
<InputNumber
49+
min={1}
50+
max={10}
51+
style={{ width: 100 }}
52+
defaultValue={3}
53+
name="inputNumber"
54+
/>
55+
</FormItem>
56+
57+
<FormItem label="Switch">
58+
<Switch defaultChecked />
59+
</FormItem>
60+
61+
<FormItem label="Slider">
62+
<Slider defaultValue={70} />
63+
</FormItem>
64+
65+
<FormItem label="Select">
66+
<Select defaultValue="lucy" style={{ width: 192 }}>
67+
<Option value="jack">jack</Option>
68+
<Option value="lucy">lucy</Option>
69+
<Option value="disabled" disabled>
70+
disabled
71+
</Option>
72+
<Option value="yiminghe">yiminghe</Option>
73+
</Select>
74+
</FormItem>
75+
76+
<FormItem label="DatePicker">
77+
<DatePicker showTime onChange={onDatePickerChange} />
78+
</FormItem>
79+
<FormItem style={{ marginTop: 48 }} wrapperCol={{ offset: 8 }}>
80+
<Button type="primary" htmlType="submit">
81+
OK
82+
</Button>
83+
<Button style={{ marginLeft: 8 }}>Cancel</Button>
84+
</FormItem>
85+
</Form>
86+
</div>
87+
</div>
88+
)
89+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es5",
4+
"lib": ["dom", "dom.iterable", "esnext"],
5+
"allowJs": true,
6+
"skipLibCheck": true,
7+
"strict": true,
8+
"forceConsistentCasingInFileNames": true,
9+
"noEmit": true,
10+
"esModuleInterop": true,
11+
"module": "esnext",
12+
"moduleResolution": "node",
13+
"resolveJsonModule": true,
14+
"isolatedModules": true,
15+
"jsx": "preserve",
16+
"incremental": true
17+
},
18+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
19+
"exclude": ["node_modules"]
20+
}

0 commit comments

Comments
 (0)