@ndlib/component-library 0.0.25 → 0.0.27

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.
@@ -8,3 +8,4 @@ export declare const TruncateHeadline: Story;
8
8
  export declare const Horizontal: Story;
9
9
  export declare const DateCards: Story;
10
10
  export declare const Clickable: Story;
11
+ export declare const Raised: Story;
@@ -11,7 +11,7 @@ const meta = {
11
11
  tags: ['autodocs'],
12
12
  };
13
13
  export default meta;
14
- const basicCards = [
14
+ const headlinedCards = [
15
15
  {
16
16
  headline: 'Exhibit — Printing the Nation: A Century of Irish Book Arts',
17
17
  image: 'https://images.ctfassets.net/cfblb1f7i85j/7aCd5Sm86JdtQepGBKDUfy/dcb4d97dd3a1d3ee810e8bcaa82dc715/Spring_Exhibit_2023-Rep.jpg?w=296',
@@ -23,6 +23,16 @@ const basicCards = [
23
23
  size: CARD_SIZE.SM,
24
24
  },
25
25
  ];
26
+ const basicCards = [
27
+ {
28
+ children: _jsx(Paragraph, { children: "Basic card 1" }),
29
+ size: CARD_SIZE.SM,
30
+ },
31
+ {
32
+ children: _jsx(Paragraph, { children: "Basic card 2" }),
33
+ size: CARD_SIZE.SM,
34
+ },
35
+ ];
26
36
  const dateCards = [
27
37
  {
28
38
  displayDate: new Date().toISOString(),
@@ -58,11 +68,11 @@ const horizontalCards = [
58
68
  },
59
69
  ];
60
70
  export const Default = {
61
- render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i })))) })),
71
+ render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i })))) })),
62
72
  args: {},
63
73
  };
64
74
  export const TruncateHeadline = {
65
- render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, truncateHeadlineAfter: 2 })))) })),
75
+ render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, truncateHeadlineAfter: 2 })))) })),
66
76
  args: {},
67
77
  };
68
78
  export const Horizontal = {
@@ -74,8 +84,12 @@ export const DateCards = {
74
84
  args: {},
75
85
  };
76
86
  export const Clickable = {
77
- render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { onClick: () => {
87
+ render: () => (_jsx(Column, { children: headlinedCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { onClick: () => {
78
88
  alert('Card clicked');
79
89
  }, key: i })))) })),
80
90
  args: {},
81
91
  };
92
+ export const Raised = {
93
+ render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { raised: true, key: i })))) })),
94
+ args: {},
95
+ };
@@ -16,7 +16,7 @@ type CardState = {
16
16
  };
17
17
  type CardChildren = React.ReactNode | ((state: CardState) => React.ReactNode);
18
18
  export type CardProps = StyledElementProps<HTMLDivElement, {
19
- headline: string;
19
+ headline?: string;
20
20
  truncateHeadlineAfter?: number;
21
21
  body?: React.ReactNode;
22
22
  image?: string;
@@ -24,6 +24,7 @@ export type CardProps = StyledElementProps<HTMLDivElement, {
24
24
  size?: CARD_SIZE;
25
25
  displayDate?: string;
26
26
  onClick?: () => void;
27
+ raised?: boolean;
27
28
  }, CardChildren>;
28
29
  export declare const Card: React.FC<CardProps>;
29
30
  export {};
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Heading } from '../../elements/text/Heading';
3
3
  import { ReadMore } from '../../elements/text/ReadMore';
4
+ import { useTheme } from '../../../theme';
4
5
  import { GROUP_TYPE, Group } from '../../elements/Group';
5
6
  import { Box } from '../../elements/layout/Box';
6
7
  import { Column, FONT, FONT_SIZE, Row, TYPOGRAPHY_TYPE } from '../../..';
@@ -50,7 +51,8 @@ const DateDisplay = ({ date: dateString }) => {
50
51
  mt: 1,
51
52
  } }, { children: MONTH_LABELS[date.getMonth()] }))] })));
52
53
  };
53
- export const Card = ({ size, displayDate, headline, image, layout, onClick, truncateHeadlineAfter, sx, children, }) => {
54
+ export const Card = ({ size, displayDate, headline, image, layout, onClick, raised, truncateHeadlineAfter, sx, children, }) => {
55
+ const theme = useTheme();
54
56
  const contentPaddingX = size === CARD_SIZE.SM ? 4 : 5;
55
57
  const bodyTopMargin = size === CARD_SIZE.SM ? 2 : 3;
56
58
  const isVertical = !layout || layout === CARD_LAYOUT.VERTICAL;
@@ -67,7 +69,7 @@ export const Card = ({ size, displayDate, headline, image, layout, onClick, trun
67
69
  if (onClick && e.key === KEY_CODES.ENTER) {
68
70
  onClick();
69
71
  }
70
- }, tabIndex: onClick ? 0 : undefined, sx: Object.assign({ width: isVertical ? '400px' : '100%', height: isVertical ? '350px' : '220px', borderBottom: 'solid 2px', borderColor: COLOR.TRANSPARENT, cursor: onClick ? 'pointer' : undefined, display: 'flex', flexDirection: layout === CARD_LAYOUT.HORIZONTAL ? 'row' : 'column', alignItems: 'flex-start', ':hover,:focus': {
72
+ }, tabIndex: onClick ? 0 : undefined, sx: Object.assign({ boxShadow: raised ? theme.boxShadow.EMPHASIZED : undefined, width: isVertical ? '400px' : '100%', height: isVertical ? '350px' : '220px', borderBottom: 'solid 2px', borderColor: COLOR.TRANSPARENT, cursor: onClick ? 'pointer' : undefined, display: 'flex', flexDirection: layout === CARD_LAYOUT.HORIZONTAL ? 'row' : 'column', alignItems: 'flex-start', ':hover,:focus': {
71
73
  transform: 'scale(1.01)',
72
74
  borderColor: COLOR.ND_SKY_BLUE_DARK,
73
75
  backgroundColor: COLOR.ND_SKY_BLUE,
@@ -0,0 +1,8 @@
1
+ import type { Meta, StoryObj } from '@storybook/react';
2
+ import { EmptyState } from '.';
3
+ declare const meta: Meta<typeof EmptyState>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof EmptyState>;
6
+ export declare const Default: Story;
7
+ export declare const CustomMessage: Story;
8
+ export declare const CustomIcon: Story;
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { EmptyState } from '.';
3
+ import NotInterestedIcon from '@mui/icons-material/NotInterested';
4
+ const meta = {
5
+ title: 'Composites/EmptyState',
6
+ component: EmptyState,
7
+ tags: ['autodocs'],
8
+ };
9
+ export default meta;
10
+ export const Default = {
11
+ render: () => _jsx(EmptyState, {}),
12
+ args: {},
13
+ };
14
+ export const CustomMessage = {
15
+ render: () => _jsx(EmptyState, { message: "Custom message" }),
16
+ args: {},
17
+ };
18
+ export const CustomIcon = {
19
+ render: () => _jsx(EmptyState, { message: "Custom icon", icon: NotInterestedIcon }),
20
+ args: {},
21
+ };
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { render } from '../../../utils/test';
3
+ import { EmptyState, DEFAULT_MESSAGE } from '.';
4
+ const TEST_MESSAGE = 'test message';
5
+ const MOCK_ICON_TEST_ID = 'mock-icon';
6
+ const MockIcon = () => _jsx("div", { "data-testid": MOCK_ICON_TEST_ID });
7
+ describe('EmptyState', () => {
8
+ it('renders passed message', () => {
9
+ const { getByText } = render(_jsx(EmptyState, { message: TEST_MESSAGE }));
10
+ expect(getByText(TEST_MESSAGE)).toBeDefined();
11
+ });
12
+ it('renders default message if no message passed', () => {
13
+ const { getByText } = render(_jsx(EmptyState, {}));
14
+ expect(getByText(DEFAULT_MESSAGE)).toBeDefined();
15
+ });
16
+ it('renders passed icon', () => {
17
+ const { getByTestId } = render(_jsx(EmptyState, { icon: MockIcon }));
18
+ expect(getByTestId(MOCK_ICON_TEST_ID)).toBeDefined();
19
+ });
20
+ });
@@ -0,0 +1,9 @@
1
+ import { StyledElementProps } from '../../../theme';
2
+ import React from 'react';
3
+ type EmptyStateProps = StyledElementProps<HTMLDivElement, {
4
+ icon?: React.FC;
5
+ message?: string;
6
+ }>;
7
+ export declare const DEFAULT_MESSAGE = "No results found.";
8
+ export declare const EmptyState: React.FC<EmptyStateProps>;
9
+ export {};
@@ -0,0 +1,24 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import SearchOffIcon from '@mui/icons-material/SearchOff';
14
+ import { Row } from '../../elements/layout/Row';
15
+ import { Column } from '../../elements/layout/Column';
16
+ import { PARAGRAPH_SIZE, Paragraph } from '../../elements/text/Paragraph';
17
+ import { COLOR } from '../../../theme/colors';
18
+ import { Icon } from '../../elements/Icon';
19
+ import { FONT_SIZE } from '../../../theme/typography';
20
+ export const DEFAULT_MESSAGE = 'No results found.';
21
+ export const EmptyState = (_a) => {
22
+ var { icon, message, sx } = _a, rest = __rest(_a, ["icon", "message", "sx"]);
23
+ return (_jsxs(Column, Object.assign({ sx: Object.assign(Object.assign({}, sx), { width: '100%', alignItems: 'center', justifyContent: 'center', mt: 5 }) }, rest, { children: [_jsx(Row, { children: _jsx(Icon, { icon: icon || SearchOffIcon, size: FONT_SIZE.XL, color: COLOR.LIGHT_GRAY }) }), _jsx(Row, Object.assign({ sx: { mt: 1 } }, { children: _jsx(Paragraph, Object.assign({ sx: { color: COLOR.LIGHT_GRAY }, size: PARAGRAPH_SIZE.LG }, { children: message || DEFAULT_MESSAGE })) }))] })));
24
+ };
@@ -14,7 +14,7 @@ import { useTheme } from '../../../../theme';
14
14
  export const Checkbox = (_a) => {
15
15
  var { checked, onChange, sx } = _a, rest = __rest(_a, ["checked", "onChange", "sx"]);
16
16
  const theme = useTheme();
17
- return (_jsx("input", Object.assign({ type: "checkbox", onClick: (e) => {
17
+ return (_jsx("input", Object.assign({ type: "checkbox", onChange: (e) => {
18
18
  onChange(e.target.checked);
19
19
  }, checked: checked, sx: Object.assign({ margin: '0px', height: '1.25rem', width: '1.25rem', cursor: 'pointer', ':hover': {
20
20
  boxShadow: theme.boxShadow,
@@ -31,5 +31,5 @@ export const CheckboxGroup = (_a) => {
31
31
  updatedSet.delete(option.value);
32
32
  }
33
33
  onChange(updatedSet);
34
- }, checked: !!(checkedOptions === null || checkedOptions === void 0 ? void 0 : checkedOptions.has(option.value)), id: labelTargetId, sx: { mr: 2 } }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM)) }, { children: option.label }))] }))) })))) })));
34
+ }, checked: !!(checkedOptions === null || checkedOptions === void 0 ? void 0 : checkedOptions.has(option.value)), id: labelTargetId, sx: { mr: 2 } }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM)) }, { children: option.label }))] }))) }), option.value))) })));
35
35
  };
@@ -24,5 +24,5 @@ export const RadioGroup = (_a) => {
24
24
  alignItems: 'center',
25
25
  } }, { children: [_jsx(Radio, { onChange: () => {
26
26
  onChange(option.value);
27
- }, checked: checked === option.value, id: labelTargetId, sx: { mr: 2 } }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM)) }, { children: option.label }))] }))) })))) })));
27
+ }, checked: checked === option.value, id: labelTargetId, sx: { mr: 2 } }), _jsx(Label, Object.assign({ sx: Object.assign({ cursor: 'pointer' }, getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM)) }, { children: option.label }))] }))) }), option.value))) })));
28
28
  };
@@ -10,7 +10,6 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx } from "theme-ui/jsx-runtime";
13
- import { useMediaQuery } from '../../../utils/hooks/useMediaQuery';
14
13
  // Putting shared utils and types here so autodocs can pick them up
15
14
  export const convertFlexHelperProps = (props) => {
16
15
  const styleObject = {};
@@ -40,8 +39,14 @@ export const convertFlexHelperProps = (props) => {
40
39
  };
41
40
  export const Row = (_a) => {
42
41
  var { sx, children, breakpoint: breakpointParam } = _a, rest = __rest(_a, ["sx", "children", "breakpoint"]);
43
- const { breakpoint } = useMediaQuery();
44
- const shouldRenderAsRow = breakpointParam !== undefined ? breakpoint > breakpointParam : true;
45
42
  const flexStyles = convertFlexHelperProps(rest);
46
- return (_jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign(Object.assign({}, flexStyles), sx), { display: 'flex', flexDirection: shouldRenderAsRow ? 'row' : 'column' }) }, { children: children })));
43
+ let flexDirection = 'row';
44
+ if (breakpointParam !== undefined) {
45
+ flexDirection = [];
46
+ for (let i = 0; i <= breakpointParam; i++) {
47
+ flexDirection.push('column');
48
+ }
49
+ flexDirection.push('row');
50
+ }
51
+ return (_jsx("div", Object.assign({}, rest, { sx: Object.assign(Object.assign(Object.assign({}, flexStyles), sx), { flexDirection, display: 'flex' }) }, { children: children })));
47
52
  };
package/dist/index.d.ts CHANGED
@@ -14,7 +14,6 @@ export { Box } from './components/elements/layout/Box';
14
14
  export { Column } from './components/elements/layout/Column';
15
15
  export { Row } from './components/elements/layout/Row';
16
16
  export { Link, LINK_SIZE } from './components/elements/Link';
17
- export { NavMenu } from './components/composites/NavMenu';
18
17
  export { INPUT_SIZE, TextInput } from './components/elements/Fields/TextInput';
19
18
  export { Select } from './components/elements/Fields/Select';
20
19
  export { DatePicker } from './components/elements/Fields/DatePicker';
@@ -29,6 +28,8 @@ export { Icon } from './components/elements/Icon';
29
28
  export { Spinner, SPINNER_SIZE } from './components/elements/Spinner';
30
29
  export { Pill, PILL_SIZE, PILL_TYPE } from './components/elements/Pill';
31
30
  export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
31
+ export { NavMenu } from './components/composites/NavMenu';
32
+ export { EmptyState } from './components/composites/EmptyState';
32
33
  export { UiProvider } from './components/providers/ui';
33
34
  export { MenuProvider, useMenu } from './components/providers/menu';
34
35
  export { useAlerts, AlertsProvider, ALERT_DOMAIN, } from './components/providers/alerts';
package/dist/index.js CHANGED
@@ -14,7 +14,6 @@ export { Box } from './components/elements/layout/Box';
14
14
  export { Column } from './components/elements/layout/Column';
15
15
  export { Row } from './components/elements/layout/Row';
16
16
  export { Link, LINK_SIZE } from './components/elements/Link';
17
- export { NavMenu } from './components/composites/NavMenu';
18
17
  export { INPUT_SIZE, TextInput } from './components/elements/Fields/TextInput';
19
18
  export { Select } from './components/elements/Fields/Select';
20
19
  export { DatePicker } from './components/elements/Fields/DatePicker';
@@ -29,6 +28,8 @@ export { Icon } from './components/elements/Icon';
29
28
  export { Spinner, SPINNER_SIZE } from './components/elements/Spinner';
30
29
  export { Pill, PILL_SIZE, PILL_TYPE } from './components/elements/Pill';
31
30
  export { Card, CARD_SIZE, CARD_LAYOUT } from './components/composites/Card';
31
+ export { NavMenu } from './components/composites/NavMenu';
32
+ export { EmptyState } from './components/composites/EmptyState';
32
33
  export { UiProvider } from './components/providers/ui';
33
34
  export { MenuProvider, useMenu } from './components/providers/menu';
34
35
  export { useAlerts, AlertsProvider, ALERT_DOMAIN, } from './components/providers/alerts';
@@ -1,3 +1,4 @@
1
1
  export declare enum BOX_SHADOW {
2
- NORMAL = "0 0 8px #dfdfdf"
2
+ NORMAL = "0 0 8px #dfdfdf",
3
+ EMPHASIZED = "0 0 12px #d3d3d3"
3
4
  }
@@ -2,4 +2,5 @@
2
2
  export var BOX_SHADOW;
3
3
  (function (BOX_SHADOW) {
4
4
  BOX_SHADOW["NORMAL"] = "0 0 8px #dfdfdf";
5
+ BOX_SHADOW["EMPHASIZED"] = "0 0 12px #d3d3d3";
5
6
  })(BOX_SHADOW || (BOX_SHADOW = {}));
@@ -1,4 +1,4 @@
1
1
  export declare const useMediaQuery: () => {
2
2
  screenSize: number;
3
- breakpoint: number;
3
+ breakpoint: number | undefined;
4
4
  };
@@ -2,7 +2,7 @@ import { useEffect, useState } from 'react';
2
2
  import { useTheme } from '../../theme';
3
3
  export const useMediaQuery = () => {
4
4
  const [screenSize, setScreenSize] = useState(typeof window !== 'undefined' ? window.innerWidth : 0);
5
- const [breakpoint, setBreakpoint] = useState(5);
5
+ const [breakpoint, setBreakpoint] = useState(undefined);
6
6
  const theme = useTheme();
7
7
  const breakpoints = theme.breakpoints.map((bp) => parseInt(bp.slice(0, -2)), [theme]);
8
8
  useEffect(() => {
@@ -17,6 +17,7 @@ export const useMediaQuery = () => {
17
17
  setScreenSize(screenSize);
18
18
  };
19
19
  window.addEventListener('resize', handleResize);
20
+ handleResize();
20
21
  return () => {
21
22
  window.removeEventListener('resize', handleResize);
22
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndlib/component-library",
3
- "version": "0.0.25",
3
+ "version": "0.0.27",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "files": [