@ndlib/component-library 1.0.43 → 1.0.45

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.
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { DropdownLinksV2 } from '.';
3
+ declare const meta: Meta<typeof DropdownLinksV2>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof DropdownLinksV2>;
6
+ export declare const Default: Story;
7
+ export declare const Right: Story;
8
+ export declare const OpenInNewTab: Story;
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
3
+ import { DropdownLinksV2 } from '.';
4
+ import { ButtonV2 } from '../../elements/ButtonV2';
5
+ import { BoxV2 } from '../../elements/BoxV2';
6
+ import { RowV2 } from '../../elements/RowV2';
7
+ import { UIVersion2 } from '../../../utils/decorators/UIVersion2';
8
+ const meta = {
9
+ title: 'Composites/DropdownLinksV2',
10
+ component: DropdownLinksV2,
11
+ tags: ['autodocs'],
12
+ decorators: [UIVersion2],
13
+ };
14
+ export default meta;
15
+ const options = [
16
+ { value: 'https://google.com', label: 'Google' },
17
+ { value: 'https://facebook.com', label: 'This is intentionally long' },
18
+ ];
19
+ export const Default = {
20
+ render: () => (_jsx(BoxV2, Object.assign({ sx: { width: '200px', height: '200px' } }, { children: _jsx(DropdownLinksV2, Object.assign({ options: options }, { children: ({ anchorProps }) => (_jsx(ButtonV2, Object.assign({}, anchorProps, { rightIcon: ArrowDropDownIcon }, { children: "Links" }))) })) }))),
21
+ };
22
+ export const Right = {
23
+ render: () => (_jsx(RowV2, Object.assign({ sx: { width: '90vw', height: '200px' }, justify: "flex-end" }, { children: _jsx(DropdownLinksV2, Object.assign({ options: options }, { children: ({ anchorProps }) => (_jsx(ButtonV2, Object.assign({}, anchorProps, { rightIcon: ArrowDropDownIcon }, { children: "Links" }))) })) }))),
24
+ };
25
+ export const OpenInNewTab = {
26
+ render: () => (_jsx(BoxV2, Object.assign({ sx: { width: '200px', height: '200px' } }, { children: _jsx(DropdownLinksV2, Object.assign({ options: options, openNewTab: true }, { children: ({ anchorProps }) => _jsx(ButtonV2, Object.assign({}, anchorProps, { children: "Links" })) })) }))),
27
+ };
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { BasicOption, RenderOption } from '../../elements/option';
3
+ import { StyledElementPropsV2 } from '../../../theme';
4
+ type AnchorProps = Omit<React.HTMLAttributes<HTMLButtonElement>, 'color'>;
5
+ type LinkOption = BasicOption<string>;
6
+ type DropdownChildrenFn = (params: {
7
+ anchorProps: AnchorProps;
8
+ }) => React.ReactNode;
9
+ type DropdownLinksV2Props = StyledElementPropsV2<HTMLDivElement, {
10
+ options: BasicOption<string>[];
11
+ renderOption?: RenderOption<string, LinkOption>;
12
+ openNewTab?: boolean;
13
+ }, DropdownChildrenFn>;
14
+ export declare const DropdownLinksV2: React.FC<DropdownLinksV2Props>;
15
+ export {};
@@ -0,0 +1,27 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ListBoxV2 } from '../../elements/ListBoxV2';
3
+ import { useComponentConfigV2 } from '../../providers/componentConfigV2';
4
+ import { DropdownV2 } from '../../elements/DropdownV2';
5
+ export const DropdownLinksV2 = ({ children, options: optionsParam, renderOption: renderOptionParam, openNewTab, role = 'navigation', }) => {
6
+ const { navigate } = useComponentConfigV2().link;
7
+ const renderOption = renderOptionParam
8
+ ? renderOptionParam
9
+ : (params) => (_jsx("a", Object.assign({ href: params.option.value, target: openNewTab ? '_blank' : undefined, style: { textDecoration: 'none', fontWeight: 700 }, onClick: (e) => {
10
+ e.preventDefault();
11
+ } }, { children: params.option.label })));
12
+ return (_jsx(DropdownV2, { shouldRenderDropdownContainer: false, renderAnchor: children, renderDropdown: ({ ref, styles, id, setIsOpen }) => {
13
+ const options = optionsParam.map((option) => (Object.assign(Object.assign({}, option), { onClick: () => {
14
+ if (option.onClick) {
15
+ option.onClick();
16
+ }
17
+ else if (openNewTab) {
18
+ window.open(option.value, '_blank');
19
+ }
20
+ else {
21
+ navigate(option.value);
22
+ }
23
+ setIsOpen(false);
24
+ } })));
25
+ return (_jsx(ListBoxV2, { role: role, id: id, options: options, ref: ref, renderOption: renderOption, style: styles }));
26
+ } }));
27
+ };
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { StyledElementPropsV2 } from '../../../theme';
3
+ type NavMenuV2Props = StyledElementPropsV2<HTMLDivElement>;
4
+ export declare const NavMenuV2: React.FC<NavMenuV2Props>;
5
+ export {};
@@ -46,7 +46,7 @@ export const NavMenuV2 = (props) => {
46
46
  const leafMenuItems = submenuItem.action.submenu.items;
47
47
  const submenuPath = [topLevelMenuId, submenuItem.id];
48
48
  const link = '//' + document.location.host + topLevelMenuId;
49
- const category = topLevelMenuId.charAt(1).toUpperCase() + topLevelMenuId.slice(2);
49
+ const category = topLevelMenuId.charAt(0).toUpperCase() + topLevelMenuId.slice(1);
50
50
  return (_jsxs(ColumnV2, Object.assign({ className: typeSafeStyles.submenuCol }, { children: [_jsx("div", Object.assign({}, getPropsWithoutStyle(() => getMenuItemProps(submenuPath)), { children: _jsx(HeadingV2, Object.assign({ standalone: true, size: HEADINGV2_SIZE.SM, underline: true }, { children: submenuItem.label })) })), _jsx(ListV2, Object.assign({}, getPropsWithoutStyle(() => getMenuProps(submenuPath)), { icon: ChevronRightIcon, iconSize: FONT_SIZE.MS }, { children: leafMenuItems.map((leafMenuItem, i) => {
51
51
  var _a;
52
52
  const leafMenuPath = submenuPath.concat(leafMenuItem.id);
package/dist/index.d.ts CHANGED
@@ -67,9 +67,10 @@ export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
67
67
  export { CardV2, CARDV2_SIZE, CARDV2_LAYOUT, } from './components/composites/CardV2';
68
68
  export { SnackBar } from './components/composites/SnackBar';
69
69
  export { NavMenu } from './components/composites/NavMenu';
70
- export { NavMenuV2 } from './components/composites/NavMenu2';
70
+ export { NavMenuV2 } from './components/composites/NavMenuV2';
71
71
  export { EmptyState, EMPTY_STATE_SIZE, } from './components/composites/EmptyState';
72
72
  export { DropdownLinks } from './components/composites/DropdownLinks';
73
+ export { DropdownLinksV2 } from './components/composites/DropdownLinksV2';
73
74
  export { Modal } from './components/composites/Modal';
74
75
  export { ModalV2 } from './components/composites/ModalV2';
75
76
  export { DragDropList, DragHandle } from './components/composites/DragDropList';
package/dist/index.js CHANGED
@@ -66,9 +66,10 @@ export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
66
66
  export { CardV2, CARDV2_SIZE, CARDV2_LAYOUT, } from './components/composites/CardV2';
67
67
  export { SnackBar } from './components/composites/SnackBar';
68
68
  export { NavMenu } from './components/composites/NavMenu';
69
- export { NavMenuV2 } from './components/composites/NavMenu2';
69
+ export { NavMenuV2 } from './components/composites/NavMenuV2';
70
70
  export { EmptyState, EMPTY_STATE_SIZE, } from './components/composites/EmptyState';
71
71
  export { DropdownLinks } from './components/composites/DropdownLinks';
72
+ export { DropdownLinksV2 } from './components/composites/DropdownLinksV2';
72
73
  export { Modal } from './components/composites/Modal';
73
74
  export { ModalV2 } from './components/composites/ModalV2';
74
75
  export { DragDropList, DragHandle } from './components/composites/DragDropList';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import { StyledElementPropsV2 } from '../../../theme';
3
- type NavMenu2Props = StyledElementPropsV2<HTMLDivElement>;
4
- export declare const NavMenuV2: React.FC<NavMenu2Props>;
5
- export {};