-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enhance
OverflowTooltip
overflow detection for precise handli…
…ng of non-integral width or height (#806) * fix: fix the OverflowTooltip issue in a specific environment * feat: improve overflow detection using `getClientRects() * feat: import utility functions from `@tonic-ui/utils` * docs: update overtool tooltip examples * docs: update tooltip and overflow-tooltip examples * docs: update popover examples --------- Co-authored-by: cheton <[email protected]>
- Loading branch information
Showing
46 changed files
with
1,355 additions
and
929 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
packages/react-docs/pages/components/overflow-tooltip/basic.js
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,30 @@ | ||
import { Box, Divider, OverflowTooltip } from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<> | ||
<OverflowTooltip | ||
label="This is a tooltip" | ||
> | ||
This text string will be truncated when exceeding its container width. To see this in action, try resizing your browser viewport. If the text overflows, a tooltip will appear, displaying the full content. | ||
</OverflowTooltip> | ||
<Divider my="4x" /> | ||
<Box width={140.7}> | ||
<OverflowTooltip | ||
label="This is a tooltip" | ||
> | ||
This text string is truncted | ||
</OverflowTooltip> | ||
</Box> | ||
<Divider my="4x" /> | ||
<OverflowTooltip | ||
label="This is a tooltip" | ||
> | ||
This text string is not truncated | ||
</OverflowTooltip> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
15 changes: 15 additions & 0 deletions
15
packages/react-docs/pages/components/overflow-tooltip/faq-use-portal.js
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,15 @@ | ||
import { OverflowTooltip } from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<OverflowTooltip | ||
PopperProps={{ usePortal: true }} | ||
label="This is a tooltip" | ||
> | ||
This text string will be truncated when exceeding its container width. To see this in action, try resizing your browser viewport. If the text overflows, a tooltip will appear, displaying the full content. | ||
</OverflowTooltip> | ||
); | ||
}; | ||
|
||
export default App; |
21 changes: 21 additions & 0 deletions
21
packages/react-docs/pages/components/overflow-tooltip/function-as-child-component.js
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,21 @@ | ||
import { Icon, Flex, OverflowTooltip, Text } from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<OverflowTooltip | ||
label="This is a tooltip" | ||
> | ||
{({ ref, style }) => ( | ||
<Flex alignItems="center" columnGap="2x"> | ||
<Icon icon="menu" /> | ||
<Text ref={ref} {...style}> | ||
This text string will be truncated when exceeding its container width. To see this in action, try resizing your browser viewport. If the text overflows, a tooltip will appear, displaying the full content. | ||
</Text> | ||
</Flex> | ||
)} | ||
</OverflowTooltip> | ||
); | ||
}; | ||
|
||
export default App; |
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
50 changes: 50 additions & 0 deletions
50
packages/react-docs/pages/components/overflow-tooltip/multi-line.js
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,50 @@ | ||
import { Box, Divider, OverflowTooltip, Text } from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
return ( | ||
<> | ||
<Box width={360}> | ||
<OverflowTooltip | ||
label="This is a tooltip" | ||
> | ||
{({ ref, style }) => ( | ||
<Text | ||
ref={ref} | ||
style={{ | ||
display: '-webkit-box', | ||
WebkitBoxOrient: 'vertical', | ||
WebkitLineClamp: 3, | ||
overflow: 'hidden', | ||
}} | ||
> | ||
This text string will be truncated when exceeding its container width. To see this in action, try resizing your browser viewport. If the text overflows, a tooltip will appear, displaying the full content. | ||
</Text> | ||
)} | ||
</OverflowTooltip> | ||
</Box> | ||
<Divider my="4x" /> | ||
<Box width={480}> | ||
<OverflowTooltip | ||
label="This is a tooltip" | ||
> | ||
{({ ref, style }) => ( | ||
<Text | ||
ref={ref} | ||
style={{ | ||
display: '-webkit-box', | ||
WebkitBoxOrient: 'vertical', | ||
WebkitLineClamp: 3, | ||
overflow: 'hidden', | ||
}} | ||
> | ||
This text string will be truncated when exceeding its container width. To see this in action, try resizing your browser viewport. If the text overflows, a tooltip will appear, displaying the full content. | ||
</Text> | ||
)} | ||
</OverflowTooltip> | ||
</Box> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
30 changes: 30 additions & 0 deletions
30
packages/react-docs/pages/components/popover/controlled.js
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,30 @@ | ||
import { Button, Flex, Popover, PopoverContent, PopoverTrigger, Switch, Text } from '@tonic-ui/react'; | ||
import { useToggle } from '@tonic-ui/react-hooks'; | ||
import React from 'react'; | ||
|
||
const App = () => { | ||
const [on, toggle] = useToggle(false); | ||
|
||
return ( | ||
<> | ||
<Flex mb="4x"> | ||
<Switch checked={on} onChange={toggle} /> | ||
</Flex> | ||
<Popover | ||
isOpen={on} | ||
placement="bottom" | ||
> | ||
<PopoverTrigger> | ||
<Button onClick={toggle}> | ||
Trigger | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<Text>This is a controlled popover</Text> | ||
</PopoverContent> | ||
</Popover> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
83 changes: 83 additions & 0 deletions
83
packages/react-docs/pages/components/popover/faq-flip-modifier.js
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,83 @@ | ||
import { | ||
Box, | ||
Checkbox, | ||
Divider, | ||
Flex, | ||
Popover, | ||
PopoverContent, | ||
PopoverTrigger, | ||
Scrollbar, | ||
Space, | ||
Text, | ||
TextLabel, | ||
useColorMode, | ||
useColorStyle, | ||
} from '@tonic-ui/react'; | ||
import { useToggle } from '@tonic-ui/react-hooks'; | ||
import React from 'react'; | ||
|
||
const FormGroup = (props) => ( | ||
<Box mb="4x" {...props} /> | ||
); | ||
|
||
const App = () => { | ||
const [colorMode] = useColorMode(); | ||
const [colorStyle] = useColorStyle({ colorMode }); | ||
const [isFlipModifierEnabled, toggleIsFlipModifierEnabled] = useToggle(true); | ||
|
||
return ( | ||
<> | ||
<Box mb="4x"> | ||
<Text fontSize="lg" lineHeight="lg"> | ||
Modifiers | ||
</Text> | ||
</Box> | ||
<FormGroup> | ||
<TextLabel display="inline-flex" alignItems="center"> | ||
<Checkbox | ||
checked={isFlipModifierEnabled} | ||
onChange={() => toggleIsFlipModifierEnabled()} | ||
/> | ||
<Space width="2x" /> | ||
<Text fontFamily="mono" whiteSpace="nowrap">Enable flip modifier</Text> | ||
</TextLabel> | ||
</FormGroup> | ||
<Divider my="4x" /> | ||
<Scrollbar | ||
height={180} | ||
width={180} | ||
overflowY="visible" | ||
border={1} | ||
borderColor={colorStyle.divider} | ||
> | ||
<Flex | ||
alignItems="center" | ||
justifyContent="center" | ||
height={300} | ||
> | ||
<Popover isOpen placement="top"> | ||
<PopoverTrigger> | ||
<Text display="inline-block"> | ||
Reference | ||
</Text> | ||
</PopoverTrigger> | ||
<PopoverContent | ||
PopperProps={{ | ||
modifiers: [ | ||
{ // https://popper.js.org/docs/v2/modifiers/flip/ | ||
name: 'flip', | ||
enabled: isFlipModifierEnabled, | ||
}, | ||
], | ||
}} | ||
> | ||
Popover | ||
</PopoverContent> | ||
</Popover> | ||
</Flex> | ||
</Scrollbar> | ||
</> | ||
); | ||
}; | ||
|
||
export default App; |
19 changes: 19 additions & 0 deletions
19
packages/react-docs/pages/components/popover/faq-use-portal.js
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,19 @@ | ||
import { Button, Popover, PopoverContent, PopoverTrigger } from '@tonic-ui/react'; | ||
import React from 'react'; | ||
|
||
const App = () => ( | ||
<Popover> | ||
<PopoverTrigger> | ||
<Button variant="secondary">Trigger</Button> | ||
</PopoverTrigger> | ||
<PopoverContent | ||
PopperProps={{ | ||
usePortal: true, | ||
}} | ||
> | ||
Popover | ||
</PopoverContent> | ||
</Popover> | ||
); | ||
|
||
export default App; |
41 changes: 41 additions & 0 deletions
41
packages/react-docs/pages/components/popover/focus-control-initial-focus-ref.js
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,41 @@ | ||
import { Button, Input, Popover, PopoverBody, PopoverContent, PopoverTrigger, Stack, Text } from '@tonic-ui/react'; | ||
import React, { useRef } from 'react'; | ||
|
||
const App = () => { | ||
const initialFocusRef1 = useRef(); | ||
const initialFocusRef2 = useRef(); | ||
|
||
return ( | ||
<Stack spacing="6x" width="fit-content"> | ||
<Popover initialFocusRef={initialFocusRef1}> | ||
<PopoverTrigger> | ||
<Button variant="secondary"> | ||
Interactive Trigger | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<PopoverBody> | ||
<Input mt="3x" ref={initialFocusRef1} defaultValue="Popover" /> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
<Popover initialFocusRef={initialFocusRef2}> | ||
<PopoverTrigger tabIndex={-1}> | ||
<Text | ||
userSelect="none" | ||
_hover={{ cursor: 'pointer' }} | ||
> | ||
Non-interactive Trigger | ||
</Text> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<PopoverBody> | ||
<Input mt="3x" ref={initialFocusRef2} defaultValue="Popover" /> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default App; |
47 changes: 47 additions & 0 deletions
47
packages/react-docs/pages/components/popover/focus-control-return-focus-on-close.js
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,47 @@ | ||
import { Button, Input, Popover, PopoverBody, PopoverContent, PopoverTrigger, Stack, Text } from '@tonic-ui/react'; | ||
import React, { useRef } from 'react'; | ||
|
||
const App = () => { | ||
const initialFocusRef1 = useRef(); | ||
const initialFocusRef2 = useRef(); | ||
|
||
return ( | ||
<Stack spacing="6x" width="fit-content"> | ||
<Popover | ||
initialFocusRef={initialFocusRef1} | ||
returnFocusOnClose={false} | ||
> | ||
<PopoverTrigger> | ||
<Button variant="secondary"> | ||
Interactive Trigger | ||
</Button> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<PopoverBody> | ||
<Input mt="3x" ref={initialFocusRef1} defaultValue="Popover" /> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
<Popover | ||
initialFocusRef={initialFocusRef2} | ||
returnFocusOnClose={false} | ||
> | ||
<PopoverTrigger tabIndex={-1}> | ||
<Text | ||
userSelect="none" | ||
_hover={{ cursor: 'pointer' }} | ||
> | ||
Non-interactive Trigger | ||
</Text> | ||
</PopoverTrigger> | ||
<PopoverContent> | ||
<PopoverBody> | ||
<Input mt="3x" ref={initialFocusRef2} defaultValue="Popover" /> | ||
</PopoverBody> | ||
</PopoverContent> | ||
</Popover> | ||
</Stack> | ||
); | ||
}; | ||
|
||
export default App; |
Oops, something went wrong.