Unverified Commit 0febcc37 authored by Cupid Valentine's avatar Cupid Valentine Committed by GitHub

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: 's avatarBalázs Orbán <18369201+balazsorban44@users.noreply.github.com>
parent 147a24e3
/**
* This example previously used antd-dayjs-webpack-plugin
* (https://github.com/ant-design/antd-dayjs-webpack-plugin) to attempt to
* replace Moment.js with Day.js, but it would crash the page when the user
* clicked on the DatePicker. Using this custom component (following Ant Design
* guidelines at https://ant.design/docs/react/replace-moment) instead of the
* webpack plugin fixes that bug.
*/
import dayjsGenerateConfig from 'rc-picker/lib/generate/dayjs'
import generatePicker from 'antd/lib/date-picker/generatePicker'
const DatePicker = generatePicker(dayjsGenerateConfig)
export default DatePicker
/// <reference types="next" />
/// <reference types="next/image-types/global" />
// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
const withBundleAnalyzer = require('@next/bundle-analyzer')({ /** @type {import('next').NextConfig} */
enabled: process.env.ANALYZE === 'true', const nextConfig = {
}) reactStrictMode: true,
swcMinify: true,
}
module.exports = withBundleAnalyzer() module.exports = nextConfig
...@@ -3,26 +3,23 @@ ...@@ -3,26 +3,23 @@
"scripts": { "scripts": {
"dev": "next", "dev": "next",
"build": "next build", "build": "next build",
"start": "next start", "start": "next start"
"analyze": "cross-env ANALYZE=true next build"
}, },
"dependencies": { "dependencies": {
"@ant-design/icons": "4.2.1", "@ant-design/icons": "^4.7.0",
"@next/bundle-analyzer": "^9.1.4", "antd": "^4.21.5",
"antd": "4.3.0",
"cross-env": "^7.0.2",
"dayjs": "1.8.28",
"esm": "^3.2.25",
"next": "latest", "next": "latest",
"postcss-preset-env": "^6.7.0", "react": "18.2.0",
"react": "^17.0.2", "react-dom": "18.2.0"
"react-dom": "^17.0.2"
}, },
"browser": { "browser": {
"fs": false, "fs": false,
"path": false "path": false
}, },
"devDependencies": { "devDependencies": {
"cross-env": "^7.0.3" "@types/node": "18.0.3",
"@types/react": "18.0.15",
"@types/react-dom": "18.0.6",
"typescript": "4.7.4"
} }
} }
import type { AppProps } from 'next/app'
import 'antd/dist/antd.css' import 'antd/dist/antd.css'
import '../styles/vars.css' import '../styles/vars.css'
import '../styles/global.css' import '../styles/global.css'
export default function MyApp({ Component, pageProps }) { function MyApp({ Component, pageProps }: AppProps) {
return <Component {...pageProps} /> return <Component {...pageProps} />
} }
export default MyApp
import { Form, Select, InputNumber, Switch, Slider, Button } from 'antd' import {
Button,
// Custom DatePicker that uses Day.js instead of Moment.js DatePicker,
import DatePicker from '../components/DatePicker' Form,
InputNumber,
Select,
Slider,
Switch,
} from 'antd'
import type { DatePickerProps } from 'antd'
import { SmileFilled } from '@ant-design/icons' import { SmileFilled } from '@ant-design/icons'
import Link from 'next/link' import Link from 'next/link'
const FormItem = Form.Item const FormItem = Form.Item
...@@ -15,26 +19,33 @@ const content = { ...@@ -15,26 +19,33 @@ const content = {
} }
export default function Home() { export default function Home() {
const onDatePickerChange: DatePickerProps['onChange'] = (
date,
dateString
) => {
console.log(date, dateString)
}
return ( return (
<div style={content}> <div style={content}>
<div className="text-center mb-5"> <div className="text-center mb-5">
<Link href="#"> <Link href="#">
<a className="logo mr-0"> <a className="logo mr-0">
<SmileFilled size={48} strokeWidth={1} /> <SmileFilled style={{ fontSize: 48 }} />
</a> </a>
</Link> </Link>
<p className="mb-0 mt-3 text-disabled">Welcome to the world !</p> <p className="mb-0 mt-3 text-disabled">Welcome to the world !</p>
</div> </div>
<div> <div>
<Form layout="horizontal"> <Form
<FormItem layout="horizontal"
label="Input Number" size={'large'}
labelCol={{ span: 8 }} labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }} wrapperCol={{ span: 8 }}
> >
<FormItem label="Input Number">
<InputNumber <InputNumber
size="large"
min={1} min={1}
max={10} max={10}
style={{ width: 100 }} style={{ width: 100 }}
...@@ -43,33 +54,16 @@ export default function Home() { ...@@ -43,33 +54,16 @@ export default function Home() {
/> />
</FormItem> </FormItem>
<FormItem <FormItem label="Switch">
label="Switch" <Switch defaultChecked />
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Switch defaultChecked name="switch" />
</FormItem> </FormItem>
<FormItem <FormItem label="Slider">
label="Slider"
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Slider defaultValue={70} /> <Slider defaultValue={70} />
</FormItem> </FormItem>
<FormItem <FormItem label="Select">
label="Select" <Select defaultValue="lucy" style={{ width: 192 }}>
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<Select
size="large"
defaultValue="lucy"
style={{ width: 192 }}
name="select"
>
<Option value="jack">jack</Option> <Option value="jack">jack</Option>
<Option value="lucy">lucy</Option> <Option value="lucy">lucy</Option>
<Option value="disabled" disabled> <Option value="disabled" disabled>
...@@ -79,23 +73,14 @@ export default function Home() { ...@@ -79,23 +73,14 @@ export default function Home() {
</Select> </Select>
</FormItem> </FormItem>
<FormItem <FormItem label="DatePicker">
label="DatePicker" <DatePicker showTime onChange={onDatePickerChange} />
labelCol={{ span: 8 }}
wrapperCol={{ span: 8 }}
>
<DatePicker name="startDate" />
</FormItem> </FormItem>
<FormItem <FormItem style={{ marginTop: 48 }} wrapperCol={{ offset: 8 }}>
style={{ marginTop: 48 }} <Button type="primary" htmlType="submit">
wrapperCol={{ span: 8, offset: 8 }}
>
<Button size="large" type="primary" htmlType="submit">
OK OK
</Button> </Button>
<Button size="large" style={{ marginLeft: 8 }}> <Button style={{ marginLeft: 8 }}>Cancel</Button>
Cancel
</Button>
</FormItem> </FormItem>
</Form> </Form>
</div> </div>
......
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules"]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment