-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from DigitalCommons/directory-item-about-text
Directory item about text
- Loading branch information
Showing
7 changed files
with
279 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apps/front-end/src/components/panel/directoryPanel/DirectoryPanel.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { userEvent, within } from "@storybook/test"; | ||
import DirectoryPanel from "./DirectoryPanel"; | ||
import { ThemeProvider } from "@mui/material/styles"; | ||
import theme from "../../../theme/theme"; | ||
import GlobalCSSVariables from "../../../theme/GlobalCSSVariables"; | ||
|
||
// Simulate a click event on a link within the DirectoryPanel | ||
const clickInteraction = async (canvasElement: HTMLElement) => { | ||
const canvas = within(canvasElement); | ||
const links = await canvas.getAllByRole("link"); // Get all links in the panel | ||
|
||
links.forEach((link) => { | ||
link.addEventListener("click", (e) => e.preventDefault()); // Prevent navigation for all links | ||
}); | ||
|
||
// Simulate clicking on the first link, for example | ||
await userEvent.click(links[0]); | ||
}; | ||
|
||
const meta = { | ||
title: "DirectoryPanel", | ||
component: DirectoryPanel, | ||
decorators: [ | ||
(Story) => ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalCSSVariables /> | ||
<Story /> | ||
</ThemeProvider> | ||
), | ||
], | ||
tags: ["autodocs"], | ||
parameters: { | ||
layout: "centered", | ||
actions: { | ||
handles: ["click a"], | ||
}, | ||
}, | ||
} as Meta<typeof DirectoryPanel>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
play: ({ canvasElement }) => clickInteraction(canvasElement), | ||
}; |
75 changes: 52 additions & 23 deletions
75
apps/front-end/src/components/panel/directoryPanel/DirectoryPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
apps/front-end/src/components/panel/directoryPanel/directoryItem/DirectoryItem.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { userEvent, within } from "@storybook/test"; | ||
import DirectoryItem from "./DirectoryItem"; | ||
import { ThemeProvider } from "@mui/material/styles"; | ||
import theme from "../../../../theme/theme"; | ||
import GlobalCSSVariables from "../../../../theme/GlobalCSSVariables"; | ||
|
||
// Simulate a click event on a link | ||
const clickInteraction = async (canvasElement: HTMLElement) => { | ||
const canvas = within(canvasElement); | ||
const link = await canvas.getByRole("link"); | ||
await userEvent.click(link); | ||
}; | ||
|
||
const meta = { | ||
title: "DirectoryItem", | ||
component: DirectoryItem, | ||
decorators: [ | ||
(Story) => ( | ||
<ThemeProvider theme={theme}> | ||
<GlobalCSSVariables /> | ||
<Story /> | ||
</ThemeProvider> | ||
), | ||
], | ||
tags: ["autodocs"], | ||
argTypes: { | ||
onClick: { action: "clicked" }, // This action will log the event | ||
}, | ||
args: { | ||
link: "javascript:void(0)", // Prevent navigation by using this link | ||
}, | ||
parameters: { | ||
layout: "centered", | ||
actions: { | ||
handles: ["click a"], | ||
}, | ||
}, | ||
} as Meta<typeof DirectoryItem>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
name: "Directory Item", | ||
onClick: (e: React.MouseEvent) => { | ||
e.preventDefault(); | ||
console.log("Link clicked"); // Log the event to show it's working | ||
}, | ||
}, | ||
play: ({ canvasElement }) => clickInteraction(canvasElement), | ||
}; |
20 changes: 17 additions & 3 deletions
20
apps/front-end/src/components/panel/directoryPanel/directoryItem/DirectoryItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,27 @@ | ||
import React from "react"; | ||
import ListItem from "@mui/material/ListItem"; | ||
import { styled } from "@mui/material/styles"; | ||
import Link from "@mui/material/Link"; | ||
|
||
interface DirectoryItemProps { | ||
id: string; | ||
name: string; | ||
link: string; | ||
onClick?: (e: React.MouseEvent) => void; // for storybook testing | ||
} | ||
|
||
const DirectoryItem = ({id, name, link}: DirectoryItemProps) => { | ||
return <ListItem key={id}>{name}</ListItem>; | ||
const StyledLink = styled(Link)(() => ({ | ||
color: "var(--color-text)", | ||
"&:hover": { | ||
backgroundColor: "var(--color-neutral-light)", | ||
}, | ||
})); | ||
|
||
const DirectoryItem = ({ id, name, link, onClick }: DirectoryItemProps) => { | ||
return ( | ||
<ListItem key={id}> | ||
<StyledLink href={link} role="link" onClick={onClick}>{name}</StyledLink> | ||
</ListItem> | ||
); | ||
}; | ||
|
||
export default DirectoryItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.