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

feat(DefinitionTooltip): add Definition Tooltip #10262

Merged
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
738f98f
feat(DefinitionTooltip): add definition tooltip
dakahn Nov 17, 2021
7982689
Merge branch 'main' into implement-definition-tooltip
dakahn Nov 30, 2021
162e249
feat(DefinitionTooltip): add DefinitionTooltip styles
dakahn Nov 30, 2021
b7f8e9e
Update packages/styles/scss/components/tooltip/_tooltip.scss
dakahn Nov 30, 2021
07d9523
fix(DefintionTooltip): fix blur trigger inconsitencies/adjust story copy
dakahn Dec 8, 2021
7c1c705
fix(Tooltip): format _tooltip.scss
dakahn Dec 8, 2021
830d805
Merge branch 'main' into implement-definition-tooltip
dakahn Dec 8, 2021
27ed082
Update packages/styles/scss/components/tooltip/_tooltip.scss
dakahn Dec 8, 2021
d722304
Update packages/styles/scss/components/tooltip/_tooltip.scss
dakahn Dec 8, 2021
91d4cef
fix(DefinitionTooltip): remove unneeded clickHandler
dakahn Dec 8, 2021
ff74709
test(DefinitionTooltip): add DefinitionTooltip tests
dakahn Dec 8, 2021
b09bd33
test(DefinitionTooltip): add distinct DefinitionTooltip test file
dakahn Dec 9, 2021
a1479f3
Merge branch 'main' into implement-definition-tooltip
joshblack Dec 14, 2021
ba51da0
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 12, 2022
1bfd894
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 13, 2022
6327802
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 13, 2022
b7f8fe9
feat(DefinitionTooltip): update underline styling, onClick bug
dakahn Jan 14, 2022
7c4bf24
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 14, 2022
39e8ac7
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 18, 2022
674a293
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 19, 2022
d30a062
fix(DefinitionTooltip): fix font weight/color
dakahn Jan 20, 2022
c987689
feat(DefinitionTooltip): add openOnClick prop, update story
dakahn Jan 20, 2022
7a5cf52
Merge branch 'main' of github.com:carbon-design-system/carbon into im…
dakahn Jan 24, 2022
5a0f788
fix(TooltipDefinition): add on-hover styling
dakahn Jan 24, 2022
7d0e5f5
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 24, 2022
e1908e9
fix(react): update definition tooltip reveal behavior
joshblack Jan 25, 2022
b948704
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 25, 2022
35d385f
Merge branch 'main' of github.com:carbon-design-system/carbon into im…
dakahn Jan 26, 2022
86838da
fix(DefinitionTooltip): move spread props after className prop
dakahn Jan 26, 2022
2e86f04
Merge branch 'main' into implement-definition-tooltip
dakahn Jan 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions packages/react/src/components/Tooltip/next/DefinitionTooltip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import PropTypes from 'prop-types';
import React, { useState } from 'react';
import { Popover, PopoverContent } from '../../Popover';
import { match, keys } from '../../../internal/keyboard';
import { usePrefix } from '../../../internal/usePrefix';
import { useId } from '../../../internal/useId';

function DefinitionTooltip({ children, definition, openOnClick, ...rest }) {
const [isOpen, setOpen] = useState(false);
const prefix = usePrefix();
const id = useId();

function handleKeyDown(event) {
if (isOpen && match(event, keys.Escape)) {
event.stopPropagation();
setOpen(false);
}
if (openOnClick && match(event, [keys.Enter, keys.Space])) {
event.stopPropagation();
setOpen(!isOpen);
}
}

return (
<Popover open={isOpen} highContrast dropShadow={false} align="bottom-left">
<button
type="button"
className={`${prefix}--definition-term`}
aria-controls="definition-id"
aria-expanded={isOpen}
onMouseOut={() => !openOnClick && setOpen(false)}
onMouseOver={() => !openOnClick && setOpen(true)}
onBlur={() => setOpen(false)}
onKeyDown={handleKeyDown}
onClick={() => setOpen(!isOpen)}
onFocus={() => !openOnClick && setOpen(true)}
{...rest}>
{children}
</button>
<PopoverContent className={`${prefix}--definition-tooltip`} id={id}>
{definition}
</PopoverContent>
</Popover>
);
}

DefinitionTooltip.propTypes = {
/**
* Provide the content being defined
*/
children: PropTypes.node,

/**
* Provide the content being defined
*/
definition: PropTypes.string.isRequired,
/**
* Specify whether the tooltip should toggle on click and NOT on mouse enter/leave
*/
openOnClick: PropTypes.bool,
};

export { DefinitionTooltip };
19 changes: 19 additions & 0 deletions packages/react/src/components/Tooltip/next/Tooltip.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import './story.scss';
import { Checkbox16 } from '@carbon/icons-react';
import React from 'react';
import { Tooltip } from '../next';
import { DefinitionTooltip } from './DefinitionTooltip.js';

export default {
title: 'Experimental/unstable_Tooltip',
Expand Down Expand Up @@ -68,6 +69,24 @@ export const Duration = () => {
);
};

export const Definition = () => {
const definition =
'Uniform Resource Locator; the address of a resource (such as a document or website) on the Internet.';
return (
<div>
<p>
Custom domains direct requests for your apps in this Cloud Foundry
organization to a{' '}
<DefinitionTooltip openOnClick definition={definition}>
URL
</DefinitionTooltip>{' '}
that you own. A custom domain can be a shared domain, a shared
subdomain, or a shared domain and host.
</p>
</div>
);
};

const PlaygroundStory = (props) => {
const {
align,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Copyright IBM Corp. 2016, 2018
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/

import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import React from 'react';
import { DefinitionTooltip } from '../../next/DefinitionTooltip';

describe('DefintiionTooltip', () => {
it('should support a custom className with the `className` prop', () => {
const definition = 'Uniform Resource Locator';
render(
<DefinitionTooltip definition={definition} className="tooltip-class">
URL
</DefinitionTooltip>
);
expect(screen.getByText('URL')).toHaveClass('tooltip-class');
});

it('should apply additional props to the outermost element', () => {
const definition = 'Uniform Resource Locator';
render(
<DefinitionTooltip
data-testid="test"
definition={definition}
className="tooltip-class">
URL
</DefinitionTooltip>
);
expect(screen.getByText('URL')).toHaveAttribute('data-testid', 'test');
});

it('should display onClick a defintion provided via prop', () => {
const definition = 'Uniform Resource Locator';
render(
<DefinitionTooltip
data-testid="test"
definition={definition}
className="tooltip-class">
URL
</DefinitionTooltip>
);
userEvent.click(screen.getByText('URL'));
expect(screen.getByText(definition)).toHaveTextContent(definition);
});
});
1 change: 1 addition & 0 deletions packages/styles/scss/components/tooltip/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@

@include tooltip.tooltip;
@include tooltip.icon-tooltip;
@include tooltip.definition-tooltip;
26 changes: 26 additions & 0 deletions packages/styles/scss/components/tooltip/_tooltip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@use '../../type';
@use '../../utilities/custom-property';
@use '../../utilities/convert';
@use '../../utilities/button-reset';
@use '../../utilities/focus-outline';

$tooltip-padding-block: custom-property.get-var(
'tooltip-padding-block',
Expand All @@ -37,6 +39,30 @@ $tooltip-padding-inline: custom-property.get-var(
}
}

@mixin definition-tooltip {
.#{$prefix}--definition-term {
@include button-reset.reset;

border-bottom: 1px dotted theme.$border-strong;
border-radius: 0;

color: theme.$text-primary;
}

.#{$prefix}--definition-term:focus {
@include focus-outline.focus-outline;

border-bottom-color: theme.$border-interactive;
}

.#{$prefix}--definition-tooltip {
@include type.type-style('body-long-01');

max-width: convert.rem(176px);
padding: convert.rem(8px) convert.rem(16px);
}
}

@mixin icon-tooltip {
.#{$prefix}--icon-tooltip {
@include custom-property.declaration(
Expand Down