Skip to content

Commit

Permalink
feat: properly type accordions
Browse files Browse the repository at this point in the history
  • Loading branch information
Sporiff committed Sep 2, 2023
1 parent 383de8d commit 0bba365
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/components/atlas/BuildAccordion.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @jsxImportSource react */
import { Accordion } from "@adjust/components";
import type { AccordionItem } from "@adjust/components/build/Accordion/Item";
import { htmlWithTitles } from "@components/utils/htmlWithTitles";
import type { FC } from "react";

Expand All @@ -14,12 +15,9 @@ const BuildAccordion: FC<{

const content = htmlWithTitles(props.content);

// Each accordion exists in its own list, so we can hardcode the value of `id` to 1.
// If we want to create multi-accordion lists in future we will need to iterate the `id`.

const data = [
const data: AccordionItem[] = [
{
id: 1,
id: content.anchor,
title: content.title || "",
content: content.body,
badge: {},
Expand Down
8 changes: 6 additions & 2 deletions src/components/utils/htmlWithTitles.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ export const htmlWithTitles = (content: string) => {
We need to extract the first header 3 and use it as the label */

const title = el.querySelector("body > h3");
let label: string = "";
let anchor: string = "";

const label = title?.textContent?.toString();
const anchor = title?.id.toString();
if (title && title.textContent) {
label = title.textContent.toString();
anchor = title.id.toString();
}

// If the next sibling of the header is a header 4, we need to store this.

Expand Down

0 comments on commit 0bba365

Please sign in to comment.