Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs(web): Showcase placement valuse on Tooltip demo #1120

Merged
merged 7 commits into from
Nov 9, 2023
4 changes: 2 additions & 2 deletions packages/web-react/src/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useMemo, forwardRef, LegacyRef } from 'react';
import classNames from 'classnames';
import React, { LegacyRef, forwardRef, useMemo } from 'react';
import { useStyleProps } from '../../hooks';
import { SpiritTooltipProps } from '../../types';
import TooltipCloseButton from './TooltipCloseButton';
import { useTooltipStyleProps } from './useTooltipStyleProps';

const Tooltip = forwardRef((props: SpiritTooltipProps, ref) => {
export const Tooltip = forwardRef((props: SpiritTooltipProps, ref) => {
const { children, isDismissible, closeLabel = 'Close', open, onClose, ...restProps } = props;

const { classProps, props: modifiedProps } = useTooltipStyleProps({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Icon } from '../Icon';
import { VisuallyHidden } from '../VisuallyHidden';
import { useTooltipStyleProps } from './useTooltipStyleProps';

const TooltipCloseButton = ({ label = 'Close', onClick, ...restProps }: TooltipCloseButtonProps) => {
export const TooltipCloseButton = ({ label = 'Close', onClick, ...restProps }: TooltipCloseButtonProps) => {
const { classProps, props: modifiedProps } = useTooltipStyleProps({ ...restProps });
const { styleProps } = useStyleProps({ ...modifiedProps });

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from 'react';
import classNames from 'classnames';
import React from 'react';
import { useStyleProps } from '../../hooks';
import { TooltipWrapperProps } from '../../types';
import { useTooltipStyleProps } from './useTooltipStyleProps';

const TooltipWrapper = ({ children, ...restProps }: TooltipWrapperProps) => {
export const TooltipWrapper = ({ children, ...restProps }: TooltipWrapperProps) => {
const { classProps, props: modifiedProps } = useTooltipStyleProps({ ...restProps });
const { styleProps } = useStyleProps({ ...modifiedProps });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { UncontrolledTooltipProps } from '../../types';
import Tooltip from './Tooltip';
import { useTooltip } from './useTooltip';

const UncontrolledTooltip = (props: UncontrolledTooltipProps) => {
export const UncontrolledTooltip = (props: UncontrolledTooltipProps) => {
const { children, isDismissible, ...restProps } = props;

const { open, onClose } = useTooltip({ isDismissible });
Expand Down
23 changes: 10 additions & 13 deletions packages/web-react/src/components/Tooltip/demo/TooltipOnHover.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
import React from 'react';
import { ButtonLink } from '../../Button';
import TooltipWrapper from '../TooltipWrapper';
import Tooltip from '../Tooltip';
import TooltipWrapper from '../TooltipWrapper';

const TooltipOnHover = () => (
<>
<TooltipWrapper>
<div>
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-top" UNSAFE_className="TooltipTarget">
Tooltip on top
</ButtonLink>
<Tooltip id="my-tooltip-hover-top" placement="top">
Hello there!
</Tooltip>
</TooltipWrapper>

<TooltipWrapper>
</TooltipWrapper>{' '}
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-right" UNSAFE_className="TooltipTarget">
Tooltip on right
</ButtonLink>
<Tooltip id="my-tooltip-hover-right" placement="right">
Hello there!
</Tooltip>
</TooltipWrapper>

<TooltipWrapper>
</TooltipWrapper>{' '}
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-bottom" UNSAFE_className="TooltipTarget">
Tooltip on bottom
</ButtonLink>
<Tooltip id="my-tooltip-hover-bottom" placement="bottom">
Hello there!
</Tooltip>
</TooltipWrapper>

<TooltipWrapper>
</TooltipWrapper>{' '}
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-left" UNSAFE_className="TooltipTarget">
Tooltip on left
</ButtonLink>
<Tooltip id="my-tooltip-hover-left" placement="left">
Hello there!
</Tooltip>
</TooltipWrapper>
</>
</div>
);

export default TooltipOnHover;
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ const TooltipPlacements = () => {
};

return (
<form autoComplete="off" className="mx-auto">
<Grid cols={3} UNSAFE_style={{ alignItems: 'center', justifyItems: 'center' }}>
<form autoComplete="off">
<Grid
cols={3}
UNSAFE_className="mx-auto"
UNSAFE_style={{ alignItems: 'center', justifyItems: 'center', maxWidth: '30rem' }}
>
<div style={{ gridRow: 1, gridColumn: 2 }}>
<Radio
name="placement"
Expand Down Expand Up @@ -74,7 +78,7 @@ const TooltipPlacements = () => {
value="bottom-right"
/>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gridRow: 2, gridColumn: 1 }}>
<div style={{ display: 'flex', flexDirection: 'column', gridRow: 2, gridColumn: 1, justifySelf: 'start' }}>
<Radio
name="placement"
isChecked={placement === 'left-top'}
Expand Down Expand Up @@ -103,7 +107,7 @@ const TooltipPlacements = () => {
value="left-bottom"
/>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gridRow: 2, gridColumn: 3 }}>
<div style={{ display: 'flex', flexDirection: 'column', gridRow: 2, gridColumn: 3, justifySelf: 'end' }}>
<Radio
name="placement"
isChecked={placement === 'right-top'}
Expand Down Expand Up @@ -133,9 +137,12 @@ const TooltipPlacements = () => {
/>
</div>
<div style={{ gridRow: 2, gridColumn: 2 }}>
<TooltipWrapper UNSAFE_style={{ margin: '6rem auto' }}>
<DocsBox>Click the dots!</DocsBox>
<Tooltip placement={placement as PlacementDictionaryType}>Hello!</Tooltip>
<TooltipWrapper UNSAFE_style={{ margin: '5rem auto' }}>
<DocsBox UNSAFE_className="px-900 py-900">
Click
<br /> the dots!
</DocsBox>
<Tooltip placement={placement as PlacementDictionaryType}>{placement}</Tooltip>
</TooltipWrapper>
</div>
</Grid>
Expand Down
12 changes: 6 additions & 6 deletions packages/web-react/src/components/Tooltip/demo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@ import ReactDOM from 'react-dom/client';
import icons from '@lmc-eu/spirit-icons/dist/icons';
import DocsSection from '../../../../docs/DocsSections';
import { IconsProvider } from '../../../context';
import TooltipPlacements from './TooltipPlacements';
import TooltipDefault from './TooltipDefault';
import TooltipOnHover from './TooltipOnHover';
import TooltipClickable from './TooltipClickable';
import TooltipDefault from './TooltipDefault';
import TooltipDismissible from './TooltipDismissible';
import TooltipFloatingUI from './TooltipFloatingUi';
import TooltipDismissibleViaJS from './TooltipDismissibleViaJS';
import TooltipFloatingUI from './TooltipFloatingUi';
import TooltipOnHover from './TooltipOnHover';
import TooltipPlacements from './TooltipPlacements';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
<React.StrictMode>
<IconsProvider value={icons}>
<DocsSection title="Placements">
<DocsSection title="Placements" stackAlignment="stretch">
<TooltipPlacements />
</DocsSection>
<DocsSection title="Static Tooltip (No Interaction)">
<TooltipDefault />
</DocsSection>
<DocsSection title="Tooltip on Hover (Pure CSS)">
<DocsSection title="Tooltip on Hover (Pure CSS)" stackAlignment="stretch">
<TooltipOnHover />
</DocsSection>
<DocsSection title="Tooltip on Click (JavaScript)">
Expand Down
9 changes: 5 additions & 4 deletions packages/web-react/src/components/Tooltip/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
export * from './Tooltip';
export * from './TooltipWrapper';
export { default as Tooltip } from './Tooltip';
export * from './TooltipCloseButton';
export { default as TooltipCloseButton } from './TooltipCloseButton';
export * from './TooltipWrapper';
export { default as TooltipWrapper } from './TooltipWrapper';
export * from './UncontrolledTooltip';
export { default as UncontrolledTooltip } from './UncontrolledTooltip';
export * from './useTooltip';
export * from './useTooltipStyleProps';
export { default as Tooltip } from './Tooltip';
export { default as TooltipWrapper } from './TooltipWrapper';
export { default as UncontrolledTooltip } from './UncontrolledTooltip';
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

{% block content %}

<DocsSection title="Placements">
<DocsSection title="Placements" stackAlignment="stretch">
{% include '@components/Tooltip/stories/TooltipPlacements.twig' %}
</DocsSection>

<DocsSection title="Static Tooltip (No Interaction)" stackAlignment="stretch">
{% include '@components/Tooltip/stories/TooltipStatic.twig' %}
</DocsSection>

<DocsSection title="Tooltip on Hover (Pure CSS)">
<DocsSection title="Tooltip on Hover (Pure CSS)" stackAlignment="stretch">
{% include '@components/Tooltip/stories/TooltipOnHover.twig' %}
</DocsSection>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
<TooltipWrapper>
<ButtonLink
href="#"
aria-describedby="my-tooltip-hover-top"
UNSAFE_className="TooltipTarget"
>
Tooltip on top
</ButtonLink>
<Tooltip id="my-tooltip-hover-top" placement="top">
Hello there!
</Tooltip>
</TooltipWrapper>
<div>
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-top" UNSAFE_className="TooltipTarget">
Tooltip on top
</ButtonLink>
<Tooltip id="my-tooltip-hover-top" placement="top">
Hello there!
</Tooltip>
</TooltipWrapper>

<TooltipWrapper>
<ButtonLink
href="#"
aria-describedby="my-tooltip-hover-right"
UNSAFE_className="TooltipTarget"
>
Tooltip on right
</ButtonLink>
<Tooltip id="my-tooltip-hover-right" placement="right">
Hello there!
</Tooltip>
</TooltipWrapper>
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-right" UNSAFE_className="TooltipTarget">
Tooltip on right
</ButtonLink>
<Tooltip id="my-tooltip-hover-right" placement="right">
Hello there!
</Tooltip>
</TooltipWrapper>

<TooltipWrapper>
<ButtonLink
href="#"
aria-describedby="my-tooltip-hover-bottom"
UNSAFE_className="TooltipTarget"
>
Tooltip on bottom
</ButtonLink>
<Tooltip id="my-tooltip-hover-bottom" placement="bottom">
Hello there!
</Tooltip>
</TooltipWrapper>
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-bottom" UNSAFE_className="TooltipTarget">
Tooltip on bottom
</ButtonLink>
<Tooltip id="my-tooltip-hover-bottom" placement="bottom">
Hello there!
</Tooltip>
</TooltipWrapper>

<TooltipWrapper>
<ButtonLink
href="#"
aria-describedby="my-tooltip-hover-left"
UNSAFE_className="TooltipTarget"
>
Tooltip on left
</ButtonLink>
<Tooltip id="my-tooltip-hover-left" placement="left">
Hello there!
</Tooltip>
</TooltipWrapper>
<TooltipWrapper UNSAFE_className="d-inline-block mr-600 mb-600">
<ButtonLink href="#" aria-describedby="my-tooltip-hover-left" UNSAFE_className="TooltipTarget">
Tooltip on left
</ButtonLink>
<Tooltip id="my-tooltip-hover-left" placement="left">
Hello there!
</Tooltip>
</TooltipWrapper>
</div>
Original file line number Diff line number Diff line change
@@ -1,53 +1,56 @@
<form autocomplete="off" class="mx-auto">
<Grid cols="3" UNSAFE_style="align-items: center; justify-items: center">
<form autocomplete="off">
<Grid cols="3" UNSAFE_className="mx-auto" UNSAFE_style="align-items: center; justify-items: center; max-width: 30rem;">
<div style="grid-row: 1; grid-column: 2">

<Radio name="placement" isLabelHidden value="topLeft" id="placement_top_left" label="top-left" />
<Radio name="placement" isLabelHidden value="top" id="placement_top" label="top" />
<Radio name="placement" isLabelHidden value="topRight" id="placement_top_right" label="top-right" />
<Radio name="placement" isLabelHidden value="topLeft" id="placement_top_left" label="top-left"/>
<Radio name="placement" isLabelHidden value="top" id="placement_top" label="top"/>
<Radio name="placement" isLabelHidden value="topRight" id="placement_top_right" label="top-right"/>

</div>
<div style="grid-row: 3; grid-column: 2">

<Radio name="placement" isLabelHidden value="bottomLeft" id="placement_bottom_left" label="bottom-left" />
<Radio name="placement" isLabelHidden value="bottom" id="placement_bottom" label="bottom" isChecked />
<Radio name="placement" isLabelHidden value="bottomRight" id="placement_bottom_right" label="bottom-right" />
<Radio name="placement" isLabelHidden value="bottomLeft" id="placement_bottom_left" label="bottom-left"/>
<Radio name="placement" isLabelHidden value="bottom" id="placement_bottom" label="bottom" isChecked/>
<Radio name="placement" isLabelHidden value="bottomRight" id="placement_bottom_right" label="bottom-right"/>

</div>
<div style="display: flex; flex-direction: column; grid-row: 2; grid-column: 1">
<div style="display: flex; flex-direction: column; grid-row: 2; grid-column: 1; justify-self: start;">

<Radio name="placement" isLabelHidden value="leftTop" id="placement_left_top" label="left-top" />
<Radio name="placement" isLabelHidden value="left" id="placement_left" label="left" />
<Radio name="placement" isLabelHidden value="leftBottom" id="placement_left_bottom" label="left-bottom" />
<Radio name="placement" isLabelHidden value="leftTop" id="placement_left_top" label="left-top"/>
<Radio name="placement" isLabelHidden value="left" id="placement_left" label="left"/>
<Radio name="placement" isLabelHidden value="leftBottom" id="placement_left_bottom" label="left-bottom"/>

</div>
<div style="display: flex; flex-direction: column; grid-row: 2; grid-column: 3">
<div style="display: flex; flex-direction: column; grid-row: 2; grid-column: 3; justify-self: end;">

<Radio name="placement" isLabelHidden value="rightTop" id="placement_right_top" label="right-top" />
<Radio name="placement" isLabelHidden value="right" id="placement_right" label="right" />
<Radio name="placement" isLabelHidden value="rightBottom" id="placement_right_bottom" label="right-bottom" />
<Radio name="placement" isLabelHidden value="rightTop" id="placement_right_top" label="right-top"/>
<Radio name="placement" isLabelHidden value="right" id="placement_right" label="right"/>
<Radio name="placement" isLabelHidden value="rightBottom" id="placement_right_bottom" label="right-bottom"/>

</div>
<div style="grid-row: 2; grid-column: 2">

<TooltipWrapper UNSAFE_style="margin: 6rem auto">
<DocsBox>Click the dots!</DocsBox>
<Tooltip id="tooltip_placements_example">Hello!</Tooltip>
<TooltipWrapper UNSAFE_style="margin: 5rem auto">
<DocsBox UNSAFE_className="px-900 py-900">Click<br /> the dots!</DocsBox>
<Tooltip id="tooltip_placements_example">
<span id="tooltip_placements_example_text">bottom</span>
</Tooltip>
</TooltipWrapper>

</div>
</Grid>
</form>

<script>
const radios = document.querySelectorAll('input[type="radio"]');

radios.forEach(radio => {
radio.addEventListener('change', () => {
const placement = radio.value;
const tooltip = document.getElementById('tooltip_placements_example');
const tooltipText = document.getElementById('tooltip_placements_example_text');

tooltip.classList.replace(tooltip.classList[1], `Tooltip--${placement}`);
tooltipText.textContent = placement.split(/(?=[A-Z])/).join('-').toLowerCase();
});
});
</script>
Loading