Skip to content

Commit

Permalink
feat: add menu to list component types
Browse files Browse the repository at this point in the history
  • Loading branch information
theisel committed Oct 30, 2022
1 parent c9edc93 commit c9547e1
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eighty-parrots-walk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-portabletext": patch
---

Feat: Added [`<menu>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/menu) to `components` props `list` type
1 change: 1 addition & 0 deletions astro-portabletext/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import { PortableText } from "astro-portabletext";
list: {
bullet: /* <ul {...attrs}><slot /></ul> */,
number: /* <ol {...attrs}><slot /></ol> */,
menu: /* <menu {...attrs}><slot /></menu> */,
},
listItem: {
bullet: /* <li {...attrs}><slot /></li> */,
Expand Down
6 changes: 5 additions & 1 deletion astro-portabletext/components/List.astro
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ const listItemIs = (listItem: string) => listItem === node.listItem;
---

{
listItemIs("number") ? (
listItemIs("menu") ? (
<menu {...attrs}>
<slot />
</menu>
) : listItemIs("number") ? (
<ol {...attrs}>
<slot />
</ol>
Expand Down
1 change: 1 addition & 0 deletions astro-portabletext/components/PortableText.astro
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const components = mergeComponents(
list: {
bullet: List,
number: List,
menu: List,
},
unknownList: UnknownList,
listItem: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
import Layout from "../../layouts/Default.astro";
import { PortableText } from "astro-portabletext";
const blocks = [
{
_type: "block",
listItem: "menu",
children: [
{
_type: "span",
text: "Menu Item 1",
},
],
},
];
---

<Layout>
<PortableText value={blocks} />
</Layout>
7 changes: 7 additions & 0 deletions astro-portabletext/test/components/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import { fetchContent } from "../utils.mjs";

const list = suite("list");

list("menu", async () => {
const $ = await fetchContent("list/menu");
const $el = $("menu");

assert.is($el.length, 1);
});

list("ol", async () => {
const $ = await fetchContent("list/ordered");
const $el = $("ol");
Expand Down

0 comments on commit c9547e1

Please sign in to comment.