Skip to content

Commit

Permalink
feat: get w3console looking acceptable on mobile (#500)
Browse files Browse the repository at this point in the history
Plenty of polish we could still do, but this takes care of the most
egregious problems on smaller screens:


https://user-images.githubusercontent.com/1113/230239853-c93deef4-f8fd-426c-8002-1a8ff192cd5c.mov

We're using HeadlessUI's Dialog and Transition components to make the
small-screen sidebar feel nice.
  • Loading branch information
Travis Vachon authored Apr 6, 2023
1 parent 56eddef commit 118cb22
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 38 deletions.
4 changes: 2 additions & 2 deletions examples/react/w3console/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"preview": "vite preview"
},
"dependencies": {
"@headlessui/react": "^1.7.7",
"@heroicons/react": "^2.0.13",
"@headlessui/react": "^1.7.13",
"@heroicons/react": "^2.0.17",
"@ipld/car": "^5.1.0",
"@ipld/dag-ucan": "^3.2.0",
"@w3ui/keyring-core": "workspace:^",
Expand Down
100 changes: 80 additions & 20 deletions examples/react/w3console/src/components/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,90 @@
import { tosUrl, Logo } from '../brand'
import { Logo } from '../brand'
import { Fragment, useState } from 'react'
import { Dialog, Transition } from '@headlessui/react'
import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline'

interface LayoutComponentProps {
const navLinks = [
{ name: 'Terms', href: '/terms' },
{ name: 'Docs', href: '/docs' },
{ name: 'Support', href: 'https://github.com/web3-storage/w3ui/issues' },
]

interface SidebarComponentProps {
sidebar?: JSX.Element | JSX.Element[]
}

function Sidebar ({ sidebar = <div></div> }: SidebarComponentProps): JSX.Element {
return (
<nav className='flex-none w-64 bg-gray-900 text-white px-4 pb-4 border-r border-gray-800 h-screen'>
<div className='flex flex-col justify-between h-full'>
{sidebar}
<div className='flex flex-col items-center'>
<a href='/'><Logo className='w-36 mb-2' /></a>
<div className='flex flex-row space-x-2'>
{navLinks.map(link => (
<a className='text-xs block text-center mt-2' href={link.href}>{link.name}</a>
))}
</div>
</div>
</div>
</nav>
)
}

interface LayoutComponentProps extends SidebarComponentProps {
children: JSX.Element | JSX.Element[]
}
type LayoutComponent = (props: LayoutComponentProps) => JSX.Element

export const DefaultLayout: LayoutComponent = ({ sidebar = <div></div>, children }) => {
export function DefaultLayout ({ sidebar = <div></div>, children }: LayoutComponentProps): JSX.Element {
const [sidebarOpen, setSidebarOpen] = useState(false)

return (
<div className='flex min-h-full w-full'>
<nav className='flex-none w-64 bg-gray-900 text-white px-4 pb-4 border-r border-gray-800 h-screen'>
<div className='flex flex-col justify-between h-full'>
{sidebar}
<div className='flex flex-col items-center'>
<a href='/'><Logo className='w-36 mb-2' /></a>
<div className='flex flex-row space-x-2'>
<a className='text-xs block text-center mt-2' href='/terms'>Terms</a>
<a className='text-xs block text-center mt-2' href='/docs'>Docs</a>
<a className='text-xs block text-center mt-2' href='https://github.com/web3-storage/w3ui/issues'>Support</a>
</div>
<div className='flex min-h-full w-full text-white'>
{/* dialog sidebar for narrow browsers */}
<Transition.Root show={sidebarOpen} >
<Dialog onClose={() => setSidebarOpen(false)} as='div' className='relative z-50'>
<Transition.Child
as={Fragment}
enter="transition-opacity duration-200"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="transition-opacity duration-400"
leaveFrom="opacity-100"
leaveTo="opacity-0">
<div className="fixed inset-0 bg-black/70" aria-hidden="true" />
</Transition.Child>
<div className="fixed inset-0 flex justify-left">
<Transition.Child
as={Fragment}
enter="transition duration-200"
enterFrom="-translate-x-full"
enterTo="translate-x-0"
leave="transition duration-400"
leaveFrom="translate-x-0"
leaveTo="-translate-x-full">
<Dialog.Panel>
<XMarkIcon className='text-white w-6 h-6 fixed top-2 -right-8' onClick={() => setSidebarOpen(false)} />
<Sidebar sidebar={sidebar} />
</Dialog.Panel>
</Transition.Child>
</div>
</Dialog>
</Transition.Root>

{/* static sidebar for wide browsers */}
<div className='hidden lg:block'>
<Sidebar sidebar={sidebar} />
</div>
<div className='w-full h-screen overflow-scroll'>
{/* top nav bar for narrow browsers, mainly to have a place to put the hamburger */}
<div className='lg:hidden flex justify-between pt-4 px-4'>
<Bars3Icon className='w-6 h-6' onClick={() => setSidebarOpen(true)} />
<a href='/'><Logo className='w-36 mb-2' /></a>
</div>
</nav>
<main className='grow bg-gray-dark text-white p-4 h-screen overflow-scroll'>
{children}
</main>
<main className='grow bg-gray-dark text-white p-4'>
{children}
</main>
</div>
</div>
)
}
}
14 changes: 7 additions & 7 deletions examples/react/w3console/src/components/Uploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ export const Uploading = ({
file?: File
storedDAGShards?: CARMetadata[]
}): JSX.Element => (
<div className='flex flex-col items-center'>
<div className='flex flex-col items-center w-full'>
<h1 className='font-bold text-sm uppercase text-gray-400'>Uploading {file?.name}</h1>
{storedDAGShards?.map(({ cid, size }) => (
<p className='text-xs' key={cid.toString()}>
<p className='text-xs max-w-full overflow-hidden text-ellipsis' key={cid.toString()}>
shard {cid.toString()} ({humanFileSize(size)}) uploaded
</p>
))}
Expand All @@ -46,10 +46,10 @@ export const Done = ({ dataCID }: DoneProps): JSX.Element => {
const [, { setFile }] = useUploaderComponent()
const cid: string = dataCID?.toString() ?? ''
return (
<div className='flex flex-col items-center'>
<h1 className='font-bold text-sm uppercase text-gray-400 mb-1'>Uploaded</h1>
<div className='flex flex-col items-center w-full'>
<h1 className='font-bold text-sm uppercase text-gray-400 mb-1 '>Uploaded</h1>
<a
className='font-mono text-xs'
className='font-mono text-xs max-w-full overflow-hidden no-wrap text-ellipsis'
href={`https://${cid}.ipfs.${gatewayHost}/`}
>
{cid}
Expand Down Expand Up @@ -136,9 +136,9 @@ const UploaderContents = (): JSX.Element => {
: <></>
} else {
return (
<div>
<>
<UploaderConsole />
</div>
</>
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions examples/react/w3console/src/components/UploadsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Uploads ({ uploads, loading }: UploadsProps): JSX.Element {
: (
<>
<div className='rounded-md border border-zinc-300'>
<table className='border-collapse w-full divide-y divide-zinc-300'>
<table className='border-collapse table-fixed w-full divide-y divide-zinc-300'>
<thead className='text-left text-sm text-zinc-300'>
<tr>
<th className="p-3">Root CID</th>
Expand All @@ -33,7 +33,7 @@ function Uploads ({ uploads, loading }: UploadsProps): JSX.Element {
<tbody>
{uploads.map(({ root }) => (
<tr key={root.toString()}>
<td className="w-64 p-2 pl-3 font-mono text-sm">
<td className="p-2 pl-3 font-mono text-sm overflow-hidden no-wrap text-ellipsis">
<a href={`https://${root.toString()}.ipfs.${gatewayHost}/`}>
{root.toString()}
</a>
Expand Down
6 changes: 3 additions & 3 deletions examples/react/w3console/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ function SpaceSection (props: SpaceSectionProps): JSX.Element {
)}?d=identicon`}
className='w-10 hover:saturate-200 saturate-0 invert border-solid border-gray-500 border'
/>
<div className='grow'>
<h1 className='text-xl font-semibold leading-5'>
<div className='grow overflow-hidden whitespace-nowrap text-ellipsis text-gray-500'>
<h1 className='text-xl font-semibold leading-5 text-white'>
{space.name() ?? 'Untitled'}
</h1>
<label className='font-mono text-xs text-gray-500'>
<label className='font-mono text-xs'>
{space.did()}
</label>
</div>
Expand Down
24 changes: 20 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 118cb22

Please # to comment.