Skip to content

Commit 08b555b

Browse files
committed
Migrate pattern library site and tests to Tailwind v4
Migrate the pattern library website and tests to use Tailwind v4. The npm package remains usable with either Tailwind v3 or v4 downstream. The changes here are similar to those in h (hypothesis/h#9877).
1 parent 32c5aeb commit 08b555b

File tree

13 files changed

+498
-528
lines changed

13 files changed

+498
-528
lines changed

gulpfile.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { buildCSS, runTests, watchJS } from '@hypothesis/frontend-build';
22
import gulp from 'gulp';
33

44
import { servePatternLibrary } from './scripts/serve-pattern-library.js';
5-
import tailwindConfig from './tailwind.config.js';
65

76
gulp.task('serve-pattern-library', () => {
87
servePatternLibrary();
@@ -12,7 +11,10 @@ gulp.task('serve-pattern-library', () => {
1211
// during development. Bundled JS and CSS are not published with the package.
1312

1413
gulp.task('bundle-css', () =>
15-
buildCSS(['./styles/pattern-library.scss'], { tailwindConfig }),
14+
buildCSS(['./styles/pattern-library.css'], {
15+
autoprefixer: false,
16+
tailwind: true,
17+
}),
1618
);
1719

1820
gulp.task(
@@ -44,7 +46,7 @@ gulp.task(
4446
* nb. This is only used for unit tests that need CSS to verify accessibility requirements.
4547
*/
4648
gulp.task('build-test-css', () =>
47-
buildCSS(['styles/test.scss'], { tailwindConfig }),
49+
buildCSS(['styles/test.css'], { autoprefixer: false, tailwind: true }),
4850
);
4951

5052
// Some (eg. a11y) tests rely on CSS bundles. We assume that JS will always take

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
"@babel/preset-env": "^7.1.6",
1111
"@babel/preset-react": "^7.0.0",
1212
"@babel/preset-typescript": "^7.18.6",
13-
"@hypothesis/frontend-build": "^4.0.0",
13+
"@hypothesis/frontend-build": "^4.1.0",
1414
"@hypothesis/frontend-testing": "^1.7.1",
1515
"@rollup/plugin-babel": "^6.0.0",
1616
"@rollup/plugin-commonjs": "^28.0.0",
1717
"@rollup/plugin-dynamic-import-vars": "^2.1.2",
1818
"@rollup/plugin-node-resolve": "^16.0.0",
1919
"@rollup/plugin-terser": "^0.4.4",
2020
"@rollup/plugin-virtual": "^3.0.0",
21+
"@tailwindcss/postcss": "^4.1.13",
2122
"@trivago/prettier-plugin-sort-imports": "^5.2.0",
2223
"@vitest/browser": "^3.1.1",
2324
"@vitest/coverage-istanbul": "^3.1.1",
2425
"@vitest/eslint-plugin": "^1.1.44",
25-
"autoprefixer": "^10.3.7",
2626
"axe-core": "^4.0.0",
2727
"babel-plugin-istanbul": "^7.0.0",
2828
"babel-plugin-mockable-imports": "^2.0.1",
@@ -47,10 +47,9 @@
4747
"prettier": "^3.0.0",
4848
"rollup": "^4.0.2",
4949
"rollup-plugin-string": "^3.0.0",
50-
"sass": "^1.43.2",
5150
"sinon": "^21.0.0",
5251
"svgo": "^4.0.0",
53-
"tailwindcss": "3.4.17",
52+
"tailwindcss": "^4.1.13",
5453
"typescript": "^5.0.2",
5554
"typescript-eslint": "^8.10.0",
5655
"vitest": "^3.1.1",

src/components/data/test/DataTable-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ describe('DataTable', () => {
392392
assert.approximately(
393393
stickyHeaderHeight,
394394
scrollEl.scrollTop,
395-
1,
395+
2,
396396
'Scroll is adjusted to ensure selected row is visible below sticky header',
397397
);
398398
});

src/components/layout/test/Panel-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('Panel', () => {
7171
assert.isTrue(loremWrapper.find('p').getDOMNode().clientHeight > 200);
7272
// But when in a Panel, and the Panel is within a height-constrained
7373
// element, the total Panel height will not exceed parent height (200px)
74-
assert.equal(
74+
assert.isBelow(
7575
wrapper.find('div[data-composite-component="Panel"]').getDOMNode()
7676
.clientHeight,
7777
200,

src/tailwind.focus-visible-ring.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import plugin from 'tailwindcss/plugin.js';
3030
*
3131
* Ring width is this theme's `ringWidth.DEFAULT`
3232
*/
33+
34+
/** @type {any} */
3335
export const focusVisibleRing = plugin(({ addUtilities, theme }) => {
3436
const ringWidth = theme('ringWidth.DEFAULT');
3537
// Based on TW ring/shadow rules https://tailwindcss.com/docs/ring-width

src/tailwind.scroll-shadows.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import plugin from 'tailwindcss/plugin.js';
3333
* - The bottom scroll-hint shadow is always present, even if content is
3434
* fully scrolled
3535
*/
36+
37+
/** @type {any} */
3638
export const scrollShadows = plugin(({ addUtilities }) => {
3739
// These "shadow covers" scroll with the content. They align with and
3840
// obscure the shadows when an element is scrolled all the way in one

src/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"lib": ["es2018", "dom"],
77
"jsx": "react-jsx",
88
"jsxImportSource": "preact",
9-
"module": "commonjs",
9+
"module": "es2022",
10+
"moduleResolution": "bundler",
1011
"declaration": true,
1112
"emitDeclarationOnly": true,
1213
"declarationDir": "../lib",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
@layer components {
6-
// Support some basic text styling in Library components
6+
/* Support some basic text styling in Library components. */
77
.styled-text {
88
:where(a):not(:where([class~='unstyled-text'] *)) {
99
@apply text-brand underline hover:text-brand-dark transition-colors;

styles/pattern-library.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* This stylesheet provides all of the styles needed to run a standalone
3+
* pattern library application, including resets, component styles, util
4+
* styles and component styles.
5+
*/
6+
@import 'tailwindcss';
7+
8+
/* Syntax highlighting style for Highlight.js. */
9+
@import 'highlight.js/styles/github-dark.css';
10+
11+
@config '../tailwind.config.js';
12+
@import './library.css';
13+
14+
@layer base {
15+
/* For consistency with Tailwind v3. See https://tailwindcss.com/docs/upgrade-guide#default-border-color. */
16+
* {
17+
border-color: #dbdbdb;
18+
}
19+
}
20+
21+
/* For consistency with Tailwind v3. See https://tailwindcss.com/docs/upgrade-guide#default-ring-width-and-color. */
22+
@theme {
23+
--default-ring-width: 2px;
24+
--default-ring-color: #59a7e8;
25+
}

styles/pattern-library.scss

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

0 commit comments

Comments
 (0)