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: add css-hooks example #389

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions css-hooks/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: ["@remix-run/eslint-config", "@remix-run/eslint-config/node"],
};
6 changes: 6 additions & 0 deletions css-hooks/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules

/.cache
/build
/public/build
.env
19 changes: 19 additions & 0 deletions css-hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# CSS Hooks

Hooks bring CSS features to native inline styles, enabling you to target various states such as `:hover`, `:focus`, and `:active`, all without leaving the `style` prop.

## Preview

Open this example on [CodeSandbox](https://codesandbox.com):

[![Open in CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/remix-run/examples/tree/main/css-hooks)

## Example

This quick example shows how CSS Hooks can be used to apply `:hover` and `:active` styles on links.

## Related Links

- [Website](https://css-hooks.com)
- [Getting started](https://css-hooks.com/docs/react/getting-started)
- [Explanation: _From CSS madness to CSS Hooks_](https://nsaunders.dev/posts/css-madness-to-hooks)
6 changes: 6 additions & 0 deletions css-hooks/app/css-hooks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createHooks, recommended } from "@css-hooks/react";

const [css, hooks] = createHooks(recommended);

export default hooks;
export { css }
34 changes: 34 additions & 0 deletions css-hooks/app/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { MetaFunction } from "@remix-run/node";
import {

Check failure on line 2 in css-hooks/app/root.tsx

View workflow job for this annotation

GitHub Actions / ⬣ Lint

There should be at least one empty line between import groups
Links,
LiveReload,
Meta,
Outlet,
Scripts,
ScrollRestoration,
} from "@remix-run/react";
import { css } from "./css-hooks";

export const meta: MetaFunction = () => ({
charset: "utf-8",
title: "Remix with CSS Hooks",
viewport: "width=device-width,initial-scale=1",
});

export default function App() {
return (
<html lang="en">
<head>
<Meta />
<Links />
<style dangerouslySetInnerHTML={{ __html: css }} />
</head>
<body>
<Outlet />
<ScrollRestoration />
<Scripts />
<LiveReload />
</body>
</html>
);
}
42 changes: 42 additions & 0 deletions css-hooks/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ComponentPropsWithoutRef } from "react";

Check failure on line 1 in css-hooks/app/routes/_index.tsx

View workflow job for this annotation

GitHub Actions / ⬣ Lint

There should be at least one empty line between import groups

Check failure on line 1 in css-hooks/app/routes/_index.tsx

View workflow job for this annotation

GitHub Actions / ⬣ Lint

All imports in the declaration are only used as types. Use `import type`
import hooks from "../css-hooks";

function A(props: Omit<ComponentPropsWithoutRef<"a">, "style">) {
return (
<a

Check warning on line 6 in css-hooks/app/routes/_index.tsx

View workflow job for this annotation

GitHub Actions / ⬣ Lint

Anchors must have content and the content must be accessible by a screen reader
{...props}
style={hooks({
color: "#00c",
hover: {
color: "#00f",
textDecoration: "underline"
},
active: {
color: "#c00"
}
})} />
);
}

export default function Index() {
return (
<div style={{ fontFamily: "system-ui, sans-serif", lineHeight: "1.8" }}>
<h1>Welcome to Remix with CSS Hooks</h1>
<p>
Everyone insists that you
{" "}
<A href="https://stackoverflow.com/questions/1033156/how-can-i-write-ahover-in-inline-css#answer-1033166">
can't write <code>a:hover</code>
</A>
{" "}
in inline styles, but I just did. 😉
</p>
<p>
Learn more at <A href="https://css-hooks.com/">css-hooks.com</A>.
</p>
<p>
Or, for a detailed explanation, read <em><A href="https://nsaunders.dev/posts/css-madness-to-hooks">From CSS madness to CSS Hooks</A></em>.
</p>
</div>
);
}
30 changes: 30 additions & 0 deletions css-hooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"private": true,
"sideEffects": false,
"scripts": {
"build": "remix build",
"dev": "remix dev",
"start": "remix-serve build",
"typecheck": "tsc"
},
"dependencies": {
"@css-hooks/react": "^1.2.1",
"@remix-run/node": "^1.19.3",
"@remix-run/react": "^1.19.3",
"@remix-run/serve": "^1.19.3",
"isbot": "^3.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@remix-run/dev": "^1.19.3",
"@remix-run/eslint-config": "^1.19.3",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.8",
"eslint": "^8.27.0",
"typescript": "^4.8.4"
},
"engines": {
"node": ">=14.0.0"
}
}
Binary file added css-hooks/public/favicon.ico
Binary file not shown.
11 changes: 11 additions & 0 deletions css-hooks/remix.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
future: {
v2_routeConvention: true,
},
ignoredRouteFiles: ["**/.*"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// publicPath: "/build/",
// serverBuildPath: "build/index.js",
};
2 changes: 2 additions & 0 deletions css-hooks/remix.env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// <reference types="@remix-run/dev" />
/// <reference types="@remix-run/node" />
7 changes: 7 additions & 0 deletions css-hooks/sandbox.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"hardReloadOnChange": true,
"template": "remix",
"container": {
"port": 3000
}
}
22 changes: 22 additions & 0 deletions css-hooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},

// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
Loading