Skip to content

Commit bf91455

Browse files
committed
Add the PopupMenu component.
1 parent af64363 commit bf91455

File tree

8 files changed

+282
-2
lines changed

8 files changed

+282
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ The components in this library will be described below.
4343
- [OptionList](https://github.com/macroing/simple-react-components/tree/master/documentation/option-list) provides a component that defines an option list.
4444
- [Pagination](https://github.com/macroing/simple-react-components/tree/master/documentation/pagination) provides a component that defines a pagination.
4545
- [Panel](https://github.com/macroing/simple-react-components/tree/master/documentation/panel) provides a component that defines a panel.
46+
- [PopupMenu](https://github.com/macroing/simple-react-components/tree/master/documentation/popup-menu) provides a component that defines a popup menu.
4647
- [Select](https://github.com/macroing/simple-react-components/tree/master/documentation/select) provides a component that defines a select.
4748
- [Stars](https://github.com/macroing/simple-react-components/tree/master/documentation/stars) provides a component that defines stars.
4849
- [TabPane](https://github.com/macroing/simple-react-components/tree/master/documentation/tab-pane) provides a component that defines a tab pane.

dist/index/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index/src/PopupMenu.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index/src/PopupMenu.module.css.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

documentation/popup-menu/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# `PopupMenu`

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import OneColumnLayout from "./src/OneColumnLayout";
2323
import OptionList from "./src/OptionList";
2424
import Pagination from "./src/Pagination";
2525
import Panel from "./src/Panel";
26+
import PopupMenu from "./src/PopupMenu";
2627
import Select from "./src/Select";
2728
import Stars from "./src/Stars";
2829
import TabPane from "./src/TabPane";
@@ -33,4 +34,4 @@ import ThreeColumnLayout from "./src/ThreeColumnLayout";
3334
import TooltipContainer from "./src/TooltipContainer";
3435
import TwoColumnLayout from "./src/TwoColumnLayout";
3536

36-
export { Accordion, Background, Button, ButtonLink, Card, Carousel, Chip, DesktopMenuBar, Dialog, FileInputButtonLabel, Footer, Form, Header, IconButton, Image, ImageViewer, Input, Jumbotron, LinkButton, MenuBar, MobileMenuBar, OneColumnLayout, OptionList, Pagination, Panel, Select, Stars, TabPane, Table, TaskBar, TextArea, ThreeColumnLayout, TooltipContainer, TwoColumnLayout };
37+
export { Accordion, Background, Button, ButtonLink, Card, Carousel, Chip, DesktopMenuBar, Dialog, FileInputButtonLabel, Footer, Form, Header, IconButton, Image, ImageViewer, Input, Jumbotron, LinkButton, MenuBar, MobileMenuBar, OneColumnLayout, OptionList, Pagination, Panel, PopupMenu, Select, Stars, TabPane, Table, TaskBar, TextArea, ThreeColumnLayout, TooltipContainer, TwoColumnLayout };

src/PopupMenu.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
"use client";
2+
3+
import importedStyles from "./PopupMenu.module.css";
4+
5+
export default function PopupMenu(props) {
6+
const isVisible = props.isVisible;
7+
const items = props.items;
8+
const linkFactory = props.linkFactory || defaultLinkFactory;
9+
const setIsVisible = props.setIsVisible;
10+
const styles = props.styles || importedStyles;
11+
const title = props.title;
12+
13+
function defaultLinkFactory(className, href, onClick, children) {
14+
return (
15+
<a className={className} href={href} onClick={onClick}>
16+
{children}
17+
</a>
18+
);
19+
}
20+
21+
if (!isVisible) {
22+
return null;
23+
}
24+
25+
return (
26+
<div className={styles.popup_menu}>
27+
<div className={styles.header}>
28+
<div className={styles.title}>{title}</div>
29+
<button className={styles.close} onClick={(e) => setIsVisible(false)}>
30+
<span aria-hidden className="fa fa-times"></span>
31+
</button>
32+
</div>
33+
<div className={styles.content}>
34+
<ul className={styles.ul}>
35+
{items.map((item, itemIndex) => (
36+
<li className={styles.li + (item.heading ? " " + styles.li_heading : "") + (item.indented ? " " + styles.li_indented : "")} key={"item-" + itemIndex}>
37+
{item.href ? (
38+
linkFactory(
39+
styles.a,
40+
item.href,
41+
(e) => setIsVisible(false),
42+
<>
43+
{item.icon && <span aria-hidden className={item.icon + " " + styles.icon}></span>} <span>{item.text}</span> {item.badge && <span className={styles.badge}>{item.badge}</span>}
44+
</>
45+
)
46+
) : item.onClick ? (
47+
<button className={styles.button} onClick={item.onClick}>
48+
{item.icon && <span aria-hidden className={item.icon + " " + styles.icon}></span>} <span>{item.text}</span> {item.badge && <span className={styles.badge}>{item.badge}</span>}
49+
</button>
50+
) : (
51+
<div className={styles.div}>
52+
{item.icon && <span aria-hidden className={item.icon + " " + styles.icon}></span>} <span>{item.text}</span> {item.badge && <span className={styles.badge}>{item.badge}</span>}
53+
</div>
54+
)}
55+
</li>
56+
))}
57+
</ul>
58+
</div>
59+
</div>
60+
);
61+
}

0 commit comments

Comments
 (0)