@ilo-org/react 0.4.6 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @ilo-org/react
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 25c3bca99: feat(react): add breadcrumb as a new component
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [11801070b]
12
+ - Updated dependencies [1b942833b]
13
+ - @ilo-org/styles@0.3.5
14
+
3
15
  ## 0.4.6
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,37 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var require$$0 = require('react');
5
+ var hooks_useGlobalSettings = require('../../hooks/useGlobalSettings.js');
6
+ var classNames = require('classnames');
7
+ var components_ContextMenu_ContextMenu = require('../ContextMenu/ContextMenu.js');
8
+ require('tslib');
9
+ require('../../GlobalCtx-97e4b433.js');
10
+
11
+ const Breadcrumb = ({ home, links }) => {
12
+ const { prefix } = hooks_useGlobalSettings();
13
+ const [showContextMenu, enableContextMenu] = require$$0.useState(false);
14
+ const [toggleMenuOpen, setContextMenuToggleOpen] = require$$0.useState(false);
15
+ const handleScreenResize = () => {
16
+ enableContextMenu(window.innerWidth <= 1024); // turn on context menu when screen is resized to a smaller size
17
+ };
18
+ require$$0.useEffect(() => {
19
+ window.addEventListener("resize", handleScreenResize);
20
+ handleScreenResize();
21
+ return () => {
22
+ window.removeEventListener("resize", handleScreenResize);
23
+ };
24
+ }, []);
25
+ const handleContextMenuToggle = () => {
26
+ setContextMenuToggleOpen(!toggleMenuOpen);
27
+ };
28
+ const showContext = links.length > 4 || showContextMenu ? true : false;
29
+ const baseClass = `${prefix}--breadcrumb`;
30
+ const BreadcrumbClasses = classNames(baseClass);
31
+ const lastLink = links[links.length - 1];
32
+ const menuLinks = links.slice(0, -1);
33
+ return (jsxRuntime.jsx("nav", Object.assign({ className: `${BreadcrumbClasses} ${showContext ? " contextmenu" : ""}` }, { children: jsxRuntime.jsxs("ol", Object.assign({ className: `${baseClass}--items` }, { children: [jsxRuntime.jsx("li", Object.assign({ className: `${baseClass}--item home` }, { children: jsxRuntime.jsx("a", Object.assign({ className: `${baseClass}--link`, href: home.url }, { children: jsxRuntime.jsx("span", Object.assign({ className: `${baseClass}--link--label` }, { children: home.label })) })) })), jsxRuntime.jsx("li", Object.assign({ className: `${baseClass}--item--context`, onClick: handleContextMenuToggle }, { children: jsxRuntime.jsxs("ul", Object.assign({ className: `${baseClass}--items context--menu ${toggleMenuOpen ? " open" : ""}` }, { children: [showContext && jsxRuntime.jsx(components_ContextMenu_ContextMenu, { links: menuLinks }), !showContext &&
34
+ menuLinks.map((link, index) => (jsxRuntime.jsx("li", Object.assign({ className: `${baseClass}--item` }, { children: jsxRuntime.jsx("a", Object.assign({ href: link.url, className: `${baseClass}--link` }, { children: jsxRuntime.jsx("span", Object.assign({ className: `${baseClass}--link--label` }, { children: link.label })) })) }), index)))] })) })), jsxRuntime.jsx("li", Object.assign({ className: `${baseClass}--item final` }, { children: jsxRuntime.jsx("a", Object.assign({ className: `${baseClass}--link`, href: lastLink.url }, { children: jsxRuntime.jsx("span", Object.assign({ className: `${baseClass}--link--label` }, { children: lastLink.label })) })) }))] })) })));
35
+ };
36
+
37
+ module.exports = Breadcrumb;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var components_Breadcrumb_Breadcrumb = require('./Breadcrumb.js');
4
+ require('react/jsx-runtime');
5
+ require('react');
6
+ require('../../hooks/useGlobalSettings.js');
7
+ require('tslib');
8
+ require('../../GlobalCtx-97e4b433.js');
9
+ require('classnames');
10
+ require('../ContextMenu/ContextMenu.js');
11
+
12
+
13
+
14
+ exports.Breadcrumb = components_Breadcrumb_Breadcrumb;
@@ -55,6 +55,7 @@ var components_LocalNav_LocalNav = require('./LocalNav/LocalNav.js');
55
55
  var components_Navigation_Navigation = require('./Navigation/Navigation.js');
56
56
  var components_Card_Card = require('./Card/Card.js');
57
57
  var components_Card_CardGroup = require('./Card/CardGroup.js');
58
+ var components_Breadcrumb_Breadcrumb = require('./Breadcrumb/Breadcrumb.js');
58
59
  require('../hooks/useGlobalSettings.js');
59
60
  require('../AccordionCtx-fe08ff45.js');
60
61
  require('@ilo-org/utils');
@@ -123,3 +124,4 @@ exports.LocalNav = components_LocalNav_LocalNav;
123
124
  exports.Navigation = components_Navigation_Navigation;
124
125
  exports.Card = components_Card_Card;
125
126
  exports.CardGroup = components_Card_CardGroup;
127
+ exports.Breadcrumb = components_Breadcrumb_Breadcrumb;
package/lib/cjs/index.js CHANGED
@@ -55,6 +55,7 @@ var components_LocalNav_LocalNav = require('./components/LocalNav/LocalNav.js');
55
55
  var components_Navigation_Navigation = require('./components/Navigation/Navigation.js');
56
56
  var components_Card_Card = require('./components/Card/Card.js');
57
57
  var components_Card_CardGroup = require('./components/Card/CardGroup.js');
58
+ var components_Breadcrumb_Breadcrumb = require('./components/Breadcrumb/Breadcrumb.js');
58
59
  require('./hooks/useGlobalSettings.js');
59
60
  require('./AccordionCtx-fe08ff45.js');
60
61
  require('@ilo-org/utils');
@@ -123,3 +124,4 @@ exports.LocalNav = components_LocalNav_LocalNav;
123
124
  exports.Navigation = components_Navigation_Navigation;
124
125
  exports.Card = components_Card_Card;
125
126
  exports.CardGroup = components_Card_CardGroup;
127
+ exports.Breadcrumb = components_Breadcrumb_Breadcrumb;
@@ -0,0 +1,35 @@
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
+ import { useState, useEffect } from 'react';
3
+ import useGlobalSettings from '../../hooks/useGlobalSettings.js';
4
+ import classNames from 'classnames';
5
+ import ContextMenu from '../ContextMenu/ContextMenu.js';
6
+ import 'tslib';
7
+ import '../../GlobalCtx-7fb23cfa.js';
8
+
9
+ const Breadcrumb = ({ home, links }) => {
10
+ const { prefix } = useGlobalSettings();
11
+ const [showContextMenu, enableContextMenu] = useState(false);
12
+ const [toggleMenuOpen, setContextMenuToggleOpen] = useState(false);
13
+ const handleScreenResize = () => {
14
+ enableContextMenu(window.innerWidth <= 1024); // turn on context menu when screen is resized to a smaller size
15
+ };
16
+ useEffect(() => {
17
+ window.addEventListener("resize", handleScreenResize);
18
+ handleScreenResize();
19
+ return () => {
20
+ window.removeEventListener("resize", handleScreenResize);
21
+ };
22
+ }, []);
23
+ const handleContextMenuToggle = () => {
24
+ setContextMenuToggleOpen(!toggleMenuOpen);
25
+ };
26
+ const showContext = links.length > 4 || showContextMenu ? true : false;
27
+ const baseClass = `${prefix}--breadcrumb`;
28
+ const BreadcrumbClasses = classNames(baseClass);
29
+ const lastLink = links[links.length - 1];
30
+ const menuLinks = links.slice(0, -1);
31
+ return (jsx("nav", Object.assign({ className: `${BreadcrumbClasses} ${showContext ? " contextmenu" : ""}` }, { children: jsxs("ol", Object.assign({ className: `${baseClass}--items` }, { children: [jsx("li", Object.assign({ className: `${baseClass}--item home` }, { children: jsx("a", Object.assign({ className: `${baseClass}--link`, href: home.url }, { children: jsx("span", Object.assign({ className: `${baseClass}--link--label` }, { children: home.label })) })) })), jsx("li", Object.assign({ className: `${baseClass}--item--context`, onClick: handleContextMenuToggle }, { children: jsxs("ul", Object.assign({ className: `${baseClass}--items context--menu ${toggleMenuOpen ? " open" : ""}` }, { children: [showContext && jsx(ContextMenu, { links: menuLinks }), !showContext &&
32
+ menuLinks.map((link, index) => (jsx("li", Object.assign({ className: `${baseClass}--item` }, { children: jsx("a", Object.assign({ href: link.url, className: `${baseClass}--link` }, { children: jsx("span", Object.assign({ className: `${baseClass}--link--label` }, { children: link.label })) })) }), index)))] })) })), jsx("li", Object.assign({ className: `${baseClass}--item final` }, { children: jsx("a", Object.assign({ className: `${baseClass}--link`, href: lastLink.url }, { children: jsx("span", Object.assign({ className: `${baseClass}--link--label` }, { children: lastLink.label })) })) }))] })) })));
33
+ };
34
+
35
+ export { Breadcrumb as default };
@@ -0,0 +1,8 @@
1
+ export { default as Breadcrumb } from './Breadcrumb.js';
2
+ import 'react/jsx-runtime';
3
+ import 'react';
4
+ import '../../hooks/useGlobalSettings.js';
5
+ import 'tslib';
6
+ import '../../GlobalCtx-7fb23cfa.js';
7
+ import 'classnames';
8
+ import '../ContextMenu/ContextMenu.js';
@@ -53,6 +53,7 @@ export { default as LocalNav } from './LocalNav/LocalNav.js';
53
53
  export { default as Navigation } from './Navigation/Navigation.js';
54
54
  export { default as Card } from './Card/Card.js';
55
55
  export { default as CardGroup } from './Card/CardGroup.js';
56
+ export { default as Breadcrumb } from './Breadcrumb/Breadcrumb.js';
56
57
  import '../hooks/useGlobalSettings.js';
57
58
  import '../AccordionCtx-8c051900.js';
58
59
  import '@ilo-org/utils';
package/lib/esm/index.js CHANGED
@@ -53,6 +53,7 @@ export { default as LocalNav } from './components/LocalNav/LocalNav.js';
53
53
  export { default as Navigation } from './components/Navigation/Navigation.js';
54
54
  export { default as Card } from './components/Card/Card.js';
55
55
  export { default as CardGroup } from './components/Card/CardGroup.js';
56
+ export { default as Breadcrumb } from './components/Breadcrumb/Breadcrumb.js';
56
57
  import './hooks/useGlobalSettings.js';
57
58
  import './AccordionCtx-8c051900.js';
58
59
  import '@ilo-org/utils';
@@ -0,0 +1,4 @@
1
+ import { FC } from "react";
2
+ import { BreadcrumbProps } from "./Breadcrumb.props";
3
+ declare const Breadcrumb: FC<BreadcrumbProps>;
4
+ export default Breadcrumb;
@@ -0,0 +1,11 @@
1
+ import { LinkProps } from "../LinkList/LinkList.props";
2
+ export interface BreadcrumbProps {
3
+ /**
4
+ * Specify the HOME link in the Breadcrumb
5
+ */
6
+ home: Required<LinkProps>;
7
+ /**
8
+ * Specify the links to be displayed in the Breadcrumb
9
+ */
10
+ links: Required<Array<LinkProps>>;
11
+ }
@@ -0,0 +1 @@
1
+ export { default as Breadcrumb } from "./Breadcrumb";
@@ -41,3 +41,4 @@ export { Footer } from "./Footer";
41
41
  export { LocalNav } from "./LocalNav";
42
42
  export { Navigation } from "./Navigation";
43
43
  export { Card, CardGroup } from "./Card";
44
+ export { Breadcrumb } from "./Breadcrumb";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ilo-org/react",
3
- "version": "0.4.6",
3
+ "version": "0.5.0",
4
4
  "description": "React components for the ILO's Design System",
5
5
  "keywords": [
6
6
  "ui_patterns",
@@ -75,7 +75,7 @@
75
75
  "@ilo-org/brand-assets": "0.1.0",
76
76
  "@ilo-org/fonts": "0.1.0",
77
77
  "@ilo-org/icons-react": "0.0.19",
78
- "@ilo-org/styles": "0.3.4",
78
+ "@ilo-org/styles": "0.3.5",
79
79
  "@ilo-org/themes": "0.1.15",
80
80
  "@ilo-org/utils": "0.0.11"
81
81
  },
@@ -0,0 +1,61 @@
1
+ import { BreadcrumbProps } from "./Breadcrumb.props";
2
+
3
+ const basic: BreadcrumbProps = {
4
+ home: {
5
+ indented: false,
6
+ label: "Home",
7
+ url: "/",
8
+ },
9
+ links: [
10
+ {
11
+ label: "Link One",
12
+ url: "https://www.ilo.org/",
13
+ },
14
+ {
15
+ label: "Link Two",
16
+ url: "https://www.ilo.org/",
17
+ },
18
+ {
19
+ label: "Link Three",
20
+ url: "https://www.ilo.org/",
21
+ },
22
+ {
23
+ label: "Link Four",
24
+ url: "https://www.ilo.org/",
25
+ },
26
+ ],
27
+ };
28
+
29
+ const fiveLinks: BreadcrumbProps = {
30
+ home: {
31
+ indented: false,
32
+ label: "Home",
33
+ url: "/",
34
+ },
35
+ links: [
36
+ {
37
+ label: "Link One",
38
+ url: "https://www.ilo.org/",
39
+ },
40
+ {
41
+ label: "Link Two",
42
+ url: "https://www.ilo.org/",
43
+ },
44
+ {
45
+ label: "Link Three",
46
+ url: "https://www.ilo.org/",
47
+ },
48
+ {
49
+ label: "Link Four",
50
+ url: "https://www.ilo.org/",
51
+ },
52
+ {
53
+ label: "Link Five",
54
+ url: "https://www.ilo.org/",
55
+ },
56
+ ],
57
+ };
58
+
59
+ const BreadcrumbArgs = { basic, fiveLinks };
60
+
61
+ export default BreadcrumbArgs;
@@ -0,0 +1,13 @@
1
+ import { LinkProps } from "../LinkList/LinkList.props";
2
+
3
+ export interface BreadcrumbProps {
4
+ /**
5
+ * Specify the HOME link in the Breadcrumb
6
+ */
7
+ home: Required<LinkProps>;
8
+
9
+ /**
10
+ * Specify the links to be displayed in the Breadcrumb
11
+ */
12
+ links: Required<Array<LinkProps>>;
13
+ }
@@ -0,0 +1,82 @@
1
+ import { FC, useState, useEffect } from "react";
2
+ import useGlobalSettings from "../../hooks/useGlobalSettings";
3
+ import classnames from "classnames";
4
+ import { BreadcrumbProps } from "./Breadcrumb.props";
5
+ import { ContextMenu } from "../ContextMenu";
6
+
7
+ const Breadcrumb: FC<BreadcrumbProps> = ({ home, links }) => {
8
+ const { prefix } = useGlobalSettings();
9
+
10
+ const [showContextMenu, enableContextMenu] = useState(false);
11
+ const [toggleMenuOpen, setContextMenuToggleOpen] = useState(false);
12
+
13
+ const handleScreenResize = () => {
14
+ enableContextMenu(window.innerWidth <= 1024); // turn on context menu when screen is resized to a smaller size
15
+ };
16
+
17
+ useEffect(() => {
18
+ window.addEventListener("resize", handleScreenResize);
19
+ handleScreenResize();
20
+
21
+ return () => {
22
+ window.removeEventListener("resize", handleScreenResize);
23
+ };
24
+ }, []);
25
+
26
+ const handleContextMenuToggle = () => {
27
+ setContextMenuToggleOpen(!toggleMenuOpen);
28
+ };
29
+
30
+ const showContext = links.length > 4 || showContextMenu ? true : false;
31
+
32
+ const baseClass = `${prefix}--breadcrumb`;
33
+ const BreadcrumbClasses = classnames(baseClass);
34
+
35
+ const lastLink = links[links.length - 1];
36
+ const menuLinks = links.slice(0, -1);
37
+
38
+ return (
39
+ <nav
40
+ className={`${BreadcrumbClasses} ${showContext ? " contextmenu" : ""}`}
41
+ >
42
+ <ol className={`${baseClass}--items`}>
43
+ <li className={`${baseClass}--item home`}>
44
+ <a className={`${baseClass}--link`} href={home.url}>
45
+ <span className={`${baseClass}--link--label`}>{home.label}</span>
46
+ </a>
47
+ </li>
48
+ <li
49
+ className={`${baseClass}--item--context`}
50
+ onClick={handleContextMenuToggle}
51
+ >
52
+ <ul
53
+ className={`${baseClass}--items context--menu ${
54
+ toggleMenuOpen ? " open" : ""
55
+ }`}
56
+ >
57
+ {showContext && <ContextMenu links={menuLinks}></ContextMenu>}
58
+ {!showContext &&
59
+ menuLinks.map((link, index) => (
60
+ <li className={`${baseClass}--item`} key={index}>
61
+ <a href={link.url} className={`${baseClass}--link`}>
62
+ <span className={`${baseClass}--link--label`}>
63
+ {link.label}
64
+ </span>
65
+ </a>
66
+ </li>
67
+ ))}
68
+ </ul>
69
+ </li>
70
+ <li className={`${baseClass}--item final`}>
71
+ <a className={`${baseClass}--link`} href={lastLink.url}>
72
+ <span className={`${baseClass}--link--label`}>
73
+ {lastLink.label}
74
+ </span>
75
+ </a>
76
+ </li>
77
+ </ol>
78
+ </nav>
79
+ );
80
+ };
81
+
82
+ export default Breadcrumb;
@@ -0,0 +1 @@
1
+ export { default as Breadcrumb } from "./Breadcrumb";
@@ -46,3 +46,4 @@ export { Footer } from "./Footer";
46
46
  export { LocalNav } from "./LocalNav";
47
47
  export { Navigation } from "./Navigation";
48
48
  export { Card, CardGroup } from "./Card";
49
+ export { Breadcrumb } from "./Breadcrumb";