Skip to content

Commit

Permalink
refactor: Consolidate Markdown usage
Browse files Browse the repository at this point in the history
...so that we will be able to define components in a single place.
  • Loading branch information
bprusinowski committed Dec 12, 2024
1 parent 1bb7145 commit 3d01df7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/components/chart-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Box, BoxProps, Theme } from "@mui/material";
import { makeStyles } from "@mui/styles";
import clsx from "clsx";
import { forwardRef, HTMLProps, PropsWithChildren, useCallback } from "react";
import Markdown from "react-markdown";

import {
ChartPanelLayoutCanvas,
Expand All @@ -12,6 +11,7 @@ import { ChartPanelLayoutTall } from "@/components/chart-panel-layout-tall";
import { ChartPanelLayoutVertical } from "@/components/chart-panel-layout-vertical";
import { ChartSelectionTabs } from "@/components/chart-selection-tabs";
import { DashboardInteractiveFilters } from "@/components/dashboard-interactive-filters";
import { Markdown } from "@/components/markdown";
import { ChartConfig, Layout, LayoutDashboard } from "@/config-types";
import { hasChartConfigs, LayoutBlock, LayoutTextBlock } from "@/configurator";
import { useConfiguratorState, useLocale } from "@/src";
Expand Down
10 changes: 10 additions & 0 deletions app/components/markdown.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ComponentProps } from "react";
import ReactMarkdown from "react-markdown";

const components: ComponentProps<typeof ReactMarkdown>["components"] = {};

export const Markdown = (
props: Omit<ComponentProps<typeof ReactMarkdown>, "components">
) => {
return <ReactMarkdown components={components} {...props} />;
};
27 changes: 20 additions & 7 deletions app/configurator/components/annotators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Trans } from "@lingui/macro";
import { Theme, Typography, TypographyProps } from "@mui/material";
import { makeStyles } from "@mui/styles";
import clsx from "clsx";
import Markdown from "react-markdown";

import { Markdown } from "@/components/markdown";
import { getChartConfig } from "@/config-types";
import {
ControlSection,
Expand Down Expand Up @@ -41,10 +41,17 @@ type Props = TypographyProps & {
smaller?: boolean;
};

export const Title = (props: Props) => {
const { text, lighterColor, smaller, onClick, className, sx, ...rest } =
props;
export const Title = ({
text,
lighterColor,
smaller,
onClick,
className,
sx,
...rest
}: Props) => {
const classes = useStyles({ interactive: !!onClick });

return (
<Typography
{...rest}
Expand All @@ -67,9 +74,15 @@ export const Title = (props: Props) => {
);
};

export const Description = (props: Props) => {
const { text, lighterColor, smaller, onClick, className, sx, ...rest } =
props;
export const Description = ({
text,
lighterColor,
smaller,
onClick,
className,
sx,
...rest
}: Props) => {
const classes = useStyles({ interactive: !!onClick });

return (
Expand Down

0 comments on commit 3d01df7

Please sign in to comment.