-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2684 from XiaoMi/feature/2677(popover)
feat(popover): #2677
- Loading branch information
Showing
15 changed files
with
429 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@hi-ui/hiui": patch | ||
--- | ||
|
||
feat(popover): 1.气泡卡片支持 API 的方式调用;2.气泡卡片增加分割线标题 |
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,5 @@ | ||
--- | ||
"@hi-ui/container": minor | ||
--- | ||
|
||
feat: getContainer 方法增加 customWrapper 参数,用于自定义容器节点 |
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,5 @@ | ||
--- | ||
"@hi-ui/popper": patch | ||
--- | ||
|
||
chore: 扩充 PopperOverlayProps 参数, 'closeOnOutsideClick' | 'onExited' | 'crossGap' | 'arrow' | 'disabledPortal' | 'zIndex' |
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,5 @@ | ||
--- | ||
"@hi-ui/popover": minor | ||
--- | ||
|
||
feat: 1.增加 showTitleDivider api,设置后会是另外一种更紧凑的具有分割线的标题布局;2.增加以 API 的方式调用组件的能力 |
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,6 +1,11 @@ | ||
import './styles/index.scss' | ||
|
||
import { Popover as PurePopover } from './Popover' | ||
import { withPopover } from './with-api' | ||
|
||
export * from './Popover' | ||
export { Popover as default } from './Popover' | ||
|
||
export const Popover = withPopover(PurePopover) | ||
export default Popover | ||
|
||
export * from './types' |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { createRef, createElement } from 'react' | ||
import { render, unmountComponentAtNode } from 'react-dom' | ||
import * as Container from '@hi-ui/container' | ||
import { uuid } from '@hi-ui/use-id' | ||
|
||
import { prefix as popoverPrefix, Popover, PopoverProps } from './Popover' | ||
|
||
const prefixCls = popoverPrefix | ||
const selector = `.${prefixCls}-wrapper` | ||
|
||
const popoverInstanceCache: { | ||
[key: string]: () => void | ||
} = {} | ||
|
||
const open = (target: HTMLElement, { key, disabledPortal, ...rest }: PopoverApiProps) => { | ||
if (!key) { | ||
key = uuid() | ||
} | ||
|
||
const selectId = `${selector}__${key}` | ||
let container: any = Container.getContainer( | ||
selectId, | ||
undefined, | ||
(disabledPortal ? target.parentNode : undefined) as Element | ||
) | ||
|
||
const popoverRef = createRef<any>() | ||
|
||
const ClonedPopover = createElement(Popover, { | ||
innerRef: popoverRef, | ||
container, | ||
attachEl: target, | ||
closeOnOutsideClick: false, | ||
shouldWrapChildren: true, | ||
onExited: () => { | ||
// 卸载 | ||
if (container) { | ||
unmountComponentAtNode(container) | ||
Container.removeContainer(selectId) | ||
} | ||
container = undefined | ||
}, | ||
...rest, | ||
}) | ||
|
||
requestAnimationFrame(() => { | ||
render(ClonedPopover, container) | ||
popoverRef.current.open() | ||
}) | ||
|
||
const close = () => { | ||
popoverRef.current?.close() | ||
} | ||
|
||
if (key) { | ||
popoverInstanceCache[key] = close | ||
} | ||
|
||
return key | ||
} | ||
|
||
const close = (key: string) => { | ||
if (typeof popoverInstanceCache[key] === 'function') { | ||
popoverInstanceCache[key]() | ||
} | ||
|
||
delete popoverInstanceCache[key] | ||
} | ||
|
||
export interface PopoverApiProps extends PopoverProps {} | ||
|
||
export function withPopover(instance: typeof Popover) { | ||
return Object.assign(instance, { open, close }) | ||
} |
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
Oops, something went wrong.