diff --git a/packages/react-core/src/components/Tooltip/examples/Tooltip.md b/packages/react-core/src/components/Tooltip/examples/Tooltip.md index 1d015eebe51..485b8e3be82 100644 --- a/packages/react-core/src/components/Tooltip/examples/Tooltip.md +++ b/packages/react-core/src/components/Tooltip/examples/Tooltip.md @@ -13,68 +13,17 @@ import './TooltipExamples.css'; ### Basic -```js -import React from 'react'; -import { Tooltip } from '@patternfly/react-core'; - -
- Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
- } - > - - I have a tooltip! - - -; +```ts file="./TooltipBasic.tsx" ``` ### Tooltip react ref -```js -import React from 'react'; -import { Tooltip } from '@patternfly/react-core'; - -TooltipReactRef = () => { - const tooltipRef = React.useRef(); - return ( -
- - - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. -
- } - reference={tooltipRef} - /> - - ); -}; +```ts file="./TooltipReactRef.tsx" ``` ### Tooltip selector ref -```js -import React from 'react'; -import { Tooltip } from '@patternfly/react-core'; - -
- - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.
- } - reference={() => document.getElementById('tooltip-selector')} - /> -; +```ts file="./TooltipSelectorRef.tsx" ``` ### On icon with dynamic content @@ -83,239 +32,10 @@ When the tooltip is used as a wrapper and its content will dynamically update, t When using a React or selector ref with a tooltip that has dynamic content, the `aria` and `aria-live` props do not need to be manually passed in. -```js -import React from 'react'; -import { Tooltip, Button } from '@patternfly/react-core'; -import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon'; - -IconExample = () => { - const [showSuccessContent, setShowSuccessContent] = React.useState(false); - const copyText = 'Copy to clipboard'; - const doneCopyText = 'Successfully copied to clipboard!'; - const [content, setContent] = React.useState(copyText); - return ( -
- - - -
- ); -}; +```ts file="./TooltipIcon.tsx" ``` ### Options -```js -import React from 'react'; -import { Button, Tooltip, Checkbox, Select, SelectOption, TextInput } from '@patternfly/react-core'; - -OptionsTooltip = () => { - const [trigger, setTrigger] = React.useState(['mouseenter', 'focus']); - const [isVisible, setIsVisible] = React.useState(true); - const [contentLeftAligned, setContentLeftAligned] = React.useState(false); - const [enableFlip, setEnableFlip] = React.useState(true); - const [position, setPosition] = React.useState('top'); - const [positionSelectOpen, setPositionSelectOpen] = React.useState(false); - const [flipSelectOpen, setFlipSelectOpen] = React.useState(false); - const [flipBehavior, setFlipBehavior] = React.useState('flip'); - const [entryDelayInput, setEntryDelayInput] = React.useState(0); - const [exitDelayInput, setExitDelayInput] = React.useState(0); - const [animationDuration, setAnimationDuration] = React.useState(300); - const tipBoxRef = React.useRef(null); - - const scrollToRef = ref => { - if (ref && ref.current) { - ref.current.scrollTop = 400; - ref.current.scrollLeft = 300; - } - }; - - React.useEffect(() => { - scrollToRef(tipBoxRef); - }, []); - - return ( - <> -
-
- { - let updatedTrigger; - checked && (updatedTrigger = trigger.concat('mouseenter')); - !checked && (updatedTrigger = trigger.filter(t => t !== 'mouseenter')); - setIsVisible(false); - setTrigger(updatedTrigger); - }} - aria-label="trigger: mouseenter" - id="trigger_mouseenter" - /> - { - let updatedTrigger; - checked && (updatedTrigger = trigger.concat('focus')); - !checked && (updatedTrigger = trigger.filter(t => t !== 'focus')); - setIsVisible(false); - setTrigger(updatedTrigger); - }} - aria-label="trigger: focus" - id="trigger_focus" - /> - { - let updatedTrigger; - checked && (updatedTrigger = trigger.concat('click')); - !checked && (updatedTrigger = trigger.filter(t => t !== 'click')); - setIsVisible(false); - setTimeout(() => setTrigger(updatedTrigger)); - }} - aria-label="trigger: click" - id="trigger_click" - /> - { - let updatedTrigger; - checked && (updatedTrigger = trigger.concat('manual')); - !checked && (updatedTrigger = trigger.filter(t => t !== 'manual')); - setIsVisible(false); - setTrigger(updatedTrigger); - }} - aria-label="trigger: manual" - id="trigger_manual" - /> -
-
- setContentLeftAligned(checked)} - aria-label="content left-aligned" - id="content_left_aligned" - /> -
-
- setEnableFlip(checked)} - aria-label="enableFlip" - id="enable_flip" - /> -
-
- position (will flip if enableFlip is true). The 'auto' position requires enableFlip to be set to true. - -
-
- setIsVisible(checked)} - aria-label="isVisible" - id="is_visible" - /> -
-
- Entry delay (ms){' '} - setEntryDelayInput(val)} - aria-label="entry delay" - /> - Exit delay (ms) setExitDelayInput(val)} - aria-label="exit delay" - /> - Animation duration (ms){' '} - setAnimationDuration(val)} - aria-label="animation duration" - /> -
-
- flip behavior examples (enableFlip has to be true). "flip" will try to flip the tooltip to the opposite of the - starting position. The second option ensures that there are 3 escape positions for every possible starting - position (default). This setting is ignored if position prop is set to 'auto'. - -
-
-
- - Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. -
- } - trigger={trigger.join(' ')} - enableFlip={enableFlip} - flipBehavior={flipBehavior === 'flip' ? 'flip' : ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom']} - position={position} - isVisible={isVisible} - entryDelay={entryDelayInput} - exitDelay={exitDelayInput} - animationDuration={animationDuration} - isContentLeftAligned={contentLeftAligned} - appendTo={() => document.getElementById('tooltip-boundary')} - > - - - - - ); -}; +```ts file="./TooltipOptions.tsx" ``` diff --git a/packages/react-core/src/components/Tooltip/examples/TooltipBasic.tsx b/packages/react-core/src/components/Tooltip/examples/TooltipBasic.tsx new file mode 100644 index 00000000000..47b9ef478b2 --- /dev/null +++ b/packages/react-core/src/components/Tooltip/examples/TooltipBasic.tsx @@ -0,0 +1,16 @@ +import React from 'react'; +import { Button, Tooltip } from '@patternfly/react-core'; + +export const TooltipBasic: React.FunctionComponent = () => ( +
+ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + > + + + +); diff --git a/packages/react-core/src/components/Tooltip/examples/TooltipIcon.tsx b/packages/react-core/src/components/Tooltip/examples/TooltipIcon.tsx new file mode 100644 index 00000000000..d2de7a0c2bf --- /dev/null +++ b/packages/react-core/src/components/Tooltip/examples/TooltipIcon.tsx @@ -0,0 +1,24 @@ +import React from 'react'; +import { Tooltip, Button } from '@patternfly/react-core'; +import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon'; + +export const TooltipIcon: React.FunctionComponent = () => { + const [showSuccessContent, setShowSuccessContent] = React.useState(false); + const copyText: string = 'Copy to clipboard'; + const doneCopyText: string = 'Successfully copied to clipboard!'; + + return ( +
+ + + +
+ ); +}; diff --git a/packages/react-core/src/components/Tooltip/examples/TooltipOptions.tsx b/packages/react-core/src/components/Tooltip/examples/TooltipOptions.tsx new file mode 100644 index 00000000000..c5280ac4f37 --- /dev/null +++ b/packages/react-core/src/components/Tooltip/examples/TooltipOptions.tsx @@ -0,0 +1,197 @@ +import React from 'react'; +import { Button, Tooltip, Checkbox, Select, SelectOption, TextInput, TooltipPosition } from '@patternfly/react-core'; + +export const TooltipOptions: React.FunctionComponent = () => { + const [trigger, setTrigger] = React.useState(['mouseenter', 'focus']); + const [isVisible, setIsVisible] = React.useState(true); + const [contentLeftAligned, setContentLeftAligned] = React.useState(false); + const [enableFlip, setEnableFlip] = React.useState(true); + const [position, setPosition] = React.useState(TooltipPosition.top); + const [positionSelectOpen, setPositionSelectOpen] = React.useState(false); + const [flipSelectOpen, setFlipSelectOpen] = React.useState(false); + const [flipBehavior, setFlipBehavior] = React.useState('flip'); + const [entryDelayInput, setEntryDelayInput] = React.useState(0); + const [exitDelayInput, setExitDelayInput] = React.useState(0); + const [animationDuration, setAnimationDuration] = React.useState(300); + const tipBoxRef = React.useRef(null); + + const scrollToRef = (ref: React.RefObject) => { + if (ref && ref.current) { + ref.current.scrollTop = 400; + ref.current.scrollLeft = 300; + } + }; + + React.useEffect(() => { + scrollToRef(tipBoxRef); + }, []); + + return ( + <> +
+
+ { + const updatedTrigger = checked ? trigger.concat('mouseenter') : trigger.filter(t => t !== 'mouseenter'); + setIsVisible(false); + setTrigger(updatedTrigger); + }} + aria-label="trigger: mouseenter" + id="trigger_mouseenter" + /> + { + const updatedTrigger = checked ? trigger.concat('focus') : trigger.filter(t => t !== 'focus'); + setIsVisible(false); + setTrigger(updatedTrigger); + }} + aria-label="trigger: focus" + id="trigger_focus" + /> + { + const updatedTrigger = checked ? trigger.concat('click') : trigger.filter(t => t !== 'click'); + setIsVisible(false); + setTimeout(() => setTrigger(updatedTrigger)); + }} + aria-label="trigger: click" + id="trigger_click" + /> + { + const updatedTrigger = checked ? trigger.concat('manual') : trigger.filter(t => t !== 'manual'); + setIsVisible(false); + setTrigger(updatedTrigger); + }} + aria-label="trigger: manual" + id="trigger_manual" + /> +
+
+ setContentLeftAligned(checked)} + aria-label="content left-aligned" + id="content_left_aligned" + /> +
+
+ setEnableFlip(checked)} + aria-label="enableFlip" + id="enable_flip" + /> +
+
+ position (will flip if enableFlip is true). The 'auto' position requires enableFlip to be set to true. + +
+
+ setIsVisible(checked)} + aria-label="isVisible" + id="is_visible" + /> +
+
+ Entry delay (ms){' '} + setEntryDelayInput(Number(val))} + aria-label="entry delay" + /> + Exit delay (ms){' '} + setExitDelayInput(Number(val))} + aria-label="exit delay" + /> + Animation duration (ms){' '} + setAnimationDuration(Number(val))} + aria-label="animation duration" + /> +
+
+ flip behavior examples (enableFlip has to be true). "flip" will try to flip the tooltip to the opposite of the + starting position. The second option ensures that there are 3 escape positions for every possible starting + position (default). This setting is ignored if position prop is set to 'auto'. + +
+
+
+ + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + trigger={trigger.join(' ')} + enableFlip={enableFlip} + flipBehavior={flipBehavior === 'flip' ? 'flip' : ['top', 'right', 'bottom', 'left', 'top', 'right', 'bottom']} + position={position} + isVisible={isVisible} + entryDelay={entryDelayInput} + exitDelay={exitDelayInput} + animationDuration={animationDuration} + isContentLeftAligned={contentLeftAligned} + appendTo={() => document.getElementById('tooltip-boundary') as HTMLElement} + > + + + + + ); +}; diff --git a/packages/react-core/src/components/Tooltip/examples/TooltipReactRef.tsx b/packages/react-core/src/components/Tooltip/examples/TooltipReactRef.tsx new file mode 100644 index 00000000000..d36cb67103a --- /dev/null +++ b/packages/react-core/src/components/Tooltip/examples/TooltipReactRef.tsx @@ -0,0 +1,22 @@ +import React from 'react'; +import { Tooltip } from '@patternfly/react-core'; + +export const TooltipReactRef: React.FunctionComponent = () => { + const tooltipRef = React.useRef(null); + return ( +
+ + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + reference={tooltipRef} + /> + + ); +}; diff --git a/packages/react-core/src/components/Tooltip/examples/TooltipSelectorRef.tsx b/packages/react-core/src/components/Tooltip/examples/TooltipSelectorRef.tsx new file mode 100644 index 00000000000..e90b55ae770 --- /dev/null +++ b/packages/react-core/src/components/Tooltip/examples/TooltipSelectorRef.tsx @@ -0,0 +1,19 @@ +import React from 'react'; +import { Tooltip } from '@patternfly/react-core'; + +export const TooltipSelectorRef: React.FunctionComponent = () => ( +
+ + + Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis. +
+ } + reference={() => document.getElementById('tooltip-selector') as HTMLButtonElement} + /> + +);