From 50dedb3bf04a6b2ea609e4d9bb30528042a6b9bf Mon Sep 17 00:00:00 2001 From: louis-md Date: Tue, 14 May 2024 16:51:12 +0200 Subject: [PATCH] Clickable headings; various design fixes --- components/ApiReference/Parameter.tsx | 10 +--- components/ApiReference/Response.tsx | 9 +-- components/ApiReference/mainnet-swagger.json | 6 +- components/Hr.tsx | 4 +- lib/mdx.tsx | 60 +++++++++++++++----- 5 files changed, 60 insertions(+), 29 deletions(-) diff --git a/components/ApiReference/Parameter.tsx b/components/ApiReference/Parameter.tsx index 1149d509..6d7b34e0 100644 --- a/components/ApiReference/Parameter.tsx +++ b/components/ApiReference/Parameter.tsx @@ -1,6 +1,6 @@ -import Typography from '@mui/material/Typography' import Property from './Property' import Hr from '../Hr' +import { MdxHeading } from '../../lib/mdx' // eslint-disable-next-line @typescript-eslint/no-explicit-any const Parameters: React.FC<{ parameters: any[] }> = ({ parameters }) => { @@ -11,9 +11,7 @@ const Parameters: React.FC<{ parameters: any[] }> = ({ parameters }) => { <> {query.length > 0 && ( <> - - Query Parameters - + Query Parameters
)} @@ -29,9 +27,7 @@ const Parameters: React.FC<{ parameters: any[] }> = ({ parameters }) => { ))} {body.length > 0 && ( <> - - Request Body - + Request Body
)} diff --git a/components/ApiReference/Response.tsx b/components/ApiReference/Response.tsx index 13a09858..e3b68905 100644 --- a/components/ApiReference/Response.tsx +++ b/components/ApiReference/Response.tsx @@ -8,6 +8,7 @@ import ExpandMore from '@mui/icons-material/ExpandMore' import Property from './Property' import Hr from '../Hr' +import { MdxHeading } from '../../lib/mdx' // eslint-disable-next-line @typescript-eslint/no-explicit-any const Response: React.FC<{ response: any, index: number }> = ({ @@ -90,7 +91,9 @@ const Response: React.FC<{ response: any, index: number }> = ({ borderRadius: 1, border: 'none', mr: 1, - backgroundColor: isSuccess ? 'success.background' : 'error.background' + backgroundColor: isSuccess + ? 'success.background' + : 'error.background' }} /> @@ -136,9 +139,7 @@ const Response: React.FC<{ response: any, index: number }> = ({ const Responses: React.FC<{ responses: any[] }> = ({ responses }) => { return ( - - Responses - + Responses
{responses?.map?.((response, index) => ( diff --git a/components/ApiReference/mainnet-swagger.json b/components/ApiReference/mainnet-swagger.json index 6f79df8a..7e1681f4 100644 --- a/components/ApiReference/mainnet-swagger.json +++ b/components/ApiReference/mainnet-swagger.json @@ -1112,7 +1112,7 @@ ], "deprecated": false, "path": "/v1/safes/{address}/balances/", - "title": "List a Safe's Balances", + "title": "List a Safe's Balances (Deprecated)", "additionalInfo": "" }, "parameters": { @@ -3470,7 +3470,7 @@ "title": "Uuid", "type": "string", "format": "uuid", - "default": "0287b78d-96ed-4a9c-b80b-1965c1753dc9" + "default": "bb1a4b6f-98b1-4379-bdc6-dab2ce1fb87a" }, "safes": { "type": "array", @@ -3539,7 +3539,7 @@ "title": "Uuid", "type": "string", "format": "uuid", - "default": "8da0a387-58c9-4028-9c98-73857f3c5a3b" + "default": "92c9255f-1c80-42bf-80d9-a86a4ea1b1e1" }, "safes": { "type": "array", diff --git a/components/Hr.tsx b/components/Hr.tsx index d3db559d..f76a6662 100644 --- a/components/Hr.tsx +++ b/components/Hr.tsx @@ -1,9 +1,11 @@ +import { palette } from '../styles/palette' + // eslint-disable-next-line @typescript-eslint/no-explicit-any const Hr: React.FC<{ style?: any }> = props => (
string = text => - text?.replace?.(/ /g, '-').replace(/\//g, '-') + text?.replace(' #', '')?.replace?.(/ /g, '-').replace(/\//g, '-') export const getHeadingChildren: (heading: string) => Heading[] = heading => { const headingPath = '/v1/' + heading + '/' @@ -60,6 +61,7 @@ export const getHeadingsFromHtml: ( const headingText = heading .replace(/<[^>]*>/g, '') .replace(/ /g, ' ') + .replace(' #', '') .trim() const link = `#${slugify(headingText)}` return { @@ -73,22 +75,52 @@ export const getHeadingsFromHtml: ( return [] } +export const MdxHeading: React.FC<{ + headingLevel: number + children: ReactNode +}> = ({ headingLevel, children }) => ( + + {children as string}{' '} + {headingLevel > 1 && ( + + )} + +) + const getMarkdownHeaderComponent: ( headingLevel: number ) => React.FC<{ children: ReactNode }> = headingLevel => - ({ children }) => { - const HeadingComponent: React.FC = () => ( - - {children as string} - - ) - return HeadingComponent({}) - } + ({ children }) => + MdxHeading({ headingLevel, children }) export const useCurrentTocIndex: ( headings: Heading[], @@ -129,7 +161,7 @@ export const useCurrentTocIndex: ( setCurrentIndex( isNextHeadingInView ? nextHeading?.link ?? '' : active?.link ?? '' ) - } else setCurrentIndex('') + } else setCurrentIndex(_headings[0]?.children?.[0]?.link ?? '') }, [headings, navHeight]) const scrollListener = useMemo(