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

refactor(docs): breadcrumbs dx #3968

Merged
merged 8 commits into from
Nov 7, 2024
Merged
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: 2 additions & 2 deletions apps/docs/components/docs/components/code-demo/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {get} from "lodash";

import {FileCode} from "./types";

const importRegex = /^(import)\s(?!type(of\s|\s)(?!from)).*?$/gm;
const importRegex = /^(import\s+(?!type\s+\{)[\s\S]*?;)/gm;
wingkwong marked this conversation as resolved.
Show resolved Hide resolved

const exportDefaultRegex = /export\s+default\s+function\s+\w+\s*\(\s*\)\s*\{/;

Expand All @@ -29,7 +29,7 @@ export const transformCode = (code: string, imports = {}, compName = "App") => {
// replace match with const Name = () => (
return `const ${compName} = () => {`;
})
.replace("export", "");
.replace(/export/g, "");

// add render(<App/>) to cleanedCode if has const App = () => {
if (cleanedCode.includes(`const App = () => {`)) {
Expand Down
13 changes: 13 additions & 0 deletions apps/docs/content/components/breadcrumbs/collapsing-items.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
return (
<Breadcrumbs itemsAfterCollapse={2} itemsBeforeCollapse={1} maxItems={3}>
<BreadcrumbItem href="#home">Home</BreadcrumbItem>
<BreadcrumbItem href="#music">Music</BreadcrumbItem>
<BreadcrumbItem href="#artist">Artist</BreadcrumbItem>
<BreadcrumbItem href="#album">Album</BreadcrumbItem>
<BreadcrumbItem href="#song">Song</BreadcrumbItem>
</Breadcrumbs>
);
}
14 changes: 1 addition & 13 deletions apps/docs/content/components/breadcrumbs/collapsing-items.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
const App = `import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
return (
<Breadcrumbs maxItems={3} itemsBeforeCollapse={1} itemsAfterCollapse={2}>
<BreadcrumbItem href="#home">Home</BreadcrumbItem>
<BreadcrumbItem href="#music">Music</BreadcrumbItem>
<BreadcrumbItem href="#artist">Artist</BreadcrumbItem>
<BreadcrumbItem href="#album">Album</BreadcrumbItem>
<BreadcrumbItem href="#song">Song</BreadcrumbItem>
</Breadcrumbs>
);
}`;
import App from "./collapsing-items.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
19 changes: 19 additions & 0 deletions apps/docs/content/components/breadcrumbs/colors.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
const colors = ["foreground", "primary", "secondary", "success", "warning", "danger"];

return (
<div className="flex flex-col flex-wrap gap-4">
{colors.map((color) => (
<Breadcrumbs key={color} color={color}>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>Music</BreadcrumbItem>
<BreadcrumbItem>Artist</BreadcrumbItem>
<BreadcrumbItem>Album</BreadcrumbItem>
<BreadcrumbItem>Song</BreadcrumbItem>
</Breadcrumbs>
))}
</div>
);
}
20 changes: 1 addition & 19 deletions apps/docs/content/components/breadcrumbs/colors.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
const App = `import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
const colors = ["foreground", "primary", "secondary", "success", "warning", "danger"];

return (
<div className="flex flex-col flex-wrap gap-4">
{colors.map((color) => (
<Breadcrumbs key={color} color={color}>
<BreadcrumbItem>Home</BreadcrumbItem>
<BreadcrumbItem>Music</BreadcrumbItem>
<BreadcrumbItem>Artist</BreadcrumbItem>
<BreadcrumbItem>Album</BreadcrumbItem>
<BreadcrumbItem>Song</BreadcrumbItem>
</Breadcrumbs>
))}
</div>
);
}`;
import App from "./colors.raw.jsx?raw";

const react = {
"/App.jsx": App,
Expand Down
25 changes: 25 additions & 0 deletions apps/docs/content/components/breadcrumbs/controlled.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
const [currentPage, setCurrentPage] = React.useState("song");

return (
<Breadcrumbs underline="active" onAction={(key) => setCurrentPage(key)}>
<BreadcrumbItem key="home" isCurrent={currentPage === "home"}>
Home
</BreadcrumbItem>
<BreadcrumbItem key="music" isCurrent={currentPage === "music"}>
Music
</BreadcrumbItem>
<BreadcrumbItem key="artist" isCurrent={currentPage === "artist"}>
Artist
</BreadcrumbItem>
<BreadcrumbItem key="album" isCurrent={currentPage === "album"}>
Album
</BreadcrumbItem>
<BreadcrumbItem key="song" isCurrent={currentPage === "song"}>
Song
</BreadcrumbItem>
</Breadcrumbs>
);
}
26 changes: 26 additions & 0 deletions apps/docs/content/components/breadcrumbs/controlled.raw.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
const [currentPage, setCurrentPage] = React.useState<React.Key>("song");

return (
<Breadcrumbs underline="active" onAction={(key) => setCurrentPage(key)}>
<BreadcrumbItem key="home" isCurrent={currentPage === "home"}>
Home
</BreadcrumbItem>
<BreadcrumbItem key="music" isCurrent={currentPage === "music"}>
Music
</BreadcrumbItem>
<BreadcrumbItem key="artist" isCurrent={currentPage === "artist"}>
Artist
</BreadcrumbItem>
<BreadcrumbItem key="album" isCurrent={currentPage === "album"}>
Album
</BreadcrumbItem>
<BreadcrumbItem key="song" isCurrent={currentPage === "song"}>
Song
</BreadcrumbItem>
</Breadcrumbs>
);
}
53 changes: 2 additions & 51 deletions apps/docs/content/components/breadcrumbs/controlled.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,5 @@
const App = `import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
const [currentPage, setCurrentPage] = React.useState("song");

return (
<Breadcrumbs underline="active" onAction={(key) => setCurrentPage(key)}>
<BreadcrumbItem key="home" isCurrent={currentPage === "home"}>
Home
</BreadcrumbItem>
<BreadcrumbItem key="music" isCurrent={currentPage === "music"}>
Music
</BreadcrumbItem>
<BreadcrumbItem key="artist" isCurrent={currentPage === "artist"}>
Artist
</BreadcrumbItem>
<BreadcrumbItem key="album" isCurrent={currentPage === "album"}>
Album
</BreadcrumbItem>
<BreadcrumbItem key="song" isCurrent={currentPage === "song"}>
Song
</BreadcrumbItem>
</Breadcrumbs>
);
}`;

const AppTs = `import {Breadcrumbs, BreadcrumbItem} from "@nextui-org/react";

export default function App() {
const [currentPage, setCurrentPage] = React.useState<React.Key>("song");

return (
<Breadcrumbs underline="active" onAction={(key) => setCurrentPage(key)}>
<BreadcrumbItem key="home" isCurrent={currentPage === "home"}>
Home
</BreadcrumbItem>
<BreadcrumbItem key="music" isCurrent={currentPage === "music"}>
Music
</BreadcrumbItem>
<BreadcrumbItem key="artist" isCurrent={currentPage === "artist"}>
Artist
</BreadcrumbItem>
<BreadcrumbItem key="album" isCurrent={currentPage === "album"}>
Album
</BreadcrumbItem>
<BreadcrumbItem key="song" isCurrent={currentPage === "song"}>
Song
</BreadcrumbItem>
</Breadcrumbs>
);
}`;
import App from "./controlled.raw.jsx?raw";
import AppTs from "./controlled.raw.tsx?raw";

const react = {
"/App.jsx": App,
Expand Down
68 changes: 68 additions & 0 deletions apps/docs/content/components/breadcrumbs/custom-items.raw.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import {
wingkwong marked this conversation as resolved.
Show resolved Hide resolved
Breadcrumbs,
BreadcrumbItem,
Dropdown,
DropdownTrigger,
DropdownMenu,
DropdownItem,
Button,
} from "@nextui-org/react";

export const ChevronDownIcon = (props) => (
<svg
aria-hidden="true"
fill="none"
focusable="false"
height="1em"
role="presentation"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
viewBox="0 0 24 24"
width="1em"
{...props}
>
<path d="m6 9 6 6 6-6" />
</svg>
);

export default function App() {
return (
<Breadcrumbs
itemClasses={{
item: "px-2",
separator: "px-0",
}}
>
<BreadcrumbItem href="#home">Home</BreadcrumbItem>
<BreadcrumbItem href="#music">Music</BreadcrumbItem>
<BreadcrumbItem href="#artist">Artist</BreadcrumbItem>
<BreadcrumbItem href="#album">Album</BreadcrumbItem>
<BreadcrumbItem
classNames={{
item: "px-0",
}}
>
<Dropdown>
<DropdownTrigger>
<Button
className="h-6 pr-2 text-small"
endContent={<ChevronDownIcon className="text-default-500" />}
radius="full"
size="sm"
variant="light"
>
Songs
</Button>
</DropdownTrigger>
<DropdownMenu aria-label="Routes">
<DropdownItem href="#song-1">Song 1</DropdownItem>
<DropdownItem href="#song2">Song 2</DropdownItem>
<DropdownItem href="#song3">Song 3</DropdownItem>
</DropdownMenu>
</Dropdown>
</BreadcrumbItem>
</Breadcrumbs>
);
}
69 changes: 1 addition & 68 deletions apps/docs/content/components/breadcrumbs/custom-items.ts
Original file line number Diff line number Diff line change
@@ -1,74 +1,7 @@
const ChevronDownIcon = `export const ChevronDownIcon = (props) => (
<svg
aria-hidden="true"
fill="none"
focusable="false"
height="1em"
role="presentation"
stroke="currentColor"
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth="1.5"
viewBox="0 0 24 24"
width="1em"
{...props}
>
<path d="m6 9 6 6 6-6" />
</svg>
);`;

const App = `import {Breadcrumbs, BreadcrumbItem, Dropdown, DropdownTrigger, DropdownMenu, DropdownItem, Button} from "@nextui-org/react";
import {ChevronDownIcon} from "./ChevronDownIcon";

export default function App() {
return (
<Breadcrumbs
itemClasses={{
item: "px-2",
separator: "px-0",
}}
>
<BreadcrumbItem href="#home">Home</BreadcrumbItem>
<BreadcrumbItem href="#music">Music</BreadcrumbItem>
<BreadcrumbItem href="#artist">Artist</BreadcrumbItem>
<BreadcrumbItem href="#album">Album</BreadcrumbItem>
<BreadcrumbItem
classNames={{
item: "px-0",
}}
>
<Dropdown>
<DropdownTrigger>
<Button
className="h-6 pr-2 text-small"
endContent={<ChevronDownIcon className="text-default-500" />}
radius="full"
size="sm"
variant="light"
>
Songs
</Button>
</DropdownTrigger>
<DropdownMenu aria-label="Routes">
<DropdownItem href="#song-1">
Song 1
</DropdownItem>
<DropdownItem href="#song2">
Song 2
</DropdownItem>
<DropdownItem href="#song3">
Song 3
</DropdownItem>
</DropdownMenu>
</Dropdown>
</BreadcrumbItem>
</Breadcrumbs>
);
}`;
import App from "./custom-items.raw.jsx?raw";

const react = {
"/App.jsx": App,
"/ChevronDownIcon.jsx": ChevronDownIcon,
};

export default {
Expand Down
Loading