summaryrefslogtreecommitdiff
path: root/examples/with-mdx/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/with-mdx/src')
-rw-r--r--examples/with-mdx/src/components/Counter.jsx18
-rw-r--r--examples/with-mdx/src/components/Title.astro7
-rw-r--r--examples/with-mdx/src/pages/index.mdx19
3 files changed, 44 insertions, 0 deletions
diff --git a/examples/with-mdx/src/components/Counter.jsx b/examples/with-mdx/src/components/Counter.jsx
new file mode 100644
index 000000000..801eefe73
--- /dev/null
+++ b/examples/with-mdx/src/components/Counter.jsx
@@ -0,0 +1,18 @@
+import { useState } from 'preact/hooks';
+
+export default function Counter({ children }) {
+ const [count, setCount] = useState(0);
+ const add = () => setCount((i) => i + 1);
+ const subtract = () => setCount((i) => i - 1);
+
+ return (
+ <>
+ <div class="counter">
+ <button onClick={subtract}>-</button>
+ <pre>{count}</pre>
+ <button onClick={add}>+</button>
+ </div>
+ <div class="counter-message">{children}</div>
+ </>
+ );
+}
diff --git a/examples/with-mdx/src/components/Title.astro b/examples/with-mdx/src/components/Title.astro
new file mode 100644
index 000000000..6d0dcb86c
--- /dev/null
+++ b/examples/with-mdx/src/components/Title.astro
@@ -0,0 +1,7 @@
+<h1><slot /></h1>
+
+<style>
+ h1 {
+ color: red;
+ }
+</style>
diff --git a/examples/with-mdx/src/pages/index.mdx b/examples/with-mdx/src/pages/index.mdx
new file mode 100644
index 000000000..e541df27c
--- /dev/null
+++ b/examples/with-mdx/src/pages/index.mdx
@@ -0,0 +1,19 @@
+import Counter from '../components/Counter.jsx'
+import Title from '../components/Title.astro'
+export const components = { h1: Title }
+
+# Hello world!
+
+export const authors = [
+ {name: 'Jane', email: 'hi@jane.com'},
+ {name: 'John', twitter: '@john2002'}
+]
+export const published = new Date('2022-02-01')
+
+Written by: {new Intl.ListFormat('en').format(authors.map(d => d.name))}.
+
+Published on: {new Intl.DateTimeFormat('en', {dateStyle: 'long'}).format(published)}.
+
+<Counter client:idle>
+## Counter
+</Counter>