forked from mui/base-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
181 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from 'react'; | ||
import * as Tooltip from '@base_ui/react/Tooltip'; | ||
import { styled } from '@mui/system'; | ||
|
||
export default function UnstyledTooltipIntroduction() { | ||
return ( | ||
<div style={{ width: 700, margin: '0 auto', padding: 50 }}> | ||
<Tooltip.Root> | ||
<Tooltip.AnchorFragment> | ||
<AnchorButton>Anchor</AnchorButton> | ||
</Tooltip.AnchorFragment> | ||
<TooltipContent sideOffset={7} arrowPadding={3}> | ||
Tooltip | ||
</TooltipContent> | ||
</Tooltip.Root> | ||
</div> | ||
); | ||
} | ||
|
||
const blue = { | ||
400: '#3399FF', | ||
600: '#0072E6', | ||
800: '#004C99', | ||
}; | ||
|
||
export const TooltipContent = styled(Tooltip.Content)` | ||
${({ theme }) => ` | ||
font-family: 'IBM Plex Sans', sans-serif; | ||
background: ${theme.palette.mode === 'dark' ? 'white' : 'black'}; | ||
color: ${theme.palette.mode === 'dark' ? 'black' : 'white'}; | ||
padding: 4px 6px; | ||
border-radius: 4px; | ||
font-size: 95%; | ||
cursor: default; | ||
transition-property: opacity, transform; | ||
transform-origin: var(--transform-origin); | ||
&[data-status='opened'], | ||
&[data-status='closed'] { | ||
transition-duration: 0.2s; | ||
} | ||
&[data-status='initial'], | ||
&[data-status='closed'] { | ||
opacity: 0; | ||
transform: scale(0.9); | ||
} | ||
`} | ||
`; | ||
|
||
export const AnchorButton = styled('button')` | ||
border: none; | ||
background: ${blue[600]}; | ||
color: white; | ||
padding: 8px 16px; | ||
border-radius: 4px; | ||
font-size: 16px; | ||
&:focus-visible { | ||
outline: 2px solid ${blue[400]}; | ||
outline-offset: 2px; | ||
} | ||
&:hover, | ||
&[data-state='open'] { | ||
background: ${blue[800]}; | ||
} | ||
`; |
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.
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,40 @@ | ||
import useEnhancedEffect from '@mui/utils/useEnhancedEffect'; | ||
import * as React from 'react'; | ||
|
||
type Status = 'unmounted' | 'initial' | 'opened' | 'closed'; | ||
|
||
/** | ||
* @ignore - internal hook. | ||
*/ | ||
export function useTransitionStatus(trigger: boolean) { | ||
const [status, setStatus] = React.useState<Status>('unmounted'); | ||
const [mounted, setMounted] = React.useState(trigger); | ||
|
||
if (trigger && !mounted) { | ||
setMounted(true); | ||
} | ||
|
||
useEnhancedEffect(() => { | ||
if (trigger) { | ||
setStatus('initial'); | ||
|
||
const frame = requestAnimationFrame(() => { | ||
setStatus('opened'); | ||
}); | ||
|
||
return () => { | ||
cancelAnimationFrame(frame); | ||
}; | ||
} | ||
|
||
setStatus('closed'); | ||
|
||
return undefined; | ||
}, [trigger]); | ||
|
||
return { | ||
mounted, | ||
setMounted, | ||
status, | ||
}; | ||
} |
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