-
Notifications
You must be signed in to change notification settings - Fork 22
chore(GenericLabel): migrate to CSS Modules with visual regression baseline #1048
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1962621
test(GenericLabel): add visual regression baseline before CSS Modules…
DreaminDani 498c512
chore(GenericLabel): migrate styling from styled-components to CSS Mo…
DreaminDani f682d42
chore(GenericLabel): move spec from tests/utils/ to tests/display/
DreaminDani 15c70fc
chore(GenericLabel): disable the input in the Disabled story
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 GenericLabel 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* stylelint-disable custom-property-pattern -- design tokens use camelCase (e.g. genericLabel) */ | ||
|
|
||
| .generic-label { | ||
| color: var(--click-field-color-genericLabel-default); | ||
| font: var(--click-field-typography-genericLabel-default); | ||
| cursor: pointer; | ||
| } | ||
|
|
||
| .generic-label:hover { | ||
| color: var(--click-field-color-genericLabel-hover); | ||
| font: var(--click-field-typography-genericLabel-hover); | ||
| } | ||
|
|
||
| .generic-label:focus, | ||
| .generic-label:focus-within { | ||
| color: var(--click-field-color-genericLabel-active); | ||
| font: var(--click-field-typography-genericLabel-active); | ||
| } | ||
|
|
||
| /* stylelint-disable no-descending-specificity -- disabled state intentionally | ||
| defined after hover/focus to neutralize them; the original styled-components | ||
| emits no hover/focus rules when disabled is true. */ | ||
| .generic-label.generic-label_disabled, | ||
| .generic-label.generic-label_disabled:hover, | ||
| .generic-label.generic-label_disabled:focus, | ||
| .generic-label.generic-label_disabled:focus-within { | ||
| color: var(--click-field-color-genericLabel-disabled); | ||
| font: var(--click-field-typography-genericLabel-disabled); | ||
| cursor: not-allowed; | ||
| } | ||
| /* stylelint-enable no-descending-specificity */ |
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 |
|---|---|---|
| @@ -1,42 +1,25 @@ | ||
| import { styled } from 'styled-components'; | ||
| import { cn, cva } from '@/lib/cva'; | ||
| import { GenericLabelProps } from './GenericLabel.types'; | ||
| import styles from './GenericLabel.module.css'; | ||
|
|
||
| interface FormFieldLableProps { | ||
| disabled?: boolean; | ||
| htmlFor?: string; | ||
| } | ||
| const genericLabelVariants = cva(styles['generic-label'], { | ||
| variants: { | ||
| disabled: { | ||
| true: styles['generic-label_disabled'], | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const FormFieldLabel = styled.label<FormFieldLableProps>` | ||
| ${({ theme, disabled }) => ` | ||
| ${ | ||
| disabled | ||
| ? ` | ||
| color: ${theme.click.field.color.genericLabel.disabled}; | ||
| font: ${theme.click.field.typography.genericLabel.disabled}; | ||
| cursor: not-allowed; | ||
| ` | ||
| : ` | ||
| cursor: pointer; | ||
| color: ${theme.click.field.color.genericLabel.default}; | ||
| font: ${theme.click.field.typography.genericLabel.default}; | ||
| &:hover { | ||
| color: ${theme.click.field.color.genericLabel.hover}; | ||
| font: ${theme.click.field.typography.genericLabel.hover}; | ||
| } | ||
| &:focus, &:focus-within { | ||
| color: ${theme.click.field.color.genericLabel.active}; | ||
| font: ${theme.click.field.typography.genericLabel.active}; | ||
| } | ||
| ` | ||
| }; | ||
| `} | ||
| `; | ||
|
|
||
| export const GenericLabel = ({ disabled, children, ...props }: GenericLabelProps) => ( | ||
| <FormFieldLabel | ||
| disabled={disabled} | ||
| export const GenericLabel = ({ | ||
| disabled, | ||
| children, | ||
| className, | ||
| ...props | ||
| }: GenericLabelProps) => ( | ||
| <label | ||
| {...props} | ||
| className={cn(genericLabelVariants({ disabled }), className)} | ||
| > | ||
| {children} | ||
| </FormFieldLabel> | ||
| </label> | ||
| ); |
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,120 @@ | ||
| import { test as it, expect } from '@playwright/test'; | ||
| import { getStoryUrl } from '../utils'; | ||
|
|
||
| const { describe, use } = it; | ||
|
|
||
| const labelLocator = 'label'; | ||
|
|
||
| describe('GenericLabel Visual Regression', () => { | ||
| describe('Light Theme (Storybook Global)', () => { | ||
| describe('States', () => { | ||
| it('default matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await expect(label).toHaveScreenshot('generic-label-default-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('disabled matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--disabled', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await expect(label).toHaveScreenshot('generic-label-disabled-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Interactive States', () => { | ||
| it('hover state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await label.hover(); | ||
| await page.waitForTimeout(100); | ||
| await expect(label).toHaveScreenshot('generic-label-hover-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('focus-within state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--default', 'light'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| await page.locator('body').click(); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await page.locator('#default-input').focus(); | ||
| await page.waitForTimeout(100); | ||
| await expect(label).toHaveScreenshot('generic-label-focus-light.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Dark Theme (System prefers-color-scheme)', () => { | ||
| use({ colorScheme: 'dark' }); | ||
|
|
||
| describe('States', () => { | ||
| it('default matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--default'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await expect(label).toHaveScreenshot('generic-label-default-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('disabled matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--disabled'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await expect(label).toHaveScreenshot('generic-label-disabled-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Interactive States', () => { | ||
| it('hover state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--default'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await label.hover(); | ||
| await page.waitForTimeout(100); | ||
| await expect(label).toHaveScreenshot('generic-label-hover-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
|
|
||
| it('focus-within state matches snapshot', async ({ page }) => { | ||
| await page.goto(getStoryUrl('forms-genericlabel--default'), { | ||
| waitUntil: 'networkidle', | ||
| }); | ||
| await page.locator('body').click(); | ||
| const label = page.locator(labelLocator).first(); | ||
| await expect(label).toBeVisible({ timeout: 10000 }); | ||
| await page.locator('#default-input').focus(); | ||
| await page.waitForTimeout(100); | ||
| await expect(label).toHaveScreenshot('generic-label-focus-dark.png', { | ||
| maxDiffPixels: 100, | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Binary file added
BIN
+2.14 KB
...y/generic-label.spec.ts-snapshots/generic-label-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.05 KB
.../generic-label.spec.ts-snapshots/generic-label-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
+2.23 KB
.../generic-label.spec.ts-snapshots/generic-label-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
+2.13 KB
...generic-label.spec.ts-snapshots/generic-label-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.19 KB
...lay/generic-label.spec.ts-snapshots/generic-label-focus-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.1 KB
...ay/generic-label.spec.ts-snapshots/generic-label-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.14 KB
...lay/generic-label.spec.ts-snapshots/generic-label-hover-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.05 KB
...ay/generic-label.spec.ts-snapshots/generic-label-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.
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.