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

refactor: overlay(v2.0) #886

Merged
merged 8 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions migrate-from-v1.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
#### Icon
#### Image
#### Overlay
- `overlayClass` 重命名为 `className`
- `overlayStyle` 重命名为 `style`
- `closeOnClickOverlay` 重命名为 `closeOnOverlayClick`
- 增加 afterClose和afterShow,用于完全关闭后触发的回调和完全展示后触发的回调
- 完善overlay的demo示例
#### Popup

### 布局组件
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -202,4 +202,4 @@
"@types/react": "18",
"@types/react-dom": "18"
}
}
}
4 changes: 2 additions & 2 deletions src/packages/menuitem/menuitem.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ export const MenuItem = forwardRef((props: Partial<MenuItemProps>, ref) => {
onClick={() => parent.toggleItemShow(orderKey)}
/>
<Overlay
overlayClass="nut-menu__overlay"
className="nut-menu__overlay"
Copy link
Collaborator

Choose a reason for hiding this comment

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

提出 classprefix

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个在开发menu组件的时候再自行提取classprefix即可。

style={getPosition()}
lockScroll={parent.lockScroll}
visible={_showPopup}
closeOnClickOverlay={parent.closeOnClickOverlay}
closeOnOverlayClick={parent.closeOnClickOverlay}
Copy link
Collaborator

Choose a reason for hiding this comment

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

parent.closeOnClickOverlay 这个顺便改了吧,改成一致的。

Copy link
Collaborator

Choose a reason for hiding this comment

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

menu 没有处理。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个closeOnClickOverlay是MenuProps的一个属性,这个在开发menu组件的时候再修改即可。

onClick={() => {
parent.closeOnClickOverlay && parent.toggleItemShow(orderKey)
}}
Expand Down
4 changes: 2 additions & 2 deletions src/packages/menuitem/menuitem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ export const MenuItem = forwardRef((props: Partial<MenuItemProps>, ref) => {
onClick={() => parent.toggleItemShow(orderKey)}
/>
<Overlay
overlayClass="nut-menu__overlay"
className="nut-menu__overlay"
style={getPosition()}
lockScroll={parent.lockScroll}
visible={_showPopup}
closeOnClickOverlay={parent.closeOnClickOverlay}
closeOnOverlayClick={parent.closeOnClickOverlay}
onClick={() => {
parent.closeOnClickOverlay && parent.toggleItemShow(orderKey)
}}
Expand Down
4 changes: 2 additions & 2 deletions src/packages/overlay/__tests__/overlay.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ test('prop close-on-click-overlay test', () => {
<Overlay
data-testid="overlay-closeFalsy"
visible
closeOnClickOverlay={false}
closeOnOverlayClick={false}
onClick={onClose}
/>
)
Expand All @@ -38,7 +38,7 @@ test('event click test', () => {
<Overlay
data-testid="overlay-click"
visible
closeOnClickOverlay
closeOnOverlayClick
onClick={onClose}
/>
)
Expand Down
101 changes: 93 additions & 8 deletions src/packages/overlay/demo.taro.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,53 @@ import Header from '@/sites/components/header'
interface T {
'84aa6bce': string
'2a9e4928': string
duration: string
lockscroll: string
abbf9359: string
ec0d7acf: string
ce1e18a2: string
closeClickLay: string
}
const OverlayDemo = () => {
const [translated] = useTranslate<T>({
'zh-CN': {
'84aa6bce': '基础用法',
'2a9e4928': '显示遮罩层',
duration: '设置动画时间',
lockscroll: '锁定背景滚动',
abbf9359: '遮罩样式',
ec0d7acf: '嵌套内容',
ce1e18a2: '这里是正文',
closeClickLay: '点击遮罩不关闭',
},
'zh-TW': {
'84aa6bce': '基礎用法',
'2a9e4928': '顯示遮罩層',
duration: '設置動畫時間',
lockscroll: '鎖定背景滾動',
abbf9359: '遮罩樣式',
ec0d7acf: '嵌套內容',
ce1e18a2: '這裡是正文',
closeClickLay: '點擊遮罩不關閉',
},
'en-US': {
'84aa6bce': 'Basic usage',
'2a9e4928': 'show mask layer',
abbf9359: 'mask style',
'2a9e4928': 'Show mask layer',
duration: 'Set animation time',
lockscroll: 'Lock background scrolling',
abbf9359: 'Mask style',
ec0d7acf: 'nested content',
ce1e18a2: 'here is the text',
closeClickLay: 'Click the mask not to close',
},
})

const [visible, setVisible] = useState(false)
const [visible2, setVisible2] = useState(false)
const [visible3, setVisible3] = useState(false)
const [visible4, setVisible4] = useState(false)
const [visible5, setVisible5] = useState(false)
const [visible6, setVisible6] = useState(false)

const handleToggleShow = () => {
setVisible(true)
Expand All @@ -48,8 +63,18 @@ const OverlayDemo = () => {
setVisible2(true)
}
const handleToggleShow3 = () => {
console.log('visible3', visible3)
setVisible3(true)
}
const handleToggleShow4 = () => {
setVisible4(true)
}
const handleToggleShow5 = () => {
setVisible5(true)
}
const handleToggleShow6 = () => {
setVisible6(true)
}

const onClose = () => {
setVisible(false)
Expand All @@ -60,6 +85,15 @@ const OverlayDemo = () => {
const onClose3 = () => {
setVisible3(false)
}
const onClose4 = () => {
setVisible4(false)
}
const onClose5 = () => {
setVisible5(false)
}
const onClose6 = () => {
setVisible6(false)
}
return (
<>
<Header />
Expand All @@ -71,32 +105,83 @@ const OverlayDemo = () => {
<Button type="primary" onClick={handleToggleShow}>
{translated['2a9e4928']}
</Button>
<Overlay visible={visible} onClick={onClose} />
<Overlay
visible={visible}
onClick={onClose}
zIndex={2020}
lockScroll
afterShow={() => {
console.log('afterShow')
}}
/>
</Cell>

<h2>{translated.abbf9359}</h2>
<Cell>
<Button type="primary" onClick={handleToggleShow2}>
{translated['2a9e4928']}
{translated['abbf9359']}
</Button>
<Overlay
visible={visible2}
onClick={onClose2}
overlayStyle={{
backgroundColor: '#38333333',
zIndex={2000}
style={{
backgroundColor: 'rgba(0, 0, 0, .2)',
}}
/>
</Cell>

<h2>{translated.duration}</h2>
<Cell>
<Button type="primary" onClick={handleToggleShow3}>
{translated['duration']}
</Button>
<Overlay
visible={visible3}
onClick={onClose3}
duration={2.5}
afterShow={() => {
console.log('afterShow')
}}
afterClose={() => {
console.log('afterClose')
}}
/>
</Cell>

<h2>{translated.lockscroll}</h2>
<Cell>
<Button type="primary" onClick={handleToggleShow4}>
{translated['lockscroll']}
</Button>
<Overlay visible={visible4} onClick={onClose4} lockScroll />
</Cell>

<h2>{translated.ec0d7acf}</h2>
<Cell>
<Button type="success" onClick={handleToggleShow3}>
<Button type="success" onClick={handleToggleShow5}>
{translated.ec0d7acf}
</Button>
<Overlay visible={visible3} onClick={onClose3}>
<Overlay visible={visible5} onClick={onClose5}>
<div className="wrapper">
<div className="content">{translated.ce1e18a2}</div>
</div>
</Overlay>
</Cell>

<h2>{translated.closeClickLay}</h2>
<Cell>
<Button type="primary" onClick={handleToggleShow6}>
{translated.closeClickLay}
</Button>
<Overlay visible={visible6} lockScroll closeOnOverlayClick={false}>
<div className="wrapper">
<div className="content" onClick={onClose6}>
{translated.ce1e18a2}
</div>
</div>
</Overlay>
</Cell>
</div>
</>
)
Expand Down
Loading