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 3 commits
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
4 changes: 4 additions & 0 deletions .dumi/pages/index/common/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const useStyle = createStyles(({ token, css }) => {
color: #fff;
text-align: center;
padding-bottom: ${token.padding}px;

@media only screen and (max-width: ${token.mobileMaxWidth}px) {
font-size: ${token.fontSizeHeading1}px;
}
Comment on lines +26 to +29
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

移动端适配验证完成,建议进一步优化!

根据代码库分析,发现以下情况:

  • 目前只有少数组件实现了移动端响应式设计
  • .dumi/pages/index/common/Container.tsx 中的移动端适配是合适的
  • 其他包含标题样式的组件(如 Welcome、Prompts、Sender 等)可能也需要类似的移动端适配

建议:

  • 为其他包含标题的组件添加类似的移动端适配,特别是 Welcome 和 Prompts 组件
  • 确保所有用户界面组件在移动端都有良好的显示效果
🔗 Analysis chain

响应式设计实现得当!

媒体查询的添加很好地解决了移动端标题字体大小的适配问题,使用 token 来控制断点和字体大小也符合设计系统规范。

建议运行以下脚本,确认其他相关组件是否也需要类似的移动端适配:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查其他组件是否缺少移动端适配
# 搜索包含 title 样式但可能缺少媒体查询的文件

rg -l 'title.*css`' | xargs rg -L 'mobileMaxWidth'

Length of output: 50


Script:

#!/bin/bash
# 让我们使用更精确的搜索策略

# 1. 搜索包含样式化标题的组件
rg -A 5 'title.*{' --type tsx

# 2. 检查使用了 mobileMaxWidth 的文件
rg 'mobileMaxWidth' --type tsx

# 3. 查找所有可能的响应式设计相关代码
rg '@media.*max-width' --type tsx

Length of output: 234


Script:

#!/bin/bash
# 修正搜索命令

# 1. 搜索包含样式化标题的组件
rg -A 5 "title.*\{" .

# 2. 检查使用了 mobileMaxWidth 的文件
rg "mobileMaxWidth" .

# 3. 查找所有可能的响应式设计相关代码
rg "@media.*max-width" .

Length of output: 14518

`,
desc: css`
color: ${token.colorTextSecondary};
Expand Down
4 changes: 4 additions & 0 deletions .dumi/pages/index/components/DesignGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ const useStyle = createStyles(({ token, css }) => {
font-size: ${token.fontSizeHeading1 + 10}px;
line-height: 56px;
font-weight: bold;

@media only screen and (max-width: ${token.mobileMaxWidth}px) {
font-size: ${token.fontSizeHeading2}px;
}
`,
chain_item_desc: css`
font-size: ${token.fontSizeHeading5}px;
Expand Down
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
79 changes: 56 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 @@ -48,11 +49,16 @@ const useStyle = createStyles(({ token, css }) => {
return {
container: css`
position: relative;

@media screen and (max-width: ${token.mobileMaxWidth}px) {
height: 80vh;
}
`,
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 +67,15 @@ const useStyle = createStyles(({ token, css }) => {
width: 100%;
margin-top: ${token.pcContainerMargin / 2}px;
`,
mobile_content: css`
background: #0c0e10cc;
border-radius: 24px;
margin: ${token.marginXXL}px 0;

img {
width: 100%;
}
`,
tab: css`
width: 280px;
display: flex;
Expand Down Expand Up @@ -134,24 +149,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 +195,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
18 changes: 14 additions & 4 deletions .dumi/theme/layouts/GlobalLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,17 @@ const getAlgorithm = (themes: ThemeName[] = []) =>
const GlobalLayout: React.FC = () => {
const outlet = useOutlet();
const { pathname } = useLocation();
const { token } = antdTheme.useToken();
const [searchParams, setSearchParams] = useSearchParams();
const [{ theme = [], direction, isMobile }, setSiteState] = useLayoutState<SiteState>({
isMobile: false,
direction: 'ltr',
theme: [],
});
const isIndexPage = React.useMemo(
() => pathname === '' || pathname.startsWith('/index'),
[pathname],
);

const updateSiteConfig = useCallback(
(props: SiteState) => {
Expand Down Expand Up @@ -97,6 +102,14 @@ const GlobalLayout: React.FC = () => {
updateSiteConfig({ isMobile: window.innerWidth < RESPONSIVE_MOBILE });
};

useEffect(() => {
const metaThemeColor = document.querySelector('meta[name="theme-color"]');

if (metaThemeColor) {
metaThemeColor.setAttribute('content', isIndexPage ? '#0c0e10cc' : token.colorBgContainer);
}
}, [theme.length, isIndexPage]);

useEffect(() => {
const _theme = searchParams.getAll('theme') as ThemeName[];
const _direction = searchParams.get('direction') as DirectionType;
Expand Down Expand Up @@ -131,10 +144,7 @@ const GlobalLayout: React.FC = () => {
const themeConfig = React.useMemo<ThemeConfig>(
() => ({
// index page should always use dark theme
algorithm:
pathname.startsWith('/index') || pathname === ''
? getAlgorithm(['dark'])
: getAlgorithm(theme),
algorithm: isIndexPage ? getAlgorithm(['dark']) : getAlgorithm(theme),
token: { motion: !theme.includes('motion-off') },
cssVar: true,
hashed: false,
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
5 changes: 3 additions & 2 deletions docs/playground/independent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ const useStyle = createStyles(({ token, css }) => {
return {
layout: css`
width: 100%;
min-width: 1000px;
height: 722px;
border-radius: 8px;
border-radius: ${token.borderRadius}px;
Comment on lines +46 to +48
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

需要优化响应式设计

设置固定的 min-width: 1000px 可能会在小屏设备上造成水平滚动,影响用户体验。建议使用媒体查询来适配不同屏幕尺寸。

建议修改如下:

-      min-width: 1000px;
+      min-width: ${token.screenXS}px;
+      @media (min-width: ${token.screenSM}px) {
+        min-width: 1000px;
+      }

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

display: flex;
background: ${token.colorBgContainer};
font-family: AlibabaPuHuiTi, ${token.fontFamily}, sans-serif;
Expand Down Expand Up @@ -72,7 +73,7 @@ const useStyle = createStyles(({ token, css }) => {
box-sizing: border-box;
display: flex;
flex-direction: column;
padding: 24px 0;
padding: ${token.paddingLG}px;
gap: 16px;
`,
messages: css`
Expand Down