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

Migrate tooltip to ts #4524

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ import { space } from 'styled-system';
export const StyledTooltip = styled.span`
display: inline-block;
position: relative;

${space}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should provide typings for StyledTooltip which are:

  • SpaceProps (imported from styled-system)
  • HTML span element attributes
import styled from 'styled-components';
import { space, SpaceProps } from 'styled-system';

export interface StyledTooltipProps
  extends SpaceProps,
    React.ComponentPropsWithRef<'span'> {}

export const StyledTooltip = styled.span<SpaceProps>`
  display: inline-block;
  position: relative;

  ${space}
`;

`;
`;
31 changes: 31 additions & 0 deletions console/src/components/UIKit/atoms/Tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger';
import Tooltip from 'react-bootstrap/lib/Tooltip';
import { StyledTooltip } from './Tooltip';

export type ToolTypeGeneratorProps = {
message: string;
};

export const tooltipGenerator: React.FC<ToolTypeGeneratorProps> = ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tooltipGenerator was a function from string to JSX.Element. Could you revert this change?

message,
}) => {
return <Tooltip id={message}>{message}</Tooltip>;
};

export type ToolTipProps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use interface that extends StyledTooltipProps.
export interface ToolTipProps extends StyledTooltipProps { ... }

message: ToolTypeGeneratorProps;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to pass message as a string.

Suggested change
message: ToolTypeGeneratorProps;
message: string;

placement: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we narrow this type?

Suggested change
placement: string;
placement: 'top' | 'right' | 'bottom' | 'left';

children: any;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're using React.FC typings for children are already there.

Suggested change
children: any;

};

export const ToolTip: React.FC<ToolTipProps> = props => {
const { message, placement, children } = props;
return (
<OverlayTrigger placement={placement} overlay={tooltipGenerator(message)}>
<StyledTooltip aria-hidden="true" {...props}>
{children}
</StyledTooltip>
</OverlayTrigger>
);
};
1 change: 1 addition & 0 deletions console/src/declaration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ declare namespace SvgPanZoom {
}

declare module 'react-bootstrap/lib/Tooltip';
declare module 'react-bootstrap/lib/OverlayTrigger';