-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Fran McDade <[email protected]>
- Loading branch information
1 parent
5860f5c
commit 5f3cfee
Showing
10 changed files
with
18,305 additions
and
12,629 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
app/components/Detail/components/MDX/components/Description/common/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Link } from "../../../../../../Layout/components/Content/components/Link/link"; | ||
import { Table } from "../../Table/table"; | ||
import { H1, H2, H3, H4, P } from "./../description.styles"; | ||
|
||
/** | ||
* Components used when rendering MDX content in Description. Note when | ||
* generalizing this constant, description styles also need to be generalized. | ||
*/ | ||
export const MDX_COMPONENTS = { | ||
a: Link, | ||
h1: H1, | ||
h2: H2, | ||
h3: H3, | ||
h4: H4, | ||
p: P, | ||
table: Table, | ||
}; |
52 changes: 52 additions & 0 deletions
52
app/components/Detail/components/MDX/components/Description/description.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
textBodyLarge500, | ||
textHeadingLarge, | ||
textHeadingSmall, | ||
} from "@databiosphere/findable-ui/lib/styles/common/mixins/fonts"; | ||
import styled from "@emotion/styled"; | ||
|
||
/** | ||
* H1 styled component. Matches H1 in the Portal. | ||
*/ | ||
export const H1 = styled.h1` | ||
${textHeadingLarge}; | ||
font-size: 30px; | ||
letter-spacing: -0.8px; | ||
line-height: 40px; | ||
margin: 0 0 16px; /* Matching margin-bottom of H1 in docs */ | ||
`; | ||
|
||
/** | ||
* H2 styled component. Removed textHeadingLarge mixin to prevent `font-size: 30px` | ||
* for tablet+ (to match H2's in the Portal). | ||
*/ | ||
export const H2 = styled.h2` | ||
font-size: 24px; | ||
font-weight: 500; | ||
letter-spacing: -0.4px; | ||
line-height: 32px; | ||
margin: 32px 0 16px; /* Matching margin-bottom of H2 in docs */ | ||
`; | ||
|
||
/** | ||
* H3 styled component. | ||
*/ | ||
export const H3 = styled.h3` | ||
${textHeadingSmall} | ||
margin: 40px 0 16px; /* Matching margin-bottom of H3 in docs */ | ||
`; | ||
|
||
/* | ||
* H4 styled component. | ||
*/ | ||
export const H4 = styled.h4` | ||
${textBodyLarge500} | ||
margin: 16px 0; /* Matching margin-bottom of H4 in docs */ | ||
`; | ||
|
||
/** | ||
* P styled component. | ||
*/ | ||
export const P = styled.p` | ||
margin: 0 0 16px; /* Matching margin-bottom of P in docs */ | ||
`; |
35 changes: 35 additions & 0 deletions
35
app/components/Detail/components/MDX/components/Description/description.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { CollapsableSection } from "@databiosphere/findable-ui/lib/components/common/Section/components/CollapsableSection/collapsableSection"; | ||
import type { EvaluateOptions } from "@mdx-js/mdx"; | ||
import { evaluate } from "@mdx-js/mdx"; | ||
import type { MDXProps } from "mdx/types"; | ||
import { ReactNode, useEffect, useState } from "react"; | ||
import { Fragment, jsx, jsxs } from "react/jsx-runtime"; | ||
import remarkGfm from "remark-gfm"; | ||
import { MDX_COMPONENTS } from "./common/constants"; | ||
import { DescriptionProps } from "./types"; | ||
|
||
type ReactMDXContent = (props: MDXProps) => ReactNode; | ||
type Runtime = Pick<EvaluateOptions, "jsx" | "jsxs" | "Fragment">; | ||
|
||
const runtime = { Fragment, jsx, jsxs } as Runtime; | ||
|
||
export const Description = ({ content }: DescriptionProps): JSX.Element => { | ||
const [MdxContent, setMdxContent] = useState<ReactMDXContent>( | ||
() => (): null => null | ||
); | ||
|
||
useEffect(() => { | ||
evaluate(content, { ...runtime, remarkPlugins: [remarkGfm] }).then((r) => | ||
setMdxContent(() => r.default) | ||
); | ||
}, [content]); | ||
|
||
// Wrapping <MdxContent> with <div> to force `display: block` | ||
return ( | ||
<CollapsableSection collapsable={false} title="Description"> | ||
<div> | ||
{MdxContent ? <MdxContent components={MDX_COMPONENTS} /> : null} | ||
</div> | ||
</CollapsableSection> | ||
); | ||
}; |
3 changes: 3 additions & 0 deletions
3
app/components/Detail/components/MDX/components/Description/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface DescriptionProps { | ||
content: string; | ||
} |
47 changes: 47 additions & 0 deletions
47
app/components/Detail/components/MDX/components/Table/table.styles.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { smokeMain } from "@databiosphere/findable-ui/lib/styles/common/mixins/colors"; | ||
import { | ||
textBody400, | ||
textBody500, | ||
} from "@databiosphere/findable-ui/lib/styles/common/mixins/fonts"; | ||
import styled from "@emotion/styled"; | ||
import { TableContainer as MTableContainer } from "@mui/material"; | ||
|
||
/** | ||
* Table style component. TODO De-dupe with Table component in the Portal. | ||
*/ | ||
export const TableContainer = styled(MTableContainer)` | ||
margin: 24px 0; | ||
.MuiTable-root { | ||
min-width: calc(390px - 32px); | ||
tr { | ||
td, | ||
th { | ||
border-bottom: 1px solid ${smokeMain}; | ||
padding: 12px; | ||
text-align: left; | ||
&:first-of-type { | ||
padding-left: 0; | ||
} | ||
&:last-of-type { | ||
padding-right: 0; | ||
} | ||
} | ||
th { | ||
${textBody500}; | ||
&:empty { | ||
padding: 0; | ||
} | ||
} | ||
td { | ||
${textBody400}; | ||
} | ||
} | ||
} | ||
`; |
10 changes: 10 additions & 0 deletions
10
app/components/Detail/components/MDX/components/Table/table.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { Table as MTable } from "@mui/material"; | ||
import { TableContainer } from "./table.styles"; | ||
|
||
export const Table = ({ ...props }): JSX.Element => { | ||
return ( | ||
<TableContainer> | ||
<MTable>{props.children}</MTable> | ||
</TableContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.