-
Notifications
You must be signed in to change notification settings - Fork 1
feat: mobile responsive layout for default theme #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,9 @@ import { | |
| CodeBracketSquareIcon, | ||
| RectangleStackIcon, | ||
| DocumentTextIcon, | ||
| Squares2X2Icon | ||
| Squares2X2Icon, | ||
| Bars3Icon, | ||
| XMarkIcon | ||
| } from '@heroicons/react/24/outline'; | ||
| import { Flex, IconButton, Button, Sidebar } from '@raystack/apsara'; | ||
| import { PlayIcon } from '@radix-ui/react-icons'; | ||
|
|
@@ -70,6 +72,7 @@ export function Layout({ | |
| const navigate = useNavigate(); | ||
| const { page, version } = usePageContext(); | ||
| const scrollRef = useRef<HTMLDivElement>(null); | ||
| const [mobileSidebarOpen, setMobileSidebarOpen] = useState(false); | ||
| const isApiRoute = pathname === '/apis' || pathname.startsWith('/apis/'); | ||
| const isApiBase = (basePath: string) => | ||
| pathname === basePath || pathname.startsWith(`${basePath}/`); | ||
|
|
@@ -106,10 +109,72 @@ export function Layout({ | |
| requestAnimationFrame(() => { | ||
| el.scrollTop = savedScrollTop; | ||
| }); | ||
| setMobileSidebarOpen(false); | ||
| }, [pathname]); | ||
|
|
||
| return ( | ||
| <Flex direction='column' className={cx(styles.layout, classNames?.layout)}> | ||
| <div className={styles.mobileHeader}> | ||
| <SidebarLogo config={config} /> | ||
| <Flex align='center' gap={3}> | ||
| {config.search?.enabled && <Search />} | ||
| <ClientThemeSwitcher size={16} /> | ||
| <button | ||
| className={styles.mobileMenuBtn} | ||
| onClick={() => setMobileSidebarOpen(o => !o)} | ||
| aria-label={mobileSidebarOpen ? 'Close menu' : 'Open menu'} | ||
| > | ||
| {mobileSidebarOpen | ||
| ? <XMarkIcon width={16} height={16} /> | ||
| : <Bars3Icon width={16} height={16} />} | ||
| </button> | ||
| </Flex> | ||
| </div> | ||
| <div className={styles.mobileMenu} data-open={mobileSidebarOpen}> | ||
|
Comment on lines
+122
to
+133
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add explicit menu-toggle semantics and prevent implicit form submit. Please add Suggested patch- <button
+ <button
+ type='button'
className={styles.mobileMenuBtn}
onClick={() => setMobileSidebarOpen(o => !o)}
aria-label={mobileSidebarOpen ? 'Close menu' : 'Open menu'}
+ aria-expanded={mobileSidebarOpen}
+ aria-controls='mobile-navigation'
>
@@
- <div className={styles.mobileMenu} data-open={mobileSidebarOpen}>
+ <div id='mobile-navigation' className={styles.mobileMenu} data-open={mobileSidebarOpen}>🤖 Prompt for AI Agents |
||
| {showTopLinks ? ( | ||
| <div className={styles.topLinks}> | ||
| {contentEntries.map(entry => ( | ||
| <Sidebar.Item | ||
| key={entry.href} | ||
| href={entry.href} | ||
| active={activeContentDir === entry.contentDir} | ||
| leadingIcon={renderConfigIcon(entry.icon, entry.label, <DocumentTextIcon width={16} height={16} />)} | ||
| classNames={{ root: styles.topLinkItem, text: styles.topLinkText }} | ||
| render={<RouterLink to={entry.href} />} | ||
| > | ||
| {entry.label} | ||
| </Sidebar.Item> | ||
| ))} | ||
| {apiEntries.map(api => ( | ||
| <Sidebar.Item | ||
| key={`${api.basePath}-${api.name}`} | ||
| href={api.basePath} | ||
| active={isApiBase(api.basePath)} | ||
| leadingIcon={renderConfigIcon(api.icon, api.name, <CodeBracketSquareIcon width={16} height={16} />)} | ||
| classNames={{ root: styles.topLinkItem, text: styles.topLinkText }} | ||
| render={<RouterLink to={api.basePath} />} | ||
| > | ||
| {api.name} API | ||
| </Sidebar.Item> | ||
| ))} | ||
| </div> | ||
| ) : null} | ||
| {tree.children.map((item, i) => ( | ||
| isApiRoute ? ( | ||
| <ApiSidebarNode | ||
| key={item.type === 'page' ? item.url : (item.name?.toString() ?? i)} | ||
| item={item} | ||
| pathname={pathname} | ||
| /> | ||
| ) : ( | ||
| <SidebarNode | ||
| key={item.type === 'page' ? item.url : (item.name?.toString() ?? i)} | ||
| item={item} | ||
| pathname={pathname} | ||
| /> | ||
| ) | ||
| ))} | ||
| </div> | ||
| <Flex className={cx(styles.body, classNames?.body)}> | ||
| {hideSidebar ? null : ( | ||
| <Sidebar | ||
|
|
@@ -218,6 +283,20 @@ export function Layout({ | |
| <main className={cx(styles.content, classNames?.content)}> | ||
| {children} | ||
| </main> | ||
| <div className={styles.mobileNav}> | ||
| {prev ? ( | ||
| <RouterLink to={prev.url} className={styles.mobileNavLink}> | ||
| <ArrowLeftIcon width={16} height={16} /> | ||
| <span className={styles.mobileNavLabel}>{prev.title}</span> | ||
| </RouterLink> | ||
| ) : <div />} | ||
| {next ? ( | ||
| <RouterLink to={next.url} className={styles.mobileNavLink} data-direction='next'> | ||
| <span className={styles.mobileNavLabel}>{next.title}</span> | ||
| <ArrowRightIcon width={16} height={16} /> | ||
| </RouterLink> | ||
| ) : <div />} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </Flex> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.