Skip to content

Commit

Permalink
imporve(BasicLayout): less => css-in-js
Browse files Browse the repository at this point in the history
  • Loading branch information
Vanleehao committed Oct 20, 2023
1 parent 4a5e3a0 commit 2b33af7
Show file tree
Hide file tree
Showing 10 changed files with 1,187 additions and 315 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"files.associations": {
"*.svg": "html"
},
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@emotion/css": "^11.11.2",
"@emotion/react": "^11.11.1",
"@emotion/server": "^11.11.0",
"@chenshuai2144/less2cssinjs": "^1.0.7",
"@qixian.cs/github-contributors-list": "^1.1.0",
"@stackblitz/sdk": "^1.9.0",
"@testing-library/dom": "^9.3.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ import { Button, Dropdown, Menu, Modal, Space, Tooltip } from '@oceanbase/design
import classNames from 'classnames';
import moment from 'moment';
import React, { useState } from 'react';
import { OB_SITE_LINK } from '../constant';
import type { Locale } from '../interface';
import type { LocaleWrapperProps } from '../locale/LocaleWrapper';
import LocaleWrapper from '../locale/LocaleWrapper';
import { directTo, getPrefix } from '../_util';
import useNavigate from '../_util/useNavigate';
import zhCN from './locale/zh-CN';
import { OB_SITE_LINK } from '../../constant';
import type { Locale } from '../../interface';
import type { LocaleWrapperProps } from '../../locale/LocaleWrapper';
import LocaleWrapper from '../../locale/LocaleWrapper';
import { directTo, getPrefix } from '../../_util';
import useNavigate from '../../_util/useNavigate';
import zhCN from '../locale/zh-CN';
// @ts-ignore
import logoImg from '../assets/logo/oceanbase_logo.svg';
import logoImg from '../../assets/logo/oceanbase_logo.svg';
// @ts-ignore
// 自定义 SVG 图标需要将其导入为图片,而不能是 ReactComponent,因为需要依赖 webpack 插件
// 虽然本地开发可以生效,但构建后的产物在上层项目中不会生效,导致 SVG 展示为空
import UserSvg from '../assets/user.svg';
import LocaleDropdown from '../LocaleDropdown';
import './Header.less';
import UserSvg from '../../assets/user.svg';
import LocaleDropdown from '../../LocaleDropdown';
import useStyle from './style';

export type OverlayFunc = () => React.ReactElement;

Expand Down Expand Up @@ -102,6 +102,10 @@ const Header: React.FC<HeaderProps> = ({
}) => {
const navigate = useNavigate();
const [visible, setVisible] = useState(false);

const prefixCls = getPrefix('layout-header');
const { wrapSSR } = useStyle(prefixCls);

// 是否为欢迎页
// 主要是为了处理与欢迎页搭配使用的场景
const isWelcome = pathname === welcomePath;
Expand All @@ -125,14 +129,15 @@ const Header: React.FC<HeaderProps> = ({
}}
>
{welcomePath && <Menu.Item key="welcome">{locale.welcome}</Menu.Item>}
{docsPath && <Menu.Item key="viewDocs">{locale.viewDocs}</Menu.Item>}
{pdfPath && <Menu.Item key="downloadDocs">{locale.downloadDocs}</Menu.Item>}
<Menu.Item key="about">{`${locale.about}${
appData.shortName ? ` ${appData.shortName}` : ''
}`}</Menu.Item>
</Menu>
);

return (
return wrapSSR(
<div
{...restProps}
className={classNames(`${prefix}`, {
Expand All @@ -148,6 +153,7 @@ const Header: React.FC<HeaderProps> = ({
}}
className={`${prefix}-logo`}
/>

{title && <div className={`${prefix}-title`}>{title}</div>}
{showLabel ? (
<div className={`${prefix}-extra ${prefix}-extra-with-label`}>
Expand All @@ -160,11 +166,13 @@ const Header: React.FC<HeaderProps> = ({
</Space>
</Dropdown>
)}

{showLocale && (
<span className={`${prefix}-extra-item`}>
<LocaleDropdown locales={locales || langs} />
</span>
)}

{userMenu ? (
<Dropdown overlay={userMenu}>
<Button shape="round" size="small">
Expand Down Expand Up @@ -211,11 +219,13 @@ const Header: React.FC<HeaderProps> = ({
</span>
</Tooltip>
)}

{showLocale && (
<span className={`${prefix}-extra-item`}>
<LocaleDropdown showLabel={true} locales={locales || langs} />
</span>
)}

{userMenu ? (
<span className={`${prefix}-extra-item`}>
<Dropdown overlay={userMenu}>
Expand All @@ -226,6 +236,7 @@ const Header: React.FC<HeaderProps> = ({
className={`${prefix}-extra-user-icon`}
style={{ height: 12 }}
/>

<span className={`${prefix}-extra-username`}>{username}</span>
</span>
</Dropdown>
Expand All @@ -239,6 +250,7 @@ const Header: React.FC<HeaderProps> = ({
className={`${prefix}-extra-user-icon`}
style={{ height: 12 }}
/>

<span>{username}</span>
</span>
</span>
Expand All @@ -264,9 +276,9 @@ const Header: React.FC<HeaderProps> = ({
{locale.version}: {appData.version}
</div>
{appData.releaseTime && (
<div
className={`${prefix}-date`}
>{`${locale.releaseTime}: ${appData.releaseTime}`}</div>
<div className={`${prefix}-date`}>
{`${locale.releaseTime}: ${appData.releaseTime}`}
</div>
)}
</div>
<div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '../variable.less';
@import '../../variable.less';

@prefix: ob-layout-header;

Expand Down Expand Up @@ -113,12 +113,12 @@
margin-top: 20px;
margin-bottom: 50px;

.@{prefix}-version {
color: #000;
}
// .@{prefix}-version {
// color: #000;
// }

.@{prefix}-date {
color: #000;
// color: #000;
font-size: 12px;
font-family: Helvetica;
opacity: 0.45;
Expand Down
146 changes: 146 additions & 0 deletions packages/ui/src/BasicLayout/Header/style/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import type { CSSObject } from '@ant-design/cssinjs';
import type { FullToken, GenerateStyle } from 'antd/es/theme/internal';
import { genComponentStyleHook } from '../../../_util/genComponentStyleHook';

export type HeaderToken = FullToken<any>;


export const genHeaderStyle: GenerateStyle<HeaderToken> = (
token: HeaderToken
): CSSObject => {
const { componentCls } = token;

return {
[`${componentCls}`]: {
position: "fixed",
zIndex: 10,
width: "100%",
height: 48,
padding: "10px 24px",
lineHeight: '48px',
backgroundColor: token.colorBgLayout,
boxShadow: "inset 0 -1px 0 0 #e2e8f3",

[`${componentCls}-content`]: {
display: "flex",
alignItems: "center",
justifyContent: "space-between",
maxWidth: token.maxWidth,
height: "100%",
margin: "0 auto",
},

[`${componentCls}-logo`]: {
height: 24,
cursor: 'pointer'
},
[`${componentCls}-icon`]: {
width: 52,
height: 48,
lineHeight: 48,
textAlign: "center",
borderRight: "1px solid #e2e8f3",
borderBottom: "1px solid #e2e8f3",
cursor: "pointer",
img: {
height: 32,
marginTop: 8
},
},
[`${componentCls}-title`]: {
/* 占据剩余的全部空间 */
flex: 1,
margin: "0 16px",
},

[`${componentCls}-extra`]: {
display: "flex",
alignItems: "center",
justifyContent: "space-between",
[`${componentCls}-extra-item`]: {
display: "inline-flex",
fontSize: 12,
cursor: "pointer",
'&:not(:last-child)': {
marginRight: 24
},
[`${componentCls}-extra-icon-wrapper`]: {
width: 28,
height: 28,
lineHeight: 28,
textAlign: "center",
border: "0.88px solid #ced4e1",
borderRadius: 14,
},
[`${componentCls}-extra-user-wrapper`]: {
height: 28,
padding: "0 10px",
lineHeight: 28,
border: "0.88px solid #ced4e1",
borderRadius: 14,
[`${componentCls}-extra-user-icon`]: {
marginRight: 6,
marginBottom: -2,
},
},
},
},

[`${componentCls}-extra-with-label`]: {
[`${componentCls}-extra-item`]: {
'&:not(:last-child)': {
marginRight: '24px !important'
}
}
},

},

[`${componentCls}-welcome`]: {
color: "#fff",
backgroundColor: "transparent",
borderBottom: "none",
[`${componentCls}-extra`]: {
"@{prefixCls}-btn": {
color: "#fff",
backgroundColor: "rgba(255, 255, 255, 0.25)",
border: "0.5px solid rgba(0, 0, 0, 0.1)",
},
},
},


[`${componentCls}-about-wrapper`]: {
[`${componentCls}-about`]: {
marginTop: 12,
},
[`${componentCls}-logo`]: {
marginTop: 72,
},
[`${componentCls}-release-info`]: {
marginTop: 20,
marginBottom: 50,
[`${componentCls}-date`]: {
fontSize: 12,
fontFamily: 'Helvetica',
opacity: 0.45,
},
},

[`${componentCls}-copyright`]: {
color: "#000",
fontSize: 12,
opacity: 0.45,
},
}

};
};

export default (prefixCls: string) => {
const useStyle = genComponentStyleHook('Header', token => {
return [genHeaderStyle(token as HeaderToken)];
});

return useStyle(prefixCls);
};
Loading

0 comments on commit 2b33af7

Please sign in to comment.