### Basic TextLink Example Source: https://github.com/grafana/design-system/blob/main/docs/05-components/text-link.mdx Renders a TextLink component that navigates to an external URL. Use this for linking to external websites. ```tsx Go to Google ``` -------------------------------- ### Basic Tooltip Example Source: https://github.com/grafana/design-system/blob/main/docs/05-components/tooltip.mdx Displays a tooltip with custom content when hovering over a button. Ensure the content is contextual and non-critical. ```tsx ``` -------------------------------- ### Checkbox Usage Example Source: https://github.com/grafana/design-system/blob/main/docs/05-components/checkbox.mdx Demonstrates the basic import and usage of the Checkbox component. Ensure to provide appropriate values for `value`, `label`, `description`, and `onChange` props. ```jsx import { Forms } from '@grafana/ui'; ``` -------------------------------- ### Basic RadioButtonGroup Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/radio-button-group.mdx Demonstrates the basic setup of a RadioButtonGroup with options and state management for the selected value. ```tsx function Basic() { const [value, setValue] = useState(); return ( ); } ``` -------------------------------- ### Basic InteractiveTable Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/interactive-table.mdx This example demonstrates the basic usage of the InteractiveTable component with predefined data and columns. Ensure the InteractiveTable component and its dependencies are imported before use. ```tsx const data = [ { size: 'Small', width: '24px', fontSize: '12px' }, { size: 'Medium', width: '32px', fontSize: '14px' }, { size: 'Large', width: '48px', fontSize: '18px' }, ]; const columns = [ { id: 'size', header: 'Size' }, { id: 'width', header: 'Width' }, { id: 'fontSize', header: 'Font Size' }, ]; render(); ``` -------------------------------- ### Basic Stack Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/stack.mdx Demonstrates the basic usage of the Stack component with direction, wrap, alignment, justification, and gap properties. This example shows how to arrange three span elements within a responsive container. ```tsx One Two Three ``` -------------------------------- ### Basic FilterPill Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/filter-pill.mdx Demonstrates how to import and use the FilterPill component with a label and an onClick handler. Ensure you have '@grafana/ui' installed. ```jsx import { FilterPill } from '@grafana/ui'; console.log('toggle')} />; ``` -------------------------------- ### Add Datasource Form Example Source: https://context7.com/grafana/design-system/llms.txt A React component demonstrating a form for adding a new data source, utilizing Grafana UI components and react-hook-form for state management and validation. Ensure `@grafana/ui` and `react-hook-form` are installed. ```tsx import { Field, Input, Select, Switch, Button, Stack, Box, Text } from '@grafana/ui'; import { useForm } from 'react-hook-form'; type DatasourceForm = { name: string; url: string; type: string; default: boolean; }; const AddDatasourceForm = () => { const { register, handleSubmit, formState: { errors } } = useForm(); return (
console.log(data))}> {/* Form header */} Add datasource Connect Grafana to an external data source. {/* Form body – single-column, 16px gap between fields */} // Controlled placement Grafana ``` -------------------------------- ### Empty State without Button Source: https://github.com/grafana/design-system/blob/main/docs/06-patterns/empty-state.mdx Omit the button prop when there isn't a single, direct action to create an item. Instead, provide descriptive text to guide the user on how to create the resource. ```tsx import { EmptyState, TextLink } from '@grafana/ui'; Create a library panel from any existing dashboard panel through the panel context menu.{' '} Learn more. ; ``` -------------------------------- ### Inline Alert Example Source: https://github.com/grafana/design-system/blob/main/docs/05-components/alert.mdx Use Inline Alerts to provide direct, contextual feedback to users within the main content area. They are suitable for both system and user-triggered events. ```tsx import { Alert } from "@grafana/ui";
Child content that includes some alert details, like maybe what actually happened.
``` -------------------------------- ### Badge Examples in React Source: https://context7.com/grafana/design-system/llms.txt Badges add meta information like status or counts to adjacent content. They support named colors and optional icons. Note that colors use the visualization palette, not semantic design tokens. ```tsx import { Badge, Stack } from '@grafana/ui'; // Status badges // Badge with icon and tooltip ``` -------------------------------- ### Basic Pagination Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/pagination.mdx Demonstrates how to integrate the Pagination component into your application. Ensure you provide the current page number, the total number of pages, and a navigation handler. ```jsx
Page 1 content
fetchPage(2)} />
``` -------------------------------- ### Steps Configuration Source: https://github.com/grafana/design-system/blob/main/docs/07-templates/multistep-form-page.mdx Configuration file that likely defines the order, titles, and potentially the components associated with each step in the multistep form. ```ts import { CodeCollapse } from '@site/src/components/templates/CodeCollapse'; import stepsRaw from '!!raw-loader!@site/src/components/templates/MultistepFormPage/utils/steps'; {stepsRaw} ``` -------------------------------- ### Basic RadioButtonList Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/radio-button.mdx Demonstrates the basic import and usage of the RadioButtonList component. Ensure you provide options, a value, and an onChange handler. ```jsx import { RadioButtonList } from '@grafana/ui'; ``` -------------------------------- ### Toast Alert Example Source: https://github.com/grafana/design-system/blob/main/docs/05-components/alert.mdx Toast Alerts are temporary messages that appear in the top-right corner of the screen. They are dismissible and disappear after a few seconds, ideal for non-disruptive notifications. ```tsx import { Alert } from "@grafana/ui";
Child content that includes some alert details, like maybe what actually happened.
``` -------------------------------- ### Empty State with Call to Action Button Source: https://github.com/grafana/design-system/blob/main/docs/06-patterns/empty-state.mdx Use this variant when no data exists and you want to prompt the user to create an item or complete initial configuration. It includes a message and a button for the primary action. ```tsx import { EmptyState, LinkButton, TextLink } from '@grafana/ui'; Create playlist } > You can use playlists to cycle dashboards on TVs without user control.{' '} Learn more. ; ``` -------------------------------- ### Input with Addon After Source: https://github.com/grafana/design-system/blob/main/docs/05-components/input.mdx An accessory, commonly a button, can be placed after the input using the `addonAfter` prop. ```tsx Load} /> ``` -------------------------------- ### Basic FileDropzone Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/file-dropzone.mdx Import and use the FileDropzone component. The onLoad callback receives the file result. ```jsx import { FileDropzone } from '@grafana/ui'; console.log(result)} />; ``` -------------------------------- ### Box Component Layout and Styling Source: https://context7.com/grafana/design-system/llms.txt Demonstrates the Box component for layout primitives, including spacing, visual styling, flex properties, and responsive design using breakpoint-specific props. ```tsx import { Box } from '@grafana/ui'; // Spacing using ThemeSpacingTokens (0 | 0.25 | 0.5 | 1 | 1.5 | 2 | 2.5 | 3 | 4 | 5 | 6 | 8 | 10) Content with margin and padding // Visual styling Warning callout // Flex layout via Box Label // Responsive props – different values per breakpoint Responsive spacing ``` -------------------------------- ### Toggletip Examples in React Source: https://context7.com/grafana/design-system/llms.txt Toggletip is similar to Tooltip but is triggered by click and remains visible until dismissed. It supports interactive content, optional titles, and footer slots. Use it for persistent popovers with actionable elements. ```tsx import { Toggletip, Button } from '@grafana/ui'; // Basic toggletip with header, body, and footer Learn more} > // Toggletip with an interactive call-to-action inside
} > ``` -------------------------------- ### Responsive Grid Columns Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/grid.mdx Define responsive behavior for the `columns` prop by passing an object with breakpoint keys (e.g., `xs`, `md`). This allows the number of columns to adapt to different screen sizes. ```tsx import { Grid } from '@grafana/ui'; Content ``` -------------------------------- ### Truncated Span with Parent Container Styling Source: https://github.com/grafana/design-system/blob/main/docs/05-components/text.mdx This example shows how to truncate a Text component rendered as a span by applying CSS properties to its parent div. A Tooltip is used to display the full text on hover. ```jsx
{'This is an example of a span element truncated by its parent container.'}
``` -------------------------------- ### Button Hierarchy and Pairings Source: https://github.com/grafana/design-system/blob/main/docs/05-components/02-buttons/button.mdx Illustrates how to use different button types (Primary/Destructive, Secondary/Icon, Outline/Text) to convey varying levels of importance and user attention. Use primary buttons for the main action, secondary for less critical actions, and outline/text for informational links. ```markdown - **Primary/Destructive Button — High Emphasis:** A single page should only display one button with the highest importance for the main action. Other buttons should have lower emphasis and be visually different within the UI. This primary button has to attract the user's attention. - **Secondary/Icon Button — Default Emphasis:** A single screen can show more than one button, the other buttons can be in the same page with a primary button, these buttons have to be less important according to the actions, and do not distract users from the main content page. You should only group calls to action that are related to each other. A higher emphasis button can be paired with multiple buttons which are lower emphasis. - **Outline/Text Button — Low Emphasis:** These buttons have less impact and are less distracting to the user's attention, on the same screen several of them can be used. They are actionable to take users to a new page, the main objective being to provide more information about that section. ``` -------------------------------- ### Responsive Box Component Props Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/box.mdx Demonstrates how to apply responsive values to Box component props using an object with breakpoint keys (e.g., xs, md). This allows for different styling based on screen size. ```tsx margin={{ xs: 3, md: 5 }} ``` -------------------------------- ### Async Select Input Source: https://github.com/grafana/design-system/blob/main/docs/05-components/select.mdx Configure for dropdowns populated asynchronously. Provide a `loadOptions` function returning a promise and optionally `defaultOptions` for initial loading. `cacheOptions` can improve performance. ```tsx const loadAsyncOptions = (inputValue: string) => { return new Promise>>((resolve) => { setTimeout(() => { resolve([ { label: 'Option 1', value: '1' }, { label: 'Option 2', value: '2' }, { label: 'Option 3', value: '3' }, ]); }, 1000); }); }; const BasicSelectAsync = () => { const [value, setValue] = React.useState>(); return ( ); }; render(); ``` -------------------------------- ### Card Action with Metadata Interaction Note Source: https://github.com/grafana/design-system/blob/main/docs/05-components/card.mdx When using both Card actions (href/onClick) and Card.Meta, clicking elements within Card.Meta will not trigger the card's primary action. This example demonstrates that clicking the Description triggers the alert, while clicking the Meta text does not. ```jsx alert('Hello, Grafana!')}> Hello, Grafana Clicking on this text (Meta) WILL NOT trigger the alert! Clicking on this text (Description) WILL trigger the alert! ``` -------------------------------- ### Basic Button Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/02-buttons/button.mdx Demonstrates the basic usage of the Button component. This is suitable for primary actions. ```tsx ``` -------------------------------- ### Responsive Grid Minimum Column Width Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/grid.mdx Define responsive behavior for the `minColumnWidth` prop by passing an object with breakpoint keys. This allows the minimum column width to adapt to different screen sizes. ```tsx import { Grid } from '@grafana/ui'; Content ``` -------------------------------- ### Run Docusaurus Locally Source: https://github.com/grafana/design-system/blob/main/README.md To run the Docusaurus instance locally, execute this command in your terminal. A local instance will be available at 'http://localhost:3000/developers/saga/'. ```bash yarn start ``` -------------------------------- ### Preview Step Component Source Source: https://github.com/grafana/design-system/blob/main/docs/07-templates/multistep-form-page.mdx The Preview step component allows users to review their selections or entered information before final submission. ```tsx import { CodeCollapse } from '@site/src/components/templates/CodeCollapse'; import PreviewRaw from '!!raw-loader!@site/src/components/templates/MultistepFormPage/Steps/Preview'; {PreviewRaw} ``` -------------------------------- ### Basic IconButton Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/02-buttons/iconButton.mdx Use this snippet to render a basic IconButton with a tooltip and an icon. Ensure the tooltip provides a clear label for the action. ```tsx ``` -------------------------------- ### Basic Switch Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/switch.mdx Demonstrates the basic usage of the Switch component with a label and disabled state. ```jsx ``` -------------------------------- ### Basic Toggletip with Header and Footer Source: https://github.com/grafana/design-system/blob/main/docs/05-components/toggletip.mdx Demonstrates a basic Toggletip with a title, content, and footer, triggered by a button click. Ensure the trigger element is focusable and has an accessible label. ```tsx ``` -------------------------------- ### Button Component Usage Source: https://context7.com/grafana/design-system/llms.txt Demonstrates various emphasis levels, sizes, and icon usage for the Button component. Use only one primary button per page. ```tsx import { Button } from '@grafana/ui'; // Primary action (high emphasis) // Secondary (default emphasis) – most common usage // Destructive – paired with a confirmation modal // Icon + label button // Button group – only one primary allowed <> ``` -------------------------------- ### Inline Switch Usage Source: https://github.com/grafana/design-system/blob/main/docs/05-components/switch.mdx Shows how to use the InlineSwitch component for a more compact toggle. ```jsx ``` -------------------------------- ### Box Component for Flex Layout Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/box.mdx Shows how to use the Box component to create a flex layout with alignment and spacing. For simpler flex needs without other styling, consider using the Stack component. ```tsx One Two ``` -------------------------------- ### Badge with Icon Source: https://github.com/grafana/design-system/blob/main/docs/05-components/badge.mdx Add an icon to the beginning of the badge by specifying the 'icon' prop with a valid icon name. ```jsx ``` -------------------------------- ### Select with Virtualized Option List Source: https://github.com/grafana/design-system/blob/main/docs/05-components/select.mdx Use for Select components with a large number of options to improve performance by enabling a virtualized list. Props like `maxVisibleValues`, `showAllSelectedWhenOpen`, `isClearable`, and `isLoading` are also applicable. ```tsx const Basic = () => { const [value, setValue] = React.useState>(); const options = [ { label: 'Option 1', value: '1' }, { label: 'Option 2', value: '2' }, { label: 'Option 3', value: '3' }, ]; return ( { setValue(v); }} allowCustomValue onCreateOption={(v) => { const customValue: SelectableValue = { value: v, label: v }; setCustomOptions([...customOptions, customValue]); setValue(customValue); }} /> ); }; render(); ``` -------------------------------- ### Card with Primary and Secondary Actions Source: https://github.com/grafana/design-system/blob/main/docs/05-components/card.mdx Use Card.Actions for primary buttons and Card.SecondaryActions for icon buttons. Ensure actions are wrapped within their respective components. ```jsx 1-ops-tools1-fallback Grafana https://ops-us-east4.grafana.net/api/prom Grafana Logo ``` -------------------------------- ### Badge with Tooltip Source: https://github.com/grafana/design-system/blob/main/docs/05-components/badge.mdx Provide additional information on hover by using the 'tooltip' prop. Keep the tooltip content concise. ```jsx ``` -------------------------------- ### Box Component with Spacing Props Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/box.mdx Demonstrates the usage of margin and padding props on the Box component. Use these props to add space around or inside the box, leveraging theme spacing tokens. ```tsx Content ``` -------------------------------- ### Grid with Minimum Column Width Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/grid.mdx Use the `minColumnWidth` prop to let the grid determine the number of columns based on available space, ensuring each column meets a minimum width. The `gap` prop controls spacing. ```tsx import { Grid } from '@grafana/ui'; 1 2 3 4 5 6 7 8 ``` -------------------------------- ### Select and AsyncSelect Components Source: https://context7.com/grafana/design-system/llms.txt Use Select for single or multi-value selections with predefined options. AsyncSelect is suitable for dynamic data loading with debounced search. Ensure options are formatted as SelectableValue. For multi-select, maxVisibleValues limits displayed chips. ```tsx import { Select, AsyncSelect } from '@grafana/ui'; import { SelectableValue } from '@grafana/data'; import React, { useState } from 'react'; // Basic controlled select const BasicSelect = () => { const [value, setValue] = useState>(); const options = [ { label: 'Prometheus', value: 'prometheus' }, { label: 'Loki', value: 'loki' }, { label: 'Tempo', value: 'tempo' }, ]; return ( // Async select with debounced search const loadOptions = (query: string) => fetch(`/api/search?q=${query}`) .then(r => r.json()) .then(items => items.map(i => ({ label: i.name, value: i.id }))); // Allow user-created values ``` -------------------------------- ### Form Input with Label Source: https://github.com/grafana/design-system/blob/main/docs/05-components/input.mdx Use inputs with the Field component to provide labels and descriptions. This is the standard way to use inputs in forms. ```tsx ``` -------------------------------- ### Import ListPage Component Source Source: https://github.com/grafana/design-system/blob/main/docs/07-templates/list-page.mdx Import the raw source code of the ListPage component for reference or analysis. ```jsx import ListPageRaw from '!!raw-loader!@site/src/components/templates/ListPage/ListPage'; ``` -------------------------------- ### Card as a Link Source: https://github.com/grafana/design-system/blob/main/docs/05-components/card.mdx Configure the Card to act as a clickable link by providing an 'href' prop. This is suitable for redirecting users to external or internal resources. ```jsx Redirect to Grafana Clicking this card will redirect to grafana website ``` -------------------------------- ### Card with HTML Metadata Source: https://github.com/grafana/design-system/blob/main/docs/05-components/card.mdx Metadata can include HTML elements like links. For non-string elements, a 'key' prop must be manually specified to ensure proper rendering and identification. ```jsx Test dashboard Grafana https://ops-us-east4.grafana.net/api/prom ``` -------------------------------- ### AdditionalInfo Step Component Source Source: https://github.com/grafana/design-system/blob/main/docs/07-templates/multistep-form-page.mdx A specific step component for collecting additional information. This might include advanced settings or supplementary details. ```tsx import { CodeCollapse } from '@site/src/components/templates/CodeCollapse'; import AdditionalInfoRaw from '!!raw-loader!@site/src/components/templates/MultistepFormPage/Steps/AdditionalInfo'; {AdditionalInfoRaw} ``` -------------------------------- ### Render Multistep Form Page Source: https://github.com/grafana/design-system/blob/main/docs/07-templates/multistep-form-page.mdx This snippet shows how to render the MultistepFormPage component within a DataProvider context. Ensure the Page component is set up with appropriate title and subtitle. ```tsx import { Page } from '@site/src/components/templates/Page/Page'; import { DataProvider } from '@site/src/components/templates/MultistepFormPage/DataProvider'; import MultistepFormPage from '@site/src/components/templates/MultistepFormPage/MultistepFormPage'; ``` -------------------------------- ### Grid with Fixed Columns Source: https://github.com/grafana/design-system/blob/main/docs/05-components/03-primitives/grid.mdx Use the `columns` prop to define a fixed number of equally sized columns. The `gap` prop controls the spacing between grid items. ```tsx import { Grid } from '@grafana/ui'; 1 2 3 4 5 6 7 8 ``` -------------------------------- ### Input with Prefix Icon Source: https://github.com/grafana/design-system/blob/main/docs/05-components/input.mdx Add a prefix element, such as an icon, to the beginning of the input. Useful for search fields. ```tsx } placeholder="Search dashboards" /> ```