-
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
21 changed files
with
2,034 additions
and
123 deletions.
There are no files selected for viewing
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
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 Group() { | ||
return ( | ||
<CellGroup theme="card"> | ||
<Cell leftIcon={<LockOnIcon />} title="单行标题" arrow /> | ||
<Cell leftIcon={<ServiceIcon />} title="单行标题" arrow /> | ||
<Cell leftIcon={<InternetIcon />} title="单行标题" arrow /> | ||
</CellGroup> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.