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 docs + preview #175

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions @stellar/design-system-website/docs/components/accents/tooltip.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
slug: /tooltip
---

# Tooltip

<ComponentDescription componentName="Tooltip" />

## Example

```tsx live
<PreviewBlock componentName="Tooltip">
<Tooltip isVisible isContrast triggerEl={<>Tooltip trigger</>}>
Lorem ipsum dolor sit
</Tooltip>
</PreviewBlock>
```

## Props

<ComponentProps componentName="Tooltip" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { ComponentPreview } from "@site/src/components/PreviewBlock";

export const tooltipPreview: ComponentPreview = {
options: [
{
type: "select",
prop: "placement",
options: [
{
value: "",
label: "Placement",
},
{
value: "bottom",
label: "Bottom",
},
{
value: "bottom-start",
label: "Bottom start",
},
{
value: "bottom-end",
label: "Bottom end",
},
{
value: "left",
label: "Left",
},
{
value: "left-start",
label: "Left start",
},
{
value: "left-end",
label: "Left end",
},
{
value: "right",
label: "Right",
},
{
value: "right-start",
label: "Right start",
},
{
value: "right-end",
label: "Right end",
},
{
value: "top",
label: "Top",
},
{
value: "top-start",
label: "Top start",
},
{
value: "top-end",
label: "Top end",
},
],
},
{
type: "select",
prop: "isVisible",
customValue: false,
options: [
{
value: "",
label: "Visible",
},
{
value: "hidden",
label: "Hidden",
},
],
},
{
type: "select",
prop: "isContrast",
customValue: false,
options: [
{
value: "",
label: "Contrast",
},
{
value: "noContrast",
label: "No contrast",
},
],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { paragraphPreview } from "@site/src/componentPreview/paragraphPreview";
import { profilePreview } from "@site/src/componentPreview/profilePreview";
import { projectLogoPreview } from "@site/src/componentPreview/projectLogoPreview";
import { titlePreview } from "@site/src/componentPreview/titlePreview";
import { tooltipPreview } from "@site/src/componentPreview/tooltipPreview";

// =============================================================================
// Component previews
Expand All @@ -37,6 +38,7 @@ const previews: { [key: string]: ComponentPreview } = {
Profile: profilePreview,
ProjectLogo: projectLogoPreview,
Title: titlePreview,
Tooltip: tooltipPreview,
};

type Theme = "sds-theme-light" | "sds-theme-dark";
Expand Down
27 changes: 24 additions & 3 deletions @stellar/design-system/src/components/Tooltip/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
import { Floater, FloaterPlacement } from "../Floater";
import { Floater } from "../Floater";
import "./styles.scss";

interface TooltipProps {
/** */
export interface TooltipProps {
/** Element that shows/hides tooltip */
triggerEl: JSX.Element;
/** Content of the tooltip */
children: React.ReactNode;
placement?: FloaterPlacement;
/** Placement of tooltip relative to the trigger element @defaultValue `right` */
placement?:
| "top"
| "right"
| "bottom"
| "left"
| "top-start"
| "top-end"
| "right-start"
| "right-end"
| "bottom-start"
| "bottom-end"
| "left-start"
| "left-end";
/** Manually show/hide tooltip */
isVisible?: boolean;
/** Use contrast theme color @defaultValue `true` */
isContrast?: boolean;
}

/**
* Tooltip is used to display info in a bubble. We are using [Floating UI](https://floating-ui.com/) for tooltip positioning.
*/
export const Tooltip: React.FC<TooltipProps> = ({
triggerEl,
children,
Expand Down
Loading