|
1 | | -react-monorepo-template |
| 1 | +Layout |
2 | 2 | === |
3 | 3 |
|
4 | | -Simple [React](https://github.com/facebook/react) package development project example template. |
5 | | - |
6 | | -## Directory Structure |
7 | | - |
8 | | -```bash |
9 | | -├── LICENSE |
10 | | -├── README.md -> core/README.md |
11 | | -├── core # 📦 package @uiw/react-monorepo-template |
12 | | -│ ├── README.md |
13 | | -│ ├── cjs # 🔄 Compiled cjs directory |
14 | | -│ ├── esm # 🔄 Compiled esm directory |
15 | | -│ ├── src # Package source directory |
16 | | -│ ├── dist.css # 🔄 compile less to css |
17 | | -│ ├── package.json # name => @uiw/react-monorepo-template |
18 | | -│ └── tsconfig.json |
19 | | -├── lerna.json |
20 | | -├── package.json |
21 | | -├── tsconfig.json |
22 | | -├── test # ⛑ test case |
23 | | -└── website # 🐝 Package example test, website |
24 | | - ├── README.md |
25 | | - ├── package.json |
26 | | - ├── public |
27 | | - ├── src |
28 | | - └── tsconfig.json |
29 | | -``` |
30 | | - |
31 | | -## Development |
| 4 | +Handling the overall layout of a page. |
32 | 5 |
|
33 | | -1. Install |
| 6 | +> ⚠️ Note: Implemented with flex layout, please pay attention to [browser compatibility](http://caniuse.com/#search=flex) issues. |
| 7 | +<!--rehype:style=border-left: 8px solid #ffe564;background-color: #ffe56440;padding: 12px 16px;--> |
34 | 8 |
|
35 | | -```bash |
36 | | -npm install |
| 9 | +<!--rehype--> |
| 10 | +```jsx |
| 11 | +import { Layout } from 'uiw'; |
| 12 | +// or |
| 13 | +import Layout from '@uiw/react-layout'; |
| 14 | +const { Header, Footer, Sider, Content } = Layout; |
37 | 15 | ``` |
38 | 16 |
|
39 | | -2. Dependencies in the installation package and example |
40 | | - |
41 | | -```bash |
42 | | -npm run hoist |
| 17 | +## Basic Usage |
| 18 | + |
| 19 | +<!--rehype:bgWhite=true&codeSandbox=true&codePen=true&noScroll=true--> |
| 20 | +```jsx |
| 21 | +import React from 'react'; |
| 22 | +import ReactDOM from 'react-dom'; |
| 23 | +import { Layout } from '@uiw/react-layout'; |
| 24 | +const { Header, Footer, Sider, Content } = Layout; |
| 25 | + |
| 26 | +const stylHeader = { color: '#fff' } |
| 27 | +const stylSider = { background: '#484a4e', color: '#fff', lineHeight: `120px`, textAlign: 'center' } |
| 28 | +const stylConten = { textAlign: 'center', background: 'rgba(16, 142, 233, 1)', minHeight: 120, lineHeight: '120px', color: '#fff' } |
| 29 | + |
| 30 | +function Demo() { |
| 31 | + const [collapsed, setCollapsed] = React.useState(false) |
| 32 | + return ( |
| 33 | + <div> |
| 34 | + <Layout style={{ marginBottom: 20 }}> |
| 35 | + <Sider collapsed={collapsed} style={stylSider}>Sider</Sider> |
| 36 | + <Layout> |
| 37 | + <Header style={stylHeader}> |
| 38 | + <button onClick={() => setCollapsed(!collapsed)}>{collapsed ? '>>' : '<<'}</button> |
| 39 | + </Header> |
| 40 | + <Content style={stylConten}>Content</Content> |
| 41 | + <Footer>Footer</Footer> |
| 42 | + </Layout> |
| 43 | + </Layout> |
| 44 | + |
| 45 | + <Layout style={{ marginBottom: 20 }}> |
| 46 | + <Header style={stylHeader}>Header</Header> |
| 47 | + <Content style={stylConten}>Content</Content> |
| 48 | + <Footer>Footer</Footer> |
| 49 | + </Layout> |
| 50 | + |
| 51 | + <Layout style={{ marginBottom: 20 }}> |
| 52 | + <Header style={stylHeader}>Header</Header> |
| 53 | + <Layout> |
| 54 | + <Sider style={stylSider}>Sider</Sider> |
| 55 | + <Content style={stylConten}>Content</Content> |
| 56 | + </Layout> |
| 57 | + <Footer>Footer</Footer> |
| 58 | + </Layout> |
| 59 | + |
| 60 | + <Layout> |
| 61 | + <Header style={stylHeader}>Header</Header> |
| 62 | + <Layout> |
| 63 | + <Content style={stylConten}>Content</Content> |
| 64 | + <Sider style={stylSider}>Sider</Sider> |
| 65 | + </Layout> |
| 66 | + <Footer>Footer</Footer> |
| 67 | + </Layout> |
| 68 | + </div> |
| 69 | + ); |
| 70 | +} |
| 71 | + |
| 72 | +ReactDOM.render(<Demo />, _mount_); |
43 | 73 | ``` |
44 | 74 |
|
45 | | -3. To develop, run the self-reloading build: |
46 | | - |
47 | | -```bash |
48 | | -npm run build # Compile packages 📦 @uiw/react-monorepo-template |
49 | | -npm run watch # Real-time compilation 📦 @uiw/react-monorepo-template |
50 | | -``` |
| 75 | +## Layout |
51 | 76 |
|
52 | | -4. Run Document Website Environment: |
| 77 | +布局容器,其下可嵌套 `Header` `Sider` `Content` `Footer` 或 `Layout` 本身,可以放在任何父容器中。 |
53 | 78 |
|
54 | | -```bash |
55 | | -npm run start |
56 | | -``` |
| 79 | +* `Header`:顶部布局,自带默认样式,其下可嵌套任何元素,只能放在 `Layout` 中。 |
| 80 | +* `Sider`:侧边栏,自带默认样式及基本功能,其下可嵌套任何元素,只能放在 `Layout` 中。 |
| 81 | +* `Content`:内容部分,自带默认样式,其下可嵌套任何元素,只能放在 `Layout` 中。 |
| 82 | +* `Footer`:底部布局,自带默认样式,其下可嵌套任何元素,只能放在 `Layout` 中。 |
57 | 83 |
|
58 | | -5. To contribute, please fork repos, add your patch and tests for it (in the `test/` folder) and submit a pull request. |
| 84 | +| 参数 | 说明 | 类型 | 默认值 | |
| 85 | +|--------- |-------- |--------- |-------- | |
| 86 | +| className | 容器 className | string | - | |
| 87 | +| style | 指定样式 | CSSProperties | - | |
| 88 | +| theme | 主题颜色 | `light`、`dark` | `dark` | |
| 89 | +| hasSider | 表示子元素里有 Sider,一般不用指定。可用于服务端渲染时避免样式闪动 | boolean | - | |
59 | 90 |
|
60 | | -``` |
61 | | -npm run test |
62 | | -``` |
| 91 | +## Layout.Sider |
63 | 92 |
|
64 | | -## License |
| 93 | +| 参数 | 说明 | 类型 | 默认值 | |
| 94 | +|--------- |-------- |--------- |-------- | |
| 95 | +| className | 容器 className | string | - | |
| 96 | +| style | 指定样式 | CSSProperties | - | |
| 97 | +| collapsed | 当前收起状态 | boolean | - | |
| 98 | +| collapsedWidth | 收缩宽度,设置为 `0` | boolean | `80` | |
| 99 | +| width | 宽度 | number/string | 200 | |
65 | 100 |
|
66 | | -Licensed under the MIT License. |
|
0 commit comments