Skip to content
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

feat: Storybook story improvements #294

Merged
merged 13 commits into from
Feb 1, 2023
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { AuthenticationSubmitted } from '@w3ui/react'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

musing: perhaps we should make the naming consistent here so that we have ComponentName and ComponentNameStateName

Suggested change
import { AuthenticationSubmitted } from '@w3ui/react'
import { AuthenticatorSubmitted } from '@w3ui/react'

like

  • SpaceCreator -> SpaceCreatorCreating

or perhaps we should export a "view(s) only" component, that takes a state prop that we can set from a single story per Component, so our docs pages show all the things... tho that would force us to make a component that takes all the needed state and handlers for each of it's states, so perhaps the current pattern is better for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeaaaaa - I'm not totally happy with the naming/structure here either, but similarly uncertain on the best "API design" here - I'll leave it as it is, but am doing a pass getting ready for Adam to come in and do some design work and will keep this in mind as I do, thanks!

import '@w3ui/react/src/styles/authenticator.css'

export default {
title: 'w3ui/AuthenticationSubmitted',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe force this to appear in the same section, and change the export name like

Suggested change
title: 'w3ui/AuthenticationSubmitted',
title: 'w3ui/Authenticator', // force name to match so it appears in same section

then later in the file export it with a different name to distinguish it from the other one

export const Submitted = {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SICK, great idea, this is much nicer

component: AuthenticationSubmitted,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is neat!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh let's set it in the defaults rather than per story for now
https://storybook.js.org/docs/react/essentials/backgrounds#configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're noodling with defaults, no one wants to see times new roman lets set at least a nice default font via
https://storybook.js.org/docs/react/configure/story-rendering#adding-to-body

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so real. will do!

}
}
}

export const Primary = {
args: {
}
}
20 changes: 20 additions & 0 deletions examples/react/playground/src/stories/Authenticator.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Authenticator } from '@w3ui/react'
import '@w3ui/react/src/styles/authenticator.css'

export default {
title: 'w3ui/Authenticator',
component: Authenticator,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
}
}
}

export const Primary = {
args: {
}
}
20 changes: 20 additions & 0 deletions examples/react/playground/src/stories/SpaceCreator.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { SpaceCreator } from '@w3ui/react'
import '@w3ui/react/src/styles/space-creator.css'

export default {
title: 'w3ui/SpaceCreator',
component: SpaceCreator,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
}
}
}

export const Primary = {
args: {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { SpaceCreatorCreating } from '@w3ui/react'
import '@w3ui/react/src/styles/space-creator.css'

export default {
title: 'w3ui/SpaceCreatorCreating',
component: SpaceCreatorCreating,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
}
}
}

export const Primary = {
args: {
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, we can fix up the titles and exports to group states of the same logical components

Suggested change
export default {
title: 'w3ui/SpaceCreatorCreating',
component: SpaceCreatorCreating,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
}
}
}
export const Primary = {
args: {
}
}
export default {
title: 'w3ui/SpaceCreator',
component: SpaceCreatorCreating,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
}
}
}
export const Creating = {}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

32 changes: 32 additions & 0 deletions examples/react/playground/src/stories/SpaceFinder.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react'
import type { DID } from '@ucanto/interface'
import { SpaceFinder } from '@w3ui/react'
import { Space } from '@w3ui/keyring-core'
import '@w3ui/react/src/styles/space-finder.css'

export default {
title: 'w3ui/SpaceFinder',
component: SpaceFinder,
tags: ['autodocs'],
argTypes: {
setSelected: { action: 'set space' }
}
}

const spaces = ['did:example:abc123', 'did:example:xyz789', 'did:example:lmn456'].map(
(did: string, i) => new Space(did as DID, { name: `Space ${i}` })
)

export const Primary = {
args: {
spaces,
selected: spaces[0]
},
decorators: [
(Story) => (
<div style={{ margin: '3em' }}>
<Story />
</div>
)
]
}
38 changes: 0 additions & 38 deletions examples/react/playground/src/stories/SpaceList.stories.tsx

This file was deleted.

5 changes: 5 additions & 0 deletions examples/react/playground/src/stories/Uploader.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ export default {
component: Uploader,
tags: ['autodocs'],
argTypes: {
},
parameters: {
backgrounds: {
default: 'dark'
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ import { CID } from 'multiformats/cid'
// import * as raw from 'multiformats/codecs/raw'
import { UploadsList } from '@w3ui/react'
import { UploadsListContext } from '@w3ui/react-uploads-list'
import '@w3ui/react/src/styles/uploads-list.css'

// More on how to set up stories at: https://storybook.js.org/docs/7.0/react/writing-stories/introduction
export default {
title: 'w3ui/UploadsList',
component: UploadsList,
tags: ['autodocs']
tags: ['autodocs'],
parameters: {
backgrounds: {
default: 'dark'
}
}
}

// More on writing stories with args: https://storybook.js.org/docs/7.0/react/writing-stories/args
Expand Down
73 changes: 4 additions & 69 deletions examples/react/w3console/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import type { ChangeEvent } from 'react'
import type { Space } from '@w3ui/keyring-core'

import { useEffect, useState } from 'react'
import { Authenticator, Uploader, UploadsList, W3APIProvider, SpaceFinder } from '@w3ui/react'
import { Authenticator, Uploader, UploadsList, W3APIProvider, SpaceFinder, SpaceCreator } from '@w3ui/react'
import { useKeyring } from '@w3ui/react-keyring'
import { useUploadsList } from '@w3ui/react-uploads-list'
import { ArrowPathIcon, ShareIcon } from '@heroicons/react/20/solid'
import { ShareIcon } from '@heroicons/react/20/solid'
import md5 from 'blueimp-md5'
import '@w3ui/react/src/styles/uploader.css'
import '@w3ui/react/src/styles/space-finder.css'
import '@w3ui/react/src/styles/uploads-list.css'
import { SpaceShare } from './share'

function SpaceRegistrar (): JSX.Element {
Expand Down Expand Up @@ -110,73 +112,6 @@ function SpaceSection (): JSX.Element {
)
}

function SpaceCreator (props: any): JSX.Element {
const [, { createSpace, registerSpace }] = useKeyring()
const [creating, setCreating] = useState(false)
const [submitted, setSubmitted] = useState(false)
const [email, setEmail] = useState('')
const [name, setName] = useState('')

function resetForm (): void {
setEmail('')
setName('')
}

async function onSubmit (e: React.FormEvent<HTMLFormElement>): Promise<void> {
e.preventDefault()
setSubmitted(true)
try {
await createSpace(name)
// ignore this because the UI knows how to help the user recover
// from space registration failure
void registerSpace(email)
} catch (err) {
console.log(err)
throw new Error('failed to register', { cause: err })
} finally {
resetForm()
setSubmitted(false)
}
}
return (
<div {...props}>
{(creating)
? submitted
? (
<div className='flex flex-col items-center space-y-4'>
<h5>Creating Space...</h5>
<ArrowPathIcon className='animate-spin w-6' />
</div>
)
: (
<form
className='flex flex-col space-y-2'
onSubmit={(e: React.FormEvent<HTMLFormElement>) => { void onSubmit(e) }}
>
<input
className='text-black py-1 px-2 rounded'
type='email' placeholder='Email' autofocus
value={email}
onChange={(e: ChangeEvent<HTMLInputElement>) => { setEmail(e.target.value) }}
/>
<input
className='text-black py-1 px-2 rounded'
placeholder='Name'
value={name}
onChange={(e: ChangeEvent<HTMLInputElement>) => { setName(e.target.value) }}
/>
<input type='submit' className='w3ui-button' value='Create' />
</form>
)
: (
<button className='w3ui-button py-2' onClick={() => setCreating(true)}>
Add Space
</button>
)}
</div>
)
}

function SpaceSelector (props: any): JSX.Element {
const [{ space: currentSpace, spaces }, { setCurrentSpace }] = useKeyring()
async function selectSpace (space: Space): Promise<void> {
Expand Down
64 changes: 0 additions & 64 deletions examples/react/w3console/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,3 @@
@tailwind components;
@tailwind utilities;

:root {
--w3ui-uploader-primary: theme(colors.slate.800);
--w3ui-uploader-primary-hover: theme(colors.blue.900);
}

.w3-uploads-list {
@apply mb-5;
}

.w3-uploads-list-data {
@apply overflow-auto rounded-md border border-gray-300 dark:border-gray-700;
}

.w3-uploads-list table {
@apply w-full border-collapse divide-y dark:divide-gray-700;
}

.w3-uploads-list thead {
@apply text-left bg-opacity-50 text-xs tracking-wide text-zinc-300;
}

.w3-uploads-list th {
@apply p-3;
}

.w3-uploads-list td {
@apply block w-64 p-2 pl-3 font-mono text-xs;
}

.w3-uploads-list nav {
@apply flex flex-row space-x-4 my-4;
}

.w3ui-simple-authenticator-verify-email {
@apply bg-gray-400 dark:bg-gray-800 px-24 py-16 rounded-md;
}

.w3ui-simple-authenticator-verify-email .message {
@apply text-xl;
}

.w3ui-simple-authenticator-verify-email .detail {
@apply pt-2 pb-4;
}

.w3ui-simple-authenticator {
@apply w-full h-screen flex flex-col justify-center items-center;
}

.w3ui-simple-authenticator-form {
@apply bg-gray-400 dark:bg-gray-800 px-24 py-16 rounded-md;
}

.w3ui-simple-authenticator-form .email-field label {
@apply block mb-2;
}

.w3ui-simple-authenticator-form .email-field input {
@apply rounded block p-2 w-72 bg-gray-300 dark:bg-gray-900;
}

.w3ui-simple-authenticator-form .register {
@apply mt-2;
}
2 changes: 1 addition & 1 deletion examples/test/playwright/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"type": "module",
"scripts": {
"serve": "serve ../../",
"test": "playwright test",
"test": "playwright install && playwright test",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be reverted now #298 landed

"test:debug": "playwright test --project=chromium --headed"
},
"author": "olzilla",
Expand Down
10 changes: 5 additions & 5 deletions packages/react/src/Authenticator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export function AuthenticationForm (): JSX.Element {
const [{ submitted }] = useAuthenticator()

return (
<AuthCore.Form className='w3ui-simple-authenticator-form'>
<AuthCore.Form className='w3ui-authenticator-form'>
<div className='email-field'>
<label htmlFor='w3ui-simple-authenticator-email'>Email address:</label>
<AuthCore.EmailInput id='w3ui-simple-authenticator-email' required />
<label htmlFor='w3ui-authenticator-email'>Email address:</label>
<AuthCore.EmailInput id='w3ui-authenticator-email' required />
</div>
<button className='register w3ui-button' type='submit' disabled={submitted}>Register</button>
</AuthCore.Form>
Expand All @@ -19,7 +19,7 @@ export function AuthenticationSubmitted (): JSX.Element {
const [{ email }] = useAuthenticator()

return (
<div className='w3ui-simple-authenticator-verify-email'>
<div className='w3ui-authenticator-verify-email'>
<h1 className='message'>Verify your email address!</h1>
<p className='detail'>Click the link in the email we sent to {email} to sign in.</p>
<AuthCore.CancelButton className='cancel w3ui-button'>
Expand All @@ -43,7 +43,7 @@ export function AuthenticationEnsurer ({ children }: { children: JSX.Element | J

export function Authenticator ({ children }: { children: JSX.Element | JSX.Element[] }): JSX.Element {
return (
<AuthCore as='div' className='w3ui-simple-authenticator'>
<AuthCore as='div' className='w3ui-authenticator'>
<AuthenticationEnsurer>
{children}
</AuthenticationEnsurer>
Expand Down
Loading