Skip to content

Commit

Permalink
Merge pull request #41 from MacPaw/feat/add-tooltip-component
Browse files Browse the repository at this point in the history
feat: add tooltip component
  • Loading branch information
wallwhite authored Jan 12, 2022
2 parents 2d5b936 + f07d6ba commit 25805cc
Show file tree
Hide file tree
Showing 10 changed files with 445 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# dependencies
node_modules

# idea setting
.idea

# MacOS filesystem
.DS_Store

# next.js
.next

# built components
lib

# static pages
out

# VS code setting
**/.vscode/*
1 change: 1 addition & 0 deletions internal/Navigation/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const pages = [
'select',
'tag',
'table',
'tooltip',
'typography',
]

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@macpaw/macpaw-ui",
"version": "3.8.2",
"version": "3.8.3",
"main": "lib/ui.js",
"scripts": {
"dev": "next -p 1234",
Expand Down
251 changes: 251 additions & 0 deletions pages/tooltip.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { Tooltip, Button, Grid, GridRow, GridCell } from '../src/ui';

# Tooltip

<Tooltip position="top" content="Hi there!">
<Button>
Hover me
</Button>
</Tooltip>

```
<Tooltip position="top" content="Hi there">
<Button>
Hover me
</Button>
</Tooltip>
```

## Tooltip position

<Grid>
<GridRow>
<GridCell>
<Tooltip position="top" content="Hi there! I'm on the top">
<Button>
Top
</Button>
</Tooltip>
</GridCell>
<GridCell>
<Tooltip position="bottom" content="Hi there! I'm on the bottom">
<Button>
Bottom
</Button>
</Tooltip>
</GridCell>
<GridCell>
<Tooltip position="left" content="Hi there! I'm on the left">
<Button>
Left
</Button>
</Tooltip>
</GridCell>
<GridCell>
<Tooltip position="right" content="Hi there! I'm on the right">
<Button>
Right
</Button>
</Tooltip>
</GridCell>
</GridRow>
</Grid>

```
<Tooltip position="top" content="Hi there! I'm on the top">
<Button>
Top
</Button>
</Tooltip>
<Tooltip position="bottom" content="Hi there! I'm on the bottom">
<Button>
Bottom
</Button>
</Tooltip>
<Tooltip position="left" content="Hi there! I'm on the left">
<Button>
Left
</Button>
</Tooltip>
<Tooltip position="right" content="Hi there! I'm on the right">
<Button>
Right
</Button>
</Tooltip>
```

## Tooltip with max width

<Tooltip
maxWidth={100}
position="right"
content="So small"
>
<Button>
Hover me
</Button>
</Tooltip>

```
<Tooltip
maxWidth={100}
position="right"
content="Hi there"
>
<Button>
Hover me
</Button>
</Tooltip>
```

## Tooltip force showing

export const ControlledTooltip = () => {
const [isVisible, setIsVisible] = React.useState(false);
const tooltipBehaviorTitle = isVisible ? 'always visible' : 'normal'
return (
<Grid>
<GridRow>
<GridCell>
<Button onClick={() => setIsVisible(current=>!current)}>
Toggle behavior: {tooltipBehaviorTitle}
</Button>
</GridCell>
<GridCell>
<Tooltip
position="top"
content={`Hi there! I'm ${tooltipBehaviorTitle} tooltip.`}
forceShow={isVisible}
>
<Button>
Button with tooltip
</Button>
</Tooltip>
</GridCell>
</GridRow>
</Grid>
);
};

<ControlledTooltip />

```
const [isVisible, setIsVisible] = React.useState(false);
const tooltipBehaviorTitle = isVisible ? 'always visible' : 'normal'
<Button onClick={() => setIsVisible(current=>!current)}>
Toggle behavior: {tooltipBehaviorTitle}
</Button>
<Tooltip
position="top"
content={`Hi there! I'm ${tooltipBehaviorTitle} tooltip.`}
forceShow={isVisible}
>
<Button>
Button with tooltip
</Button>
</Tooltip>
```

## Tooltip force hidding

export const HiddenTooltip = () => {
const [isHidden, setIsHidden] = React.useState(false);
const tooltipBehaviorTitle = isHidden ? 'always hidden' : 'normal';
return (
<Grid>
<GridRow>
<GridCell>
<Button onClick={() => setIsHidden(current=>!current)}>
Toggle behavior: {tooltipBehaviorTitle}
</Button>
</GridCell>
<GridCell>
<Tooltip
position="top"
content={`Hi there! I'm ${tooltipBehaviorTitle} tooltip.`}
forceHide={isHidden}
>
<Button>
Button with tooltip
</Button>
</Tooltip>
</GridCell>
</GridRow>
</Grid>
);
};

<HiddenTooltip />

```
const [isHidden, setIsHidden] = React.useState(false);
const tooltipBehaviorTitle = isHidden ? 'always hidden' : 'normal';
<Button onClick={() => setIsHidden(current=>!current)}>
Toggle behavior: {tooltipBehaviorTitle}
</Button>
<Tooltip
position="top"
content={`Hi there! I'm ${tooltipBehaviorTitle} tooltip.`}
forceHide={isHidden}
>
<Button>
Button with tooltip
</Button>
</Tooltip>
```

## Fully controlled

export const FullyControlledTooltip = () => {
const [isVisible, setIsVisible] = React.useState(false);
const tooltipBehaviorTitle = isVisible ? 'always visible' : 'always hidden';
return (
<Grid>
<GridRow>
<GridCell>
<Button onClick={() => setIsVisible(current=>!current)}>
Toggle behavior: {tooltipBehaviorTitle}
</Button>
</GridCell>
<GridCell>
<Tooltip
position="top"
content={`Hi there! I'm ${tooltipBehaviorTitle} tooltip.`}
forceShow={isVisible}
forceHide={!isVisible}
>
<Button>
Button with tooltip
</Button>
</Tooltip>
</GridCell>
</GridRow>
</Grid>
);
};

<FullyControlledTooltip />

```
const [isVisible, setIsVisible] = React.useState(false);
const tooltipBehaviorTitle = isVisible ? 'always visible' : 'always hidden';
<Button onClick={() => setIsVisible(current=>!current)}>
Toggle behavior: {tooltipBehaviorTitle}
</Button>
<Tooltip
position="top"
content={`Hi there! I'm ${tooltipBehaviorTitle} tooltip.`}
forceShow={isVisible}
forceHide={!isVisible}
>
<Button>
Button with tooltip
</Button>
</Tooltip>
```
Loading

0 comments on commit 25805cc

Please sign in to comment.