diff --git a/.changeset/four-schools-grin.md b/.changeset/four-schools-grin.md deleted file mode 100644 index 72c447d1a85..00000000000 --- a/.changeset/four-schools-grin.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -'@primer/react': minor ---- - -Update BranchName to use CSS Modules behind feature flag diff --git a/e2e/components/BranchName.test.ts b/e2e/components/BranchName.test.ts index 24a7ce82102..feb776b3101 100644 --- a/e2e/components/BranchName.test.ts +++ b/e2e/components/BranchName.test.ts @@ -2,90 +2,110 @@ import {test, expect} from '@playwright/test' import {visit} from '../test-helpers/storybook' import {themes} from '../test-helpers/themes' -const stories = [ - { - title: 'Default', - id: 'components-branchname--default', - focus: true, - }, - { - title: 'Not A Link', - id: 'components-branchname-features--not-a-link', - focus: false, - }, - { - title: 'With A Branch Icon', - id: 'components-branchname-features--with-branch-icon', - focus: false, - }, -] as const - test.describe('BranchName', () => { - for (const story of stories) { - test.describe(story.title, () => { - for (const theme of themes) { - test.describe(theme, () => { - test('default @vrt', async ({page}) => { - await visit(page, { - id: story.id, - globals: { - colorScheme: theme, - primer_react_css_modules_team: true, - }, - }) + test.describe('Default', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-branchname--default', + globals: { + colorScheme: theme, + }, + }) - // Default state - expect(await page.screenshot()).toMatchSnapshot(`BranchName.${story.title}.${theme}.png`) + // Default state + expect(await page.screenshot()).toMatchSnapshot(`BranchName.Default.${theme}.png`) - // Focus state - if (story.focus) { - await page.keyboard.press('Tab') - expect(await page.screenshot()).toMatchSnapshot(`BranchName.${story.title}.${theme}.focus.png`) - } - }) + // Focus state + await page.keyboard.press('Tab') + expect(await page.screenshot()).toMatchSnapshot(`BranchName.Default.${theme}.focus.png`) + }) - test('default (styled-components) @vrt', async ({page}) => { - await visit(page, { - id: story.id, - globals: { - colorScheme: theme, - primer_react_css_modules_team: false, + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-branchname--default', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations({ + rules: { + 'color-contrast': { + enabled: theme !== 'dark_dimmed', }, - }) - - // Default state - expect(await page.screenshot()).toMatchSnapshot(`BranchName.${story.title}.${theme}.png`) + }, + }) + }) + }) + } + }) - // Focus state - if (story.focus) { - await page.keyboard.press('Tab') - expect(await page.screenshot()).toMatchSnapshot(`BranchName.${story.title}.${theme}.focus.png`) - } + test.describe('Not A Link', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-branchname-features--not-a-link', + globals: { + colorScheme: theme, + }, }) - test('axe @aat', async ({page}) => { - await visit(page, { - id: story.id, - globals: { - colorScheme: theme, - primer_react_css_modules_team: true, + // Default state + expect(await page.screenshot()).toMatchSnapshot(`BranchName.Not A Link.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-branchname-features--not-a-link', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations({ + rules: { + 'color-contrast': { + enabled: theme !== 'dark_dimmed', }, - }) - await expect(page).toHaveNoViolations() + }, }) + }) + }) + } + }) - test('axe (styled-components) @aat', async ({page}) => { - await visit(page, { - id: story.id, - globals: { - colorScheme: theme, - primer_react_css_modules_team: false, + test.describe('With A Branch Icon', () => { + for (const theme of themes) { + test.describe(theme, () => { + test('default @vrt', async ({page}) => { + await visit(page, { + id: 'components-branchname-features--with-branch-icon', + globals: { + colorScheme: theme, + }, + }) + + // Default state + expect(await page.screenshot()).toMatchSnapshot(`BranchName.With A Branch Icon.${theme}.png`) + }) + + test('axe @aat', async ({page}) => { + await visit(page, { + id: 'components-branchname-features--with-branch-icon', + globals: { + colorScheme: theme, + }, + }) + await expect(page).toHaveNoViolations({ + rules: { + 'color-contrast': { + enabled: theme !== 'dark_dimmed', }, - }) - await expect(page).toHaveNoViolations() + }, }) }) - } - }) - } + }) + } + }) }) diff --git a/packages/react/src/BranchName/BranchName.module.css b/packages/react/src/BranchName/BranchName.module.css deleted file mode 100644 index 66e9abc2d50..00000000000 --- a/packages/react/src/BranchName/BranchName.module.css +++ /dev/null @@ -1,14 +0,0 @@ -.BranchName { - display: inline-block; - padding: var(--base-size-2) var(--base-size-6); - font-family: var(--fontStack-monospace); - font-size: var(--text-body-size-small); - color: var(--fgColor-link); - text-decoration: none; - background-color: var(--bgColor-accent-muted); - border-radius: var(--borderRadius-medium); - - &:is(:not(a)) { - color: var(--fgColor-muted); - } -} diff --git a/packages/react/src/BranchName/BranchName.tsx b/packages/react/src/BranchName/BranchName.tsx index e07460191f9..010777c4a2a 100644 --- a/packages/react/src/BranchName/BranchName.tsx +++ b/packages/react/src/BranchName/BranchName.tsx @@ -1,14 +1,10 @@ -import React from 'react' -import {clsx} from 'clsx' import styled from 'styled-components' import {get} from '../constants' import type {SxProp} from '../sx' import sx from '../sx' -import {useFeatureFlag} from '../FeatureFlags' -import Box from '../Box' -import classes from './BranchName.module.css' +import type {ComponentProps} from '../utils/types' -const StyledBranchName = styled.a` +const BranchName = styled.a` display: inline-block; padding: 2px 6px; font-size: var(--text-body-size-small, ${get('fontSizes.0')}); @@ -23,34 +19,5 @@ const StyledBranchName = styled.a` ${sx}; ` -type BranchNameProps = { - as?: As -} & React.ComponentPropsWithoutRef & - SxProp - -function BranchName(props: BranchNameProps) { - const {as: BaseComponent = 'a', className, children, sx, ...rest} = props - const enabled = useFeatureFlag('primer_react_css_modules_team') - if (enabled) { - if (sx) { - return ( - - {children} - - ) - } - return ( - - {children} - - ) - } - return ( - - {children} - - ) -} - -export type {BranchNameProps} +export type BranchNameProps = ComponentProps export default BranchName