-
Notifications
You must be signed in to change notification settings - Fork 23
chore(EmptyButton): migrate to CSS Modules with visual regression baseline #1105
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
Open
DreaminDani
wants to merge
4
commits into
main
Choose a base branch
from
chore/migrate-emptybutton-css-modules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
07ffa8e
test(EmptyButton): add visual regression baseline before CSS Modules …
DreaminDani 443f9a6
chore(EmptyButton): migrate styling from styled-components to CSS Mod…
DreaminDani 8f45099
fix(EmptyButton): scope :disabled with :where() so consumer overrides…
DreaminDani 90092ad
test(EmptyButton): add visual regression guards for as-prop consumers
DreaminDani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@clickhouse/click-ui': patch | ||
| --- | ||
|
|
||
| Migrate EmptyButton from styled-components to css modules with no change in behavior |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* Kept at zero specificity via :where() so that downstream styled-components | ||
| overrides on a styled(EmptyButton) (e.g. CrossButton overriding background and | ||
| padding, the Popover/CodeBlock close/copy buttons overriding color and padding) | ||
| win without needing a specificity hack — EmptyButton is a CSS Module, whose | ||
| rules otherwise beat equal-specificity styled-components by source order. */ | ||
| :where(.empty-button) { | ||
| padding: 0; | ||
| border: 0; | ||
| background: transparent; | ||
| color: inherit; | ||
| font: inherit; | ||
| outline: none; | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| /* Also scoped with :where() so the disabled cursor stays at zero specificity | ||
| and a downstream styled(EmptyButton) `&:disabled` override wins naturally, | ||
| rather than tying on specificity and losing to the CSS Module by source order. */ | ||
| :where(.empty-button):disabled { | ||
| cursor: not-allowed; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import { Meta, StoryObj } from '@storybook/react-vite'; | ||
| import { EmptyButton } from '@/components/EmptyButton'; | ||
|
|
||
| const meta: Meta<typeof EmptyButton> = { | ||
| component: EmptyButton, | ||
| title: 'Buttons/EmptyButton', | ||
| tags: ['emptybutton', 'autodocs'], | ||
| // EmptyButton resets to a transparent, padding-less button that inherits its | ||
| // parent's color and font. The decorator gives it a contrasting parent with a | ||
| // distinct color and font so the inheritance is visible and measurable in the | ||
| // snapshot. | ||
| decorators: [ | ||
| Story => ( | ||
| <div | ||
| data-testid="emptybutton-harness" | ||
| style={{ | ||
| display: 'inline-flex', | ||
| padding: '24px', | ||
| color: '#c2185b', | ||
| fontFamily: 'Georgia, serif', | ||
| fontSize: '20px', | ||
| fontStyle: 'italic', | ||
| background: '#f5f5f5', | ||
| }} | ||
| > | ||
| <Story /> | ||
| </div> | ||
| ), | ||
| ], | ||
| }; | ||
|
|
||
| export default meta; | ||
|
|
||
| type Story = StoryObj<typeof EmptyButton>; | ||
|
|
||
| export const Default: Story = { | ||
| args: { | ||
| children: 'Empty button', | ||
| }, | ||
| }; | ||
|
|
||
| export const Disabled: Story = { | ||
| args: { | ||
| children: 'Disabled empty button', | ||
| disabled: true, | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,16 @@ | ||
| import { styled } from 'styled-components'; | ||
| import { ButtonHTMLAttributes, forwardRef } from 'react'; | ||
| import { cn } from '@/lib/cva'; | ||
| import styles from './EmptyButton.module.css'; | ||
|
|
||
| export const EmptyButton = styled.button` | ||
| background: transparent; | ||
| border: none; | ||
| cursor: pointer; | ||
| outline: none; | ||
| padding: 0; | ||
| border: 0; | ||
| color: inherit; | ||
| font: inherit; | ||
| &:disabled { | ||
| cursor: not-allowed; | ||
| } | ||
| `; | ||
| export const EmptyButton = forwardRef< | ||
| HTMLButtonElement, | ||
| ButtonHTMLAttributes<HTMLButtonElement> | ||
| >(({ className, ...props }, ref) => ( | ||
| <button | ||
| ref={ref} | ||
| {...props} | ||
| className={cn(styles['empty-button'], className)} | ||
| /> | ||
| )); | ||
|
|
||
| EmptyButton.displayName = 'EmptyButton'; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Affected-spec coverage for scoped visual-regression runs in CI. | ||
| // See .scripts/js/affected-visual-specs | ||
| // @covers src/components/EmptyButton | ||
| import { test as it, expect } from '@playwright/test'; | ||
| import { getStoryUrl } from '../utils'; | ||
|
|
||
| const { describe, use } = it; | ||
|
|
||
| const harnessLocator = '[data-testid="emptybutton-harness"]'; | ||
|
|
||
| describe('EmptyButton Visual Regression', () => { | ||
| describe('Light Theme (Storybook Global)', () => { | ||
| it('default matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const harness = page.locator(harnessLocator); | ||
| await expect(harness).toBeVisible({ timeout: 10000 }); | ||
| await expect(harness).toHaveScreenshot('emptybutton-default-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('disabled matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--disabled', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const harness = page.locator(harnessLocator); | ||
| await expect(harness).toBeVisible({ timeout: 10000 }); | ||
| const button = page.getByRole('button'); | ||
| await expect(button).toBeDisabled(); | ||
| await expect(harness).toHaveScreenshot('emptybutton-disabled-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('hover state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const harness = page.locator(harnessLocator); | ||
| await expect(harness).toBeVisible({ timeout: 10000 }); | ||
| await page.getByRole('button').hover(); | ||
| await page.waitForTimeout(100); | ||
| await expect(harness).toHaveScreenshot('emptybutton-hover-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('focus state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const harness = page.locator(harnessLocator); | ||
| await expect(harness).toBeVisible({ timeout: 10000 }); | ||
| await page.getByRole('button').focus(); | ||
| await page.waitForTimeout(100); | ||
| await expect(harness).toHaveScreenshot('emptybutton-focus-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Dark Theme (System prefers-color-scheme)', () => { | ||
| use({ colorScheme: 'dark' }); | ||
|
|
||
| it('default matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--default'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const harness = page.locator(harnessLocator); | ||
| await expect(harness).toBeVisible({ timeout: 10000 }); | ||
| await expect(harness).toHaveScreenshot('emptybutton-default-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('disabled matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--disabled'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const harness = page.locator(harnessLocator); | ||
| await expect(harness).toBeVisible({ timeout: 10000 }); | ||
| const button = page.getByRole('button'); | ||
| await expect(button).toBeDisabled(); | ||
| await expect(harness).toHaveScreenshot('emptybutton-disabled-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Behavior', () => { | ||
| it('click event fires', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const button = page.getByRole('button'); | ||
| await expect(button).toBeVisible({ timeout: 10000 }); | ||
| await expect(button).toBeEnabled(); | ||
| await button.click(); | ||
| }); | ||
|
|
||
| it('disabled button reports disabled', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--disabled', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const button = page.getByRole('button'); | ||
| await expect(button).toBeDisabled(); | ||
| }); | ||
|
|
||
| it('keyboard navigation works', async ({ page }) => { | ||
| await page.goto(getStoryUrl('buttons-emptybutton--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const button = page.getByRole('button'); | ||
| await expect(button).toBeVisible({ timeout: 10000 }); | ||
| await page.locator('body').click(); | ||
| await page.keyboard.press('Tab'); | ||
| await expect(button).toBeFocused(); | ||
| await page.keyboard.press('Enter'); | ||
| }); | ||
| }); | ||
| }); |
Binary file added
BIN
+2.65 KB
...ttons/emptybutton.spec.ts-snapshots/emptybutton-default-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.71 KB
...tons/emptybutton.spec.ts-snapshots/emptybutton-default-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.16 KB
...tons/emptybutton.spec.ts-snapshots/emptybutton-disabled-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.15 KB
...ons/emptybutton.spec.ts-snapshots/emptybutton-disabled-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.71 KB
...uttons/emptybutton.spec.ts-snapshots/emptybutton-focus-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+2.71 KB
...uttons/emptybutton.spec.ts-snapshots/emptybutton-hover-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Affected-spec coverage for scoped visual-regression runs in CI. | ||
| // See .scripts/js/affected-visual-specs | ||
| // @covers src/components/CodeBlock | ||
| // @covers src/components/EmptyButton | ||
| import { test as it, expect } from '@playwright/test'; | ||
| import { getStoryUrl } from '../utils'; | ||
|
|
||
| const { describe, use } = it; | ||
|
|
||
| // The copy and wrap buttons are rendered via `<CodeButton as={IconButton}>` where | ||
| // CodeButton = styled(EmptyButton). The `as` prop bypasses EmptyButton's own | ||
| // render, so this spec guards that those buttons still render correctly after | ||
| // EmptyButton's CSS Modules migration. The WithWrapButton story shows both. | ||
| const rootLocator = '[data-testid="codeblock-harness"]'; | ||
|
|
||
| describe('CodeBlock Visual Regression', () => { | ||
| describe('Light Theme (Storybook Global)', () => { | ||
| it('with wrap button matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('codeblocks-codeblock--with-wrap-button', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const root = page.locator(rootLocator); | ||
| await expect(root).toBeVisible({ timeout: 10000 }); | ||
| await expect(page.getByRole('button').first()).toBeVisible(); | ||
| await expect(root).toHaveScreenshot('codeblock-with-wrap-button-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('copied state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('codeblocks-codeblock--with-wrap-button', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const root = page.locator(rootLocator); | ||
| await expect(root).toBeVisible({ timeout: 10000 }); | ||
| // The last button is the copy button; clicking it flips to the copied state. | ||
| await page.getByRole('button').last().click(); | ||
| await page.waitForTimeout(100); | ||
| await expect(root).toHaveScreenshot('codeblock-copied-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Dark Theme (System prefers-color-scheme)', () => { | ||
| use({ colorScheme: 'dark' }); | ||
|
|
||
| it('with wrap button matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('codeblocks-codeblock--with-wrap-button'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const root = page.locator(rootLocator); | ||
| await expect(root).toBeVisible({ timeout: 10000 }); | ||
| await expect(page.getByRole('button').first()).toBeVisible(); | ||
| await expect(root).toHaveScreenshot('codeblock-with-wrap-button-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Behavior', () => { | ||
| it('renders copy and wrap buttons', async ({ page }) => { | ||
| await page.goto(getStoryUrl('codeblocks-codeblock--with-wrap-button', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| await expect(page.getByRole('button')).toHaveCount(2); | ||
| }); | ||
| }); | ||
| }); |
Binary file added
BIN
+4.65 KB
...odeblocks/codeblock.spec.ts-snapshots/codeblock-copied-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.68 KB
.../codeblock.spec.ts-snapshots/codeblock-with-wrap-button-dark-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.63 KB
...codeblock.spec.ts-snapshots/codeblock-with-wrap-button-light-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.