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

feat: source editor that supports multiple files #759

Open
wants to merge 63 commits into
base: better-playground
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
546076d
Docs: Add proper playground
nmn Nov 29, 2023
21e8cef
Improve compilation to not insert inject calls
nmn Nov 29, 2023
2ad472b
Add Vercel headers
nmn Nov 29, 2023
c052704
Configure local development for playground
nmn Dec 5, 2023
4310651
Add codemirror editor
nmn Dec 5, 2023
52f2a71
Use rollup and static server.
nmn Dec 5, 2023
9b82f83
Delay preview to wait for built files
nmn Dec 5, 2023
0b46504
chore: update to latest StyleX for playground
nmn Oct 17, 2024
73af4ce
chore: fix build
nmn Oct 21, 2024
e962bf8
chore: playground actually builds
nmn Oct 21, 2024
9b1015f
chore: add additional StyleX logos (#756)
nmn Oct 21, 2024
e6c6d47
chore: improve contribution guide
nmn Oct 21, 2024
a14f529
## What changed / motivation ? Please include relevant motivation an…
aminaopio Oct 30, 2024
81bdfd9
Implemeted sidebar
aminaopio Nov 6, 2024
e1f7e60
chore: update dependencies and type definitions (#755)
nmn Oct 30, 2024
41f98c2
docs: add brand page (#757)
p0nch000 Oct 31, 2024
1f7ad80
feat: automatically resolve name from containing package.json (#745)
nmn Oct 31, 2024
ea44af5
release: v0.9.0
nmn Nov 1, 2024
33b15ef
fix: convert esm-resolve paths to absolute paths (#763)
nmn Nov 1, 2024
335d945
release: v0.9.1
nmn Nov 1, 2024
454e7d2
fix: additional handling of relative path from esm-resolve (#764)
nmn Nov 1, 2024
1a43476
release: v0.9.2
nmn Nov 1, 2024
8b4abc3
BREAKING CHANGE: Themes set *all* variables in a VarGroup. always. (#…
nmn Nov 1, 2024
f19df5b
release: v0.9.3
nmn Nov 1, 2024
0cd44cc
feat: add no-unused eslint rule to find unused styles (#767)
Samantha-Zhan Nov 11, 2024
71e55d1
chore: extract eslint get souce code to util (#772)
Samantha-Zhan Nov 12, 2024
0e7b092
Interpolate size (#775)
nikeee Nov 20, 2024
7eeb6bf
feat: CLI can use additional Babel plugins (#780)
nmn Nov 26, 2024
2de1a12
feat: add postcss-plugin (#781)
javascripter Nov 26, 2024
b65353f
chore: Clean up Nextjs-example with postcss-plugin (#784)
nmn Nov 27, 2024
3c43c86
chore: add explainer comment back in
nmn Nov 27, 2024
cd0a12f
fix: don't 'content' values in quotes unnecessarily (#782)
p0nch000 Nov 27, 2024
d5f483a
[feat] add caching for CLI file transform (#790)
mellyeliu Dec 3, 2024
54c861a
fix: add support for view-transition-name in ESLint valid-styles rule…
nmn Dec 4, 2024
a3777f5
feat: dynamic styles set inherits to false (#794)
Samantha-Zhan Dec 4, 2024
6c33363
fix: Use POSIX paths when inserting import statements (#795)
nmn Dec 4, 2024
43d487a
[feat] add support for custom CLI cache path (#792)
mellyeliu Dec 5, 2024
abeb3a2
fix: Use POSIX paths when inserting import statements correctly this …
nmn Dec 5, 2024
a03a7a3
fix: do not use path.posix.relative (#801)
nmn Dec 5, 2024
c34c72a
chore: make cli testing async (#804)
mellyeliu Dec 10, 2024
04f91b7
feat: add autofix for logical to inline properties in valid-styles ru…
mellyeliu Dec 10, 2024
eeeaf12
chore: fix @property inherits syntax (#806)
Samantha-Zhan Dec 11, 2024
5460c6a
feat: add dynamic styles to benchmarks fixture (#807)
Samantha-Zhan Dec 13, 2024
859e9fb
feat: better dev theme names (#803)
mellyeliu Dec 16, 2024
0de7d45
fix valid-shorthands null object error from null css-shorthand-expand…
mellyeliu Dec 17, 2024
e697241
fix: add inline processing for borderWidth, borderRadius, borderColor…
mellyeliu Dec 20, 2024
c2e9fe3
fix: Babel plugin should no longer require `unstable_moduleResolutio…
nmn Dec 21, 2024
f25d369
Configure local development for playground
nmn Dec 5, 2023
6d6f5b6
chore: fix build
nmn Oct 21, 2024
28cdb24
feat: loading indicator for sidebar while WC boots
aminaopio Oct 30, 2024
0775590
chore: update dependencies and type definitions (#755)
nmn Oct 30, 2024
0ee3d6e
feat: add no-unused eslint rule to find unused styles (#767)
Samantha-Zhan Nov 11, 2024
518d63e
feat: add postcss-plugin (#781)
javascripter Nov 26, 2024
ac3d569
chore: Clean up Nextjs-example with postcss-plugin (#784)
nmn Nov 27, 2024
901a617
feat: adjust build setup to use vite
6ri4n Dec 5, 2023
0e3edd8
Docs: Add proper playground
nmn Nov 29, 2023
ad9273f
Improve compilation to not insert inject calls
nmn Nov 29, 2023
7703321
rebasing
aminaopio Oct 30, 2024
e54d671
Implemeted sidebar
aminaopio Nov 6, 2024
2cc9e14
release: v0.9.1
nmn Nov 1, 2024
1a187c2
feat: add postcss-plugin (#781)
javascripter Nov 26, 2024
a422b80
chore: Clean up Nextjs-example with postcss-plugin (#784)
nmn Nov 27, 2024
2e4cc99
feat: loading indicator for sidebar while WC boots
aminaopio Oct 30, 2024
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
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[version]
0.245.2
0.249.0

[ignore]
.*/build/.*
Expand Down
43 changes: 35 additions & 8 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,24 @@ To run flow:
npm run flow
```

To run all the unit tests:
## Compile and build

To compile the source code:

```
npm run test
npm run build
```

…in watch mode:
To run all the unit tests (will build automatically):

```
npm run test -- --watch
npm run test
```

## Compile and build

To compile the source code:
…in watch mode (will build only once):

```
npm run build
npm run test -- --watch
```

## Documentation
Expand Down Expand Up @@ -92,3 +92,30 @@ After you have submitted your pull request, we'll try to get back to you as soon
as possible. We may suggest some changes or improvements.

Thank you for contributing!

## Typical Editor setup

### VS Code

If you're using Visual Studio Code, we recommend the following setup for the
best experience.

#### Extensions

We recommend you have the following extensions installed:

- [Flow Language Support](https://marketplace.visualstudio.com/items?itemName=flowtype.flow-for-vscode)
- [ESLint](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)
- [Prettier - Code formatter](https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode)

#### Turn off Typescript within JS files

Additionally, since StyleX is authored with the
[Flow typesystem](https://flow.org), it is helpful to turn off Typescript
type-checking within Javascript files:

```json
{
"javascript.validate.enable": false
}
```
2 changes: 1 addition & 1 deletion apps/cli-example/.stylex.json5
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
cssBundleName: 'stylex_bundle.css',
babelPresets: [
['@babel/preset-typescript', { allExtensions: true, isTSX: true }],
'@babel/preset-react',
// '@babel/preset-react',
],
modules_EXPERIMENTAL: [
['@stylexjs/open-props', { ignore: ['src', '__tests__'] }],
Expand Down
14 changes: 7 additions & 7 deletions apps/cli-example/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "stylex-cli-example",
"version": "0.8.0",
"version": "0.9.3",
"private": true,
"scripts": {
"transform": "stylex --config .stylex.json5"
},
"dependencies": {
"@stylexjs/open-props": "0.8.0",
"@stylexjs/open-props": "0.9.3",
"react": "^18",
"react-dom": "^18"
},
"devDependencies": {
"@babel/preset-react": "^7.24.1",
"@babel/preset-typescript": "^7.24.1",
"@stylexjs/cli": "0.8.0",
"@types/react": "^18",
"@types/react-dom": "^18",
"@babel/preset-react": "^7.25.7",
"@babel/preset-typescript": "^7.25.7",
"@stylexjs/cli": "0.9.3",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"typescript": "^5"
}
}
21 changes: 21 additions & 0 deletions apps/cli-example/source/app/CardThemes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/

import * as stylex from '@stylexjs/stylex';
import { tokens } from './CardTokens.stylex';

export const minorOffset = stylex.createTheme(tokens, {
arrowTransform: 'translateX(5px)',
});

export const majorOffset = stylex.createTheme(tokens, {
arrowTransform: 'translateX(10px)',
});

export const reset = stylex.createTheme(tokens, {});
1 change: 1 addition & 0 deletions apps/docs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module.exports = {
// The Eslint rule still needs work, but you can
// enable it to test things out.
'@stylexjs/valid-styles': 'error',
// '@stylexjs/no-unused': 'warn',
// 'ft-flow/space-after-type-colon': 0,
// 'ft-flow/no-types-missing-file-annotation': 0,
// 'ft-flow/generic-spacing': 0,
Expand Down
182 changes: 182 additions & 0 deletions apps/docs/blog/2024-11-01-Release-v0.9.3.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
---
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
slug: v0.9.3
title: Release 0.9.3
authors:
- nmn
tags:
- release
---

StyleX v0.9.3 is now available with some big improvements and bug-fixes.

## Improvements to Theming APIs

There are some big improvements to the predictability and reliability of our
theming APIs — `stylex.defineVars` and `stylex.createTheme`.

### Breaking Change: Themes are now exclusive

When you create a `VarGroup` with `stylex.defineVars`, you are able to theme
any subset of the variables within using the `stylex.createTheme` API. These
themes can then be applied like any other StyleX styles using `stylex.props`
(or `stylex.attrs`). If you try to apply multiple themes for the same `VarGroup`,
on the same element, *the last applied theme wins*, just as you might expect.

However, previously, if you instead applied one theme on a parent element,
and another theme on a child element, the themes would end up being merged.

```tsx
// tokens.stylex.ts
import * as stylex from '@stylexjs/stylex';

export const varGroup = stylex.defineVars({
primary: 'black',
secondary: 'grey',
});
```

```tsx
import * as stylex from '@stylexjs/stylex';
import {varGroup} from './tokens.stylex.ts';

const red = stylex.createTheme(varGroup, {
primary: 'red',
});

const blue = stylex.createTheme(varGroup, {
secondary: 'blue',
});

const styles = stylex.create({
primary: {color: varGroup.primary},
secondary: {color: varGroup.secondary},
});

function App() {
return (
<div {...stylex.props(red)}>
<div {...stylex.props(blue)}>
<span {...stylex.props(styles.primary)}>Hello </span>
<span {...stylex.props(styles.secondary)}>World!</span>
</div>
</div>
);
}
```

Previously this would have resulted in the text "Hello World!" being styled
with a red primary color and a blue secondary color. Now, the text will be
styled with a black primary color and a blue secondary color.

You can think of themes conceptually as *re-applying* the default values for any
variables that are not explicitly overridden by the theme. This change simplifies
the mental model for how themes work, and has the added benefit of making it
easy to create "reset" themes:

```tsx
const reset = stylex.createTheme(varGroup, {});
```

:::tip
You can define this "reset" theme multiple times within your app and they
will all be de-duplicated by the compiler. We encourage you to "repeat yourself"!
:::


### `rootDir` is now optional!

Previously, when configuring the StyleX Babel plugin, you had to explicitly
specify a `rootDir` value. Internally, this path was used to generate a canonical
file path for every `.stylex.js` file in your project.

However, this was not only cumbersome, but it also resulted in errors when importing
`VarGroup`s from `node_modules`. Different package managers deal with packages differently,
and this can be particularly consequential for mono-repos.

Now, the `rootDir` option is optional, and StyleX will use the nearest `package.json` file
to determine the canonical path, automatically. This should make theming APIs work more
reliably.

:::note
When determining the canonical path, StyleX will use the `name` field from the nearest
`package.json` file and the relative path to the `.stylex.js` file. We intentionally
ignore the `version` number.

This means that your project happens to contain multiple versions of the same package,
StyleX will only generate a single set of variables for them. This will usually be
the desired behavior, but you may see some unexpected results if the variables within
the two versions are different.

We will be making further improvements to minimize any such edge-cases.
:::

### More reliable ESM resolution

The StyleX Babel plugin now uses the `esm-resolve` package to resolve ESM imports.
This should fix most situations where the compiler would fail to resolve `VarGroup`
imports in result in the compilation of `stylex.create` to fail.

Thanks [hipstersmoothie](https://github.com/hipstersmoothie)!

## Dynamic style improvements

Dynamic Styles within StyleX have been improved to be more reliable and efficient.
Previously, if the dynamic value of a style resolved to `null` at runtime, StyleX
would represent that with the `revert` keyword in CSS. This did not always work as
expected, ran into certain browser bugs and resulted in styles that were unnecessarily
bloated.

In v0.9.3, `null` values for Dynamic styles work exactly the same as using `null`
as a static value within `stylex.create`. This means any previously applied value
for the given property will be removed and no className will be applied for that
property.


## `@stylexjs/dev-runtime` overhaul

The `@stylexjs/dev-runtime` package is a development-only package that lets you use
a *much slower* version of StyleX that runs entirely at runtime. Previously, it worked
by patching the main `@stylexjs/stylex` package at runtime. However, this did not always
work reliably.

**Breaking Change**: The `@stylexjs/dev-runtime` package now *returns* the StyleX API.

```tsx
import makeStyleX from '@stylexjs/dev-runtime';

const stylex = makeStyleX({
// configuration options
classNamePrefix: 'x',
dev: true,
test: false,
});

const styles = stylex.create({
color: 'red',
});
```

:::warning
The `@stylexjs/dev-runtime` only exists as a convenience for development purposes.
It does not completely match the behavior of the StyleX compiler and will always
lack certain features.

**DO NOT** use it in production.
:::

## Improved handling of nested pseudo-elements and pseudo-classes

Fixed a bug where using Pseudo Classes (such as `:hover`) within Pseudo Elements (such as `::before`)
(or vice-versa) would sometimes result in surprising behavior. StyleX now handles such cases, with
an arbitrary level of nesting, correctly.

## Miscellaneous

- Added support for additional Pseudo Elements and Pseudo Classes to our ESLint rule and type definitions.
- Thanks [aspizu](https://github.com/aspizu) and [nikeee](https://github.com/nikeee)!
- Slightly better compiler error messages.
- Thanks [EvanBacon](https://github.com/EvanBacon)!
Loading