Skip to content

Commit

Permalink
fix: package exports & examples (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
moritzjacobs authored Jan 16, 2024
1 parent 52503f8 commit 90a9a1f
Show file tree
Hide file tree
Showing 42 changed files with 2,879 additions and 48 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
node_modules
packages/react/dist/
apps/**/dist/

# misc
.DS_Store
Expand Down
22 changes: 22 additions & 0 deletions apps/docs/app/routes/_index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,28 @@ renders as:

<HxBoundary>

<Hx>How can I use it with my UI library? 🤔</Hx>

We have examples for [Chakra UI](https://github.com/peerigon/uberschrift/tree/main/apps/vite-chakra-ui-example) and [Material UI](https://github.com/peerigon/uberschrift/tree/main/apps/vite-mui-example). Essentially you can either use the context hook `useHx` (see below) or you can leverage `Hx` into another component.

Example for Chakra:

```tsx
import { Hx, HxBoundary } from "uberschrift";
import {
Heading as ChakraHeading,
HeadingProps,
} from "@chakra-ui/react";

const Heading = (props: HeadingProps) => <ChakraHeading {...props} as={Hx} />;

//

<Heading size="xl">…</Heading>
```



<Hx>How does it handle heading elements nested below the 6th level? 7️⃣</Hx>

The [HTML Spec](https://html.spec.whatwg.org/#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements) only allows h1 through h6 as elements and for most documents this should be more than enough.
Expand Down
4 changes: 4 additions & 0 deletions apps/vite-chakra-ui-example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@uberschrift/eslint-config/base.js"]
}
30 changes: 30 additions & 0 deletions apps/vite-chakra-ui-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
17 changes: 17 additions & 0 deletions apps/vite-chakra-ui-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="icon"
type="image/svg+xml"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🧢</text></svg>"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>uberschrift chakra-ui example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
36 changes: 36 additions & 0 deletions apps/vite-chakra-ui-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@uberschrift/vite-chakra-ui-example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"test": "run-p test:*",
"test:lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test:types": "tsc --noEmit",
"preview": "vite preview"
},
"dependencies": {
"@chakra-ui/react": "^2.8.2",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"framer-motion": "^10.18.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"uberschrift": "*"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@uberschrift/eslint-config": "*",
"@uberschrift/tsconfig": "*",
"@vitejs/plugin-react": "^4.2.1",
"eslint": "^8.55.0",
"npm-run-all": "^4.1.5",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
54 changes: 54 additions & 0 deletions apps/vite-chakra-ui-example/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { Hx, HxBoundary } from "uberschrift";
import {
Heading as ChakraHeading,
HeadingProps,
VStack,
} from "@chakra-ui/react";
import { SubComponent } from "./sub-component";

const Heading = (props: HeadingProps) => <ChakraHeading {...props} as={Hx} />;

export const App = () => {
return (
<VStack as="main" align="left" maxW="2xl" py="8" mx="auto">
<Heading size="xl">chakra-ui — Main Title (h1)</Heading>

<HxBoundary>
<p>
Lorem ipsum dolor sit amet convallis dictumst duis risus
nulla aliqua tortor.
</p>

<Heading size="lg">Chapter 1 (h2)</Heading>

<p>
Senectus netus aliquet nunc egestas habitasse sapien morbi
eu sagittis adipiscing. Maecenas diam tellus nulla ac
incididunt molestie libero.
</p>

<HxBoundary>
<Heading size="md">Chapter 1.1 (h3)</Heading>
<p>
Lorem ipsum dolor sit amet pulvinar venenatis eiusmod
feugiat dapibus duis. Aenean fusce nunc hendrerit mollis
senectus consectetur magna fames at convallis.
</p>

<SubComponent />

<p>Lorem ipsum dolor sit amet ac consequat netus mi.</p>
</HxBoundary>

<Heading size="lg">Chapter 2 (h2)</Heading>

<p>
Urna senectus lobortis risus consequat laoreet quam volutpat
convallis. Fermentum ullamcorper duis vel consequat
incididunt donec nisl vestibulum. Auctor egestas pretium
erat arcu adipiscing eros et libero nunc.
</p>
</HxBoundary>
</VStack>
);
};
12 changes: 12 additions & 0 deletions apps/vite-chakra-ui-example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";
import { ChakraProvider } from "@chakra-ui/react";
import ReactDOM from "react-dom/client";
import { App } from "./app";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<ChakraProvider>
<App />
</ChakraProvider>
</React.StrictMode>,
);
12 changes: 12 additions & 0 deletions apps/vite-chakra-ui-example/src/sub-component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Heading } from "@chakra-ui/react";
import { useHx } from "uberschrift";

export const SubComponent = () => {
const { Element, level } = useHx();

return (
<Heading size="sm" as={Element}>
This is an {Element} (level = {level})
</Heading>
);
};
1 change: 1 addition & 0 deletions apps/vite-chakra-ui-example/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
7 changes: 7 additions & 0 deletions apps/vite-chakra-ui-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "@uberschrift/tsconfig/base.json",
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"noEmit": true
}
}
10 changes: 10 additions & 0 deletions apps/vite-chakra-ui-example/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
7 changes: 7 additions & 0 deletions apps/vite-chakra-ui-example/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
});
4 changes: 4 additions & 0 deletions apps/vite-example/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"root": true,
"extends": ["@uberschrift/eslint-config/base.js"]
}
30 changes: 30 additions & 0 deletions apps/vite-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# React + TypeScript + Vite

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.

Currently, two official plugins are available:

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh

## Expanding the ESLint configuration

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:

- Configure the top-level `parserOptions` property like this:

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
project: ["./tsconfig.json", "./tsconfig.node.json"],
tsconfigRootDir: __dirname,
},
};
```

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
17 changes: 17 additions & 0 deletions apps/vite-example/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link
rel="icon"
type="image/svg+xml"
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🧢</text></svg>"
/>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>uberschrift vite example</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
35 changes: 35 additions & 0 deletions apps/vite-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@uberschrift/vite-example",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"test": "run-p test:*",
"test:lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"test:types": "tsc --noEmit",
"preview": "vite preview"
},
"dependencies": {
"@tailwindcss/typography": "^0.5.10",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"uberschrift": "*"
},
"devDependencies": {
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@uberschrift/eslint-config": "*",
"@uberschrift/tsconfig": "*",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"eslint": "^8.55.0",
"npm-run-all": "^4.1.5",
"postcss": "^8.4.33",
"typescript": "^5.2.2",
"vite": "^5.0.8"
}
}
6 changes: 6 additions & 0 deletions apps/vite-example/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
47 changes: 47 additions & 0 deletions apps/vite-example/src/app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Hx, HxBoundary } from "uberschrift";
import { SubComponent } from "./sub-component";

export const App = () => {
return (
<main className="prose max-w-screen-lg m-auto py-8">
<Hx>Vite — Main Title (h1)</Hx>

<HxBoundary>
<p>
Lorem ipsum dolor sit amet convallis dictumst duis risus
nulla aliqua tortor.
</p>

<Hx>Chapter 1 (h2)</Hx>

<p>
Senectus netus aliquet nunc egestas habitasse sapien morbi
eu sagittis adipiscing. Maecenas diam tellus nulla ac
incididunt molestie libero.
</p>

<HxBoundary>
<Hx>Chapter 1.1 (h3)</Hx>
<p>
Lorem ipsum dolor sit amet pulvinar venenatis eiusmod
feugiat dapibus duis. Aenean fusce nunc hendrerit mollis
senectus consectetur magna fames at convallis.
</p>

<SubComponent />

<p>Lorem ipsum dolor sit amet ac consequat netus mi.</p>
</HxBoundary>

<Hx>Chapter 2 (h2)</Hx>

<p>
Urna senectus lobortis risus consequat laoreet quam volutpat
convallis. Fermentum ullamcorper duis vel consequat
incididunt donec nisl vestibulum. Auctor egestas pretium
erat arcu adipiscing eros et libero nunc.
</p>
</HxBoundary>
</main>
);
};
3 changes: 3 additions & 0 deletions apps/vite-example/src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
10 changes: 10 additions & 0 deletions apps/vite-example/src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from "react";
import ReactDOM from "react-dom/client";
import { App } from "./app";
import "./index.css";

ReactDOM.createRoot(document.getElementById("root")!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
);
Loading

0 comments on commit 90a9a1f

Please sign in to comment.