npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astro-stylex

v0.3.0

Published

This **[Astro integration][astro-integration]** brings [StyleX's](https://stylexjs.com/docs/learn/) CSS compiler to every `.astro` file and [framework component](https://docs.astro.build/en/core-concepts/framework-components/) in your project.

Downloads

501

Readme

astro-stylex 🎄

This Astro integration brings StyleX's CSS compiler to every .astro file and framework component in your project.

Installation

Manual Install

First, install the astro-stylex package using your package manager. If you're using npm or aren't sure, run this in the terminal:

npm install astro-stylex @stylexjs/stylex

Next, apply this integration to your astro.config.* file using the integrations property:

  // astro.config.mjs
  import { defineConfig } from 'astro/config';
+ import stylex from 'astro-stylex';

  export default defineConfig({
    // ...
    integrations: [stylex()],
    //             ^^^^^^^^^
  });

Usage

Once the integration is installed and added to the configuration file, you can import and use stylex as a normal library.

React

// src/components/react.jsx
import stylex from '@stylexjs/stylex';

const styles = stylex.create({
  root: {
    width: '100%',
    color: 'rgb(60,60,60)',
    '@media (min-width: 800px)': {
      maxWidth: '800px',
    },
  },
  highlighted: {
    color: 'yellow',
    ':hover': {
      opacity: '0.9',
    },
  },
});

export function Component(props) {
  return (
    <div {...props} {...stylex.props([styles.root, props.highlighted])} />
  );
}

Svelte

The code within a <script> tag of a svelte component is run once for each use of the component. It is, therefore compiled into a function. Stylex requires the stylex.create() call to happen at the top-level of a module. This means that style definitions can not be written inside a normal <script> tag. For cases like this, Svelte allows you to write top-level code in a <script context="module"> tag. All your style definitions must be written inside one these tags, or imported from a separate module.

<script context="module">
  import stylex from "@stylexjs/stylex"
  const colorStyles = stylex.create({
        red: {
            backgroundColor: 'red',
            borderColor: 'darkred',
        },
        green: {
            backgroundColor: 'lightgreen',
            borderColor: 'darkgreen',
        },
    });
</script>
<button {...stylex.attrs(colorStyles.red)} />
<button {...stylex.attrs(colorStyles.green)} />

stylex.attrs() vs stylex.props()

The stylex.props() function returns the generated classes in the className prop. This works only for React and frameworks compatible with it. To improve usability with other frameworks, @stylexjs/stylex introduced stylex.attrs(). This function is identical to stylex.props(), except it returns the generated classes in the class prop.

Svelte only accepts class prop, so you would want to use stylex.attrs(). Meanwhile, React only accepts className prop - you would want to use stylex.props(), instead. Preact, and Solid accept both class and className props, and you are free to use either functions.

Troubleshooting

For help, check out the Discussions tab on the GitHub repo.

Contributing

This package is maintained by lilnasy independently from Astro. The integration code is located at packages/stylex/integration.ts. You're welcome to contribute by opening a PR or submitting an issue!

Changelog

See CHANGELOG.md for a history of changes to this integration.