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(onboarding): Dark mode #21149

Closed
wants to merge 11 commits into from
11 changes: 9 additions & 2 deletions .storybook/decorators/withTheme.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
import type { Decorator } from '@storybook/react'
import { useActions } from 'kea'
import { useEffect } from 'react'
import { userLogic } from 'scenes/userLogic'

/** Global story decorator that is used by the theming control to
* switch between themes.
*/
export const withTheme: Decorator = (Story, context) => {
const theme = context.globals.theme

// set the theme
document.body.setAttribute('theme', theme === 'dark' ? 'dark' : 'light')
const { __testOnlyOverrideThemeFromCookie } = useActions(userLogic)

useEffect(() => {
document.body.setAttribute('theme', theme)
__testOnlyOverrideThemeFromCookie(theme)
}, [theme])

return <Story />
}
27 changes: 14 additions & 13 deletions .storybook/test-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { getStoryContext, TestRunnerConfig, TestContext, waitForPageReady } from
import type { Locator, Page, LocatorScreenshotOptions } from '@playwright/test'
import type { Mocks } from '~/mocks/utils'
import { StoryContext } from '@storybook/csf'
import { UserTheme } from '~/types'

// 'firefox' is technically supported too, but as of June 2023 it has memory usage issues that make is unusable
type SupportedBrowserName = 'chromium' | 'webkit'
type SnapshotTheme = 'light' | 'dark'

// Extend Storybook interface `Parameters` with Chromatic parameters
declare module '@storybook/types' {
Expand Down Expand Up @@ -44,7 +44,7 @@ declare module '@storybook/types' {
}

interface Globals {
theme: SnapshotTheme
theme: UserTheme
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ async function expectStoryToMatchSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme,
theme: UserTheme,
targetSelector?: string
) => Promise<void>
if (storyContext.parameters?.layout === 'fullscreen') {
Expand All @@ -129,7 +129,8 @@ async function expectStoryToMatchSnapshot(
check = expectStoryToMatchComponentSnapshot
}

await waitForPageReady(page)
await waitForPageReady(page)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await waitForPageReady(page)
await waitForPageReady(page)


await page.evaluate((layout: string) => {
// Stop all animations for consistent snapshots, and adjust other styles
document.body.classList.add('storybook-test-runner')
Expand All @@ -152,26 +153,26 @@ async function expectStoryToMatchSnapshot(
Array.from(document.querySelectorAll('img')).every((i: HTMLImageElement) => i.complete)
)

// snapshot light theme
// Light theme snapshot
await page.evaluate(() => {
document.body.setAttribute('theme', 'light')
window.__testOnlyOverrideThemeFromCookie('light')
})

await check(page, context, browser, 'light', storyContext.parameters?.testOptions?.snapshotTargetSelector)

// snapshot dark theme
await page.evaluate(() => {
// Dark theme snapshot
await page.evaluate(() => {
document.body.setAttribute('theme', 'dark')
window.__testOnlyOverrideThemeFromCookie('dark')
})

await check(page, context, browser, 'dark', storyContext.parameters?.testOptions?.snapshotTargetSelector)
}

async function expectStoryToMatchViewportSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme
theme: UserTheme
): Promise<void> {
await expectLocatorToMatchStorySnapshot(page, context, browser, theme)
}
Expand All @@ -180,7 +181,7 @@ async function expectStoryToMatchSceneSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme
theme: UserTheme
): Promise<void> {
// If the `main` element isn't present, let's use `body` - this is needed in logged-out screens.
// We use .last(), because the order of selector matches is based on the order of elements in the DOM,
Expand All @@ -192,7 +193,7 @@ async function expectStoryToMatchComponentSnapshot(
page: Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme,
theme: UserTheme,
targetSelector: string = '#storybook-root'
): Promise<void> {
await page.evaluate(() => {
Expand Down Expand Up @@ -228,7 +229,7 @@ async function expectLocatorToMatchStorySnapshot(
locator: Locator | Page,
context: TestContext,
browser: SupportedBrowserName,
theme: SnapshotTheme,
theme: UserTheme,
options?: LocatorScreenshotOptions
): Promise<void> {
const image = await locator.screenshot({ ...options })
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Copy link
Contributor

Choose a reason for hiding this comment

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

added snapshot is somehow slightly cut off vertically?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/lemon-ui-code-snippet--java-script--dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified frontend/__snapshots__/scenes-other-login--cloud--dark.png
Binary file modified frontend/__snapshots__/scenes-other-login--cloud-eu--dark.png
Copy link
Contributor

Choose a reason for hiding this comment

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

PostHog Cloud logo needs a dark mode version

Binary file modified frontend/__snapshots__/scenes-other-login--sso-error--dark.png
Binary file modified frontend/__snapshots__/scenes-other-signup--cloud--dark.png
Binary file modified frontend/__snapshots__/scenes-other-signup--cloud--light.png
32 changes: 32 additions & 0 deletions frontend/public/posthog-logo-cloud-dark.svg
1 change: 1 addition & 0 deletions frontend/public/posthog-logo-dark.svg
Loading
Loading