aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/tooltip
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/molecules/tooltip')
-rw-r--r--src/components/molecules/tooltip/index.ts1
-rw-r--r--src/components/molecules/tooltip/tooltip.module.scss66
-rw-r--r--src/components/molecules/tooltip/tooltip.stories.tsx42
-rw-r--r--src/components/molecules/tooltip/tooltip.test.tsx40
-rw-r--r--src/components/molecules/tooltip/tooltip.tsx98
5 files changed, 0 insertions, 247 deletions
diff --git a/src/components/molecules/tooltip/index.ts b/src/components/molecules/tooltip/index.ts
deleted file mode 100644
index ed8326d..0000000
--- a/src/components/molecules/tooltip/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from './tooltip';
diff --git a/src/components/molecules/tooltip/tooltip.module.scss b/src/components/molecules/tooltip/tooltip.module.scss
deleted file mode 100644
index 557d9c7..0000000
--- a/src/components/molecules/tooltip/tooltip.module.scss
+++ /dev/null
@@ -1,66 +0,0 @@
-@use "../../../styles/abstracts/functions" as fun;
-@use "../../../styles/abstracts/mixins" as mix;
-@use "../../../styles/abstracts/variables" as var;
-
-.btn {
- margin-right: var(--spacing-xs);
-}
-
-.tooltip {
- position: absolute;
- z-index: 10;
- font-size: var(--font-size-sm);
- transition: all 0.75s ease-in-out 0s;
-
- @media screen and (max-height: #{var.get-breakpoint("2xs")}) {
- width: calc(97.5vw - var(--spacing-md));
- right: 0;
- }
-
- &--down {
- top: calc(100% + var(--spacing-xs));
- transform-origin: top;
- }
-
- &--up {
- bottom: calc(100% + var(--spacing-2xs));
- transform-origin: bottom;
- }
-
- &--hidden {
- flex: 0 0 0;
- opacity: 0;
- visibility: hidden;
- transform: scale(0);
- }
-
- &--visible {
- opacity: 1;
- visibility: visible;
- transform: scale(1);
- }
-}
-
-.heading {
- display: flex;
- flex-flow: row nowrap;
- align-items: center;
- height: 100%;
- margin-left: calc(var(--spacing-xs) * -1.1);
- font-size: var(--font-size-sm);
-}
-
-.icon {
- align-self: stretch;
- margin-right: var(--spacing-xs);
- background: var(--color-primary-dark);
- border: fun.convert-px(1) solid var(--color-primary-dark);
- box-shadow: fun.convert-px(1) fun.convert-px(1) 0 0 var(--color-shadow);
-
- :global {
- path {
- fill: var(--color-fg-inverted);
- margin-inline: var(--spacing-2xs);
- }
- }
-}
diff --git a/src/components/molecules/tooltip/tooltip.stories.tsx b/src/components/molecules/tooltip/tooltip.stories.tsx
deleted file mode 100644
index 8a22a06..0000000
--- a/src/components/molecules/tooltip/tooltip.stories.tsx
+++ /dev/null
@@ -1,42 +0,0 @@
-import { ComponentMeta, ComponentStory } from '@storybook/react';
-import { Tooltip } from './tooltip';
-import { useState } from 'react';
-
-/**
- * Switch - Storybook Meta
- */
-export default {
- title: 'Molecules/Tooltip',
- component: Tooltip,
- args: {},
- argTypes: {},
-} as ComponentMeta<typeof Tooltip>;
-
-const Template: ComponentStory<typeof Tooltip> = ({
- isOpen,
- onToggle: _onToggle,
- ...args
-}) => {
- const [isOpened, setIsOpened] = useState(isOpen);
-
- const toggle = () => {
- setIsOpened((prev) => !prev);
- };
-
- return (
- <div style={{ position: 'relative' }}>
- <Tooltip {...args} isOpen={isOpened} onToggle={toggle} />
- </div>
- );
-};
-
-/**
- * Tooltip Stories - Example
- */
-export const Example = Template.bind({});
-Example.args = {
- children:
- 'Inventore natus dignissimos aut illum modi asperiores. Et voluptatibus delectus.',
- heading: 'A title',
- isOpen: false,
-};
diff --git a/src/components/molecules/tooltip/tooltip.test.tsx b/src/components/molecules/tooltip/tooltip.test.tsx
deleted file mode 100644
index 25a1614..0000000
--- a/src/components/molecules/tooltip/tooltip.test.tsx
+++ /dev/null
@@ -1,40 +0,0 @@
-import { describe, expect, it } from '@jest/globals';
-import { render, screen } from '../../../../tests/utils';
-import { Tooltip } from './tooltip';
-
-const title = 'A custom title';
-const children =
- 'Labore ullam delectus sit modi quam dolores. Ratione id sint aliquid facilis ipsum. Unde necessitatibus provident minus.';
-
-describe('Tooltip', () => {
- it('renders a title and a body', () => {
- render(<Tooltip heading={title}>{children}</Tooltip>);
-
- expect(screen.getByText(title)).toBeInTheDocument();
- expect(screen.getByText(children)).toBeInTheDocument();
- });
-
- it('can render a hidden modal', () => {
- render(
- <Tooltip heading={title} isOpen={false}>
- {children}
- </Tooltip>
- );
-
- // Neither toBeVisible or toHaveStyle are working.
- //expect(screen.getByText(children)).not.toBeVisible();
- //expect(screen.getByText(children)).toHaveStyle({ visibility: 'hidden' });
- expect(screen.getByText(children)).toHaveClass('tooltip--hidden');
- });
-
- it('can render a visible modal', () => {
- render(
- <Tooltip heading={title} isOpen>
- {children}
- </Tooltip>
- );
-
- expect(screen.getByText(children)).toBeVisible();
- expect(screen.getByText(children)).toHaveStyle({ visibility: 'visible' });
- });
-});
diff --git a/src/components/molecules/tooltip/tooltip.tsx b/src/components/molecules/tooltip/tooltip.tsx
deleted file mode 100644
index 1f54d68..0000000
--- a/src/components/molecules/tooltip/tooltip.tsx
+++ /dev/null
@@ -1,98 +0,0 @@
-import { type FC, type MouseEventHandler, useRef } from 'react';
-import { useIntl } from 'react-intl';
-import { useOnClickOutside } from '../../../utils/hooks';
-import { Heading, Icon, Modal, type ModalProps } from '../../atoms';
-import { HelpButton } from '../buttons';
-import styles from './tooltip.module.scss';
-
-export type TooltipProps = Omit<ModalProps, 'heading'> & {
- /**
- * The tooltip direction when opening.
- *
- * @default "downwards"
- */
- direction?: 'downwards' | 'upwards';
- /**
- * The tooltip heading.
- */
- heading: string;
- /**
- * Should the tooltip be opened?
- *
- * @default false
- */
- isOpen?: boolean;
- /**
- * A callback function to trigger when clicking outside the modal.
- */
- onClickOutside?: () => void;
- /**
- * An event handler when clicking on the help button.
- */
- onToggle?: MouseEventHandler<HTMLButtonElement>;
-};
-
-/**
- * Tooltip component
- *
- * Render a button and a modal. Note: you should add a CSS rule
- * `position: relative;` on the consumer.
- */
-export const Tooltip: FC<TooltipProps> = ({
- children,
- className = '',
- direction = 'downwards',
- heading,
- isOpen,
- onClickOutside,
- onToggle,
- ...props
-}) => {
- const intl = useIntl();
- const helpLabel = intl.formatMessage({
- defaultMessage: 'Show help',
- description: 'Tooltip: show help label',
- id: '1Xgg7+',
- });
- const directionModifier =
- direction === 'upwards' ? 'tooltip--up' : 'tooltip--down';
- const visibilityModifier = isOpen ? 'tooltip--visible' : 'tooltip--hidden';
- const tooltipClass = `${styles.tooltip} ${styles[directionModifier]} ${styles[visibilityModifier]} ${className}`;
- const btnRef = useRef<HTMLButtonElement>(null);
-
- const closeModal = (target: Node) => {
- if (!onClickOutside) return;
-
- if (btnRef.current && !btnRef.current.contains(target)) {
- onClickOutside();
- }
- };
-
- const modalRef = useOnClickOutside<HTMLDivElement>(closeModal);
-
- return (
- <>
- <Modal
- {...props}
- className={tooltipClass}
- heading={
- <Heading className={styles.heading} isFake level={6}>
- <Icon aria-hidden className={styles.icon} shape="help" size="sm" />
- {heading}
- </Heading>
- }
- kind="secondary"
- ref={modalRef}
- >
- {children}
- </Modal>
- <HelpButton
- className={styles.btn}
- isPressed={isOpen}
- label={helpLabel}
- onClick={onToggle}
- ref={btnRef}
- />
- </>
- );
-};