Dash Mantine Components

repository·master·Indexed 20 days ago

https://github.com/snehilvj/dash-mantine-components

An extensive library of over 90 Plotly Dash components based on the Mantine React library, enabling the creation of high-quality dashboards using Python. Version 2.8.0 includes a wide range of components such as MantineProvider, DatePickerInput, and various charting tools including AreaChart, CompositeChart, DonutChart, Heatmap, and PieChart.

Tokens
11.7K
Snippets
20
Records
33
Agent score
69%

What's inside dash-mantine-components

  1. How MantineProvider works

    master
    The dmc.MantineProvider is a required top-level component in your Dash layout. It acts as a context provider for the Mantine theme, ensuring that all components within the library have access to the necessary styling, spacing, and design tokens. Without wrapping your layout in MantineProvider, components may not render with the intended Mantine aesthetics.
  2. Quickstart with MantineProvider and DatePickerInput

    master

    To use Dash Mantine Components, wrap your application layout in dmc.MantineProvider. This ensures that the Mantine theme and styles are correctly applied to all child components. The following example demonstrates how to use a dmc.DatePickerInput and update a dmc.Text component via a Dash callback.

    import dash
    from dash import Dash, Input, Output, callback, html, no_update
    
    import dash_mantine_components as dmc
    
    app = Dash()
    
    app.layout = dmc.MantineProvider(
        [
            dmc.DatePickerInput(
                id="date-picker",
                label="Start Date",
                description="You can also provide a description",
                minDate='2022-08-05',
                value=None,
                w=200
            ),
            dmc.Space(h=10),
            dmc.Text(id="selected-date"),
        ]
    )
    
    
    @callback(Output("selected-date", "children"), Input("date-picker", "value"))
    def update_output(d):
        prefix = "You have selected: "
        if d:
            return prefix + d
        else:
            return no_update
    
    
    if __name__ == "__main__":
        app.run_server(debug=True)
  3. Available components in dash-mantine-components

    master

    The dash-mantine-components library provides a comprehensive suite of UI components for Dash applications, organized into several functional categories. You can import these components directly from the main package.

    Charts

    Visual data representation components including AreaChart, BarChart, BubbleChart, CompositeChart, DonutChart, FunnelChart, Heatmap, LineChart, PieChart, RadarChart, ScatterChart, Sparkline, and SemiCircleProgress.

    Layout & Core

    Structural components for building application shells and layouts: AppShell (and its sub-components like AppShellHeader, AppShellNavbar, etc.), Container, Center, Flex, Group, Stack, Grid, GridCol, SimpleGrid, Paper, Box, Divider, Space, AspectRatio, Affix, and Stack.

    Inputs & Forms

    Interactive elements for user data entry: TextInput, Textarea, PasswordInput, NumberInput, PinInput, JsonInput, Select, MultiSelect, Autocomplete, TagsInput, Checkbox, CheckboxGroup, Radio, RadioGroup, Switch, Slider, RangeSlider, ColorInput, ColorPicker, and DateInput (along with various date/time pickers).

    Components for app navigation and transient UI: Tabs, Stepper, Breadcrumbs, NavLink, Menu (and sub-menus), Pagination, Drawer, ManagedDrawer, Modal, ManagedModal, Popover, HoverCard, and Tooltip.

    Feedback & Status

    Visual indicators for system state: Alert, Badge, Loader, LoadingOverlay, Progress, RingProgress, Skeleton, Notification, and NavigationProgress.

    Data Display

    Components for presenting information: Table (and sub-components like TableTr, TableTd, etc.), List, Timeline, Accordion, Card, Avatar, Chip, and Tree.

  4. Manage notifications with NotificationProvider and NotificationContainer

    master

    To use the notification system, you must wrap your application in a NotificationProvider. To actually render the notifications on the screen, you must also include the NotificationContainer in your layout. The appNotifications object is used to interact with the notification queue.

    Note: NotificationContainer is typically used alongside NotificationProvider to manage the lifecycle and display of notifications.

    // Conceptual usage pattern
    import {
      NotificationProvider,
      NotificationContainer,
      Notification
    } from 'dash-mantine-components';
    
    # In your Dash app layout:
    # NotificationProvider(children=[NotificationContainer(), ...your_app_layout])
  5. Configure DonutChart props

    master

    The DonutChart component is used to render a donut-style pie chart. It accepts a data array of DonutChartCell objects and provides several props to customize appearance, tooltips, and labels.

    Key Props

    PropTypeDefaultDescription
    dataDonutChartCell[]RequiredData used to render the chart segments.
    withTooltipbooleantrueWhether to display a tooltip on segment hover.
    tooltipDataSource'segment' | 'all''all''all' displays all values in tooltip; 'segment' displays only the hovered segment.
    withLabelsbooleanfalseWhether each segment should have an associated label.
    withLabelsLinebooleantrueWhether labels should have lines connecting them to the segments.
    thicknessnumber20Thickness of the chart segments.
    sizenumber80Chart width and height. Note: height increases by 40 if withLabels is true.
    chartLabelstring | number-Text or number displayed in the center of the donut.
    startAnglenumber0Starting angle. Set to 180 for a semicircle.
    endAnglenumber360Ending angle. Set to 0 for a semicircle.
    paddingAnglenumber0Padding between segments.
    strokeColorMantineColor-Color of the segments' stroke.
    labelColorMantineColor-Color of all labels.
    strokeWidthnumber1Width of the segments' stroke.
    piePropsobject-Props passed down to the underlying Recharts Pie component.
    pieChartPropsobject-Props passed down to the underlying Recharts PieChart component.
    tooltipPropsobject-Props passed down to the underlying Recharts Tooltip component.
    import { DonutChart } from '@mantine/charts'; // Assuming standard import path
    
    const data = [
      { name: 'Segment A', value: 400 },
      { name: 'Segment B', value: 300 },
    ];
    
    function MyChart() {
      return (
        <DonutChart
          data={data}
          withLabels
          chartLabel="Total"
          thickness={30}
          size={150}
        />
      );
    }
  6. Configure DatePicker components

    master

    The DatePickerBaseProps interface defines the core configuration for date picking components (including DatePicker, MonthPicker, and YearPicker).

    Key properties include:

    • type: The picker mode, which can be 'range', 'multiple', or the default (single date).
    • value: The controlled value, accepting a string, string[], or [string, string] (for ranges).
    • level: Controls the current view level ('decade', 'year', or 'month').
    • maxLevel: The maximum level the user can navigate to (e.g., 'decade' or 'year').
    • presets: An array of DatePickerPreset objects containing a value and a label for quick selection.
    • allowDeselect: Allows users to deselect a date by clicking it (only for default type).
    • allowSingleDateInRange: Allows a single date to be selected as a range (only for range type).
    // Example configuration for a DatePicker
    const props: DatePickerBaseProps = {
      type: 'range',
      value: ['2023-01-01', '2023-01-10'],
      maxLevel: 'month',
      presets: [
        { value: '2023-01-01', label: 'New Year' }
      ]
    };
  7. Configure RadarChart props

    master

    The RadarChart component is used to render radar charts. It requires a data array and a series configuration to map data to the chart axes. It also accepts various props to control visibility of UI elements like legends, grids, axes, tooltips, and dots, as well as direct props for underlying Recharts components.

    Required Props

    • data: An array of objects (Record<string, any>[]) containing the chart data.
    • series: An array of RadarChartSeries objects that determines which data fields are consumed.
    • dataKey: The key in the data objects used for axis values.

    Visibility Props

    • withLegend: Boolean. Shows the chart legend. Defaults to false.
    • withPolarGrid: Boolean. Shows the PolarGrid component. Defaults to true.
    • withPolarAngleAxis: Boolean. Shows the PolarAngleAxis component. Defaults to true.
    • withPolarRadiusAxis: Boolean. Shows the PolarRadiusAxis component. Defaults to false.
    • withTooltip: Boolean. Shows the tooltip component. Defaults to false.
    • withDots: Boolean. Shows dots on the radar lines. Defaults to false.

    Styling and Recharts Passthrough

    • gridColor: MantineColor. Color of the grid lines.
    • textColor: MantineColor. Color of all text elements.
    • legendProps: Object. Props passed to the Recharts Legend component.
    • radarChartProps: Object. Props passed to the Recharts RadarChart component.
    • radarProps: Any. Props passed to the Recharts Radar component.
    • tooltipProps: Object. Props passed to the Recharts Tooltip component.
    • dotProps: Object. Props passed to all dots (ignored if withDots is false).
    • activeDotProps: Object. Props passed to active dots (ignored if withDots is false).
    import RadarChart from '@mantine/charts/lib/RadarChart/RadarChart';
    
    const data = [
      { dimension: 'Speed', value: 80, other: 50 },
      { dimension: 'Strength', value: 90, other: 60 },
    ];
    
    const series = [
      { key: 'value', color: 'blue' },
      { key: 'other', color: 'red' },
    ];
    
    function MyChart() {
      return (
        <RadarChart
          data={data}
          series={series}
          dataKey="dimension"
          withLegend
          withTooltip
          withDots
        />
      );
    }
  8. Configure the AreaChart component

    master

    The AreaChart component is used to display area-based charts. It requires a data array and a series configuration to map data keys to visual representations. It supports various visual customizations such as gradients, curve types, and dot styling, and allows passing props directly to the underlying Recharts components via areaChartProps and areaProps.

    import AreaChart from './AreaChart';
    
    const data = [
      { time: '01:00', value: 10, value2: 20 },
      { time: '02:00', value: 15, value2: 25 },
    ];
    
    const series = [
      { name: 'value', color: 'blue.6' },
      { name: 'value2', color: 'red.6' },
    ];
    
    function MyChart() {
      return (
        <AreaChart
          data={data}
          series={series}
          withGradient
          curveType="monotone"
          withDots
        />
      );
    }
  9. Configure TimeGrid components

    master

    The TimeGridProps interface is used for grid-based time selection.

    Key properties include:

    • data: An array of unique time strings in 24h format (e.g., ['10:00', '18:30']).
    • timeRangeData: A GetTimeRange object (startTime, endTime, interval) that overrides the data prop to automatically generate a range of time values.
    • disableTime: An array of specific time strings to disable.
    • minTime / maxTime: Constraints that disable all controls before or after the specified time.
    • format: The display format, either '12h' or '24h' (defaults to '24h').
    • allowDeselect: Whether clicking an active option deselects it.
    const gridProps: TimeGridProps = {
      timeRangeData: {
        startTime: '09:00:00',
        endTime: '17:00:00',
        interval: '00:30:00'
      },
      disableTime: ['12:00:00', '13:00:00']
    };
  10. Configure Box component props

    master

    The Box component in dash-mantine-components uses the BoxProps interface, which extends Mantine's core Box properties. Most props (spacing, typography, sizing, etc.) accept a single value (theme key, CSS value, or number) or an object for responsive styles (e.g., {'sm': '10px', 'lg': '20px'}).

    Key Prop Groups:

    Visibility & Modifiers

    • hiddenFrom: Breakpoint above which the component is hidden (display: none).
    • visibleFrom: Breakpoint below which the component is hidden (display: none).
    • mod: Element modifiers transformed into data- attributes. Accepts a string, object, or an array of strings/objects. Falsy values are removed.

    Spacing (Margin & Padding)

    Accepts theme spacing keys, CSS values, or a dict for responsive styles.

    • Margin: m (all), my (block), mx (inline), mt (top), mb (bottom), ms (inline start), me (inline end), ml (left), mr (right).
    • Padding: p (all), py (block), px (inline), pt (top), pb (bottom), ps (inline start), pe (inline end), pl (left), pr (right).

    Colors & Borders

    • bd: Border (CSS value or responsive dict).
    • bdrs: Border radius (theme key, CSS value, or responsive dict).
    • bg: Background (theme color key or responsive dict).
    • c: Color (theme color key or responsive dict).
    • opacity: Opacity (CSS value, number, or responsive dict).

    Typography

    • ff: Font family.
    • fz: Font size (theme key, CSS value, or responsive dict).
    • fw: Font weight.
    • lts: Letter spacing.
    • ta: Text align.
    • lh: Line height.
    • fs: Font style.
    • tt: Text transform.
    • td: Text decoration.

    Sizing

    • w: Width.
    • miw: Minimum width.
    • maw: Maximum width.
    • h: Height.
    • mih: Minimum height.
    • mah: Maximum height.

    Layout & Positioning

    • pos: Position (e.g., relative, absolute).
    • top, left, bottom, right, inset: Offset values.
    • display: Display property.
    • flex: Flexbox properties.