Skip to content

Commit

Permalink
feat: section anchors
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed May 31, 2022
1 parent 34e0fc5 commit 465f4f8
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions src/web/questions/pages/QuestionPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,27 @@ export const getServerSideProps: GetServerSideProps<Props> = async (
};
};

const Section: React.FC<{ title: string }> = ({ title, children }) => (
<div className="space-y-4 flex flex-col items-start">
<div className="border-b-2 border-gray-200 w-full">
<h2 className="text-xl leading-3 text-gray-900">{title}</h2>
const Section: React.FC<{ title: string; id?: string }> = ({
title,
children,
id,
}) => (
<div className="space-y-4 flex flex-col items-start" id={id}>
<div className="border-b-2 border-gray-200 w-full group">
<h2 className="text-xl leading-3 text-gray-900">
<span>{title}</span>
{id ? (
<>
{" "}
<a
className="text-gray-300 no-underline hidden group-hover:inline"
href={`#${id}`}
>
#
</a>
</>
) : null}
</h2>
</div>
<div>{children}</div>
</div>
Expand All @@ -56,7 +73,7 @@ const EmbedSection: React.FC<{ question: QuestionWithHistoryFragment }> = ({
}) => {
const url = getBasePath() + `/questions/embed/${question.id}`;
return (
<Section title="Embed">
<Section title="Embed" id="embed">
<div className="mb-2">
<BoxedLink url={url} size="small">
Preview
Expand Down Expand Up @@ -86,18 +103,18 @@ const LargeQuestionCard: React.FC<{
</div>

<div className="mx-auto max-w-prose space-y-8">
<Section title="Question description">
<Section title="Question description" id="description">
<ReactMarkdown
linkTarget="_blank"
className="font-normal text-gray-900"
>
{question.description.replaceAll("---", "")}
</ReactMarkdown>
</Section>
<Section title="Indicators">
<Section title="Indicators" id="indicators">
<IndicatorsTable question={question} />
</Section>
<Section title="Capture">
<Section title="Capture" id="capture">
<CaptureQuestion question={question} />
</Section>
<EmbedSection question={question} />
Expand Down

0 comments on commit 465f4f8

Please sign in to comment.