Skip to content

Commit

Permalink
chore(popover): 示例优化 (#2677)
Browse files Browse the repository at this point in the history
  • Loading branch information
zyprepare committed Nov 30, 2023
1 parent 4290661 commit 7588de2
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions packages/ui/popover/stories/content.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const Content = () => {

const [visible, setVisible] = React.useState<boolean>(false)
const [loading, setLoading] = React.useState<boolean>(false)
const popoverVisibleRef = React.useRef<boolean>(false)
const [popoverVisible, setPopoverVisible] = React.useState<boolean>(false)

const title = (
<div
Expand All @@ -25,7 +27,14 @@ export const Content = () => {
}}
>
<span>文字标题</span>
<IconButton effect icon={<CloseOutlined />} onClick={() => setVisible(false)} />
<IconButton
effect
icon={<CloseOutlined />}
onClick={() => {
setVisible(false)
popoverVisibleRef.current = false
}}
/>
</div>
)

Expand Down Expand Up @@ -61,7 +70,14 @@ export const Content = () => {
</Form>
</div>
<div style={{ textAlign: 'right' }}>
<Button onClick={() => setVisible(false)}>取消</Button>
<Button
onClick={() => {
setVisible(false)
popoverVisibleRef.current = false
}}
>
取消
</Button>
<Button
type="primary"
loading={loading}
Expand All @@ -70,6 +86,7 @@ export const Content = () => {
setTimeout(() => {
setLoading(false)
setVisible(false)
popoverVisibleRef.current = false
}, 1000)
}}
>
Expand All @@ -94,7 +111,19 @@ export const Content = () => {
showTitleDivider
disabledPortal
>
<Button onClick={() => setVisible(true)}>trigger</Button>
<Button
onClick={() => {
if (!popoverVisibleRef.current) {
setVisible(true)
popoverVisibleRef.current = true
} else {
setVisible(false)
popoverVisibleRef.current = false
}
}}
>
trigger
</Button>
</Popover>
</div>
</>
Expand Down

0 comments on commit 7588de2

Please sign in to comment.