Skip to content

Commit

Permalink
feat: #235 v4 Deprecated existing Tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
ksolanki7 committed Dec 4, 2024
1 parent c91abbc commit 52482f9
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { styled } from '@linaria/react'
import { css } from '@linaria/core'

export const ElToolTipChild = styled.div`
/** @deprecated */
export const ElDeprecatedToolTipChild = styled.div`
position: absolute;
padding: 0.5rem;
background: var(--black);
Expand All @@ -27,7 +28,8 @@ export const elToolTipActive = css`
display: block;
`

export const ElToolTipContainer = styled.div`
/** @deprecated */
export const ElDeprecatedToolTipContainer = styled.div`
position: relative;
padding: 0.25rem;
`
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { render } from '@testing-library/react'
import { ToolTip } from '../tool-tip'
import { DeprecatedToolTip } from '../tool-tip'

describe('ToolTip', () => {
describe('DeprecatedToolTip', () => {
it('should match a snapshot and render children', () => {
const wrapper = render(
<ToolTip tip="hello there" defaultActive>
<DeprecatedToolTip tip="hello there" defaultActive>
Hover here
</ToolTip>,
</DeprecatedToolTip>,
)
expect(wrapper.asFragment()).toMatchSnapshot()
})
Expand Down
File renamed without changes.
35 changes: 35 additions & 0 deletions src/components/deprecated-tool-tip/tool-tip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { cx } from '@linaria/core'
import React, { FC, HTMLAttributes, useState } from 'react'
import { ElDeprecatedToolTipChild, elToolTipActive, ElDeprecatedToolTipContainer } from './__styles__'

/** @deprecated */
export interface DeprecatedToolTipProps extends HTMLAttributes<HTMLDivElement> {
defaultActive?: boolean
tip?: string
}

/** @deprecated */
export interface DeprecatedToolTipChildProps extends HTMLAttributes<HTMLDivElement> {
active?: boolean
tip?: string
}

/** @deprecated */
export const DeprecatedToolTip: FC<DeprecatedToolTipProps> = ({ children, defaultActive = false, tip }) => {
const [active, setActive] = useState<boolean>(defaultActive)

return (
<ElDeprecatedToolTipContainer onMouseOver={() => setActive(true)} onMouseOut={() => setActive(false)}>
{children}
<ToolTipChild active={active}>{tip}</ToolTipChild>
</ElDeprecatedToolTipContainer>
)
}

export const ToolTipChild: FC<DeprecatedToolTipChildProps> = ({ children, active }) => {
return (
<ElDeprecatedToolTipChild role="tooltip" className={cx(active && elToolTipActive)}>
{children}
</ElDeprecatedToolTipChild>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Story, Canvas, Controls, Meta } from '@storybook/blocks'
import { ToolTip } from './index'
import { RenderHtmlMarkup } from '../../storybook/render-html-markup'
import * as TooltipStories from './tooltip.stories'

Expand Down
18 changes: 18 additions & 0 deletions src/components/deprecated-tool-tip/tooltip.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { DeprecatedToolTip } from './index'

export default {
title: 'DeprecatedToolTip',
component: DeprecatedToolTip,
}

export const BasicUsage = {
render: ({}) => <DeprecatedToolTip tip="Some Data">Hover here</DeprecatedToolTip>,
}

export const DefaultActive = {
render: ({}) => (
<DeprecatedToolTip tip="Some Data" defaultActive>
Hover here
</DeprecatedToolTip>
),
}
32 changes: 0 additions & 32 deletions src/components/tool-tip/tool-tip.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions src/components/tool-tip/tooltip.stories.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export * from './components/textarea'
export * from './components/toggle'
export * from './components/typography'
export * from './components/form-layout'
export * from './components/tool-tip'
export * from './components/deprecated-tool-tip'
export * from './components/input-error'
export * from './components/file-input'
export * from './components/placeholder-image'
Expand Down

0 comments on commit 52482f9

Please sign in to comment.