Skip to content

Commit 1a674f7

Browse files
jonrohanjoshblack
andauthored
Refactor Link component to use CSS modules (#4828)
* Refactor Link to use CSS modules * Remove needless disable * Add newline * Create quick-adults-buy.md * Run tests inside fhte feature flag also * Fix naming * Rails interpolation got me * test(e2e): update e2e tests for link (#4825) Co-authored-by: Josh Black <joshblack@users.noreply.github.com> * Remove example-nextjs --------- Co-authored-by: Josh Black <joshblack@github.com> Co-authored-by: Josh Black <joshblack@users.noreply.github.com>
1 parent f3b08df commit 1a674f7

File tree

18 files changed

+148
-226
lines changed

18 files changed

+148
-226
lines changed

.changeset/pre.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"codesandbox": "0.0.0",
77
"example-app-router": "0.0.0",
88
"example-consumer-test": "0.0.0",
9-
"example-nextjs": "0.0.0",
109
"@primer/react": "36.27.0",
1110
"rollup-plugin-import-css": "0.0.0",
1211
"postcss-preset-primer": "0.0.0"
@@ -28,4 +27,4 @@
2827
"twelve-tables-leave",
2928
"young-meals-worry"
3029
]
31-
}
30+
}

.changeset/quick-adults-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": patch
3+
---
4+
5+
Refactor Link component to use CSS modules using the feature flag `primer_react_css_modules`

.eslintrc.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ module.exports = {
4242
'types/**/*',
4343
'consumer-test/**/*',
4444
'contributor-docs/adrs/*',
45-
'examples/nextjs/**',
4645
'examples/codesandbox/**',
4746
// Note: this file is inlined from an external dependency
4847
'packages/react/src/utils/polymorphic.ts',

contributor-docs/CONTRIBUTING.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
# Contribution guidelines
22

3-
1. [Roadmap](#roadmap)
4-
2. [Before Getting Started](#before-getting-started)
5-
3. [Discussing non-public features or products](#discussing-non-public-features-or-products)
6-
4. [Developing Components](#developing-components)
7-
- [Tools we use](#tools-we-use)
8-
- [File Structure](#file-structure)
9-
- [Component patterns](#component-patterns)
10-
- [SSR compatibility](#ssr-compatibility)
11-
- [Adding the sx prop](#adding-the-sx-prop)
12-
- [Linting](#linting)
13-
- [TypeScript support](#typescript-support)
14-
- [Additional resources](#additional-resources)
15-
5. [Writing documentation](#writing-documentation)
16-
6. [Creating a pull request](#creating-a-pull-request)
17-
- [Adding changeset to your pull request](#adding-changeset-to-your-pull-request)
18-
- [What to expect after opening a pull request](#what-to-expect-after-opening-a-pull-request)
19-
- [What we look for in reviews](#what-we-look-for-in-reviews)
20-
- [Previewing your changes](#previewing-your-changes)
21-
7. [Deploying](#deploying)
22-
8. [Troubleshooting](#troubleshooting)
3+
- [Contribution guidelines](#contribution-guidelines)
4+
- [Roadmap](#roadmap)
5+
- [Before Getting Started](#before-getting-started)
6+
- [Proposing new components](#proposing-new-components)
7+
- [Discussing non-public features or products](#discussing-non-public-features-or-products)
8+
- [Developing components](#developing-components)
9+
- [Tools we use](#tools-we-use)
10+
- [File structure](#file-structure)
11+
- [Component patterns](#component-patterns)
12+
- [SSR compatibility](#ssr-compatibility)
13+
- [Adding the `sx` prop](#adding-the-sx-prop)
14+
- [Linting](#linting)
15+
- [ESLint](#eslint)
16+
- [Markdownlint](#markdownlint)
17+
- [TypeScript support](#typescript-support)
18+
- [Additional resources](#additional-resources)
19+
- [Writing documentation](#writing-documentation)
20+
- [Creating a pull request](#creating-a-pull-request)
21+
- [Adding changeset to your pull request](#adding-changeset-to-your-pull-request)
22+
- [What to expect after opening a pull request](#what-to-expect-after-opening-a-pull-request)
23+
- [What we look for in reviews](#what-we-look-for-in-reviews)
24+
- [Previewing your changes](#previewing-your-changes)
25+
- [Deploying](#deploying)
26+
- [Troubleshooting](#troubleshooting)
2327

2428
## Roadmap
2529

@@ -148,8 +152,6 @@ We consider a component SSR-compatible if it...
148152

149153
We use [`eslint-plugin-ssr-friendly`](https://github.com/kopiro/eslint-plugin-ssr-friendly) to prevent misuse of DOM globals. If you see an error from this plugin, please fix it before merging your PR.
150154

151-
If your component doesn't use DOM globals, it likely won't cause layout shift during hydration. However, if you suspect that your component might cause layout shift, you can use the example Next.js app (`examples/nextjs`) to debug. Import and render your component in `examples/nextjs/src/pages/index.js` then run the example app with `cd examples/nextjs && npm run develop`.
152-
153155
### Adding the `sx` prop
154156

155157
Each component should accept a prop called `sx` that allows for setting theme-aware ad-hoc styles. See the [overriding styles](https://primer.style/react/overriding-styles) doc for more information on using the prop.

e2e/components/Link.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ test.describe('Link', () => {
3131
id: story.id,
3232
globals: {
3333
colorScheme: theme,
34+
featureFlags: {
35+
primer_react_css_modules: true,
36+
},
3437
},
3538
})
3639

@@ -47,6 +50,39 @@ test.describe('Link', () => {
4750
})
4851

4952
test('axe @aat', async ({page}) => {
53+
await visit(page, {
54+
id: story.id,
55+
globals: {
56+
colorScheme: theme,
57+
featureFlags: {
58+
primer_react_css_modules: true,
59+
},
60+
},
61+
})
62+
await expect(page).toHaveNoViolations()
63+
})
64+
65+
test('default (styled-component) @vrt', async ({page}) => {
66+
await visit(page, {
67+
id: story.id,
68+
globals: {
69+
colorScheme: theme,
70+
},
71+
})
72+
73+
// Default state
74+
expect(await page.screenshot()).toMatchSnapshot(`Link.${story.title}.${theme}.png`)
75+
76+
// Hover state
77+
await page.getByRole('link').hover()
78+
expect(await page.screenshot()).toMatchSnapshot(`Link.${story.title}.${theme}.hover.png`)
79+
80+
// Focus state
81+
await page.keyboard.press('Tab')
82+
expect(await page.screenshot()).toMatchSnapshot(`Link.${story.title}.${theme}.focus.png`)
83+
})
84+
85+
test('axe (styled-component) @aat', async ({page}) => {
5086
await visit(page, {
5187
id: story.id,
5288
globals: {

examples/nextjs/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/nextjs/next-env.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/nextjs/next.config.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/nextjs/package.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

examples/nextjs/src/components/Layout.js

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)