@ndlib/component-library 0.0.61 → 0.0.63

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.
@@ -4,4 +4,5 @@ declare const meta: Meta<typeof DropdownLinks>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof DropdownLinks>;
6
6
  export declare const Default: Story;
7
+ export declare const Right: Story;
7
8
  export declare const OpenInNewTab: Story;
@@ -3,6 +3,7 @@ import ArrowDropDownIcon from '@mui/icons-material/ArrowDropDown';
3
3
  import { DropdownLinks } from '.';
4
4
  import { Button } from '../../elements/Button';
5
5
  import { Box } from '../../elements/layout/Box';
6
+ import { Row } from '../../elements/layout/Row';
6
7
  const meta = {
7
8
  title: 'Composites/DropdownLinks',
8
9
  component: DropdownLinks,
@@ -11,11 +12,14 @@ const meta = {
11
12
  export default meta;
12
13
  const options = [
13
14
  { value: 'https://google.com', label: 'Google' },
14
- { value: 'https://facebook.com', label: 'Facebook' },
15
+ { value: 'https://facebook.com', label: 'This is intentionally long' },
15
16
  ];
16
17
  export const Default = {
17
18
  render: () => (_jsx(Box, Object.assign({ sx: { width: '200px', height: '200px' } }, { children: _jsx(DropdownLinks, Object.assign({ options: options }, { children: ({ anchorProps }) => (_jsx(Button, Object.assign({}, anchorProps, { rightIcon: ArrowDropDownIcon }, { children: "Links" }))) })) }))),
18
19
  };
20
+ export const Right = {
21
+ render: () => (_jsx(Row, Object.assign({ sx: { width: '90vw', height: '200px' }, justify: "flex-end" }, { children: _jsx(DropdownLinks, Object.assign({ options: options }, { children: ({ anchorProps }) => (_jsx(Button, Object.assign({}, anchorProps, { rightIcon: ArrowDropDownIcon }, { children: "Links" }))) })) }))),
22
+ };
19
23
  export const OpenInNewTab = {
20
24
  render: () => (_jsx(Box, Object.assign({ sx: { width: '200px', height: '200px' } }, { children: _jsx(DropdownLinks, Object.assign({ options: options, openNewTab: true }, { children: ({ anchorProps }) => _jsx(Button, Object.assign({}, anchorProps, { children: "Links" })) })) }))),
21
25
  };
@@ -11,5 +11,6 @@ type DropdownLinksProps = StyledElementProps<HTMLDivElement, {
11
11
  renderOption?: RenderOption<string, LinkOption>;
12
12
  openNewTab?: boolean;
13
13
  }, DropdownChildrenFn>;
14
+ export declare const Overlay: React.FC<StyledElementProps<HTMLDivElement>>;
14
15
  export declare const DropdownLinks: React.FC<DropdownLinksProps>;
15
16
  export {};
@@ -9,7 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { useCallback, useMemo, useState } from 'react';
14
14
  import { autoPlacement, offset, size, useFloating } from '@floating-ui/react';
15
15
  import { ListBox } from '../../elements/ListBox';
@@ -17,6 +17,15 @@ import { Link } from '../../elements/Link';
17
17
  import { Box } from '../../elements/layout/Box';
18
18
  import { useComponentConfig } from '../../providers/componentConfig';
19
19
  import { useUniqueId } from '../../providers/uniqueIds';
20
+ import { Z_INDEX } from '../../../theme/custom';
21
+ export const Overlay = (props) => (_jsx(Box, Object.assign({}, props, { sx: {
22
+ position: 'fixed',
23
+ top: 0,
24
+ left: 0,
25
+ width: '100vw',
26
+ height: '100vh',
27
+ zIndex: Z_INDEX.ELEVATED,
28
+ } })));
20
29
  export const DropdownLinks = (_a) => {
21
30
  var { children, options: optionsParam, renderOption: renderOptionParam, openNewTab, role = 'navigation' } = _a, rest = __rest(_a, ["children", "options", "renderOption", "openNewTab", "role"]);
22
31
  const [isOpen, setIsOpen] = useState(false);
@@ -51,7 +60,12 @@ export const DropdownLinks = (_a) => {
51
60
  },
52
61
  }),
53
62
  autoPlacement({
54
- allowedPlacements: ['top-start', 'bottom-start'],
63
+ allowedPlacements: [
64
+ 'top-start',
65
+ 'bottom-start',
66
+ 'top-end',
67
+ 'bottom-end',
68
+ ],
55
69
  }),
56
70
  ],
57
71
  });
@@ -69,5 +83,5 @@ export const DropdownLinks = (_a) => {
69
83
  return (_jsxs(Box, Object.assign({}, rest, { children: [children &&
70
84
  children({
71
85
  anchorProps: dropdownAnchorProps,
72
- }), isOpen && (_jsx(ListBox, { role: role, id: listboxId, options: options, ref: refs.setFloating, renderOption: renderOption, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { zIndex: 1 }) }))] })));
86
+ }), isOpen && (_jsxs(_Fragment, { children: [_jsx(ListBox, { role: role, id: listboxId, options: options, ref: refs.setFloating, renderOption: renderOption, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { zIndex: Z_INDEX.DIALOG }) }), _jsx(Overlay, { onClick: () => setIsOpen(false) })] }))] })));
73
87
  };
@@ -4,3 +4,6 @@ declare const meta: Meta<typeof Table>;
4
4
  export default meta;
5
5
  type Story = StoryObj<typeof Table>;
6
6
  export declare const Default: Story;
7
+ export declare const OmitColumn: Story;
8
+ export declare const ResponsiveColumn: Story;
9
+ export declare const ColumnGroup: Story;
@@ -40,3 +40,34 @@ export const Default = {
40
40
  width: '100px',
41
41
  } }, { children: (row) => row.age })), _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position }))] }))),
42
42
  };
43
+ export const OmitColumn = {
44
+ render: () => {
45
+ const someCondition = false;
46
+ return (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
47
+ width: '160px',
48
+ } }), someCondition ? (_jsx(TableColumn, Object.assign({ header: "Age", sx: {
49
+ width: '100px',
50
+ } }, { children: (row) => row.age }))) : null, _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position }))] })));
51
+ },
52
+ };
53
+ export const ResponsiveColumn = {
54
+ render: () => {
55
+ return (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
56
+ width: '160px',
57
+ } }), _jsx(TableColumn, Object.assign({ breakpoint: 2, header: "Age", sx: {
58
+ width: '100px',
59
+ } }, { children: (row) => row.age })), _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position }))] })));
60
+ },
61
+ };
62
+ export const ColumnGroup = {
63
+ render: () => {
64
+ return (_jsxs(Table, Object.assign({ data: data, alternateRowColor: true }, { children: [_jsx(TableColumn, { header: "Name", dataKey: "name", sx: {
65
+ width: '160px',
66
+ } }), [
67
+ _jsx(TableColumn, Object.assign({ header: "Age", sx: {
68
+ width: '100px',
69
+ } }, { children: (row) => row.age })),
70
+ _jsx(TableColumn, Object.assign({ header: "Occupation" }, { children: (row) => row.position })),
71
+ ]] })));
72
+ },
73
+ };
@@ -8,11 +8,13 @@ type ColumnProps<RowData extends object> = {
8
8
  align?: 'left' | 'center' | 'right';
9
9
  alignHeader?: 'left' | 'center' | 'right';
10
10
  children?: ColumnRenderFn<RowData>;
11
+ breakpoint?: number;
11
12
  sx?: StylesProp;
12
13
  };
14
+ type ChildList = ChildList[] | JSX.Element | null | undefined;
13
15
  type TableProps<RowData> = StyledElementProps<HTMLTableElement, {
14
16
  data: RowData[];
15
- children: JSX.Element[];
17
+ children: ChildList[];
16
18
  cellStyles?: StylesProp;
17
19
  alternateRowColor?: boolean;
18
20
  showRowDividers?: boolean;
@@ -3,10 +3,35 @@ import { useMemo } from 'react';
3
3
  import { COLOR } from '../../../theme/colors';
4
4
  import { useEnvironment } from '../../providers/env';
5
5
  import { TYPOGRAPHY_TYPE, typographyStyleMap } from '../../../theme/typography';
6
+ import { useMediaQuery } from '../../providers/media';
6
7
  const useColumnSpec = (children) => {
7
- const columnList = JSON.stringify(children.map((child) => child.props.header));
8
+ const headerList = [];
9
+ const parseHeaders = (children) => {
10
+ children.forEach((child) => {
11
+ if (Array.isArray(child)) {
12
+ parseHeaders(child);
13
+ }
14
+ else if (child) {
15
+ headerList.push(child.props.header);
16
+ }
17
+ });
18
+ };
19
+ parseHeaders(children);
20
+ const columnList = JSON.stringify(headerList);
8
21
  return useMemo(() => {
9
- return children.map((child) => child.props);
22
+ const columnProps = [];
23
+ const parseColumnProps = (children) => {
24
+ children.forEach((child) => {
25
+ if (Array.isArray(child)) {
26
+ parseColumnProps(child);
27
+ }
28
+ else if (child) {
29
+ columnProps.push(child.props);
30
+ }
31
+ });
32
+ };
33
+ parseColumnProps(children);
34
+ return columnProps;
10
35
  }, [columnList]);
11
36
  };
12
37
  export function TableColumn(props) {
@@ -19,6 +44,7 @@ export function Table(props) {
19
44
  const { role, data, alternateRowColor = true, cellStyles, sx, children, showRowDividers = true, showColumnDividers = false, } = props;
20
45
  const cellTypographyStyles = typographyStyleMap[TYPOGRAPHY_TYPE.CONDENSED_TEXT_MEDIUM];
21
46
  const headerTypographyStyles = typographyStyleMap[TYPOGRAPHY_TYPE.CONTROL_MEDIUM];
47
+ const { breakpoint } = useMediaQuery();
22
48
  const columnSpec = useColumnSpec(children);
23
49
  const getCellStyles = (params) => {
24
50
  const { columnProps, rowIndex, columnIndex } = params;
@@ -32,9 +58,15 @@ export function Table(props) {
32
58
  };
33
59
  return (_jsxs("table", Object.assign({ role: role, sx: sx }, { children: [_jsx("thead", Object.assign({ role: "rowgroup" }, { children: _jsx("tr", { children: columnSpec.map((column, i) => {
34
60
  const isLastColumn = i === columnSpec.length - 1;
61
+ if (column.breakpoint && breakpoint < column.breakpoint) {
62
+ return null;
63
+ }
35
64
  return (_jsx("th", Object.assign({ role: "columnheader", sx: Object.assign(Object.assign({ textAlign: column.alignHeader || column.align || 'left', borderBottom: '1px solid', borderRight: showColumnDividers && !isLastColumn ? '1px solid' : 'none', borderColor: COLOR.LIGHT_GRAY, px: 3, pb: 1 }, headerTypographyStyles), column.headerStyles) }, { children: column.header }), i));
36
65
  }) }) })), _jsx("tbody", Object.assign({ role: "rowgroup" }, { children: data.map((rowData, rowIndex) => {
37
66
  return (_jsx("tr", Object.assign({ role: "row" }, { children: columnSpec.map((column, columnIndex) => {
67
+ if (column.breakpoint && breakpoint < column.breakpoint) {
68
+ return null;
69
+ }
38
70
  const { children, dataKey } = column;
39
71
  const cellStyles = getCellStyles({
40
72
  columnProps: column,
package/dist/index.d.ts CHANGED
@@ -43,7 +43,7 @@ export { StructuredData } from './components/composites/StructuredData';
43
43
  export { UiProvider } from './components/providers/ui';
44
44
  export { MenuProvider, useMenu } from './components/providers/menu';
45
45
  export { SnackBarProvider, useSnackBar } from './components/providers/snackBar';
46
- export { useAlerts, AlertsProvider, ALERT_DOMAIN, } from './components/providers/alerts';
46
+ export { useAlerts, AlertsProvider, ALERT_TYPE, ALERT_DOMAIN, } from './components/providers/alerts';
47
47
  export { MediaSizeProvider, useMediaQuery } from './components/providers/media';
48
48
  export { DialogsProvider, useDialog } from './components/providers/dialogs';
49
49
  export { useUniqueId } from './components/providers/uniqueIds';
package/dist/index.js CHANGED
@@ -42,7 +42,7 @@ export { StructuredData } from './components/composites/StructuredData';
42
42
  export { UiProvider } from './components/providers/ui';
43
43
  export { MenuProvider, useMenu } from './components/providers/menu';
44
44
  export { SnackBarProvider, useSnackBar } from './components/providers/snackBar';
45
- export { useAlerts, AlertsProvider, ALERT_DOMAIN, } from './components/providers/alerts';
45
+ export { useAlerts, AlertsProvider, ALERT_TYPE, ALERT_DOMAIN, } from './components/providers/alerts';
46
46
  export { MediaSizeProvider, useMediaQuery } from './components/providers/media';
47
47
  export { DialogsProvider, useDialog } from './components/providers/dialogs';
48
48
  export { useUniqueId } from './components/providers/uniqueIds';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "0.0.61",
3
+ "version": "0.0.63",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [