-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REFACTOR: [react-ui-components] migrate Tooltip to TypeScript (#2224)
- Loading branch information
1 parent
3300db0
commit c5ba1ca
Showing
8 changed files
with
1,981 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 1 addition & 0 deletions
1
.../react-ui-components/src/Tooltip/index.js → .../react-ui-components/src/Tooltip/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, {PureComponent, ReactNode} from 'react'; | ||
import mergeClassNames from 'classnames'; | ||
import {PickDefaultProps} from '../../types'; | ||
|
||
export interface TooltipProps { | ||
/** | ||
* An optional className to render on the tooltip node. | ||
*/ | ||
readonly className?: string; | ||
|
||
/** | ||
* The children to render within the tooltip node. | ||
*/ | ||
readonly children?: ReactNode; | ||
|
||
/** | ||
* If set to true the tooltip won't be positioned absolute but relative and | ||
* show up inline | ||
*/ | ||
readonly renderInline?: boolean; | ||
|
||
/** | ||
* An optional css theme to be injected. | ||
*/ | ||
readonly theme?: TooltipTheme; | ||
|
||
/** | ||
* Whether this tooltip should indicate an error or not | ||
*/ | ||
readonly asError?: boolean; | ||
} | ||
|
||
interface TooltipTheme { | ||
readonly tooltip: string; | ||
readonly 'tooltip--asError': string; | ||
readonly 'tooltip--inline': string; | ||
readonly 'tooltip--arrow': string; | ||
readonly 'tooltip--inner': string; | ||
} | ||
|
||
export const defaultProps: PickDefaultProps<TooltipProps, 'renderInline'> = { | ||
renderInline: false, | ||
}; | ||
|
||
export default class Tooltip extends PureComponent<TooltipProps> { | ||
public static defaultProps = defaultProps; | ||
|
||
public render(): JSX.Element { | ||
const { | ||
children, | ||
className, | ||
theme, | ||
renderInline, | ||
asError, | ||
...rest | ||
} = this.props; | ||
const classNames = mergeClassNames( | ||
theme!.tooltip, | ||
{ | ||
[theme!['tooltip--asError']]: asError, | ||
[theme!['tooltip--inline']]: renderInline, | ||
}, | ||
className | ||
); | ||
|
||
return ( | ||
<div {...rest} className={classNames}> | ||
<div className={theme!['tooltip--arrow']}/> | ||
<div className={theme!['tooltip--inner']}> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.