Skip to content

Commit

Permalink
Abacus tools: use StyleX
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtnzlml committed Jun 9, 2024
1 parent cebbb7c commit 06db7f8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 31 deletions.
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/
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',
},
});

0 comments on commit 06db7f8

Please sign in to comment.