From e9aaa40e17f6246d45d094d91b7af649ecf2e32e Mon Sep 17 00:00:00 2001 From: Tobias Barsnes Date: Thu, 28 Nov 2024 11:52:37 +0100 Subject: [PATCH] chore: storefront fixes (#2844) This PR ports over changes and fixes from #2830 resolves #2840 resolves #2816 New codeblock styling is approved by @Thunear --- .../src/ClipboardButton/ClipboardButton.tsx | 2 +- .../src/CodeSnippet/CodeSnippet.module.css | 11 +++- .../src/CodeSnippet/CodeSnippet.tsx | 18 +++--- apps/_components/src/Footer/Footer.tsx | 9 ++- apps/_components/src/Header/Header.tsx | 4 +- apps/_components/src/logos/Udir.tsx | 2 +- .../_components/PostLayout/PostLayout.tsx | 2 +- .../designelementer/farger/page.mdx | 2 +- .../for-utviklere/komposisjon/page.mdx | 37 +++++------- apps/storefront/app/komponenter/page.tsx | 2 +- .../app/monstre/feilmeldinger/page.mdx | 58 +++++++++---------- .../MdxContent/MdxContent.module.css | 1 + .../components/SidebarMenu/SidebarMenu.tsx | 2 +- .../components/Tokens/TokenList/TokenList.tsx | 29 ++++++++-- .../layouts/MenuPageLayout/MenuPageLayout.tsx | 2 +- apps/storefront/tsconfig.json | 1 + .../components/TokenModal/TokenModal.tsx | 2 +- 17 files changed, 105 insertions(+), 79 deletions(-) diff --git a/apps/_components/src/ClipboardButton/ClipboardButton.tsx b/apps/_components/src/ClipboardButton/ClipboardButton.tsx index d21df7faa1..0f7545317e 100644 --- a/apps/_components/src/ClipboardButton/ClipboardButton.tsx +++ b/apps/_components/src/ClipboardButton/ClipboardButton.tsx @@ -34,7 +34,7 @@ export const ClipboardButton = ({ title={title} icon={!text} variant='tertiary' - color='neutral' + data-color='neutral' data-size='sm' > diff --git a/apps/_components/src/CodeSnippet/CodeSnippet.module.css b/apps/_components/src/CodeSnippet/CodeSnippet.module.css index 40776471c0..ddbcf60327 100644 --- a/apps/_components/src/CodeSnippet/CodeSnippet.module.css +++ b/apps/_components/src/CodeSnippet/CodeSnippet.module.css @@ -8,7 +8,16 @@ } .codeSnippet > pre { - padding-right: var(--ds-spacing-11) !important; + padding-right: var(--ds-spacing-18) !important; + background-color: var(--ds-color-neutral-background-subtle) !important; +} + +.codeSnippet > pre > code { + padding: 0; +} + +.codeSnippet > pre > code span:empty { + display: none; } .copyButton { diff --git a/apps/_components/src/CodeSnippet/CodeSnippet.tsx b/apps/_components/src/CodeSnippet/CodeSnippet.tsx index c63de3aff0..bf00ef571e 100644 --- a/apps/_components/src/CodeSnippet/CodeSnippet.tsx +++ b/apps/_components/src/CodeSnippet/CodeSnippet.tsx @@ -10,8 +10,8 @@ import * as prettierCSS from 'prettier/plugins/postcss.js'; import * as prettierTypescript from 'prettier/plugins/typescript.js'; import { format } from 'prettier/standalone.js'; import { useEffect, useState } from 'react'; -import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; -import { nightOwl } from 'react-syntax-highlighter/dist/esm/styles/prism'; +import SyntaxHighlighter from 'react-syntax-highlighter'; +import { stackoverflowDark } from 'react-syntax-highlighter/dist/esm/styles/hljs'; import classes from './CodeSnippet.module.css'; @@ -27,15 +27,13 @@ const plugins = [ ]; type CodeSnippetProps = { - language?: 'css' | 'html' | 'ts' | 'markdown' | 'json'; - syntax?: string; + language?: 'css' | 'html' | 'ts' | 'markdown' | 'json' | 'shell' | 'tsx'; children: string; } & React.HTMLAttributes; const CodeSnippet = ({ language = 'markdown', className, - syntax = 'js', children, ...rest }: CodeSnippetProps) => { @@ -49,7 +47,8 @@ const CodeSnippet = ({ ) { try { const formatted = await format(children, { - parser: language === 'ts' ? 'babel-ts' : language, + parser: + language === 'ts' || language === 'tsx' ? 'babel-ts' : language, plugins, }); setSnippet(formatted); @@ -76,6 +75,7 @@ const CodeSnippet = ({
{snippet && ( @@ -87,15 +87,15 @@ const CodeSnippet = ({ className={classes.copyButton} aria-label='Kopier' icon - color='neutral' + data-color='neutral' data-size='sm' > {
    {links.map((item, index) => (
  • - + {item.prefix} {item.text} @@ -64,7 +64,12 @@ export const Footer = forwardRef(function Footer(
-