Skip to content
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

Abacus tools: use StyleX #7793

Merged
merged 3 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/abacus-tools/.babelrc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @flow strict

const styleXPlugin = require('@stylexjs/babel-plugin');

module.exports = {
presets: [
[
Expand All @@ -12,4 +14,21 @@ module.exports = {
},
],
],
plugins: [
[
styleXPlugin,
{
// https://stylexjs.com/docs/api/configuration/babel-plugin/
dev: process.env.NODE_ENV === 'development',
test: false,
treeshakeCompensation: true,

// Required for CSS variable support
unstable_moduleResolution: {
type: 'commonJS',
rootDir: __dirname, // The absolute path to the root directory of the project
},
},
],
],
};
1 change: 1 addition & 0 deletions src/abacus-tools/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
'@adeira/eslint-config/strict', // preset with almost everything
'@adeira/eslint-config/fbt', // additional FBT rules
'@adeira/eslint-config/next', // additional Next.js rules
'@adeira/eslint-config/react',
],
settings: {
next: {
Expand Down
4 changes: 4 additions & 0 deletions src/abacus-tools/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
```bash
yw @adeira/abacus-tools dev
```

http://localhost:3000/
21 changes: 0 additions & 21 deletions src/abacus-tools/_original_version_/Dockerfile

This file was deleted.

21 changes: 0 additions & 21 deletions src/abacus-tools/_original_version_/README.md

This file was deleted.

67 changes: 0 additions & 67 deletions src/abacus-tools/_original_version_/newtab.html

This file was deleted.

5 changes: 5 additions & 0 deletions src/abacus-tools/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const withCustomBabelConfigFile = require('next-plugin-custom-babel-config')({
babelConfigFile: path.join(__dirname, '.babelrc.js'),
});

const withStylex = require('@stylexjs/nextjs-plugin')({
rootDir: __dirname,
});

module.exports = (withPlugins(
[
[withCustomBabelConfigFile],
[withStylex],
// other plugins here
],
{
Expand Down
5 changes: 4 additions & 1 deletion src/abacus-tools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
"start": "next start --port=3000"
},
"dependencies": {
"@stylexjs/nextjs-plugin": "^0.6.1",
"@stylexjs/stylex": "^0.6.1",
"next": "^14.2.3",
"next-compose-plugins": "^2.2.1",
"next-plugin-custom-babel-config": "^1.0.5",
Expand All @@ -18,6 +20,7 @@
"devDependencies": {
"@adeira/babel-preset-adeira": "^4.0.0",
"@babel/core": "^7.24.7",
"@playwright/test": "^1.44.1"
"@playwright/test": "^1.44.1",
"@stylexjs/babel-plugin": "^0.6.1"
}
}
38 changes: 22 additions & 16 deletions src/abacus-tools/pages/_app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow

import * as sx from '@stylexjs/stylex';
import * as React from 'react';
import Link from 'next/link';

Expand All @@ -10,25 +11,30 @@ export default function MyApp({ Component, pageProps }: $FlowFixMe): React.Node
<div>
<Component {...pageProps} />

<style jsx>{`
.navigation {
margin-block-start: 5em;
color: #bbb;
font-size: 0.8em;
}

.navigation a {
color: #bbb;
}
`}</style>

<div className="navigation">
<Link href="/newtab">Time</Link>
<div {...sx.props(styles.navigation)}>
<Link href="/newtab" {...sx.props(styles.navigationLink)}>
Time
</Link>
{' · '}
<Link href="/time-from-start-of-year">Elapsed Time</Link>
<Link href="/time-from-start-of-year" {...sx.props(styles.navigationLink)}>
Elapsed Time
</Link>
{' · '}
<Link href="/time-until-end-of-year">Remaining Time</Link>
<Link href="/time-until-end-of-year" {...sx.props(styles.navigationLink)}>
Remaining Time
</Link>
</div>
</div>
);
}

const styles = sx.create({
navigation: {
color: '#bbb',
fontSize: '0.8em',
marginBlockStart: '5em',
},
navigationLink: {
color: '#bbb',
},
});
27 changes: 13 additions & 14 deletions src/abacus-tools/src/components/Jumbo.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
// @flow strict

import * as sx from '@stylexjs/stylex';
import { type Node } from 'react';

export default function Jumbo(props: { +children: string }): Node {
return (
<>
<style jsx>{`
.jumbo {
font-size: 8em;
font-weight: bold;
transition: all 0.5s ease-in-out;
font-variant-numeric: tabular-nums;
}
`}</style>

<div>
<div className="jumbo">{props.children}</div>
</div>
</>
<div>
<div {...sx.props(styles.jumbo)}>{props.children}</div>
</div>
);
}

const styles = sx.create({
jumbo: {
fontSize: '8em',
fontVariantNumeric: 'tabular-nums',
fontWeight: 'bold',
transition: 'all 0.5s ease-in-out',
},
});
2 changes: 1 addition & 1 deletion src/eslint-config-adeira/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Breaking changes ahead!

- New rule enabled: `@next/next/no-async-client-component`
- New rules enabled: `@next/next/no-async-client-component`, `@stylexjs/valid-styles`, and `@stylexjs/sort-keys`

Breaking changes from `eslint-plugin-testing-library` v6 were implemented, specifically:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ exports[`rules snapshot: all stable rules 1`] = `
"eslint-plugin-jsx-a11y",
"eslint-plugin-jest-dom",
"eslint-plugin-testing-library",
"@stylexjs/eslint-plugin",
"eslint-plugin-relay",
"eslint-plugin-prettier",
],
"rules": {
"@babel/object-curly-spacing": "off",
"@babel/semi": "off",
"@stylexjs/sort-keys": 2,
"@stylexjs/valid-styles": 2,
"@typescript-eslint/block-spacing": "off",
"@typescript-eslint/brace-style": "off",
"@typescript-eslint/comma-dangle": "off",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -930,9 +930,12 @@ exports[`React preset: React preset 1`] = `
"eslint-plugin-jsx-a11y",
"eslint-plugin-jest-dom",
"eslint-plugin-testing-library",
"@stylexjs/eslint-plugin",
"eslint-plugin-prettier",
],
"rules": {
"@stylexjs/sort-keys": 2,
"@stylexjs/valid-styles": 2,
"curly": [
2,
"all",
Expand Down
1 change: 1 addition & 0 deletions src/eslint-config-adeira/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"dependencies": {
"@babel/runtime": "^7.24.7",
"@next/eslint-plugin-next": "^14.2.3",
"@stylexjs/eslint-plugin": "^0.6.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-adeira": "^0.15.0",
"eslint-plugin-eslint-comments": "^3.2.0",
Expand Down
5 changes: 5 additions & 0 deletions src/eslint-config-adeira/src/presets/react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = ({
'eslint-plugin-jsx-a11y',
'eslint-plugin-jest-dom',
'eslint-plugin-testing-library',
'@stylexjs/eslint-plugin',
],
rules: {
// React (https://github.com/yannickcr/eslint-plugin-react)
Expand Down Expand Up @@ -247,6 +248,10 @@ module.exports = ({
'jsx-a11y/role-supports-aria-props': ERROR,
'jsx-a11y/scope': ERROR,
'jsx-a11y/tabindex-no-positive': ERROR,

// StyleX (https://stylexjs.com/docs/learn/installation/#catch-mistakes-with-eslint)
'@stylexjs/valid-styles': ERROR,
'@stylexjs/sort-keys': ERROR,
},
overrides: [
{
Expand Down
Loading
Loading