first commit

pull/47/head
孙飞 5 years ago
commit 1773661f92

@ -0,0 +1,11 @@
{
"presets": ["next/babel"],
"plugins": [
[
"import", {
"libraryName": "antd",
"style": true
}
]
]
}

25
.gitignore vendored

@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# next.js
/.next/
/out/
# production
/build
# misc
.DS_Store
.env*
# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

@ -0,0 +1,6 @@
<p align="center">
<img alt="Sloan, the sloth mascot" width="250px" src="https://thepracticaldev.s3.amazonaws.com/uploads/user/profile_image/31047/af153cd6-9994-4a68-83f4-8ddf3e13f0bf.jpg">
<br>
<strong>Be A Happy Dev</strong> ❤️
</p>

@ -0,0 +1,230 @@
import React, { useState, useEffect } from "react";
//
import Link from "next/link";
import { useRouter } from "next/router";
//
import {
useWindowSize,
useWindowWidth,
useWindowHeight
} from "@react-hook/window-size";
//
import { Layout, Menu, Switch } from "antd";
import {
HomeOutlined,
AppstoreOutlined,
BarChartOutlined,
CloudOutlined,
ShopOutlined,
TeamOutlined,
UserOutlined,
UploadOutlined,
VideoCameraOutlined
} from "@ant-design/icons";
//
import { Input } from "antd";
//
//
//
//
const { Search } = Input;
//
const { Header, Content, Footer, Sider } = Layout;
const AppLayout = props => {
const [siderKey, setSiderKey] = useState("");
const [isSiderCollapsed, setSiderCollapsed] = useState(false);
const [window, setWindow] = useState({ width: -1, height: -1 });
const [width, height] = useWindowSize();
useEffect(() => {
setWindow({ width: width, height: height });
return () => {
// cleanup
};
}, [width, height]);
const router = useRouter();
useEffect(() => {
console.log(siderKey);
return () => {
// cleanup
};
}, [siderKey]);
useEffect(() => {
console.log("useEffect fired by useRouter");
const urlPath = router.pathname;
switch (urlPath) {
case "/":
setSiderKey(0);
break;
case "/profile":
setSiderKey(1);
break;
case "/videos":
setSiderKey(2);
break;
case "/backup":
setSiderKey(3);
break;
case "/analytics":
setSiderKey(4);
break;
}
return () => {
// cleanup
};
}, [router]);
const contentStyleWidth =
// responsive design
window.width < 480 ? { width: "calc(100vw - 32px)" } : {};
return (
<Layout>
<Sider
collapsible
breakpoint="lg"
collapsedWidth={window.width > 480 ? "80" : "0"} // enable responsive hidden sider for mobile only
onBreakpoint={broken => {
console.log(broken);
}}
collapsed={isSiderCollapsed}
onCollapse={(collapsed, type) => {
setSiderCollapsed(collapsed);
console.log(collapsed, type);
}}
>
<div
className="logo"
style={{
height: 64,
width: "100%",
display: "flex",
justifyContent: "center",
alignItems: "center",
color: "white",
whiteSpace: "nowrap"
}}
>
Sider Logo
</div>
<Menu theme="dark" mode="inline" selectedKeys={[siderKey.toString()]}>
<Menu.Item key="0">
<Link href="/">
<div>
<HomeOutlined />
<span className="nav-text">Home</span>
</div>
</Link>
</Menu.Item>
<Menu.Item key="1">
<Link href="/profile">
<div>
<UserOutlined />
<span className="nav-text">Profile</span>
</div>
</Link>
</Menu.Item>
<Menu.Item key="2">
<Link href="/videos">
<div>
<VideoCameraOutlined />
<span className="nav-text">Videos</span>
</div>
</Link>
</Menu.Item>
<Menu.Item key="3">
<Link href="/backup">
<div>
<UploadOutlined />
<span className="nav-text">Backup</span>
</div>
</Link>
</Menu.Item>
<Menu.Item key="4">
<Link href="/analytics">
<div>
<BarChartOutlined />
<span className="nav-text">Analytics</span>
</div>
</Link>
</Menu.Item>
<Menu.Item key="5">
<CloudOutlined />
<span className="nav-text">Cloud</span>
</Menu.Item>
<Menu.Item key="6">
<AppstoreOutlined />
<span className="nav-text">Apps</span>
</Menu.Item>
<Menu.Item key="7">
<TeamOutlined />
<span className="nav-text">Collaborate</span>
</Menu.Item>
<Menu.Item key="8">
<ShopOutlined />
<span className="nav-text">Shop</span>
</Menu.Item>
</Menu>
</Sider>
<Layout className="site-layout">
<Header
className={"site-layout-sub-header-background"}
style={{ padding: 0 }}
>
<div
className="logo"
style={{
height: 64,
color: "white",
textAlign: "center"
}}
>
Main Logo
</div>
</Header>
<Content // you may want to change these
style={{
...contentStyleWidth,
margin: "24px 16px 0",
overflow: "initial"
}}
>
<div
className="site-layout-background"
style={{
padding: 24,
textAlign: "center",
minHeight: "calc(100vh - 158px)"
}}
>
{props.children}
</div>
</Content>
<Footer style={{ ...contentStyleWidth, textAlign: "center" }}>
Footer Text
{/* <p>
width: {window.width}, height: {window.height}
</p> */}
</Footer>
</Layout>
</Layout>
);
};
export default AppLayout;

2
next-env.d.ts vendored

@ -0,0 +1,2 @@
/// <reference types="next" />
/// <reference types="next/types/global" />

@ -0,0 +1,40 @@
/* eslint-disable */
const withLess = require('@zeit/next-less')
const lessToJS = require('less-vars-to-js')
const fs = require('fs')
const path = require('path')
// Where your antd-custom.less file lives
const themeVariables = lessToJS(
fs.readFileSync(path.resolve(__dirname, './styles/antd-override.less'), 'utf8')
)
module.exports = withLess({
lessLoaderOptions: {
javascriptEnabled: true,
modifyVars: themeVariables, // make your antd custom effective
},
webpack: (config, { isServer }) => {
if (isServer) {
const antStyles = /antd\/.*?\/style.*?/
const origExternals = [...config.externals]
config.externals = [
(context, request, callback) => {
if (request.match(antStyles)) return callback()
if (typeof origExternals[0] === 'function') {
origExternals[0](context, request, callback)
} else {
callback()
}
},
...(typeof origExternals[0] === 'function' ? [] : origExternals),
]
config.module.rules.unshift({
test: antStyles,
use: 'null-loader',
})
}
return config
},
})

@ -0,0 +1,27 @@
{
"name": "next-with-ant-design-less",
"version": "1.0.0",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
"dependencies": {
"@react-hook/window-size": "^1.0.13",
"@zeit/next-less": "^1.0.1",
"antd": "4.6.5",
"babel-plugin-import": "^1.13.0",
"less": "3.11.1",
"less-vars-to-js": "1.3.0",
"next": "9.5.3",
"null-loader": "3.0.0",
"react": "^16.13.1",
"react-dom": "^16.13.1"
},
"license": "ISC",
"devDependencies": {
"@types/node": "^14.11.1",
"@types/react": "^16.9.49",
"typescript": "^4.0.3"
}
}

@ -0,0 +1,13 @@
import React from "react";
import AppLayout from "../components/AppLayout";
const analytics = props => {
return (
<AppLayout>
<div>Analytics Page</div>
</AppLayout>
);
};
export default analytics;

@ -0,0 +1,13 @@
import React from "react";
import AppLayout from "../components/AppLayout";
const backup = props => {
return (
<AppLayout>
<div>Backup Page</div>
</AppLayout>
);
};
export default backup;

@ -0,0 +1,3 @@
.main-card {
margin-left: 100px
}

@ -0,0 +1,73 @@
// core
import React from "react";
// antd
import { Typography, Divider, Button, Card } from "antd";
const { Title, Text } = Typography;
// components
import AppLayout from "../components/AppLayout";
import { T } from "antd/lib/upload/utils";
import './index.less'
const App = () => (
<AppLayout>
<div>Home Page</div>
<Title>Nextjs with Ant Design & Less</Title>
<Text>
Go ahead and edit <code>/pages/index.js</code>, and see your changes here
</Text>
<Divider />
<Title level={2}>Useful Links</Title>
<Button
href="https://nextjs.org/learn/basics/getting-started"
target="__blank"
>
Next.js Learn
</Button>
<Button href="https://nextjs.org/docs/getting-started" target="__blank">
Next.js Docs
</Button>
<Button href="https://ant.design/components/button/" target="__blank">
antd Docs
</Button>
<Divider />
<div style={{ textAlign: "start" }}>
<Card className="main-card">
<Title level={2}>Quick Recap:</Title>
<Title level={4}>Shared App Layout</Title>
<Text>
Shared/Common App Layout is located at{" "}
<code>/components/AppLayout</code>
</Text>
<br />
<Text>Sider/sidebar, header and footer are all in this file.</Text>
<br />
<br />
<Title level={4}>antd Less</Title>
<Text>
antd's Less file is present at <code>/assets/antd-custom.less</code>
</Text>
<br />
<Text>
Head over to{" "}
<a
href="https://github.com/ant-design/ant-design/blob/master/components/style/themes/default.less"
target="__blank"
>
antd's theming docs
</a>{" "}
for a list of less variables.
</Text>
<br />
<Text>
If you dont wish to mess around with Less, just delete everything in
the less file.
</Text>
</Card>
</div>
</AppLayout>
);
export default App;

@ -0,0 +1,15 @@
import React from "react";
import AppLayout from "../components/AppLayout";
import { Switch } from "antd";
const profile = props => {
return (
<AppLayout>
<div>Profile Page</div>
</AppLayout>
);
};
export default profile;

@ -0,0 +1,13 @@
import React from "react";
import AppLayout from "../components/AppLayout";
const videos = props => {
return (
<AppLayout>
<div>Videos Page</div>
</AppLayout>
);
};
export default videos;

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -0,0 +1,4 @@
<svg width="283" height="64" viewBox="0 0 283 64" fill="none"
xmlns="http://www.w3.org/2000/svg">
<path d="M141.04 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.46 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM248.72 16c-11.04 0-19 7.2-19 18s8.96 18 20 18c6.67 0 12.55-2.64 16.19-7.09l-7.65-4.42c-2.02 2.21-5.09 3.5-8.54 3.5-4.79 0-8.86-2.5-10.37-6.5h28.02c.22-1.12.35-2.28.35-3.5 0-10.79-7.96-17.99-19-17.99zm-9.45 14.5c1.25-3.99 4.67-6.5 9.45-6.5 4.79 0 8.21 2.51 9.45 6.5h-18.9zM200.24 34c0 6 3.92 10 10 10 4.12 0 7.21-1.87 8.8-4.92l7.68 4.43c-3.18 5.3-9.14 8.49-16.48 8.49-11.05 0-19-7.2-19-18s7.96-18 19-18c7.34 0 13.29 3.19 16.48 8.49l-7.68 4.43c-1.59-3.05-4.68-4.92-8.8-4.92-6.07 0-10 4-10 10zm82.48-29v46h-9V5h9zM36.95 0L73.9 64H0L36.95 0zm92.38 5l-27.71 48L73.91 5H84.3l17.32 30 17.32-30h10.39zm58.91 12v9.69c-1-.29-2.06-.49-3.2-.49-5.81 0-10 4-10 10V51h-9V17h9v9.2c0-5.08 5.91-9.2 13.2-9.2z" fill="#000"/>
</svg>

After

Width:  |  Height:  |  Size: 1.1 KiB

@ -0,0 +1,5 @@
@import "../color/colors";
@primary-color: #1da57a;
@layout-header-height: 64px;

@ -0,0 +1,29 @@
{
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"strict": false,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve"
},
"include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"node_modules"
]
}

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save