Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: fix site style and enhance user experience #262

Merged
merged 6 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: fix site style.
  • Loading branch information
YumoImer committed Nov 27, 2024
commit ed02c772f897086ec4371ce32800694042b23569
12 changes: 10 additions & 2 deletions .dumi/pages/index/components/MainBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ const useStyle = createStyles(({ token, css }) => {
align-items: center;
position: relative;
font-family: AlibabaPuHuiTi, ${token.fontFamily}, sans-serif;

@media only screen and (max-width: ${token.mobileMaxWidth}px) {
height: calc(100vh - ${token.paddingLG}px);
}
`,
background: css`
width: 100%;
Expand All @@ -51,8 +55,6 @@ const useStyle = createStyles(({ token, css }) => {
height: 100%;
max-height: calc(100vh - ${token.headerHeight * 2}px);
position: relative;


`,
title: css`
max-width: ${minBannerWidth}px;
Expand All @@ -68,6 +70,8 @@ const useStyle = createStyles(({ token, css }) => {
flex-direction: column;
align-items: center;
justify-content: center;
text-align: center;
gap: ${token.paddingXS}px;
}
`,
lottie: css`
Expand Down Expand Up @@ -150,6 +154,10 @@ const useStyle = createStyles(({ token, css }) => {
font-weight: 600;
box-shadow: ${token.boxShadow};
position: relative;

@media only screen and (max-width: ${token.mobileMaxWidth}px) {
padding: 0 ${token.paddingLG}px;
}
Comment on lines +157 to +160
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议增强按钮的可访问性

移动端内边距的调整很合理,但建议考虑以下无障碍性优化:

  1. 增加最小点击区域尺寸
  2. 确保足够的触控间距
 @media only screen and (max-width: ${token.mobileMaxWidth}px) {
   padding: 0 ${token.paddingLG}px;
+  min-height: 44px; // iOS 无障碍建议最小高度
+  margin: ${token.marginXS}px 0; // 增加按钮间距
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@media only screen and (max-width: ${token.mobileMaxWidth}px) {
padding: 0 ${token.paddingLG}px;
}
@media only screen and (max-width: ${token.mobileMaxWidth}px) {
padding: 0 ${token.paddingLG}px;
min-height: 44px; // iOS 无障碍建议最小高度
margin: ${token.marginXS}px 0; // 增加按钮间距
}

`,
startBtn: css`
background: linear-gradient(90deg, #c7deff 0%, #ffffffd9 76%);
Expand Down
75 changes: 52 additions & 23 deletions .dumi/pages/index/components/SceneIntroduction/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Button } from 'antd';
import { Button, Carousel } from 'antd';
import { createStyles } from 'antd-style';
import classnames from 'classnames';
import React from 'react';

import useLocale from '../../../../hooks/useLocale';
import Container from '../../common/Container';
import SiteContext from '../SiteContext';
import AssistantScene from './Assistant';
import Independent from './Independent';
import NestScene from './Nest';
Expand Down Expand Up @@ -51,8 +52,9 @@ const useStyle = createStyles(({ token, css }) => {
`,
content_bg: css`
position: absolute;
top: -200px;
right: -150px;
top: 0;
right: 0;
transform: translate(10%, -20%);
`,
content: css`
display: flex;
Expand All @@ -61,6 +63,15 @@ const useStyle = createStyles(({ token, css }) => {
width: 100%;
margin-top: ${token.pcContainerMargin / 2}px;
`,
mobile_content: css`
background: #0c0e10cc;
border-radius: 24px;
margin: ${token.marginLG}px 0;

img {
width: 100%;
}
`,
tab: css`
width: 280px;
display: flex;
Expand Down Expand Up @@ -134,24 +145,29 @@ const SceneBanner: React.FC = () => {
const { styles } = useStyle();
const [locale] = useLocale(locales);

const { isMobile } = React.useContext(SiteContext);

const tabItems = [
{
key: 'independent',
title: locale.independent_title,
desc: locale.independent_desc,
content: <Independent />,
img: 'https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*YVjbTqbc7ngAAAAAAAAAAAAADgCCAQ/fmt.avif',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

建议优化图片资源处理

建议对图片资源进行以下优化:

  1. 添加图片类型声明
  2. 使用图片优化组件
  3. 考虑添加图片加载失败的降级处理
+ interface TabImage {
+   src: string;
+   alt: string;
+   fallback?: string;
+ }

+ interface TabItem {
+   key: string;
+   title: string;
+   desc: string;
+   content: React.ReactNode;
+   img?: TabImage;
+   disabled?: boolean;
+ }

  const tabItems: TabItem[] = [
    {
      key: 'independent',
      title: locale.independent_title,
      desc: locale.independent_desc,
      content: <Independent />,
-     img: 'https://mdn.alipayobjects.com/...',
+     img: {
+       src: 'https://mdn.alipayobjects.com/...',
+       alt: locale.independent_title,
+       fallback: '/fallback-image.png'
+     },
    },
    // ... 其他项目类似更新
  ];

Also applies to: 178-178, 185-185

},
{
key: 'assistant',
title: locale.assistant_title,
desc: locale.assistant_desc,
content: <AssistantScene />,
img: 'https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*kCojRo0SoAAAAAAAAAAAAAAADgCCAQ/fmt.avif',
},
{
key: 'nest',
title: locale.nest_title,
desc: locale.nest_desc,
content: <NestScene />,
img: 'https://mdn.alipayobjects.com/huamei_iwk9zp/afts/img/A*krfsT5zBSuUAAAAAAAAAAAAADgCCAQ/fmt.avif',
},
{
key: 'app',
Expand All @@ -175,27 +191,40 @@ const SceneBanner: React.FC = () => {
src="https://mdn.alipayobjects.com/huamei_k0vkmw/afts/img/A*aSLTSr53DPAAAAAAAAAAAAAADsR-AQ/original"
alt="bg"
/>
<div className={styles.content}>
<div className={styles.tab}>
{tabItems.map((item) => (
<Button
key={item.key}
disabled={item.disabled}
className={classnames(
styles.item,
active === item.key && styles['item-active'],
item.disabled && styles['item-disabled'],
)}
type="text"
onClick={genHandleActive(item.key)}
>
<h3 className={styles.item_title}>{item.title}</h3>
<p className={styles.item_desc}>{item.desc}</p>
</Button>
))}
{isMobile ? (
<Carousel>
{tabItems.map(
(item) =>
item.img && (
<div className={styles.mobile_content}>
<img src={item.img} alt="item.img" loading="lazy" />
</div>
),
)}
</Carousel>
) : (
<div className={styles.content}>
<div className={styles.tab}>
{tabItems.map((item) => (
<Button
key={item.key}
disabled={item.disabled}
className={classnames(
styles.item,
active === item.key && styles['item-active'],
item.disabled && styles['item-disabled'],
)}
type="text"
onClick={genHandleActive(item.key)}
>
<h3 className={styles.item_title}>{item.title}</h3>
<p className={styles.item_desc}>{item.desc}</p>
</Button>
))}
</div>
{!!activeContent && <div className={styles.tab_content}>{activeContent}</div>}
</div>
{!!activeContent && <div className={styles.tab_content}>{activeContent}</div>}
</div>
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

移动端轮播组件实现需要增强用户体验

当前的轮播实现比较基础,建议增加以下功能来提升用户体验:

  1. 缺少轮播指示器
  2. 没有自动播放控制
  3. 缺少手势滑动支持

建议按如下方式增强轮播组件:

-        <Carousel>
+        <Carousel
+          dots={{ className: styles.carousel_dots }}
+          autoplay
+          autoplaySpeed={5000}
+          draggable
+          swipeToSlide
+        >
           {tabItems.map(
             (item) =>
               item.img && (
                 <div className={styles.mobile_content}>
-                  <img src={item.img} alt="item.img" loading="lazy" />
+                  <img
+                    src={item.img.src}
+                    alt={item.img.alt}
+                    loading={item.img.loading}
+                  />
                 </div>
               ),
           )}
         </Carousel>

Committable suggestion skipped: line range outside the PR's diff.

</Container>
);
};
Expand Down
2 changes: 1 addition & 1 deletion .dumi/theme/builtins/Previewer/CodePreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ createRoot(document.getElementById('container')).render(<Demo />);

const codeBoxDemoStyle: React.CSSProperties = {
padding: iframe || compact ? 0 : undefined,
overflow: iframe || compact ? 'hidden' : undefined,
overflow: iframe || compact ? 'hidden' : 'auto',
backgroundColor: background === 'grey' ? backgroundGrey : undefined,
};

Expand Down
9 changes: 8 additions & 1 deletion .dumi/theme/slots/Header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CloseOutlined, MenuOutlined } from '@ant-design/icons';
import { Button, Drawer } from 'antd';
import { createStyles } from 'antd-style';
import classnames from 'classnames';
import React from 'react';
import React, { useEffect } from 'react';

import useLocale from '../../../hooks/useLocale';
import useScrollY from '../../../hooks/useScrollY';
Expand All @@ -12,6 +12,7 @@ import HeaderActions from './Actions';
import Logo from './Logo';
import Navigation from './Navigation';

import { useLocation } from 'dumi';
import type { SiteContextProps } from '../SiteContext';
import type { SharedProps } from './interface';

Expand Down Expand Up @@ -96,6 +97,8 @@ const useStyle = createStyles(({ token, css }) => {
const Header: React.FC = () => {
const [open, setOpen] = React.useState<boolean>(false);
const [, lang] = useLocale();
const { pathname } = useLocation();

const { direction, isMobile } = React.useContext<SiteContextProps>(SiteContext);

const { styles } = useStyle();
Expand All @@ -113,6 +116,10 @@ const Header: React.FC = () => {

let content = null;

useEffect(() => {
isMobile && setOpen(false);
}, [pathname]);

if (isMobile) {
content = (
<Drawer
Expand Down