-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
302 additions
and
107 deletions.
There are no files selected for viewing
Submodule _common
updated
16 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
interface HoverOptions { | ||
className: string; | ||
disabled?: string | boolean; | ||
} | ||
|
||
function useHover(options: HoverOptions) { | ||
const elRef = useRef(null); | ||
const { className, disabled } = options; | ||
const startTime = 50; | ||
const stayTime = 70; | ||
|
||
useEffect(() => { | ||
let currentElement: HTMLElement | null = null; | ||
|
||
const handleTouchStart = () => { | ||
if (disabled) { | ||
return; | ||
} | ||
setTimeout(() => { | ||
currentElement?.classList.add(className); | ||
}, startTime); | ||
}; | ||
|
||
const handleTouchEnd = () => { | ||
if (disabled) { | ||
return; | ||
} | ||
setTimeout(() => { | ||
currentElement?.classList.remove(className); | ||
}, stayTime); | ||
}; | ||
|
||
if (elRef.current) { | ||
currentElement = elRef.current; | ||
currentElement.addEventListener('touchstart', handleTouchStart, { capture: false, passive: true }); | ||
currentElement.addEventListener('touchend', handleTouchEnd, false); | ||
} | ||
|
||
return () => { | ||
if (currentElement) { | ||
currentElement.removeEventListener('touchstart', handleTouchStart); | ||
currentElement.removeEventListener('touchend', handleTouchEnd); | ||
} | ||
}; | ||
}, [className, disabled]); | ||
|
||
return elRef; | ||
} | ||
|
||
export default useHover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/* eslint-disable import/no-relative-packages */ | ||
import '../../_common/style/mobile/components/cell-group/_index.less'; | ||
import '../../_common/style/mobile/components/cell-group/v2/_index.less'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { describe, it, expect, vi, render, fireEvent, screen } from '@test/utils'; | ||
import React from 'react'; | ||
import Cell from '../Cell'; | ||
|
||
describe('Cell', () => { | ||
it('renders the correct content', () => { | ||
const { getByText } = render( | ||
<Cell title="Test Title" description="Test Description"> | ||
Test Children | ||
</Cell>, | ||
); | ||
|
||
expect(getByText('Test Title')).toBeInTheDocument(); | ||
expect(getByText('Test Description')).toBeInTheDocument(); | ||
expect(getByText('Test Children')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders left icon and image if provided', () => { | ||
const { getByTestId } = render( | ||
<Cell | ||
leftIcon={<div data-testid="left-icon">Left Icon</div>} | ||
image="https://tdesign.gtimg.com/mobile/demos/avatar1.png" | ||
> | ||
Test Children | ||
</Cell>, | ||
); | ||
|
||
expect(getByTestId('left-icon')).toBeInTheDocument(); | ||
expect(screen.getByText('Test Children')).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders right icon if provided', () => { | ||
const { getByTestId } = render(<Cell rightIcon={<div data-testid="right-icon">Right Icon</div>} />); | ||
|
||
expect(getByTestId('right-icon')).toBeInTheDocument(); | ||
}); | ||
|
||
it('calls onClick when the cell is clicked', () => { | ||
const handleClick = vi.fn(); | ||
const { container } = render(<Cell onClick={handleClick} />); | ||
|
||
fireEvent.click(container.firstChild); | ||
|
||
expect(handleClick).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import { CellGroup, Cell } from 'tdesign-mobile-react'; | ||
import { LockOnIcon, ServiceIcon, InternetIcon } from 'tdesign-icons-react'; | ||
|
||
export default function () { | ||
return ( | ||
<CellGroup theme="card"> | ||
<Cell leftIcon={<LockOnIcon />} title="单行标题" arrow /> | ||
<Cell leftIcon={<ServiceIcon />} title="单行标题" arrow /> | ||
<Cell leftIcon={<InternetIcon />} title="单行标题" arrow /> | ||
</CellGroup> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,32 @@ | ||
import React from 'react'; | ||
import { Cell, CellGroup } from 'tdesign-mobile-react'; | ||
import { Icon } from 'tdesign-icons-react'; | ||
|
||
const imgUrl = 'https://tdesign.gtimg.com/mobile/%E5%9B%BE%E7%89%87.png'; | ||
|
||
const imgUrl2 = 'https://tdesign.gtimg.com/mobile/demos/avatar_1.png'; | ||
import { CellGroup, Cell, Badge, Switch, Avatar } from 'tdesign-mobile-react'; | ||
import { ChevronRightIcon, LockOnIcon } from 'tdesign-icons-react'; | ||
|
||
export default function () { | ||
const chevronRightIcon = <ChevronRightIcon />; | ||
const avatarUrl = 'https://tdesign.gtimg.com/mobile/demos/avatar1.png'; | ||
const imgUrl = 'https://tdesign.gtimg.com/mobile/demos/example4.png'; | ||
|
||
return ( | ||
<div className="tdesign-grid-base"> | ||
<CellGroup> | ||
<Cell title="多行标题" description="一段很长很长的内容文字" /> | ||
<Cell title="多行带图标" description="一段很长很长的内容文字" arrow leftIcon={<Icon name="app" />} /> | ||
<Cell | ||
title="多行带头像" | ||
description="一段很长很长的内容文字" | ||
image={<img src={imgUrl2} width={48} height={48} style={{ borderRadius: '50%' }} />} | ||
arrow | ||
/> | ||
<Cell | ||
title="多行带图片" | ||
description="一段很长很长的内容文字" | ||
image={<img src={imgUrl} width={56} height={56} />} | ||
/> | ||
<Cell title="多行标题" description="一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容" /> | ||
<Cell | ||
title="多行高度不定,长文本自动换行,该选项的描述是一段很长的内容" | ||
description="一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容" | ||
/> | ||
</CellGroup> | ||
</div> | ||
<CellGroup> | ||
<Cell title="单行标题" description="一段很长很长的内容文字" arrow /> | ||
<Cell title="单行标题" description="一段很长很长的内容文字" arrow required /> | ||
<Cell title="单行标题" description="一段很长很长的内容文字" arrow note={<Badge count={16} />} /> | ||
<Cell title="单行标题" description="一段很长很长的内容文字" note={<Switch defaultValue={true} />} /> | ||
<Cell title="单行标题" description="一段很长很长的内容文字" note="辅助信息" arrow /> | ||
<Cell title="单行标题" description="一段很长很长的内容文字" arrow leftIcon={<LockOnIcon />} /> | ||
<Cell title="单行标题" description="一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容" /> | ||
<Cell | ||
title="多行高度不定,长文本自动换行,该选项的描述是一段很长的内容" | ||
description="一段很长很长的内容文字,长文本自动换行,该选项的描述是一段很长的内容" | ||
/> | ||
<Cell | ||
title="多行带头像" | ||
description="一段很长很长的内容文字" | ||
leftIcon={<Avatar shape="circle" image={avatarUrl} />} | ||
rightIcon={chevronRightIcon} | ||
/> | ||
<Cell title="多行带图片" description="一段很长很长的内容文字" image={imgUrl} /> | ||
</CellGroup> | ||
); | ||
} |
Oops, something went wrong.