@@ -2,6 +2,7 @@ import { useEffect, useRef, useState } from 'react'
22
33const CDN_BASE = 'https://unpkg.com/@stoplight/elements@8.5.1'
44const API_URL = '/openapi.yaml'
5+ const MOBILE_QUERY = '(max-width: 1024px)'
56
67let scriptReady = false
78const readyCallbacks = [ ]
@@ -378,6 +379,43 @@ function buildStyles() {
378379 .dark .sl-elements .token.operator { color: #C9D1D9 !important; }
379380 .dark .sl-elements .token.keyword { color: #FF7B72 !important; }
380381 .dark .sl-elements .token.comment { color: #8B949E !important; }
382+
383+ /* ══════════════════════════════════════
384+ MOBILE LAYOUT
385+ Stoplight has a responsive layout mode;
386+ these overrides remove desktop-only sizing.
387+ ══════════════════════════════════════ */
388+ @media (max-width: 1024px) {
389+ :root {
390+ --api-gutter: 0px;
391+ --api-left-offset: 0px;
392+ }
393+
394+ #api-reference-root::before {
395+ display: none;
396+ }
397+
398+ #api-reference-root elements-api {
399+ margin-left: 0;
400+ width: 100%;
401+ }
402+
403+ .sl-elements aside.sl-flex {
404+ width: min(86vw, var(--vocs-sidebar_width, 300px)) !important;
405+ min-width: min(86vw, var(--vocs-sidebar_width, 300px)) !important;
406+ max-width: min(86vw, var(--vocs-sidebar_width, 300px)) !important;
407+ }
408+
409+ .sl-elements pre,
410+ .sl-elements code,
411+ .sl-elements .sl-bg-code,
412+ .sl-elements .sl-code-editor,
413+ .sl-elements [class*="sl-code-viewer"],
414+ .sl-elements [class*="CodeEditor"],
415+ .sl-elements [class*="JsonEditor"] {
416+ max-width: 100%;
417+ }
418+ }
381419 `
382420}
383421
@@ -463,8 +501,24 @@ function patchStoplightDOM(root) {
463501
464502export default function ApiReference ( ) {
465503 const [ loaded , setLoaded ] = useState ( scriptReady )
504+ const [ isMobile , setIsMobile ] = useState ( ( ) =>
505+ typeof window !== 'undefined' ? window . matchMedia ( MOBILE_QUERY ) . matches : false ,
506+ )
466507 const injected = useRef ( { link : null , style : null , topNav : null , observer : null } )
467508
509+ useEffect ( ( ) => {
510+ if ( typeof window === 'undefined' ) return
511+ const mediaQuery = window . matchMedia ( MOBILE_QUERY )
512+ const handleChange = ( event ) => setIsMobile ( event . matches )
513+ setIsMobile ( mediaQuery . matches )
514+ if ( typeof mediaQuery . addEventListener === 'function' ) {
515+ mediaQuery . addEventListener ( 'change' , handleChange )
516+ return ( ) => mediaQuery . removeEventListener ( 'change' , handleChange )
517+ }
518+ mediaQuery . addListener ( handleChange )
519+ return ( ) => mediaQuery . removeListener ( handleChange )
520+ } , [ ] )
521+
468522 useEffect ( ( ) => {
469523 const searchBtn = Array . from ( document . querySelectorAll ( 'button[type="button"]' ) ) . find ( ( btn ) =>
470524 btn . textContent . trim ( ) . startsWith ( 'Search' ) ,
@@ -589,7 +643,13 @@ export default function ApiReference() {
589643 return (
590644 < div id = "api-reference-root" >
591645 { loaded ? (
592- < elements-api apiDescriptionUrl = { API_URL } router = "hash" layout = "sidebar" />
646+ < elements-api
647+ key = { isMobile ? 'mobile' : 'desktop' }
648+ apiDescriptionUrl = { API_URL }
649+ router = "hash"
650+ layout = "responsive"
651+ hideTryItPanel = { isMobile ? 'true' : undefined }
652+ />
593653 ) : (
594654 < Loader />
595655 ) }
0 commit comments