forked from patternfly/patternfly-react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Popover): Add PF4 Popover (patternfly#754)
* feat(Popover): Add PF4 Popover Signed-off-by: Boaz Shuster <boaz.shuster.github@gmail.com> * change example and docs from js to txt otherwise build blows up * update snapshot
- Loading branch information
Showing
28 changed files
with
630 additions
and
5 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 |
---|---|---|
|
@@ -51,4 +51,4 @@ | |
"glob": "^7.1.2", | ||
"npmlog": "^4.1.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 |
---|---|---|
|
@@ -53,4 +53,4 @@ | |
"glob": "^7.1.2", | ||
"npmlog": "^4.1.2" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/patternfly-4/react-core/src/components/Popover/Popover.d.ts
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 { SFC, HTMLProps, ReactNode } from 'react'; | ||
import { OneOf } from '@patternfly/react-core/src/typeUtils'; | ||
|
||
export interface PopoverProps extends HTMLProps<HTMLDivElement> { | ||
position: OneOf<typeof PopoverPosition, keyof typeof PopoverPosition>; | ||
children: ReactNode; | ||
header: string; | ||
onClose?(event: React.SyntheticEvent<HTMLButtonElement>): void | ||
} | ||
|
||
declare const Popover: SFC<PopoverProps>; | ||
|
||
export default Popover; |
30 changes: 30 additions & 0 deletions
30
packages/patternfly-4/react-core/src/components/Popover/Popover.docs.txt
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,30 @@ | ||
import { | ||
PopoverPosition, | ||
PopoverDialog, | ||
PopoverArrow, | ||
PopoverContent, | ||
PopoverCloseButton, | ||
PopoverHeader, | ||
PopoverBody | ||
} from '@patternfly/react-core'; | ||
import SimplePopover from './examples/SimplePopover'; | ||
import HeadlessPopover from './examples/HeadlessPopover'; | ||
|
||
export default { | ||
title: 'Popover', | ||
components: { | ||
PopoverDialog, | ||
PopoverArrow, | ||
PopoverContent, | ||
PopoverCloseButton, | ||
PopoverHeader, | ||
PopoverBody | ||
}, | ||
enumValues: { | ||
'Object.values(PopoverPosition)': Object.values(PopoverPosition) | ||
}, | ||
examples: [ | ||
{ component: SimplePopover, title: 'Closable Popover Position' }, | ||
{ component: HeadlessPopover, title: 'Headless Popover' } | ||
] | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/patternfly-4/react-core/src/components/Popover/Popover.js
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,40 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css, getModifier } from '@patternfly/react-styles'; | ||
import PopoverDialog, { PopoverPosition } from './PopoverDialog'; | ||
import PopoverArrow from './PopoverArrow'; | ||
import PopoverContent from './PopoverContent'; | ||
import PopoverHeader from './PopoverHeader'; | ||
import PopoverBody from './PopoverBody'; | ||
import PopoverCloseButton from './PopoverCloseButton'; | ||
|
||
const Popover = ({ position, header, onClose, children, className }) => ( | ||
<PopoverDialog position={position}> | ||
<PopoverArrow /> | ||
<PopoverContent> | ||
<PopoverCloseButton onClose={onClose} /> | ||
<PopoverHeader id={`popover-${position}-header`}>{header}</PopoverHeader> | ||
<PopoverBody id={`popover-${position}-body`}>{children}</PopoverBody> | ||
</PopoverContent> | ||
</PopoverDialog> | ||
); | ||
|
||
const propTypes = { | ||
/** Popover position */ | ||
position: PropTypes.oneOf(Object.values(PopoverPosition)), | ||
/** Popover header text */ | ||
header: PropTypes.string.isRequired, | ||
/** Popover body text */ | ||
children: PropTypes.string.isRequired, | ||
/** Popover onClose function */ | ||
onClose: PropTypes.func | ||
}; | ||
|
||
Popover.propTypes = propTypes; | ||
Popover.defaultProps = { | ||
onClose: () => {}, | ||
position: 'top' | ||
}; | ||
|
||
export default Popover; |
21 changes: 21 additions & 0 deletions
21
packages/patternfly-4/react-core/src/components/Popover/Popover.test.js
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,21 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { Popover } from './index'; | ||
import { Button } from '@patternfly/react-core'; | ||
|
||
test('popover renders close-button, header and body', () => { | ||
const view = mount(<Popover header="popover header">popover body</Popover>); | ||
expect(view).toMatchSnapshot(); | ||
}); | ||
|
||
test('popover is calling onClose when clicking the close button', () => { | ||
const onClose = jest.fn(); | ||
const view = mount( | ||
<Popover header="popover header" onClose={onClose}> | ||
popover body | ||
</Popover> | ||
); | ||
expect(onClose.mock.calls).toHaveLength(0); | ||
view.find(Button).simulate('click'); | ||
expect(onClose.mock.calls).toHaveLength(1); | ||
}); |
8 changes: 8 additions & 0 deletions
8
packages/patternfly-4/react-core/src/components/Popover/PopoverArrow.d.ts
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,8 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
|
||
export interface PopoverArrowProps extends HTMLProps<HTMLDivElement> { | ||
} | ||
|
||
declare const PopoverArrow: SFC<PopoverArrowProps>; | ||
|
||
export default PopoverArrow; |
17 changes: 17 additions & 0 deletions
17
packages/patternfly-4/react-core/src/components/Popover/PopoverArrow.js
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,17 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
const PopoverArrow = ({ className, ...props }) => <div className={css(styles.popoverArrow, className)} {...props} />; | ||
|
||
PopoverArrow.propTypes = { | ||
/** Popover arrow additional className */ | ||
className: PropTypes.string | ||
}; | ||
|
||
PopoverArrow.defaultProps = { | ||
className: null | ||
}; | ||
|
||
export default PopoverArrow; |
10 changes: 10 additions & 0 deletions
10
packages/patternfly-4/react-core/src/components/Popover/PopoverBody.d.ts
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,10 @@ | ||
import { SFC, ReactNode } from 'react'; | ||
|
||
export interface PopoverBodyProps { | ||
id: string | ||
children: ReactNode; | ||
} | ||
|
||
declare const PopoverBody: SFC<PopoverBodyProps>; | ||
|
||
export default PopoverBody; |
19 changes: 19 additions & 0 deletions
19
packages/patternfly-4/react-core/src/components/Popover/PopoverBody.js
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,19 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
const PopoverBody = ({ children, id }) => ( | ||
<div className={css(styles.popoverBody)} id={id}> | ||
{children} | ||
</div> | ||
); | ||
|
||
PopoverBody.propTypes = { | ||
/** PopoverBody id */ | ||
id: PropTypes.string.isRequired, | ||
/** PopoverBody content */ | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
export default PopoverBody; |
9 changes: 9 additions & 0 deletions
9
packages/patternfly-4/react-core/src/components/Popover/PopoverCloseButton.d.ts
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,9 @@ | ||
import { SFC } from 'react'; | ||
|
||
export interface PopoverCloseButtonProps { | ||
onClose(event: React.SyntheticEvent<HTMLButtonElement>): void | ||
} | ||
|
||
declare const PopoverCloseButton : SFC<PopoverCloseButtonProps>; | ||
|
||
export default PopoverCloseButton; |
21 changes: 21 additions & 0 deletions
21
packages/patternfly-4/react-core/src/components/Popover/PopoverCloseButton.js
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,21 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css } from '@patternfly/react-styles'; | ||
import { Button } from '@patternfly/react-core'; | ||
import { TimesIcon } from '@patternfly/react-icons'; | ||
|
||
const PopoverCloseButton = ({ onClose }) => ( | ||
<div className={css(styles.popoverClose)}> | ||
<Button onClick={onClose} variant="plain" aria-label="Action"> | ||
<TimesIcon /> | ||
</Button> | ||
</div> | ||
); | ||
|
||
PopoverCloseButton.propTypes = { | ||
/** PopoverCloseButton onClose function */ | ||
onClose: PropTypes.func.isRequired | ||
}; | ||
|
||
export default PopoverCloseButton; |
8 changes: 8 additions & 0 deletions
8
packages/patternfly-4/react-core/src/components/Popover/PopoverContent.d.ts
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,8 @@ | ||
import { SFC, HTMLProps } from 'react'; | ||
|
||
export interface PopoverContentProps extends HTMLProps<HTMLDivElement> { | ||
} | ||
|
||
declare const PopoverContent: SFC<PopoverContentProps>; | ||
|
||
export default PopoverContent; |
23 changes: 23 additions & 0 deletions
23
packages/patternfly-4/react-core/src/components/Popover/PopoverContent.js
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,23 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
const PopoverContent = ({ className, children, ...props }) => ( | ||
<div className={css(styles.popoverContent, className)} {...props}> | ||
{children} | ||
</div> | ||
); | ||
|
||
PopoverContent.propTypes = { | ||
/** PopoverContent additional class */ | ||
className: PropTypes.string, | ||
/** PopoverContent content */ | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
PopoverContent.defaultProps = { | ||
className: null | ||
}; | ||
|
||
export default PopoverContent; |
19 changes: 19 additions & 0 deletions
19
packages/patternfly-4/react-core/src/components/Popover/PopoverDialog.d.ts
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,19 @@ | ||
import { SFC, HTMLProps, ReactNode } from 'react'; | ||
import { OneOf, Omit } from '../../typeUtils'; | ||
|
||
export const PopoverPosition: { | ||
top: 'top'; | ||
bottom: 'bottom'; | ||
left: 'left'; | ||
right: 'right'; | ||
}; | ||
|
||
export interface PopoverDialogProps extends Omit<HTMLProps<HTMLDivElement>, 'children'> { | ||
children: ReactNode | ||
position: OneOf<typeof PopoverPosition, keyof typeof PopoverPosition>; | ||
} | ||
|
||
declare const PopoverDialog: SFC<PopoverDialogProps>; | ||
|
||
export default PopoverDialog; | ||
|
38 changes: 38 additions & 0 deletions
38
packages/patternfly-4/react-core/src/components/Popover/PopoverDialog.js
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,38 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css, getModifier } from '@patternfly/react-styles'; | ||
|
||
export const PopoverPosition = { | ||
top: 'top', | ||
bottom: 'bottom', | ||
left: 'left', | ||
right: 'right' | ||
}; | ||
|
||
const PopoverDialog = ({ position, children, className, ...props }) => ( | ||
<div | ||
className={css(styles.popover, getModifier(styles, position, styles.modifiers.top), className)} | ||
role="dialog" | ||
aria-modal="true" | ||
{...props} | ||
> | ||
{children} | ||
</div> | ||
); | ||
|
||
PopoverDialog.propTypes = { | ||
/** PopoverDialog position */ | ||
position: PropTypes.oneOf(Object.values(PopoverPosition)), | ||
/** PopoverDialog additional class */ | ||
className: PropTypes.string, | ||
/** PopoverDialog body */ | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
PopoverDialog.defaultProps = { | ||
position: 'top', | ||
className: null | ||
}; | ||
|
||
export default PopoverDialog; |
10 changes: 10 additions & 0 deletions
10
packages/patternfly-4/react-core/src/components/Popover/PopoverHeader.d.ts
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,10 @@ | ||
import { SFC, ReactNode } from 'react'; | ||
|
||
export interface PopoverHeaderProps { | ||
id: string | ||
children: ReactNode; | ||
} | ||
|
||
declare const PopoverHeader: SFC<PopoverHeaderProps>; | ||
|
||
export default PopoverHeader; |
21 changes: 21 additions & 0 deletions
21
packages/patternfly-4/react-core/src/components/Popover/PopoverHeader.js
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,21 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import styles from '@patternfly/patternfly-next/components/Popover/popover.css'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
const PopoverHeader = ({ children, id }) => ( | ||
<header className={css(styles.popoverHeader)}> | ||
<h1 className={css(styles.popoverHeaderTitle)} id={id}> | ||
{children} | ||
</h1> | ||
</header> | ||
); | ||
|
||
PopoverHeader.propTypes = { | ||
/** popover id */ | ||
id: PropTypes.string.isRequired, | ||
/** header node */ | ||
children: PropTypes.node.isRequired | ||
}; | ||
|
||
export default PopoverHeader; |
Oops, something went wrong.