Skip to content

Commit

Permalink
feat: Improve tooltip syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Sporiff committed Oct 24, 2023
1 parent 940e853 commit d050111
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
6 changes: 4 additions & 2 deletions src/components/Tooltip.astro
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ let content = "";
let toolTipContent = "";
let body = "";
const tooltipRegex = /\[(.*)\]\((.*)\)/;
// Matchs the pattern "text || text"
const tooltipRegex = /(.*)\s\|\|\s(.*)/m;
if (Astro.slots.has("default")) {
content = await Astro.slots.render("default");
Expand All @@ -25,6 +26,7 @@ if (Astro.slots.has("default")) {
}
---

<BuildTooltip position={position} client:only="react" content={toolTipContent}>
<BuildTooltip position={position} client:only="react">
<Fragment set:html={body} name="children" />
<Fragment set:html={toolTipContent} slot="content" />
</BuildTooltip>
1 change: 0 additions & 1 deletion src/components/atlas/BuildTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const BuildTooltip: FC<{
children: ReactElement;
position?: Position;
}> = (props) => {
console.log(props);
return (
<>
<Tooltip
Expand Down
32 changes: 23 additions & 9 deletions src/content/docs/en/kitchen-sink/typography.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,32 +122,46 @@ Abbreviations can be written using the `<Abbr>` component. This component transf

</Table>

Tooltips can be written using the `<Tooltip>` component. This component transforms content written as `[${Article content}](${Tooltip content})` into an [Atlas `Tooltip` component](https://atlas.adeven.com/docs/components/Tooltip).
<Callout type="important">

Tooltips only support single line content.

</Callout>

Tooltips can be written using the `<Tooltip>` component. This component transforms content written as `${Article content} || %${Tooltip content}%` into an [Atlas `Tooltip` component](https://atlas.adeven.com/docs/components/Tooltip).

```mdx
<Tooltip>This is content that needs a tooltip || Here it is!</Tooltip>
```

<Tooltip>This is content that needs a tooltip || Here it is!</Tooltip>

You can use standard markdown syntax in tooltips.

```mdx
<Tooltip>[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip>**Markdown** _Syntax_ [is available](https://markdownguide.org) || _Even_ **in** ~the tooltip~</Tooltip>
```

<Tooltip>[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip>**Markdown** _Syntax_ [is available](https://markdownguide.org) || _Even_ **in** ~the tooltip~</Tooltip>

### Custom position

Tooltips are shown above the content by default. You can customize the position of the tooltip by passing a `position` prop.

```mdx
<Tooltip position="bottom">[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip position="bottom">This is content that needs a tooltip || Here it is!</Tooltip>
```

<Tooltip position="bottom">[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip position="bottom">This is content that needs a tooltip || Here it is!</Tooltip>

```mdx
<Tooltip position="left">[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip position="left">This is content that needs a tooltip || Here it is!</Tooltip>
```

<Tooltip position="left">[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip position="left">This is content that needs a tooltip || Here it is!</Tooltip>

```mdx
<Tooltip position="right">[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip position="right">This is content that needs a tooltip || Here it is!</Tooltip>
```

<Tooltip position="right">[This is content that needs a tooltip](Here it is!)</Tooltip>
<Tooltip position="right">This is content that needs a tooltip || Here it is!</Tooltip>

0 comments on commit d050111

Please sign in to comment.