site: optimize the website arrow style (#42591)

* fix

* fix

* fix

* update icon

* update
This commit is contained in:
lijianan 2023-05-25 21:02:49 +08:00 committed by GitHub
parent bd36fba393
commit a9297b6ea3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,10 @@
/* eslint import/no-unresolved: 0 */ import { RightOutlined } from '@ant-design/icons';
import { css } from '@emotion/react';
import { ConfigProvider, Table } from 'antd'; import { ConfigProvider, Table } from 'antd';
import { getDesignToken } from 'antd-token-previewer'; import { getDesignToken } from 'antd-token-previewer';
import tokenMeta from 'antd/es/version/token-meta.json'; import tokenMeta from 'antd/es/version/token-meta.json';
import tokenData from 'antd/es/version/token.json'; import tokenData from 'antd/es/version/token.json';
import React from 'react'; import React, { useMemo, useState } from 'react';
import useLocale from '../../../hooks/useLocale'; import useLocale from '../../../hooks/useLocale';
import useSiteToken from '../../../hooks/useSiteToken'; import useSiteToken from '../../../hooks/useSiteToken';
import { useColumns } from '../TokenTable'; import { useColumns } from '../TokenTable';
@ -25,17 +26,39 @@ const locales = {
}, },
}; };
const useStyle = () => ({
tableTitle: css`
cursor: pointer;
position: relative;
display: flex;
align-items: center;
justify-content: flex-start;
line-height: 40px;
`,
arrowIcon: css`
font-size: 16px;
margin-right: 8px;
& svg {
transition: all 0.3s;
}
`,
});
interface SubTokenTableProps { interface SubTokenTableProps {
defaultOpen?: boolean; defaultOpen?: boolean;
title: string; title: string;
tokens: string[]; tokens: string[];
} }
function SubTokenTable({ defaultOpen, tokens, title }: SubTokenTableProps) { const SubTokenTable: React.FC<SubTokenTableProps> = ({ defaultOpen, tokens, title }) => {
const [, lang] = useLocale(locales); const [, lang] = useLocale(locales);
const { token } = useSiteToken(); const { token } = useSiteToken();
const columns = useColumns(); const columns = useColumns();
const [open, setOpen] = useState<boolean>(defaultOpen || process.env.NODE_ENV !== 'production');
const { tableTitle, arrowIcon } = useStyle();
if (!tokens.length) { if (!tokens.length) {
return null; return null;
} }
@ -66,24 +89,19 @@ function SubTokenTable({ defaultOpen, tokens, title }: SubTokenTableProps) {
name, name,
desc: lang === 'cn' ? meta.desc : meta.descEn, desc: lang === 'cn' ? meta.desc : meta.descEn,
type: meta.type, type: meta.type,
value: (defaultToken as any)[name], value: defaultToken[name],
}; };
}) })
.filter((info) => info); .filter(Boolean);
return ( return (
// Reuse `.markdown` style <div>
<details className="markdown" open={defaultOpen || process.env.NODE_ENV !== 'production'}> <div css={tableTitle} onClick={() => setOpen(!open)}>
<summary> <RightOutlined css={arrowIcon} rotate={open ? 90 : 0} />
<h3 style={{ display: 'inline' }}>{title}</h3> <h3>{title}</h3>
</summary> </div>
<ConfigProvider {open && (
theme={{ <ConfigProvider theme={{ token: { borderRadius: 0 } }}>
token: {
borderRadius: 0,
},
}}
>
<Table <Table
size="middle" size="middle"
columns={columns} columns={columns}
@ -94,16 +112,17 @@ function SubTokenTable({ defaultOpen, tokens, title }: SubTokenTableProps) {
rowKey={(record) => record.name} rowKey={(record) => record.name}
/> />
</ConfigProvider> </ConfigProvider>
</details> )}
</div>
); );
} };
export interface ComponentTokenTableProps { export interface ComponentTokenTableProps {
component: string; component: string;
} }
function ComponentTokenTable({ component }: ComponentTokenTableProps) { const ComponentTokenTable: React.FC<ComponentTokenTableProps> = ({ component }) => {
const [mergedGlobalTokens] = React.useMemo(() => { const [mergedGlobalTokens] = useMemo(() => {
const globalTokenSet = new Set<string>(); const globalTokenSet = new Set<string>();
let componentTokens: Record<string, string> = {}; let componentTokens: Record<string, string> = {};
@ -121,16 +140,10 @@ function ComponentTokenTable({ component }: ComponentTokenTableProps) {
}; };
}); });
return [Array.from(globalTokenSet), componentTokens]; return [Array.from(globalTokenSet), componentTokens] as const;
}, [component]); }, [component]);
return ( return <SubTokenTable title="Global Token" tokens={mergedGlobalTokens} />;
<> };
{/* Component Token 先不展示 */}
{/* <SubTokenTable title="Component Token" tokens={mergedComponentTokens} defaultOpen /> */}
<SubTokenTable title="Global Token" tokens={mergedGlobalTokens} />
</>
);
}
export default React.memo(ComponentTokenTable); export default React.memo(ComponentTokenTable);