Giter Site home page Giter Site logo

fresh-jss's Introduction

fresh-jss

Use Deno fresh with jss hooks.

Example

First add the registry to your project:

// utils/registry.ts

import { createRegistry } from "https://deno.land/x/fresh-jss/mod.ts";
const { registry, createUseStyles } = createRegistry();
export { registry, createUseStyles }

Then use it in your routes, islands and components:

// routes/index.tsx
/** @jsx h */

import { h } from "preact";
import { createUseStyles } from "../utils/registry.ts";

const useStyles = createUseStyles({
  "red": { color: "red" }
});

export default function Home() {
  const { classes } = useStyles();
  return (
    <p className={classes.red}>Red text here</p>
  );
}

Finally add the registry to page template to enable SSR:

// routes/_app.tsx
/** @jsx h */
/** @jsxFrag Fragment */

import { h, Fragment } from "preact";
import { registry } from "../utils/registry.ts";
import { Head } from "$fresh/runtime.ts";
import { AppProps } from "$fresh/server.ts";

export default function App(props: AppProps) {
  return (
    <>
      <Head>
        <style>{ registry.toString() }</style>
      </Head>
      <props.Component />
    </>
  );
}

See example directory for details.

fresh-jss's People

Contributors

frizzant avatar xubaiw avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

frizzant

fresh-jss's Issues

CSS States - hover, active etc.

Hello Xubaiw

First off - thanks for making this package!

I have an issue, that I can not create hover states for my elements.
I can see that you are simply extending the JSS library, which makes sense. So I am a bit confused why the syntax seems to be different or not working.

const useStyles = createUseStyles({ red: { color: "red", "&:hover": { color: "blue", } } });

How am I to go about this? Is it implemented yet?

CSS missing after rehydration

It seems that currently the CSS is only output after initial load. Whenever the page is rehydrated on change, the CSS rules are missing.
@xubaiw can you confirm this is an issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.