Skip to content

Commit

Permalink
feat(PPDSC-2117): tooltip panel and content (#204)
Browse files Browse the repository at this point in the history
* fix(PPDSC-2117): wip

* feat(PPDSC-2117): add tooltip

* fix(PPDSC-2117): add forwardRef to iconButton and update tests

* fix(PPDSC-2117): add to index.ts

* fix(PPDSC-2117): address comments

* fix(PPDSC-2117): address comments

* fix(PPDSC-2117): address reviews

* fix(PPDSC-2117): a11y test

* fix(PPDSC-2117): naming and comment

* fix(PPDSC-2117): design feedback
  • Loading branch information
Xin00163 authored May 25, 2022
1 parent 2f093a5 commit edcc238
Show file tree
Hide file tree
Showing 18 changed files with 1,206 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
"@emotion-icons/material-outlined": "3.8.0",
"@emotion/react": "^11.1.5",
"@emotion/styled": "^11.1.5",
"@floating-ui/react-dom-interactions": "^0.6.0",
"@seznam/compose-react-refs": "^1.0.5",
"aria-hidden": "^1.1.3",
"date-fns": "^2.6.0",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Array [
"TitleBar",
"Toast",
"ToastProvider",
"Tooltip",
"UnorderedList",
"VideoPlayer",
"Visible",
Expand Down
2 changes: 1 addition & 1 deletion src/button/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ export const isButtonLink = (
props: ButtonOrButtonLinkProps,
): props is ButtonLinkProps => (props as ButtonLinkProps).href !== undefined;

export type IconButtonProps = {'aria-label': string} & ButtonOrButtonLinkProps;
export type IconButtonProps = {'aria-label'?: string} & ButtonOrButtonLinkProps;
27 changes: 25 additions & 2 deletions src/icon-button/__tests__/icon-button.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';
import {renderToFragmentWithTheme} from '../../test/test-utils';
import React, {createRef} from 'react';
import {act} from '@testing-library/react';
import {
renderToFragmentWithTheme,
renderWithTheme,
} from '../../test/test-utils';
import {IconButton} from '..';
import {ButtonSize, IconButtonProps} from '../../button';
import {IconFilledEmail} from '../../icons';
Expand Down Expand Up @@ -74,6 +78,25 @@ describe('IconButton', () => {
expect(fragment).toMatchSnapshot();
});

test('focus can be triggered with ref', async () => {
const iconButtonRef = createRef<HTMLButtonElement>();

const props = {
ref: iconButtonRef,
'aria-label': 'Test icon button',
children: <IconFilledEmail />,
};

renderWithTheme(IconButton, props);

await act(async () => {
if (iconButtonRef && iconButtonRef.current) {
iconButtonRef.current.focus();
}
});
expect(iconButtonRef.current).toHaveFocus();
});

test('renders icon button with logical prop overrides', () => {
const props: IconButtonProps = {
'aria-label': 'Test icon button',
Expand Down
11 changes: 8 additions & 3 deletions src/icon-button/icon-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import defaults from './defaults';
import stylePresets from './style-presets';
import {withOwnTheme} from '../utils/with-own-theme';

const ThemelessIconButton = ({overrides = {}, ...props}: IconButtonProps) => {
const ThemelessIconButton = React.forwardRef<
HTMLButtonElement | HTMLAnchorElement,
IconButtonProps
>(({overrides = {}, ...props}, ref) => {
const theme = useTheme();
const {size = ButtonSize.Small} = props;

Expand All @@ -15,8 +18,10 @@ const ThemelessIconButton = ({overrides = {}, ...props}: IconButtonProps) => {
...filterOutFalsyProperties(overrides),
};

return <Button {...props} size={size} overrides={iconButtonSettings} />;
};
return (
<Button {...props} size={size} ref={ref} overrides={iconButtonSettings} />
);
});

export const IconButton: React.FC<IconButtonProps> = withOwnTheme(
ThemelessIconButton,
Expand Down
2 changes: 1 addition & 1 deletion src/icon-button/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ButtonProps} from '../button';

export interface IconButtonProps extends ButtonProps {
'aria-label': string;
'aria-label'?: string;
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export * from './theme';
export * from './theme-checker';
export * from './title-bar';
export * from './toast';
export * from './tooltip';
export * from './typography';
export * from './unordered-list';
export * from './utils/hooks/use-media-query';
Expand Down
14 changes: 14 additions & 0 deletions src/theme/__tests__/__snapshots__/theme.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,13 @@ Object {
"spaceInset": "spaceInset030",
"stylePreset": "toastNeutral",
},
"tooltip": Object {
"paddingBlock": "spaceInset020",
"paddingInline": "spaceInset020",
"stylePreset": "tooltip",
"typographyPreset": "utilityLabel010",
"zIndex": 80,
},
"unorderedList": Object {
"content": Object {
"stylePreset": "inkBase",
Expand Down Expand Up @@ -4773,6 +4780,13 @@ Object {
"iconColor": "{{colors.inkInverse}}",
},
},
"tooltip": Object {
"base": Object {
"backgroundColor": "{{colors.interface060}}",
"borderRadius": "{{borders.borderRadiusDefault}}",
"color": "{{colors.inkInverse}}",
},
},
"videoPlayerControlBar": Object {
"base": Object {
"backgroundColor": "{{colors.blackTint050}}",
Expand Down
77 changes: 77 additions & 0 deletions src/tooltip/__tests__/__snapshots__/tooltip.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Tooltip should render correct styles: default 1`] = `
<DocumentFragment>
<button
aria-describedby="floating-ui-2"
type="submit"
>
Add
</button>
.emotion-0 {
margin: 0;
pointer-events: none;
z-index: 80;
background-color: #0A0A0A;
color: #FFFFFF;
border-radius: 8px;
font-family: "Poppins",sans-serif;
font-size: 12px;
line-height: 1.5;
font-weight: 500;
letter-spacing: 0;
padding-inline: 8px;
padding-block: 8px;
}
<p
class="Tooltip emotion-0"
id="floating-ui-2"
role="tooltip"
style="position: absolute;"
tabindex="-1"
>
hello
</p>
</DocumentFragment>
`;

exports[`Tooltip should render correct styles: with overrides 1`] = `
<DocumentFragment>
<button
aria-describedby="floating-ui-11"
type="submit"
>
Add
</button>
.emotion-0 {
margin: 0;
padding-inline: 8px;
padding-block: 16px;
pointer-events: none;
z-index: 70;
max-width: 80px;
min-width: 50px;
background-color: #EF1703;
border-radius: 0;
color: #0A0A0A;
font-family: "Poppins",sans-serif;
font-size: 14px;
line-height: 1.5;
font-weight: 500;
letter-spacing: 0;
padding-inline: 8px;
padding-block: 16px;
}
<p
class="Tooltip emotion-0"
id="floating-ui-11"
role="tooltip"
style="position: absolute;"
tabindex="-1"
>
hello
</p>
</DocumentFragment>
`;
Loading

0 comments on commit edcc238

Please sign in to comment.