diff --git a/packages/react-core/src/components/Popover/examples/Popover.md b/packages/react-core/src/components/Popover/examples/Popover.md index 3d34b811135..11867adcf1d 100644 --- a/packages/react-core/src/components/Popover/examples/Popover.md +++ b/packages/react-core/src/components/Popover/examples/Popover.md @@ -16,335 +16,52 @@ import BullhornIcon from '@patternfly/react-icons/dist/esm/icons/bullhorn-icon'; ### Basic -```js -import React from 'react'; -import { Popover, PopoverPosition, Button } from '@patternfly/react-core'; - -
- Popover header
} - bodyContent={
Popovers are triggered by click rather than hover.
} - footerContent="Popover footer" - > - - -; +```ts file="./PopoverBasic.tsx" ``` ### Close popover from content (controlled) -```js -import React from 'react'; -import { Popover, PopoverPosition, Button } from '@patternfly/react-core'; - -PopoverCloseControlled = () => { - const [isVisible, setIsVisible] = React.useState(false); - return ( -
- setIsVisible(true)} - shouldClose={() => setIsVisible(false)} - headerContent={
Popover header
} - bodyContent={ -
-
- All the content props (headerContent, bodyContent, footerContent) can take a function which the popover - component passes the hide function to which can be used to close the popover after some user interaction. -
-
- -
-
- } - footerContent="Popover footer" - > - -
-
- ); -}; +```ts file="./PopoverCloseControlled.tsx" ``` ### Close popover from content (uncontrolled) Note: If you use the isVisible prop, either refer to the example above or if you want to use the hide callback from the content then be sure to keep isVisible in-sync. -```js -import React from 'react'; -import { Popover, PopoverPosition, Button } from '@patternfly/react-core'; - -
- Popover header
} - bodyContent={hide => ( -
-
- All the content props (headerContent, bodyContent, footerContent) can take a function which the popover - component passes the hide function to which can be used to close the popover after some user interaction. -
-
- -
-
- )} - footerContent="Popover footer" - > - - -; +```ts file="./PopoverCloseUncontrolled.tsx" ``` ### Without header/footer/close and no padding -```js -import React from 'react'; -import { Popover, PopoverPosition, Button } from '@patternfly/react-core'; - -
- ( -
- This popover has no padding and is intended for use with content that has its own spacing and should touch the - edges of the popover container. -
- )} - withFocusTrap={false /* no focusable content in this example */} - > - -
-
; +```ts file="./PopoverWithoutHeaderFooterCloseNoPadding.tsx" ``` ### Width auto -```js -import React from 'react'; -import { Popover, PopoverPosition, Button } from '@patternfly/react-core'; - -
-
Removes fixed-width and allows width to be defined by contents
} - > - -
-
; +```ts file="./PopoverWidthAuto.tsx" ``` ### Popover react ref -```js -import React from 'react'; -import { Popover } from '@patternfly/react-core'; - -PopoverReactRef = () => { - const popoverRef = React.useRef(); - return ( -
- - Popover header
} - bodyContent={ -
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. -
- } - footerContent="Popover footer" - reference={popoverRef} - /> - - ); -}; +```ts file="./PopoverReactRef.tsx" ``` ### Popover selector ref -```js -import React from 'react'; -import { Popover } from '@patternfly/react-core'; - -
- - Popover header
} - bodyContent={ -
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
- } - footerContent="Popover footer" - reference={() => document.getElementById('popover-selector')} - /> -; +```ts file="./PopoverSelectorRef.tsx" ``` ### Advanced -```js -import React from 'react'; -import { Popover, PopoverPosition, Checkbox, Button } from '@patternfly/react-core'; - -class AdvancedPopover extends React.Component { - constructor(props) { - super(props); - this.state = { - position: 'auto', - show: false, - keepInViewChecked: true - }; - this.handleKeepInViewChange = checked => { - this.setState({ keepInViewChecked: checked }); - }; - this.handleProgrammaticChange = checked => { - this.setState({ - show: checked - }); - }; - this.shouldClose = () => { - console.log('shouldClose'); - this.setState({ show: false }); - }; - this.shouldOpen = () => { - console.log('shouldOpen'); - this.setState({ show: true }); - }; - } - - render() { - return ( -
-
- Popover position - - - -
- -
- document.body} - headerContent={
Popover header
} - bodyContent={ -
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. -
- } - footerContent="Popover footer" - > - -
-
-
- ); - } -} +```ts file="./PopoverAdvanced.tsx" ``` ### Popover with icon in the title -```ts isBeta -import React from 'react'; -import { Popover, Button } from '@patternfly/react-core'; -import BullhornIcon from '@patternfly/react-icons/dist/esm/icons/bullhorn-icon'; - -
- } - bodyContent={
Popovers are triggered by click rather than hover.
} - footerContent="Popover footer" - > - -
-
; +```ts file="./PopoverWithIconInTheTitle.tsx" isBeta ``` ### Alert popover -```ts isBeta -import React from 'react'; -import { Popover, Button } from '@patternfly/react-core'; -import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; -import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon'; -import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; -import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'; -import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; - -const AlertPopover = () => { - const [alertSeverityVariant, setAlertSeverityVariant] = React.useState('default'); - const alertIcons = { - default: , - info: , - success: , - warning: , - danger: - }; - - return ( -
-
- Alert variant: - -
-
- Popovers are triggered by click rather than hover.
} - footerContent="Popover footer" - > - - -
- - ); -}; +```ts file="./PopoverAlert.tsx" isBeta ``` diff --git a/packages/react-core/src/components/Popover/examples/PopoverAdvanced.tsx b/packages/react-core/src/components/Popover/examples/PopoverAdvanced.tsx new file mode 100644 index 00000000000..52b936f727c --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverAdvanced.tsx @@ -0,0 +1,79 @@ +import React from 'react'; +import { Popover, PopoverPosition, Checkbox, Button } from '@patternfly/react-core'; + +export const PopoverAdvanced: React.FunctionComponent = () => { + const [position, setPosition] = React.useState(PopoverPosition.auto); + const [show, setShow] = React.useState(false); + const [keepInViewChecked, setKeepInViewChecked] = React.useState(true); + + const handleKeepInViewChange = (checked: boolean) => { + setKeepInViewChecked(checked); + }; + + const handleProgrammaticChange = (checked: boolean) => { + setShow(checked); + }; + + const shouldClose = () => { + setShow(false); + }; + + const shouldOpen = () => { + setShow(true); + }; + + return ( + <> +
+ Popover position + + + +
+ +
+ Popover header
} + bodyContent={ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + footerContent="Popover footer" + > + + + + + ); +}; diff --git a/packages/react-core/src/components/Popover/examples/PopoverAlert.tsx b/packages/react-core/src/components/Popover/examples/PopoverAlert.tsx new file mode 100644 index 00000000000..023569db7ce --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverAlert.tsx @@ -0,0 +1,47 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; +import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; +import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon'; +import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; +import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'; +import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; + +export const AlertPopover: React.FunctionComponent = () => { + const [alertSeverityVariant, setAlertSeverityVariant] = React.useState('default'); + + const alertIcons = { + default: , + info: , + success: , + warning: , + danger: + }; + + return ( + <> +
+ Alert variant: + +
+
+ Popovers are triggered by click rather than hover.
} + footerContent="Popover footer" + > + + + + + ); +}; diff --git a/packages/react-core/src/components/Popover/examples/PopoverBasic.tsx b/packages/react-core/src/components/Popover/examples/PopoverBasic.tsx new file mode 100644 index 00000000000..4324eac6ee0 --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverBasic.tsx @@ -0,0 +1,15 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; + +export const PopoverBasic: React.FunctionComponent = () => ( +
+ Popover header
} + bodyContent={
Popovers are triggered by click rather than hover.
} + footerContent="Popover footer" + > + + + +); diff --git a/packages/react-core/src/components/Popover/examples/PopoverCloseControlled.tsx b/packages/react-core/src/components/Popover/examples/PopoverCloseControlled.tsx new file mode 100644 index 00000000000..45ea581fcee --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverCloseControlled.tsx @@ -0,0 +1,29 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; + +export const PopoverCloseControlled: React.FunctionComponent = () => { + const [isVisible, setIsVisible] = React.useState(false); + + return ( +
+ setIsVisible(true)} + shouldClose={() => setIsVisible(false)} + headerContent={
Popover header
} + bodyContent={ +
+
A controlled popover can be closed by updating its isVisible state after some user interaction.
+
+ +
+
+ } + footerContent="Popover footer" + > + +
+
+ ); +}; diff --git a/packages/react-core/src/components/Popover/examples/PopoverCloseUncontrolled.tsx b/packages/react-core/src/components/Popover/examples/PopoverCloseUncontrolled.tsx new file mode 100644 index 00000000000..bfab39673be --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverCloseUncontrolled.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; + +export const PopoverCloseUncontrolled: React.FunctionComponent = () => ( +
+ Popover header
} + bodyContent={hide => ( +
+
+ All the content props (headerContent, bodyContent, footerContent) can take a function which the popover + component passes the hide function to which can be used to close the popover after some user interaction. +
+
+ +
+
+ )} + footerContent="Popover footer" + > + + + +); diff --git a/packages/react-core/src/components/Popover/examples/PopoverReactRef.tsx b/packages/react-core/src/components/Popover/examples/PopoverReactRef.tsx new file mode 100644 index 00000000000..5e1d058209c --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverReactRef.tsx @@ -0,0 +1,23 @@ +import React from 'react'; +import { Popover } from '@patternfly/react-core'; + +export const PopoverReactRef: React.FunctionComponent = () => { + const popoverRef = React.useRef(null); + + return ( +
+ + Popover header
} + bodyContent={ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + footerContent="Popover footer" + reference={popoverRef} + /> + + ); +}; diff --git a/packages/react-core/src/components/Popover/examples/PopoverSelectorRef.tsx b/packages/react-core/src/components/Popover/examples/PopoverSelectorRef.tsx new file mode 100644 index 00000000000..0ce9b06e930 --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverSelectorRef.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Popover } from '@patternfly/react-core'; + +export const PopoverSelectorRef: React.FunctionComponent = () => ( +
+ + Popover header
} + bodyContent={ +
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + footerContent="Popover footer" + reference={() => document.getElementById('popover-selector') as HTMLButtonElement} + /> + +); diff --git a/packages/react-core/src/components/Popover/examples/PopoverWidthAuto.tsx b/packages/react-core/src/components/Popover/examples/PopoverWidthAuto.tsx new file mode 100644 index 00000000000..f4254147f68 --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverWidthAuto.tsx @@ -0,0 +1,14 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; + +export const PopoverWidthAuto: React.FunctionComponent = () => ( +
+
Removes fixed-width and allows width to be defined by contents
} + > + +
+
+); diff --git a/packages/react-core/src/components/Popover/examples/PopoverWithIconInTheTitle.tsx b/packages/react-core/src/components/Popover/examples/PopoverWithIconInTheTitle.tsx new file mode 100644 index 00000000000..7b8e4cb731e --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverWithIconInTheTitle.tsx @@ -0,0 +1,17 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; +import BullhornIcon from '@patternfly/react-icons/dist/esm/icons/bullhorn-icon'; + +export const PopoverWithIconInTheTitle: React.FunctionComponent = () => ( +
+ } + bodyContent={
Popovers are triggered by click rather than hover.
} + footerContent="Popover footer" + > + +
+
+); diff --git a/packages/react-core/src/components/Popover/examples/PopoverWithoutHeaderFooterCloseNoPadding.tsx b/packages/react-core/src/components/Popover/examples/PopoverWithoutHeaderFooterCloseNoPadding.tsx new file mode 100644 index 00000000000..1110afd1858 --- /dev/null +++ b/packages/react-core/src/components/Popover/examples/PopoverWithoutHeaderFooterCloseNoPadding.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { Popover, Button } from '@patternfly/react-core'; + +export const PopoverWithoutHeaderFooterCloseNoPadding: React.FunctionComponent = () => ( +
+ ( +
+ This popover has no padding and is intended for use with content that has its own spacing and should touch the + edges of the popover container. +
+ )} + withFocusTrap={false /* no focusable content in this example */} + > + +
+
+);