Skip to content

Commit

Permalink
[aksel.nav.no] Templates vises nå riktig på mønster/mal-sider (#2450)
Browse files Browse the repository at this point in the history
* 🐛 Fikset visning av templates

* 🐛 autoGenerateArrayKeys fungerte ikke for nested arrays

* 🐛 Fikset tester
  • Loading branch information
KenAJoh authored Nov 3, 2023
1 parent 9b990a2 commit 2a8533a
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const Designsystem: Story = {
innhold:
'import { Button } from "@navikt/ds-react";\n\nconst Example = () => {\n return (\n <div className="flex flex-wrap gap-2">\n <Button variant="primary">Primary</Button>\n <Button variant="secondary">Secondary</Button>\n <Button variant="tertiary">Tertiary</Button>\n <Button variant="danger">Danger</Button>\n </div>\n );\n};',
navn: "default",
title: "title",
index: 1,
},
{
Expand All @@ -34,6 +35,7 @@ export const Designsystem: Story = {
innhold:
'import { Button } from "@navikt/ds-react";\n\nconst Example = () => {\n return (\n <div className="flex flex-wrap gap-2">\n <Button variant="primary-neutral">Primary</Button>\n <Button variant="secondary-neutral">Secondary</Button>\n <Button variant="tertiary-neutral">Tertiary</Button>\n </div>\n );\n};',
navn: "neutral",
title: "title",
index: 1,
},
{
Expand All @@ -42,6 +44,7 @@ export const Designsystem: Story = {
innhold:
'import { PencilIcon } from "@navikt/aksel-icons";\nimport { Button } from "@navikt/ds-react";\n\nconst Example = () => {\n return (\n <div className="flex flex-wrap gap-2">\n <Button size="small" variant="primary" icon={<PencilIcon aria-hidden />}>\n Primary\n </Button>\n <Button size="small" variant="secondary">\n Secondary\n </Button>\n <Button size="small" variant="tertiary">\n Tertiary\n </Button>\n <Button size="small" variant="danger">\n Danger\n </Button>\n </div>\n );\n};',
navn: "small",
title: "title",
index: 1,
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ const ComponentExamples = ({ node }: CodeExamplesProps) => {
iframeId
) as HTMLIFrameElement;
const exampleIframeDOM = exampleIframe?.contentDocument;
const exampleWrapper = exampleIframeDOM?.getElementById("ds-example");

let exampleWrapper: HTMLElement;

if (node.dir.variant === "templates") {
exampleWrapper = exampleIframeDOM?.getElementById("__next");
} else {
exampleWrapper = exampleIframeDOM?.getElementById("ds-example");
}

if (exampleWrapper && exampleWrapper.offsetHeight) {
const newHeight = iframePadding + exampleWrapper.offsetHeight;
clearInterval(waitForExampleContentToRender);
Expand Down Expand Up @@ -85,6 +93,7 @@ const ComponentExamples = ({ node }: CodeExamplesProps) => {
}

const active = activeExample ?? node?.dir?.filer?.[0]?.navn;
const demoVariant = node.dir?.variant;

return (
<div>
Expand All @@ -107,7 +116,7 @@ const ComponentExamples = ({ node }: CodeExamplesProps) => {
);
}}
>
{fixName(fil.navn)}
{fixName(fil.title)}
</Chips.Toggle>
);
})}
Expand Down Expand Up @@ -138,7 +147,7 @@ const ComponentExamples = ({ node }: CodeExamplesProps) => {
)}
>
<iframe
src={`/eksempler/${node.dir.title}/${fil.navn.replace(
src={`/${demoVariant}/${node.dir.title}/${fil.navn.replace(
".tsx",
""
)}`}
Expand All @@ -148,7 +157,10 @@ const ComponentExamples = ({ node }: CodeExamplesProps) => {
aria-label={`${node?.dir?.title} ${fil.navn} eksempel`}
className={cl(
"min-w-80 block w-full max-w-full resize-x bg-white shadow-[20px_0_20px_-20px_rgba(0,0,0,0.22)]",
{ invisible: unloaded }
{
invisible: unloaded,
"p-6": demoVariant === "templates",
}
)}
title="Kode-eksempler"
ref={iframeRef}
Expand Down Expand Up @@ -199,10 +211,9 @@ const ComponentExamples = ({ node }: CodeExamplesProps) => {
target="_blank"
className="si-ignore"
as="a"
href={`/eksempler/${node.dir.title}/${fil.navn.replace(
".tsx",
""
)}`}
href={`/${demoVariant}/${
node.dir.title
}/${fil.navn.replace(".tsx", "")}`}
/>
</HStack>
</HStack>
Expand Down
1 change: 1 addition & 0 deletions aksel.nav.no/website/public/robots.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Disallow: /*_ssgManifest.js$
Disallow: /*.js$

Disallow: /eksempler
Disallow: /templates
Disallow: /admin

Sitemap: https://aksel.nav.no/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const KodeEksempelDoc = defineType({
name: "fil",
type: "object",
fields: [
{ title: "Title", name: "title", type: "string" },
{ title: "Filnavn", name: "navn", type: "string" },
{ title: "Innhold", name: "innhold", type: "string" },
{ title: "Beskrivelse", name: "description", type: "text" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe("Testing getDirectories function", () => {
});

test("getDirectories should list directories in /pages/templates", () => {
const folders = getDirectories("eksempler");
const folders = getDirectories("templates");

expect(folders.length).toBeGreaterThan(0);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export function parseCodeFiles(

return {
innhold: code,
navn: args?.title ?? file.replace(".tsx", ""),
title: args?.title ?? file.replace(".tsx", ""),
navn: file.replace(".tsx", ""),
description: args?.desc,
index: args?.index ?? 1,
};
Expand Down
1 change: 1 addition & 0 deletions aksel.nav.no/website/scripts/update-examples/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export type FileArrayT = {
innhold: string;
title: string;
navn: string;
index: number;
description?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export async function updateSanity(
_type: "kode_eksempler_fil",
title: folder.path,
variant: directory,
filer: parseCodeFiles(folder.path, directory),
filer: parseCodeFiles(folder.path, directory).map((x) => ({
...x,
_key: x.navn.split(".")[0],
})),
metadata: extractMetadata(folder.path, directory),
};

Expand Down
1 change: 1 addition & 0 deletions aksel.nav.no/website/types/sanity-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ export type CodeExampleSchemaT = {
title: string;
variant: "eksempler" | "templates";
filer: {
title: string;
innhold: string;
navn: string;
index: number;
Expand Down

0 comments on commit 2a8533a

Please sign in to comment.