-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tooltip box and use it in calendars
- Loading branch information
Showing
12 changed files
with
191 additions
and
9 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
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
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
5 changes: 5 additions & 0 deletions
5
packages/lsd-react/src/components/TooltipBase/TooltipBase.classes.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const tooltipBaseClasses = { | ||
root: `lsd-tooltip-base`, | ||
arrowTip: `lsd-tooltip-base__arrow-tip`, | ||
content: `lsd-tooltip-base__content`, | ||
} |
27 changes: 27 additions & 0 deletions
27
packages/lsd-react/src/components/TooltipBase/TooltipBase.stories.tsx
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,27 @@ | ||
import { StoryObj, Meta } from '@storybook/react' | ||
import { TooltipBase, TooltipBaseProps } from './TooltipBase' | ||
|
||
export default { | ||
title: 'TooltipBase', | ||
component: TooltipBase, | ||
argTypes: { | ||
arrowPosition: { | ||
type: { | ||
name: 'enum', | ||
value: ['top', 'bottom', 'left', 'right'], | ||
}, | ||
}, | ||
}, | ||
} as Meta | ||
|
||
export const Root: StoryObj<TooltipBaseProps> = ({ | ||
...args | ||
}: TooltipBaseProps) => { | ||
return <TooltipBase {...args} style={{ height: 200, width: 200 }} /> | ||
} | ||
|
||
Root.args = { | ||
arrowPosition: 'top', | ||
arrowOffset: 50, | ||
arrowSize: 10, | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/lsd-react/src/components/TooltipBase/TooltipBase.styles.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { css } from '@emotion/react' | ||
import { tooltipBaseClasses } from './TooltipBase.classes' | ||
|
||
export const TooltipBaseStyles = css` | ||
.${tooltipBaseClasses.root} { | ||
border: 1px solid rgb(var(--lsd-border-primary)); | ||
position: relative; | ||
} | ||
.${tooltipBaseClasses.arrowTip} { | ||
border: 1px solid rgb(var(--lsd-border-primary)); | ||
position: absolute; | ||
background: rgb(var(--lsd-surface-primary)); | ||
} | ||
.${tooltipBaseClasses.content} { | ||
background: rgb(var(--lsd-surface-primary)); | ||
width: 100%; | ||
height: 100%; | ||
/* Position relative is only used so the z-index works. */ | ||
position: relative; | ||
/* Make sure the arrow tip div is behind the tooltip's content. */ | ||
z-index: 1; | ||
} | ||
` |
68 changes: 68 additions & 0 deletions
68
packages/lsd-react/src/components/TooltipBase/TooltipBase.tsx
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,68 @@ | ||
import clsx from 'clsx' | ||
import React from 'react' | ||
import { | ||
CommonProps, | ||
omitCommonProps, | ||
useCommonProps, | ||
} from '../../utils/useCommonProps' | ||
import { tooltipBaseClasses } from './TooltipBase.classes' | ||
|
||
export type TooltipBaseProps = CommonProps & | ||
React.HTMLAttributes<HTMLDivElement> & { | ||
arrowOffset?: number | ||
arrowPosition?: 'top' | 'bottom' | 'left' | 'right' | ||
arrowSize?: number | ||
rootRef?: React.Ref<HTMLDivElement> | ||
} | ||
|
||
export const TooltipBase: React.FC<TooltipBaseProps> & { | ||
classes: typeof tooltipBaseClasses | ||
} = ({ | ||
children, | ||
arrowOffset, | ||
arrowPosition = 'top', | ||
arrowSize = 10, | ||
rootRef, | ||
...props | ||
}) => { | ||
const commonProps = useCommonProps(props) | ||
|
||
// Calculate arrow tip style based on position and offset. | ||
const arrowTipStyle: React.CSSProperties = { | ||
width: `${arrowSize}px`, | ||
height: `${arrowSize}px`, | ||
transform: 'rotate(45deg)', | ||
} | ||
|
||
// Adjust the arrow tip's position along the tooltip border based on the arrowPosition and arrowOffset. | ||
if (['top', 'bottom'].includes(arrowPosition)) { | ||
arrowTipStyle.left = `${arrowOffset}px` | ||
arrowTipStyle[arrowPosition] = `-${arrowSize / 2}px` // Halfway above the root box's border | ||
} else { | ||
arrowTipStyle.top = `${arrowOffset}px` | ||
arrowTipStyle[arrowPosition] = `-${arrowSize / 2}px` // Halfway outside the root box's border | ||
} | ||
|
||
return ( | ||
<div | ||
ref={rootRef} | ||
{...omitCommonProps(props)} | ||
className={clsx( | ||
commonProps.className, | ||
props.className, | ||
tooltipBaseClasses.root, | ||
)} | ||
> | ||
{!arrowOffset ? ( | ||
children | ||
) : ( | ||
<> | ||
<div className={tooltipBaseClasses.arrowTip} style={arrowTipStyle} /> | ||
<div className={tooltipBaseClasses.content}>{children}</div> | ||
</> | ||
)} | ||
</div> | ||
) | ||
} | ||
|
||
TooltipBase.classes = tooltipBaseClasses |
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 @@ | ||
export * from './TooltipBase' |
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