Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Tooltip] Component and Hook #264

Merged
merged 64 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
e9af242
Fix lockfile
atomiks Apr 24, 2024
66b64a3
[Tooltip] Component and Hook
atomiks Apr 3, 2024
775bc92
Docs
atomiks May 1, 2024
df2b267
Update APIs to trigger
atomiks May 3, 2024
4e3212c
Fix lockfile
atomiks May 3, 2024
5d0f55f
Sync style with Popover
atomiks May 3, 2024
20bc7ee
Rewrite docs to new template
atomiks May 6, 2024
389b1ed
Fix wording
atomiks May 6, 2024
cf6bf0c
Wait for microtasks when rendering
atomiks May 7, 2024
32ad0b5
Feedback
atomiks May 7, 2024
d2bdfb2
Fix codegen
atomiks May 7, 2024
c365955
Rename Content to Popup
atomiks May 8, 2024
93fbc1a
Update docs
atomiks May 8, 2024
dcd4965
Docgen
atomiks May 8, 2024
4793dca
Rename contentEl to popupEl
atomiks May 8, 2024
50204cf
Import useEnhancedEffect from utils
atomiks May 8, 2024
5d56633
Refactor popup hook logic
atomiks May 9, 2024
2eb69ff
Codegen
atomiks May 9, 2024
a2555bb
Update TransitionStatus
atomiks May 9, 2024
aeffa72
Refactor use Root API
atomiks May 13, 2024
8b4d70f
Refactor to use Root API
atomiks May 13, 2024
d112305
Pass delay params
atomiks May 13, 2024
d2bc9ec
Refactor Arrow API
atomiks May 15, 2024
b25e9b8
Refactor animation API
atomiks May 21, 2024
e35a7e8
Refactor animations
atomiks May 22, 2024
51ea374
Unmount animation hook
atomiks May 22, 2024
6463842
Add animated prop
atomiks May 23, 2024
cd88970
Remove useAnimationUnmount directory
atomiks May 23, 2024
6109db4
Update tests
atomiks May 23, 2024
3b4dc5e
Pass animated logic, codegen
atomiks May 23, 2024
3d28ca4
Adopt useComponentRenderer
atomiks May 23, 2024
adf35bc
Use non-breaking space
atomiks May 23, 2024
36d8d3b
Add TooltipPopupRoot component
atomiks May 23, 2024
6050a25
Update
atomiks May 23, 2024
1b4d3ed
Use main APIs
atomiks May 23, 2024
debef29
Fix lockfile
atomiks May 23, 2024
ae9ae10
Fix Group delay
atomiks May 23, 2024
3640f34
Codegen
atomiks May 23, 2024
d6a6b38
Feedback
atomiks May 24, 2024
2861154
Update useTransitionStatus
atomiks May 24, 2024
7b1925a
Omit hook params from component
atomiks May 24, 2024
ae6820f
Split types
atomiks May 24, 2024
af22269
Improve JSDocs
atomiks May 24, 2024
c14b7cd
Remove propGetter
atomiks May 24, 2024
8e47fdd
Update JSDocs
atomiks May 24, 2024
2f59183
Refactor animations hooks
atomiks May 27, 2024
16d8fef
Remove async
atomiks May 27, 2024
918e2eb
Update docs
atomiks May 27, 2024
5a5e47e
Update corejs
atomiks May 27, 2024
a229163
Allow Tooltip.Root to override Tooltip.Provider delays
atomiks May 27, 2024
62a2520
Refactor to TooltipPositioner API
atomiks May 28, 2024
9f6b247
Fix tests
atomiks May 28, 2024
a053fbc
Fix tests
atomiks May 28, 2024
9e4a5d7
Fix italic demo
atomiks May 28, 2024
61c658e
Update JSDocs
atomiks May 28, 2024
73c23bc
Update docs
atomiks May 28, 2024
bf5f50f
Fix prop-types and docs
atomiks May 28, 2024
9c66bd1
Update docs
atomiks May 28, 2024
1a7588d
Update docs
atomiks May 28, 2024
e9511b9
Update docs
atomiks May 28, 2024
fe09b08
Apply aria-hidden to arrow
atomiks May 28, 2024
74e8d17
Update docs
atomiks May 28, 2024
a1d9bcf
Improve docs consistency
atomiks May 28, 2024
e31058a
Refactor
atomiks May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fse = require('fs-extra');
const errorCodesPath = path.resolve(__dirname, './public/static/error-codes.json');

const { version: transformRuntimeVersion } = fse.readJSONSync(
require.resolve('@babel/runtime-corejs2/package.json'),
require.resolve('@babel/runtime-corejs3/package.json'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already on master, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I added it here to validate it first and because the docs/demos were broken without it before the other PR got merged

);

module.exports = {
Expand All @@ -17,7 +17,7 @@ module.exports = {
'next/babel',
{
'preset-react': { runtime: 'automatic' },
'transform-runtime': { corejs: 2, version: transformRuntimeVersion },
'transform-runtime': { corejs: 3, version: transformRuntimeVersion },
},
],
],
Expand Down
60 changes: 60 additions & 0 deletions docs/data/base/components/tooltip/UnstyledTooltipDelayGroup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as React from 'react';
import * as Tooltip from '@base_ui/react/Tooltip';
import { styled } from '@mui/system';

export default function UnstyledTooltipDelayGroup() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Tooltip.Provider delay={500} closeDelay={500}>
<Tooltip.Root>
<AnchorButton>Anchor A</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip A</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
<Tooltip.Root>
<AnchorButton>Anchor B</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip B</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
</Tooltip.Provider>
</div>
);
}

const blue = {
400: '#3399FF',
600: '#0072E6',
800: '#004C99',
};

export const TooltipPopup = styled(Tooltip.Popup)`
${({ theme }) => `
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;
`}
`;

export const AnchorButton = styled(Tooltip.Trigger)`
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]};
}
`;
60 changes: 60 additions & 0 deletions docs/data/base/components/tooltip/UnstyledTooltipDelayGroup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import * as React from 'react';
import * as Tooltip from '@base_ui/react/Tooltip';
import { styled } from '@mui/system';

export default function UnstyledTooltipDelayGroup() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Tooltip.Provider delay={500} closeDelay={500}>
<Tooltip.Root>
<AnchorButton>Anchor A</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip A</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
<Tooltip.Root>
<AnchorButton>Anchor B</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip B</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
</Tooltip.Provider>
</div>
);
}

const blue = {
400: '#3399FF',
600: '#0072E6',
800: '#004C99',
};

export const TooltipPopup = styled(Tooltip.Popup)`
${({ theme }) => `
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;
`}
`;

export const AnchorButton = styled(Tooltip.Trigger)`
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]};
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Tooltip.Provider delay={500} closeDelay={500}>
<Tooltip.Root>
<AnchorButton>Anchor A</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip A</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
<Tooltip.Root>
<AnchorButton>Anchor B</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip B</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
</Tooltip.Provider>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import * as Tooltip from '@base_ui/react/Tooltip';
import { styled } from '@mui/system';

export default function UnstyledTooltipFollowCursor() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Tooltip.Root followCursorAxis="both">
<AnchorButton>Anchor</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
</div>
);
}

const blue = {
400: '#3399FF',
600: '#0072E6',
800: '#004C99',
};

export const TooltipPopup = styled(Tooltip.Popup)`
${({ theme }) => `
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;
`}
`;

export const AnchorButton = styled(Tooltip.Trigger)`
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]};
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import * as React from 'react';
import * as Tooltip from '@base_ui/react/Tooltip';
import { styled } from '@mui/system';

export default function UnstyledTooltipFollowCursor() {
return (
<div style={{ display: 'flex', gap: 12 }}>
<Tooltip.Root followCursorAxis="both">
<AnchorButton>Anchor</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
</div>
);
}

const blue = {
400: '#3399FF',
600: '#0072E6',
800: '#004C99',
};

export const TooltipPopup = styled(Tooltip.Popup)`
${({ theme }) => `
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;
`}
`;

export const AnchorButton = styled(Tooltip.Trigger)`
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]};
}
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Tooltip.Root followCursorAxis="both">
<AnchorButton>Anchor</AnchorButton>
<Tooltip.Positioner sideOffset={5}>
<TooltipPopup>Tooltip</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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={{ display: 'flex', gap: 10 }}>
<Tooltip.Provider closeDelay={100}>
<Tooltip.Root>
<AnchorButton aria-label="bold">B</AnchorButton>
<Tooltip.Positioner sideOffset={7}>
<TooltipPopup>
Bold
<TooltipArrow />
</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
<Tooltip.Root>
<AnchorButton aria-label="italic">I</AnchorButton>
<Tooltip.Positioner sideOffset={7}>
<TooltipPopup>
Italic
<TooltipArrow />
</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
<Tooltip.Root>
<AnchorButton aria-label="underline">U</AnchorButton>
<Tooltip.Positioner sideOffset={7}>
<TooltipPopup>
Underline
<TooltipArrow />
</TooltipPopup>
</Tooltip.Positioner>
</Tooltip.Root>
</Tooltip.Provider>
</div>
);
}

const blue = {
400: '#3399FF',
600: '#0072E6',
800: '#004C99',
};

export const TooltipPopup = styled(Tooltip.Popup)`
${({ theme }) => `
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;
`}
`;

export const AnchorButton = styled(Tooltip.Trigger)`
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]};
}

&[aria-label='bold'] {
font-weight: bold;
}

&[aria-label='italic'] {
font-style: italic;
}

&[aria-label='underline'] {
text-decoration: underline;
}
`;

export const TooltipArrow = styled(Tooltip.Arrow)`
${({ theme }) => `
width: 10px;
height: 10px;
transform: rotate(45deg);
background: ${theme.palette.mode === 'dark' ? 'white' : 'black'};
z-index: -1;

&[data-side='top'] {
bottom: -5px;
}
&[data-side='right'] {
left: -5px;
}
&[data-side='bottom'] {
top: -5px;
}
&[data-side='left'] {
right: -5px;
}
`}
`;
Loading