Skip to content

Commit

Permalink
feat #93 - Extract out placement options to utils and allow tooltip s…
Browse files Browse the repository at this point in the history
…tyle customization
  • Loading branch information
github-actions committed Sep 25, 2020
1 parent 69efc73 commit 3ce05c8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
23 changes: 4 additions & 19 deletions src/components/Tooltip/Tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,19 @@
import Icon from '../Icon'
import { placementOptions } from '../utils'
import React from 'react'
import { TooltipPlacement } from 'antd/lib/tooltip'
import { Meta, Story } from '@storybook/react/types-6-0'
import Tooltip, { TooltipProps } from './index'

const placementOptions: TooltipPlacement[] = [
'bottom',
'bottomLeft',
'bottomRight',
'left',
'leftBottom',
'leftTop',
'right',
'rightBottom',
'rightTop',
'top',
'topLeft',
'topRight'
]

export default {
argTypes: {
children: { control: { disable: true } },
placement: {
control: {
options: placementOptions,
type: 'select'
},
defaultValue: 'right'
}
}
},
title: { control: { type: 'text' } }
},
component: Tooltip,
title: 'Tooltip'
Expand Down
8 changes: 8 additions & 0 deletions src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import '../assets/styles/antdAnimations.css'
import 'antd/lib/tooltip/style/index.css'
import { Tooltip as AntDTooltip } from 'antd'
import cn from 'classnames'
import { TooltipPlacement } from 'antd/es/tooltip'
import React, { FC, ReactNode } from 'react'

Expand All @@ -11,6 +12,11 @@ export interface TooltipProps {
* Element tooltip should be anchored to
*/
children: ReactNode
/**
* Array of classes to pass to element
* @default []
*/
classes?: string[]
/**
* Position of tooltip relative to the target
*/
Expand All @@ -23,11 +29,13 @@ export interface TooltipProps {

const Tooltip: FC<TooltipProps> = ({
children,
classes = [],
placement = 'right',
title
}: TooltipProps) => {
return (
<AntDTooltip
overlayClassName={cn(classes)}
overlayStyle={{ borderRadius: 4 }}
placement={placement}
title={title}
Expand Down
17 changes: 17 additions & 0 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { TooltipPlacement } from 'antd/es/tooltip'

export const TAG = 'data-test'

export const getDataTestAttributeProp = (
Expand All @@ -6,3 +8,18 @@ export const getDataTestAttributeProp = (
): { [TAG]: string } => ({
[TAG]: dataTag ? `${cmpName}-${dataTag}` : cmpName
})

export const placementOptions: TooltipPlacement[] = [
'bottom',
'bottomLeft',
'bottomRight',
'left',
'leftBottom',
'leftTop',
'right',
'rightBottom',
'rightTop',
'top',
'topLeft',
'topRight'
]

0 comments on commit 3ce05c8

Please sign in to comment.