Skip to content

Commit

Permalink
feat: layout token (ant-design#44174)
Browse files Browse the repository at this point in the history
* feat: layout token

* feat: layout component token
  • Loading branch information
MadCcc authored Aug 11, 2023
1 parent 1c1ebbe commit a5203eb
Show file tree
Hide file tree
Showing 10 changed files with 1,535 additions and 68 deletions.
959 changes: 959 additions & 0 deletions components/layout/__tests__/__snapshots__/demo-extend.test.ts.snap

Large diffs are not rendered by default.

273 changes: 273 additions & 0 deletions components/layout/__tests__/__snapshots__/demo.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,279 @@ exports[`renders components/layout/demo/basic.tsx correctly 1`] = `
</div>
`;

exports[`renders components/layout/demo/component-token.tsx correctly 1`] = `
<div
class="ant-layout"
>
<header
class="ant-layout-header"
style="display:flex;align-items:center"
>
<div
class="demo-logo"
/>
<div
style="margin-left:24px;font-size:24px"
>
Ant Design
</div>
</header>
<div
class="ant-layout"
>
<aside
class="ant-layout-sider ant-layout-sider-dark"
style="background:#ffffff;flex:0 0 200px;max-width:200px;min-width:200px;width:200px"
>
<div
class="ant-layout-sider-children"
>
<ul
class="ant-menu ant-menu-root ant-menu-inline ant-menu-light"
data-menu-list="true"
role="menu"
style="height:100%;border-right:0"
tabindex="0"
>
<li
class="ant-menu-submenu ant-menu-submenu-inline ant-menu-submenu-open"
role="none"
>
<div
aria-expanded="true"
aria-haspopup="true"
class="ant-menu-submenu-title"
role="menuitem"
style="padding-left:24px"
tabindex="-1"
>
<span
aria-label="user"
class="anticon anticon-user ant-menu-item-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="user"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M858.5 763.6a374 374 0 00-80.6-119.5 375.63 375.63 0 00-119.5-80.6c-.4-.2-.8-.3-1.2-.5C719.5 518 760 444.7 760 362c0-137-111-248-248-248S264 225 264 362c0 82.7 40.5 156 102.8 201.1-.4.2-.8.3-1.2.5-44.8 18.9-85 46-119.5 80.6a375.63 375.63 0 00-80.6 119.5A371.7 371.7 0 00136 901.8a8 8 0 008 8.2h60c4.4 0 7.9-3.5 8-7.8 2-77.2 33-149.5 87.8-204.3 56.7-56.7 132-87.9 212.2-87.9s155.5 31.2 212.2 87.9C779 752.7 810 825 812 902.2c.1 4.4 3.6 7.8 8 7.8h60a8 8 0 008-8.2c-1-47.8-10.9-94.3-29.5-138.2zM512 534c-45.9 0-89.1-17.9-121.6-50.4S340 407.9 340 362c0-45.9 17.9-89.1 50.4-121.6S466.1 190 512 190s89.1 17.9 121.6 50.4S684 316.1 684 362c0 45.9-17.9 89.1-50.4 121.6S557.9 534 512 534z"
/>
</svg>
</span>
<span
class="ant-menu-title-content"
>
subnav 1
</span>
<i
class="ant-menu-submenu-arrow"
/>
</div>
<ul
class="ant-menu ant-menu-sub ant-menu-inline"
data-menu-list="true"
role="menu"
>
<li
class="ant-menu-item ant-menu-item-selected ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
tabindex="-1"
>
<span
class="ant-menu-title-content"
>
option1
</span>
</li>
<li
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
tabindex="-1"
>
<span
class="ant-menu-title-content"
>
option2
</span>
</li>
<li
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
tabindex="-1"
>
<span
class="ant-menu-title-content"
>
option3
</span>
</li>
<li
class="ant-menu-item ant-menu-item-only-child"
role="menuitem"
style="padding-left:48px"
tabindex="-1"
>
<span
class="ant-menu-title-content"
>
option4
</span>
</li>
</ul>
</li>
<li
class="ant-menu-submenu ant-menu-submenu-inline"
role="none"
>
<div
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
role="menuitem"
style="padding-left:24px"
tabindex="-1"
>
<span
aria-label="laptop"
class="anticon anticon-laptop ant-menu-item-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="laptop"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M956.9 845.1L896.4 632V168c0-17.7-14.3-32-32-32h-704c-17.7 0-32 14.3-32 32v464L67.9 845.1C60.4 866 75.8 888 98 888h828.8c22.2 0 37.6-22 30.1-42.9zM200.4 208h624v395h-624V208zm228.3 608l8.1-37h150.3l8.1 37H428.7zm224 0l-19.1-86.7c-.8-3.7-4.1-6.3-7.8-6.3H398.2c-3.8 0-7 2.6-7.8 6.3L371.3 816H151l42.3-149h638.2l42.3 149H652.7z"
/>
</svg>
</span>
<span
class="ant-menu-title-content"
>
subnav 2
</span>
<i
class="ant-menu-submenu-arrow"
/>
</div>
</li>
<li
class="ant-menu-submenu ant-menu-submenu-inline"
role="none"
>
<div
aria-expanded="false"
aria-haspopup="true"
class="ant-menu-submenu-title"
role="menuitem"
style="padding-left:24px"
tabindex="-1"
>
<span
aria-label="notification"
class="anticon anticon-notification ant-menu-item-icon"
role="img"
>
<svg
aria-hidden="true"
data-icon="notification"
fill="currentColor"
focusable="false"
height="1em"
viewBox="64 64 896 896"
width="1em"
>
<path
d="M880 112c-3.8 0-7.7.7-11.6 2.3L292 345.9H128c-8.8 0-16 7.4-16 16.6v299c0 9.2 7.2 16.6 16 16.6h101.7c-3.7 11.6-5.7 23.9-5.7 36.4 0 65.9 53.8 119.5 120 119.5 55.4 0 102.1-37.6 115.9-88.4l408.6 164.2c3.9 1.5 7.8 2.3 11.6 2.3 16.9 0 32-14.2 32-33.2V145.2C912 126.2 897 112 880 112zM344 762.3c-26.5 0-48-21.4-48-47.8 0-11.2 3.9-21.9 11-30.4l84.9 34.1c-2 24.6-22.7 44.1-47.9 44.1zm496 58.4L318.8 611.3l-12.9-5.2H184V417.9h121.9l12.9-5.2L840 203.3v617.4z"
/>
</svg>
</span>
<span
class="ant-menu-title-content"
>
subnav 3
</span>
<i
class="ant-menu-submenu-arrow"
/>
</div>
</li>
</ul>
<div
aria-hidden="true"
style="display:none"
/>
</div>
</aside>
<div
class="ant-layout"
style="padding:0 24px 24px"
>
<nav
class="ant-breadcrumb"
style="margin:16px 0"
>
<ol>
<li>
<span
class="ant-breadcrumb-link"
>
Home
</span>
</li>
<li
aria-hidden="true"
class="ant-breadcrumb-separator"
>
/
</li>
<li>
<span
class="ant-breadcrumb-link"
>
List
</span>
</li>
<li
aria-hidden="true"
class="ant-breadcrumb-separator"
>
/
</li>
<li>
<span
class="ant-breadcrumb-link"
>
App
</span>
</li>
</ol>
</nav>
<main
class="ant-layout-content"
style="padding:24px;margin:0;min-height:280px;background:#ffffff"
>
Content
</main>
</div>
</div>
</div>
`;

exports[`renders components/layout/demo/custom-trigger.tsx correctly 1`] = `
<div
class="ant-layout"
Expand Down
7 changes: 7 additions & 0 deletions components/layout/demo/component-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## zh-CN

组件 Token

## en-US

Component Token
86 changes: 86 additions & 0 deletions components/layout/demo/component-token.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from 'react';
import { LaptopOutlined, NotificationOutlined, UserOutlined } from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Breadcrumb, ConfigProvider, Layout, Menu, theme } from 'antd';

const { Header, Content, Sider } = Layout;

const items2: MenuProps['items'] = [UserOutlined, LaptopOutlined, NotificationOutlined].map(
(icon, index) => {
const key = String(index + 1);

return {
key: `sub${key}`,
icon: React.createElement(icon),
label: `subnav ${key}`,

children: new Array(4).fill(null).map((_, j) => {
const subKey = index * 4 + j + 1;
return {
key: subKey,
label: `option${subKey}`,
};
}),
};
},
);

const App: React.FC = () => {
const {
token: { colorBgContainer },
} = theme.useToken();

return (
<ConfigProvider
theme={{
components: {
Layout: {
bodyBg: '#fff',
headerBg: '#1677ff',
headerHeight: 64,
headerPadding: `0 24px`,
headerColor: '#fff',
siderBg: '#fff',
},
},
}}
>
<Layout>
<Header style={{ display: 'flex', alignItems: 'center' }}>
<div className="demo-logo" />
<div style={{ marginLeft: 24, fontSize: 24 }}>Ant Design</div>
</Header>
<Layout>
<Sider width={200} style={{ background: colorBgContainer }}>
<Menu
mode="inline"
defaultSelectedKeys={['1']}
defaultOpenKeys={['sub1']}
style={{ height: '100%', borderRight: 0 }}
items={items2}
/>
</Sider>
<Layout style={{ padding: '0 24px 24px' }}>
<Breadcrumb style={{ margin: '16px 0' }}>
<Breadcrumb.Item>Home</Breadcrumb.Item>
<Breadcrumb.Item>List</Breadcrumb.Item>
<Breadcrumb.Item>App</Breadcrumb.Item>
</Breadcrumb>
<Content
style={{
padding: 24,
margin: 0,
minHeight: 280,
background: colorBgContainer,
}}
>
Content
</Content>
</Layout>
</Layout>
</Layout>
</ConfigProvider>
);
};

export default App;
1 change: 1 addition & 0 deletions components/layout/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ Style of a navigation should conform to its level.
<code src="./demo/fixed.tsx" iframe="360">Fixed Header</code>
<code src="./demo/fixed-sider.tsx" iframe="360">Fixed Sider</code>
<code src="./demo/custom-trigger-debug.tsx" compact background="grey" debug>Custom trigger debug</code>
<code src="./demo/component-token.tsx" compact background="grey" debug>Component Token</code>

## API

Expand Down
1 change: 1 addition & 0 deletions components/layout/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*HdS6Q5vUCDcAAA
<code src="./demo/fixed.tsx" iframe="360">固定头部</code>
<code src="./demo/fixed-sider.tsx" iframe="360">固定侧边栏</code>
<code src="./demo/custom-trigger-debug.tsx" compact background="grey" debug>自定义触发器 Debug</code>
<code src="./demo/component-token.tsx" compact background="grey" debug>组件 Token</code>

## API

Expand Down
Loading

0 comments on commit a5203eb

Please sign in to comment.