8000 refactor(CPopover): simplify the syntax of the component. · v-rr/coreui-react@80b9a05 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80b9a05

Browse files
committed
refactor(CPopover): simplify the syntax of the component.
1 parent 40ef7ab commit 80b9a05

File tree

2 files changed

+24
-52
lines changed

2 files changed

+24
-52
lines changed

src/components/popover/CPopover.tsx

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { FC, ReactElement, ReactNode, useState } from 'react'
22
import { createPortal } from 'react-dom'
33
import PropTypes from 'prop-types'
4+
import classNames from 'classnames'
45
import { Manager, Popper, Reference } from 'react-popper' 8000 ;
56
import { Transition } from 'react-transition-group'
67

7-
import { CPopoverContent } from './CPopoverContent'
8+
// import { CPopoverContent } from './CPopoverContent'
89
import { Triggers, triggerPropType } from '../Types'
910

1011
export interface CPopoverProps {
@@ -38,7 +39,7 @@ export interface CPopoverProps {
3839
/**
3940
* Describes the placement of your component after Popper.js has applied all the modifiers that may have flipped or altered the originally provided placement property.
4041
*/
41-
placement?: 'top' | 'right' | 'bottom' | 'left'
42+
placement?: 'auto' | 'top' | 'right' | 'bottom' | 'left'
4243
/**
4344
* Toggle the visibility of popover component.
4445
*/
@@ -47,10 +48,12 @@ export interface CPopoverProps {
4748

4849
export const CPopover: FC<CPopoverProps> = ({
4950
children,
51+
content,
5052
placement = 'top',
5153
offset = [0, 8],
5254
onHide,
5355
onShow,
56+
title,
5457
trigger = 'click',
5558
visible,
5659
...rest
@@ -114,15 +117,23 @@ export const CPopover: FC<CPopoverProps> = ({
114117
},
115118
]}
116119
>
117-
{(p) => (
118-
<CPopoverContent
119-
transitionClass={transitionClass}
120-
placementClassNamePostfix={
121-
placement === 'left' ? 'start' : placement === 'right' ? 'end' : placement
122-
}
120+
{({ arrowProps, style, ref }) => (
121+
<div
122+
className={classNames(
123+
`popover bs-popover-${
124+
placement === 'left' ? 'start' : placement === 'right' ? 'end' : placement
125+
}`,
126+
transitionClass,
127+
)}
128+
ref={ref}
129+
role="tooltip"
130+
style={style}
123131
{...rest}
124-
{...p}
125-
></CPopoverContent>
132+
>
133+
<div className="popover-arrow" {...arrowProps}></div>
134+
<div className="popover-header">{title}</div>
135+
<div className="popover-body">{content}</div>
136+
</div>
126137
)}
127138
</Popper>
128139
)
@@ -136,10 +147,12 @@ export const CPopover: FC<CPopoverProps> = ({
136147

137148
CPopover.propTypes = {
138149
children: PropTypes.any,
139-
placement: PropTypes.oneOf([ 867E 9;top', 'right', 'bottom', 'left']),
150+
content: PropTypes.node,
151+
placement: PropTypes.oneOf(['auto', 'top', 'right', 'bottom', 'left']),
140152
offset: PropTypes.any, // TODO: find good proptype
141153
onHide: PropTypes.func,
142154
onShow: PropTypes.func,
155+
title: PropTypes.string,
143156
trigger: triggerPropType,
144157
visible: PropTypes.bool,
145158
}

src/components/popover/CPopoverContent.tsx

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)
0