Skip to content

Commit

Permalink
feat(CheckBoxOrRadioGroup): Convert CheckBoxOrRadioGroup to CSS modul…
Browse files Browse the repository at this point in the history
…es behind feature flag (#5275)

* Convert CheckboxOrRadioGroup to CSS modules

Co-authored-by: Marie Lucca <francinelucca@users.noreply.github.com>
Co-authored-by: Tyler Jones <TylerJDev@users.noreply.github.com>

* Adding e2e test for sx prop stress test

* test(vrt): update snapshots

* Fix circular dependency

* Create lovely-stingrays-jog.md

---------

Co-authored-by: Marie Lucca <francinelucca@users.noreply.github.com>
Co-authored-by: Tyler Jones <TylerJDev@users.noreply.github.com>
Co-authored-by: jonrohan <jonrohan@users.noreply.github.com>
  • Loading branch information
4 people authored Nov 14, 2024
1 parent 1cfbf63 commit d1b7bce
Show file tree
Hide file tree
Showing 17 changed files with 393 additions and 175 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-stingrays-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@primer/react": patch
---

Convert CheckBoxOrRadioGroup to CSS modules behind feature flag
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.
219 changes: 56 additions & 163 deletions e2e/components/CheckboxGroup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,176 +2,69 @@ import {test, expect} from '@playwright/test'
import {visit} from '../test-helpers/storybook'
import {themes} from '../test-helpers/themes'

test.describe('CheckboxGroup', () => {
test.describe('Default', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup--default',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(`CheckboxGroup.Default.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup--default',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: false,
},
},
})
})
})
}
})
const stories = [
{
title: 'Default',
id: 'components-checkboxgroup--default',
},
{
title: 'Caption',
id: 'components-checkboxgroup-features--caption',
},
{
title: 'Error',
id: 'components-checkboxgroup-features--error',
},
{
title: 'Success',
id: 'components-checkboxgroup-features--success',
},
{
title: 'Visually Hidden Label',
id: 'components-checkboxgroup-features--visually-hidden-label',
},
{
title: 'SX Props',
id: 'components-checkboxgroup-dev--sx-props',
},
] as const

test.describe('Caption', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--caption',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(`CheckboxGroup.Caption.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--caption',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: false,
},
},
})
})
})
}
})

test.describe('Error', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--error',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(`CheckboxGroup.Error.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--error',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: false,
test.describe('CheckboxGroup', () => {
for (const story of stories) {
test.describe(story.title, () => {
for (const theme of themes) {
test.describe(theme, () => {
test('@vrt', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
},
})
})
})
}
})
})

test.describe('Success', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--success',
globals: {
colorScheme: theme,
},
// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`CheckboxGroup.${story.title}.${theme}.png`,
)
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(`CheckboxGroup.Success.${theme}.png`)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--success',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: false,
test('axe @aat', async ({page}) => {
await visit(page, {
id: story.id,
globals: {
colorScheme: theme,
},
},
})
})
})
}
})

test.describe('Visually Hidden Label', () => {
for (const theme of themes) {
test.describe(theme, () => {
test('default @vrt', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--visually-hidden-label',
globals: {
colorScheme: theme,
},
})

// Default state
expect(await page.screenshot({animations: 'disabled'})).toMatchSnapshot(
`CheckboxGroup.Visually Hidden Label.${theme}.png`,
)
})

test('axe @aat', async ({page}) => {
await visit(page, {
id: 'components-checkboxgroup-features--visually-hidden-label',
globals: {
colorScheme: theme,
},
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: false,
})
await expect(page).toHaveNoViolations({
rules: {
'color-contrast': {
enabled: false,
},
},
},
})
})
})
})
}
})
}
})
}
})
49 changes: 49 additions & 0 deletions packages/react/src/CheckboxGroup/CheckboxGroup.dev.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import React from 'react'
import type {Meta} from '@storybook/react'
import {Checkbox, CheckboxGroup, FormControl} from '..'

export default {
title: 'Components/CheckboxGroup/Dev',
component: CheckboxGroup,
parameters: {controls: {exclude: ['aria-labelledby', 'id', 'onChange', 'sx']}},
} as Meta

export const SxProps = () => (
<CheckboxGroup
sx={{
color: 'var(--fgColor-default, var(--color-fg-default))',
my: '15px',
}}
>
<CheckboxGroup.Caption
sx={{
color: 'fg.muted',
fontSize: 0,
fontWeight: 400,
}}
>
Caption
</CheckboxGroup.Caption>
<CheckboxGroup.Label
sx={{
color: 'var(--fgColor-default, var(--color-fg-default))',
fontSize: ['14px'],
fontWeight: 600,
}}
>
Choices
</CheckboxGroup.Label>
<FormControl required>
<Checkbox value="one" defaultChecked />
<FormControl.Label>Choice one</FormControl.Label>
</FormControl>
<FormControl>
<Checkbox value="two" defaultChecked />
<FormControl.Label>Choice two</FormControl.Label>
</FormControl>
<FormControl>
<Checkbox value="three" />
<FormControl.Label>Choice three</FormControl.Label>
</FormControl>
</CheckboxGroup>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.Body {
display: flex;
padding: 0;
margin: 0;
list-style: none;
flex-direction: column;

& > * + * {
margin-top: var(--base-size-8);
}
}

.GroupFieldset {
padding: 0;
margin: 0;
border: none;

&:where([data-validation]) {
margin-bottom: var(--base-size-8);
}
}

.GroupLegend {
padding: 0;

&:where([data-legend-visible]) {
margin-bottom: var(--base-size-8);
}
}

.CheckboxOrRadioGroupCaption {
font-size: var(--text-body-size-medium);
color: var(--fgColor-muted);
}

.RadioGroupLabel {
display: block;
font-size: var(--text-body-size-large);

&:where([data-label-disabled]) {
color: var(--fgColor-muted);
}
}

.GroupLabelChildren {
margin-right: var(--base-size-8);
}
Loading

0 comments on commit d1b7bce

Please sign in to comment.