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 updates #2068

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/website/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ module.exports = {
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'storybook-addon-next-router',
'@storybook/addon-a11y',
'@storybook/addon-interactions',
{
name: '@storybook/addon-postcss',
options: {
Expand All @@ -19,4 +22,7 @@ module.exports = {
},
},
],
features: {
interactionsDebugger: true, // 👈 Enable playback controls
},
}
4 changes: 4 additions & 0 deletions packages/website/.storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// .storybook/preview.js
import { RouterContext } from 'next/dist/shared/lib/router-context'
import '../styles/global.css'

export const parameters = {
actions: { argTypesRegex: '^on[A-Z].*' },
nextRouter: {
Provider: RouterContext.Provider,
},
}
10 changes: 10 additions & 0 deletions packages/website/.storybook/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const path = require('path')

module.exports = ({ config }) => {
config.resolve.modules = [
...(config.resolve.modules || []),
path.resolve(__dirname, '../'),
path.resolve(__dirname, '../src'),
]
return config
}
1,071 changes: 1,071 additions & 0 deletions packages/website/__snapshots__/storybook.test.js.snap

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions packages/website/components/button/button.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import Button from '.'

// eslint-disable-next-line import/no-anonymous-default-export
export default {
component: Button,
title: 'Button',
parameters: {
layout: 'centered',
controls: {
sort: 'requiredFirst',
},
},
argTypes: {
type: {
options: ['button', 'submit', 'reset'],
control: { type: 'select' },
table: {
disable: true,
},
},
children: {
control: 'text',
default: 'Button',
name: 'label',
},
variant: {
options: ['light', 'dark', 'tag', 'caution'],
control: { type: 'select' },
},
disabled: {
control: 'boolean',
},
small: {
control: 'boolean',
},
hologram: {
control: 'boolean',
default: true,
},
},
}

const Template = (
/** @type {{
* children: JSX.Element | string | 'Button';
* }} */
args
) => {
const label = args.children || 'Button'
return <Button {...args}>{label}</Button>
}

export const Default = Template.bind({})
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useCallback } from 'react'

import Link from './link'
import Link from '../link'
import clsx from 'clsx'
import countly from '../lib/countly'
import countly from 'lib/countly'

/**
* @typedef {Object} TrackingProp
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function Button({
'py-2 px-3',
variant !== 'tag' && hologram && 'hologram chicagoflf',
small && 'small',
disabled ? 'o-60' : 'interactive',
disabled ? 'opacity-60' : 'interactive',
variant
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/website/components/footer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback } from 'react'
import Link from './link'
import Link from '../components/link'
import Discord from '../icons/discord'
import Twitter from '../icons/twitter'
import Github from '../icons/github'
Expand Down
2 changes: 1 addition & 1 deletion packages/website/components/hero.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import countly from '../lib/countly'
import Button from './button.js'
import Button from './button/index.js'

export default function Hero() {
return (
Expand Down
2 changes: 1 addition & 1 deletion packages/website/components/layout.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Footer from './footer.js'
import Head from 'next/head'
import Loading from './loading'
import Navbar from './navbar.js'
import Navbar from './navbar/index.js'
import { getStatusPageSummary } from '../lib/statuspage-api'
import { getVersion } from '../lib/api'
import { useQuery } from 'react-query'
Expand Down
7 changes: 1 addition & 6 deletions packages/website/components/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ import Link from 'next/link'
*/
const WrappedLink = ({ tabIndex = 0, href = '', children, ...otherProps }) => (
<Link href={href} {...otherProps}>
<a
href="replace"
{...otherProps}
tabIndex={tabIndex}
onClick={otherProps.onClick}
>
<a {...otherProps} tabIndex={tabIndex} onClick={otherProps.onClick}>
{children}
</a>
</Link>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import Router, { useRouter } from 'next/router'
import { useCallback, useMemo, useRef, useState } from 'react'

import Button from './button.js'
import Cross from '../icons/cross'
import Hamburger from '../icons/hamburger'
import Link from './link'
import Button from '../button'
import Cross from '../../icons/cross'
import Hamburger from '../../icons/hamburger'
import Link from '../link'
import clsx from 'clsx'
import countly from '../lib/countly'
import { getMagic } from '../lib/magic.js'
import countly from 'lib/countly'
import { getMagic } from '../../lib/magic.js'
import { useQueryClient } from 'react-query'
import Logo from '../components/logo'
import Logo from '../logo'
import { useUser } from 'lib/user.js'

/**
Expand All @@ -26,7 +25,7 @@ export default function Navbar({ bgColor = 'bg-nsorange', logo, user }) {
const queryClient = useQueryClient()
const { handleClearUser } = useUser()
const [isMenuOpen, setMenuOpen] = useState(false)
const { query } = useRouter()
const { query } = useRouter() || { query: { version: '' } }
const version = /** @type {string} */ (query.version)

const logout = useCallback(async () => {
Expand Down
88 changes: 88 additions & 0 deletions packages/website/components/navbar/navbar.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import React from 'react'
import Navbar from '.'
import { QueryClient, QueryClientProvider } from 'react-query'
import { UserContext } from 'lib/user'

const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 60 * 1000 } },
})

// eslint-disable-next-line import/no-anonymous-default-export
export default {
component: Navbar,
title: 'Navbar',
parameters: {
// layout: 'centered',
},
argTypes: {
bgColor: {
options: [
'bg-orange',
'bg-forest',
'bg-yellow',
'bg-green',
'bg-peach',
'bg-ltblue',
],
defaultValue: 'bg-orange',
control: { type: 'select' },
},
// logo: {
// options: [
// '/images/logo-nft-storage-inline-dark.svg',
// '/images/logo-nft-storage-inline.svg',
// ],
// default: '/images/logo-nft-storage-inline.svg',
// control: { type: 'select' },
// },
dark: {
control: { type: 'boolean' },
defaultValue: false,
},
user: {
control: { type: 'boolean' },
},
},
}

const Template = (
/** @type {{
* bgColor: string;
* user: boolean;
* dark: boolean;
* }} */
args
) => {
const userMock = {
email: 'foo@bar.com',
isMfaEnabled: false,
issuer: 'did:ethr:0x6CA660ec2116Bd792AB7Cd5A10e1Eb8310F6f125',
phoneNumber: null,
publicAddress: '0x6CA660ec2116Bd792AB7Cd5A10e1Eb8310F6f125',
tags: {
HasAccountRestriction: false,
HasPsaAccess: false,
HasSuperHotAccess: false,
},
}

function handleClearUser() {
console.info('clear user fake')
}

return (
<QueryClientProvider client={queryClient}>
<UserContext.Provider
value={{ user: args.user ? userMock : null, handleClearUser }}
>
<Navbar
logo={{ src: '', isDark: args.dark }}
bgColor={args.bgColor}
user={args.user ? userMock : null}
/>
</UserContext.Provider>
</QueryClientProvider>
)
}

export const Default = Template.bind({})
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import Tooltip from './tooltip'

import Tooltip from '.'
import { within, userEvent, screen } from '@storybook/testing-library'
import { expect } from '@storybook/jest'
// eslint-disable-next-line import/no-anonymous-default-export
export default {
component: Tooltip,
Expand Down Expand Up @@ -49,3 +50,15 @@ const Template = (
)

export const Default = Template.bind({})
export const Active = Template.bind({})

// @ts-ignore
Active.play = async ({ canvasElement }) => {
// Starts querying the component from its root element
const canvas = await within(canvasElement).findByRole('button')
// See https://storybook.js.org/docs/react/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.hover(canvas)

// 👇 Assert DOM structure
expect(screen.getByText('Some Tooltip Content')).toBeInTheDocument()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Img from '../components/cloudflareImage'
import Img from '../cloudflareImage'

/**
* Logo Component
Expand Down Expand Up @@ -26,9 +26,9 @@ export const TrustedBy = ({ logos }) => {
<div className="max-w-4xl mx-auto py-8 px-6 sm:px-16">
<h2 className="text-center mt-0 chicagoflf">Trusted by</h2>
<div className="grid grid-cols-2 sm:grid-cols-[repeat(auto-fit,_minmax(150px,_1fr))] gap-4 p-5 justify-center mx-auto">
{logos.map((logo) => (
{logos.map((logo, index) => (
<Logo
key={`marketplace-logo-${logo.src}`}
key={`marketplace-logo-${index}`}
src={logo.src}
alt={logo.alt}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react'
import { TrustedBy } from './trustedByLogos'
import { TrustedBy } from '.'

// eslint-disable-next-line import/no-anonymous-default-export
export default {
Expand Down
2 changes: 1 addition & 1 deletion packages/website/lib/__tests__/statsUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ describe('Stats Utils unit tests', () => {
const stats = calculateStats(infinityData.data)

// passing in 0/0 should return 0, not infinity
expect(stats.growthRate).toBe(0)
expect(stats.growthRate).toBe('0')
})
})
17 changes: 13 additions & 4 deletions packages/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
"build": "yarn workspace nft.storage prepare && next build && next-sitemap && next export",
"start": "next start",
"test": "eslint './**/*.js' && tsc --build",
"test:jest": "jest",
"test:jest": "npx jest --watch",
"test:e2e": "npx playwright test",
"test:ci": "jest --runInBand --maxWorkers=4",
"lint:fix": "eslint './**/*.js' --fix-dry-run",
"analyze": "ANALYZE=true next build",
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook"
"build-storybook": "build-storybook",
"test-storybook": "test-storybook"
},
"dependencies": {
"@magic-ext/oauth": "^0.11.2",
Expand Down Expand Up @@ -48,13 +49,17 @@
"@next/bundle-analyzer": "^12.0.7",
"@playwright/test": "^1.20.1",
"@sentry/nextjs": "^6.17.7",
"@storybook/addon-a11y": "^6.5.9",
"@storybook/addon-actions": "^6.5.0-alpha.64",
"@storybook/addon-essentials": "^6.5.0-alpha.64",
"@storybook/addon-interactions": "^6.5.0-alpha.64",
"@storybook/addon-interactions": "^6.5.9",
"@storybook/addon-links": "^6.5.0-alpha.64",
"@storybook/addon-postcss": "^2.0.0",
"@storybook/addon-storyshots": "^6.5.9",
"@storybook/jest": "^0.0.10",
"@storybook/react": "^6.5.0-alpha.64",
"@storybook/testing-library": "^0.0.10--canary.9d5661e.0",
"@storybook/test-runner": "^0.3.0",
"@storybook/testing-library": "^0.0.13",
"@tailwindcss/line-clamp": "^0.3.1",
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.3",
Expand All @@ -71,6 +76,9 @@
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"git-rev-sync": "^3.0.1",
"jest": "27",
"jest-environment-jsdom": "^28.1.2",
"jest-playwright-preset": "^1.7.2",
"jscodeshift": "^0.13.1",
"next": "^12.0.7",
"next-sitemap": "^1.6.203",
Expand All @@ -80,6 +88,7 @@
"postcss-loader": "^6.2.1",
"postcss-preset-env": "^7.3.3",
"sass-loader": "^12.6.0",
"storybook-addon-next-router": "^3.1.1",
"style-loader": "^3.3.1",
"typescript": "4.4.4"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/website/pages/blog/subscribe.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEffect, useState } from 'react'
import Button from '../../components/button.js'
import Button from '../../components/button/index.js'
import countly from '../../lib/countly.js'
import { subscribe } from '../../lib/subscribe.js'
import { useRouter } from 'next/router'
Expand Down
Loading