Skip to content

Latest commit

 

History

History
207 lines (155 loc) · 5.21 KB

readme.md

File metadata and controls

207 lines (155 loc) · 5.21 KB

Tailored Components

test

Isomorphic utilities, components and hooks for Fresh and Preact.

Components

The unstyled Preact components.

Popover

Completely unstyled popover for preact built with Floating UI

import { useRef } from "preact/hooks";
import Popover from "https://deno.land/x/tailored/components/Popover.tsx";

export default function App() {
  const ref = useRef(null);
  return (
    <div>
      <button ref={ref}>Open popover</button>
      <Popover
        target={ref}
        trigger="click"
        className="bg-white shadow-lg rounded-lg p-4"
        clickOutside
      >
        <div>Content</div>
      </Popover>
    </div>
  );
}

source / typedefs

ToggleClass

A component that toggles a class on a target element. The target element can be a ref or a selector.

import { tw } from "twind/core";
import ToggleClass from "https://deno.land/x/tailored/components/ToggleClass.tsx";

export default function MenuButton(props: MenuButtonProps) {
  return (
    <ToggleClass
      target="[mobile-menu]"
      toggleAddClass={tw("flex")}
      toggleRemoveClass={tw("visibility-hidden")}
    >
      <MenuIcon />
    </ToggleClass>
  );
}

source / typedefs

LazyHydrate

Hydrate components only when they are in the viewport or when an event is emitted. You can control hydration by emmiting a custom event on the document. By default, the component supports the visible event which is implemented with an intersection observer.

import { tw } from "twind/core";
import LazyHydrate from "https://deno.land/x/tailored/components/LazyHydrate.tsx";

export default function MenuButton(props: MenuButtonProps) {
  return (
    <LazyHydrate
      id="lazy123"
      event="visible"
      classNames={[
        "x-non-hydrated",
        "x-hydrated",
      ]}
    >
      <MyComplexComponent {...props} />
    </LazyHydrate>
  );
}

source / typedefs


Fresh plugins

Useful plugins for Fresh.

Context plugin

A plugin that enables the use of global Preact Context in islands. Current verion supports only one provider and only JSON-serializable values.

import Context from "./context.ts";
import contextPlugin from "tailored/plugins/context.ts";

await start(manifest, {
  plugins: [
    contextPlugin(
      Context,
      new URL("./context.ts", import.meta.url).href,
    ),
  ],
});

context.ts | source

Client plugin

Used for client-only code:

import clientPlugin from "tailored/plugins/client.ts";

await start(manifest, {
  plugins: [
    clientPlugin(
      new URL("./client.ts", import.meta.url).href,
    ),
  ],
});

client.ts | source

Preloader plugin

Show a progress indicator while the page is loading:

import preloaderPlugin from "tailored/plugins/preloader.ts";

await start(manifest, {
  plugins: [
    preloaderPlugin("#48d1cc", "4px"),
  ],
});

Twind v1 plugin

Twind v1 plugin for Fresh. Based on the official fresh plugin for twind v0.x

Plugin | Config | source


Preact Hooks

A set of useful hooks for preact.


Development

Start the project:

deno task dev

This will watch the project directory and restart as necessary.

Testing

PUPPETEER_PRODUCT=chrome deno run -A --unstable https://deno.land/x/[email protected]/install.ts
deno task test

License

MIT