@ndlib/component-library 0.0.31 → 0.0.33
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/dist/components/composites/Card/Card.stories.d.ts +2 -0
- package/dist/components/composites/Card/Card.stories.js +27 -0
- package/dist/components/composites/Card/Card.test.js +8 -0
- package/dist/components/composites/Card/index.d.ts +5 -1
- package/dist/components/composites/Card/index.js +16 -11
- package/dist/components/composites/EmptyState/index.js +3 -1
- package/dist/components/elements/ArrowLink/ArrowLink.stories.d.ts +6 -0
- package/dist/components/elements/ArrowLink/ArrowLink.stories.js +12 -0
- package/dist/components/elements/ArrowLink/ArrowLink.test.d.ts +1 -0
- package/dist/components/elements/ArrowLink/ArrowLink.test.js +34 -0
- package/dist/components/elements/ArrowLink/index.d.ts +8 -0
- package/dist/components/elements/ArrowLink/index.js +39 -0
- package/dist/components/elements/Button/index.d.ts +1 -1
- package/dist/components/elements/Fields/AutoComplete/AutoComplete.stories.d.ts +6 -0
- package/dist/components/elements/Fields/AutoComplete/AutoComplete.stories.js +60 -0
- package/dist/components/elements/Fields/AutoComplete/index.d.ts +11 -0
- package/dist/components/elements/Fields/AutoComplete/index.js +26 -0
- package/dist/components/elements/Fields/Select/index.js +2 -2
- package/dist/components/elements/Fields/TextInput/index.d.ts +1 -1
- package/dist/components/elements/ListBox/index.d.ts +3 -3
- package/dist/components/elements/ListBox/index.js +1 -1
- package/dist/components/elements/Pill/index.d.ts +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/theme/colors.d.ts +1 -0
- package/dist/theme/colors.js +3 -1
- package/dist/theme/index.d.ts +3 -1
- package/package.json +1 -1
|
@@ -2,9 +2,11 @@ import { createElement as _createElement } from "react";
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import AccessTime from '@mui/icons-material/AccessTimeFilled';
|
|
4
4
|
import CalendarIcon from '@mui/icons-material/CalendarMonth';
|
|
5
|
+
import BookmarkIcon from '@mui/icons-material/Bookmark';
|
|
5
6
|
import { CARD_LAYOUT, CARD_SIZE, Card } from '.';
|
|
6
7
|
import { COLOR, Column, LABEL_SIZE, Label, Paragraph, ReadMore, TYPOGRAPHY_TYPE, } from '../../..';
|
|
7
8
|
import { Icon } from '../../elements/Icon';
|
|
9
|
+
import { BUTTON_TYPE, Button } from '../../elements/Button';
|
|
8
10
|
const meta = {
|
|
9
11
|
title: 'Composites/Card',
|
|
10
12
|
component: Card,
|
|
@@ -16,21 +18,33 @@ const headlinedCards = [
|
|
|
16
18
|
headline: 'Exhibit — Printing the Nation: A Century of Irish Book Arts',
|
|
17
19
|
image: 'https://images.ctfassets.net/cfblb1f7i85j/7aCd5Sm86JdtQepGBKDUfy/dcb4d97dd3a1d3ee810e8bcaa82dc715/Spring_Exhibit_2023-Rep.jpg?w=296',
|
|
18
20
|
size: CARD_SIZE.SM,
|
|
21
|
+
sx: {
|
|
22
|
+
width: '500px',
|
|
23
|
+
},
|
|
19
24
|
},
|
|
20
25
|
{
|
|
21
26
|
headline: 'One Book, One Michiana Digital Exhibit — Papers Alight: Contextualizing Mike Curato’s Flamer. Other text to make this longer than the other card.',
|
|
22
27
|
image: 'https://images.ctfassets.net/cfblb1f7i85j/2sGpdDbNkl6MPnlem6wq1R/995c786624613b5ff07228e481996385/One.Book.2023-Rep.png?w=296',
|
|
23
28
|
size: CARD_SIZE.SM,
|
|
29
|
+
sx: {
|
|
30
|
+
width: '500px',
|
|
31
|
+
},
|
|
24
32
|
},
|
|
25
33
|
];
|
|
26
34
|
const basicCards = [
|
|
27
35
|
{
|
|
28
36
|
children: _jsx(Paragraph, { children: "Basic card 1" }),
|
|
29
37
|
size: CARD_SIZE.SM,
|
|
38
|
+
sx: {
|
|
39
|
+
width: '500px',
|
|
40
|
+
},
|
|
30
41
|
},
|
|
31
42
|
{
|
|
32
43
|
children: _jsx(Paragraph, { children: "Basic card 2" }),
|
|
33
44
|
size: CARD_SIZE.SM,
|
|
45
|
+
sx: {
|
|
46
|
+
width: '500px',
|
|
47
|
+
},
|
|
34
48
|
},
|
|
35
49
|
];
|
|
36
50
|
const dateCards = [
|
|
@@ -93,3 +107,16 @@ export const Raised = {
|
|
|
93
107
|
render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { raised: true, key: i })))) })),
|
|
94
108
|
args: {},
|
|
95
109
|
};
|
|
110
|
+
export const Heading = {
|
|
111
|
+
render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, heading: "Heading", headingIcon: BookmarkIcon, headingAction: _jsx(Button, Object.assign({ type: BUTTON_TYPE.TEXT, color: COLOR.WHITE, onClick: () => { } }, { children: "Click Me" })) })))) })),
|
|
112
|
+
args: {},
|
|
113
|
+
};
|
|
114
|
+
export const CustomImageHeading = {
|
|
115
|
+
render: () => (_jsx(Column, { children: basicCards.map((props, i) => (_createElement(Card, Object.assign({}, props, { key: i, heading: "Heading", headingStyles: {
|
|
116
|
+
backgroundImage: `url(https://library.nd.edu/static/media/jesus.2.4a2b137e.png)`,
|
|
117
|
+
backgroundRepeat: 'no-repeat',
|
|
118
|
+
backgroundPositionX: 'right',
|
|
119
|
+
backgrounndPositionY: '-15px',
|
|
120
|
+
} })))) })),
|
|
121
|
+
args: {},
|
|
122
|
+
};
|
|
@@ -26,4 +26,12 @@ describe('Card', () => {
|
|
|
26
26
|
});
|
|
27
27
|
expect(mockClickHandler).toBeCalledTimes(2);
|
|
28
28
|
});
|
|
29
|
+
it('labels card with headline when passed', () => {
|
|
30
|
+
const { getByLabelText } = render(_jsx(Card, { headline: MOCK_HEADLINE }));
|
|
31
|
+
expect(getByLabelText(MOCK_HEADLINE)).toBeDefined();
|
|
32
|
+
});
|
|
33
|
+
it('labels card with heading when passed', () => {
|
|
34
|
+
const { getByLabelText } = render(_jsx(Card, { heading: MOCK_HEADLINE }));
|
|
35
|
+
expect(getByLabelText(MOCK_HEADLINE)).toBeDefined();
|
|
36
|
+
});
|
|
29
37
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StyledElementProps } from '../../../theme';
|
|
1
|
+
import { StyledElementProps, StylesProp } from '../../../theme';
|
|
2
2
|
import { COLOR } from '../../../theme/colors';
|
|
3
3
|
import React from 'react';
|
|
4
4
|
export declare enum CARD_LAYOUT {
|
|
@@ -17,6 +17,10 @@ type CardState = {
|
|
|
17
17
|
type CardChildren = React.ReactNode | ((state: CardState) => React.ReactNode);
|
|
18
18
|
export type CardProps = StyledElementProps<HTMLDivElement, {
|
|
19
19
|
headline?: string;
|
|
20
|
+
heading?: string;
|
|
21
|
+
headingStyles?: StylesProp;
|
|
22
|
+
headingIcon?: React.FC;
|
|
23
|
+
headingAction?: React.ReactNode;
|
|
20
24
|
truncateHeadlineAfter?: number;
|
|
21
25
|
body?: React.ReactNode;
|
|
22
26
|
image?: string;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { Heading } from '../../elements/text/Heading';
|
|
2
|
+
import { HEADING_SIZE, Heading } from '../../elements/text/Heading';
|
|
3
3
|
import { ReadMore } from '../../elements/text/ReadMore';
|
|
4
4
|
import { useTheme } from '../../../theme';
|
|
5
5
|
import { GROUP_TYPE, Group } from '../../elements/Group';
|
|
6
6
|
import { Box } from '../../elements/layout/Box';
|
|
7
|
+
import { Icon } from '../../elements/Icon';
|
|
7
8
|
import { Column, FONT, FONT_SIZE, Row, TYPOGRAPHY_TYPE } from '../../..';
|
|
8
9
|
import { COLOR } from '../../../theme/colors';
|
|
9
10
|
import React, { useEffect, useState } from 'react';
|
|
@@ -51,10 +52,9 @@ const DateDisplay = ({ date: dateString }) => {
|
|
|
51
52
|
mt: 1,
|
|
52
53
|
} }, { children: MONTH_LABELS[date.getMonth()] }))] })));
|
|
53
54
|
};
|
|
54
|
-
export const Card = ({ size, displayDate, headline, image, layout, onClick, raised, truncateHeadlineAfter, sx, children, }) => {
|
|
55
|
+
export const Card = ({ size, displayDate, headline, image, layout, onClick, raised, truncateHeadlineAfter, heading, headingStyles, headingIcon, headingAction, sx, children, }) => {
|
|
55
56
|
const theme = useTheme();
|
|
56
|
-
const contentPaddingX = size === CARD_SIZE.SM ?
|
|
57
|
-
const bodyTopMargin = size === CARD_SIZE.SM ? 2 : 3;
|
|
57
|
+
const contentPaddingX = size === CARD_SIZE.SM ? 3 : 4;
|
|
58
58
|
const isVertical = !layout || layout === CARD_LAYOUT.VERTICAL;
|
|
59
59
|
const { isHovered, anchorElementProps } = useHover();
|
|
60
60
|
const [activeBackground, setActiveBackground] = useState(isHovered ? COLOR.ND_SKY_BLUE : COLOR.BACKGROUND);
|
|
@@ -65,18 +65,23 @@ export const Card = ({ size, displayDate, headline, image, layout, onClick, rais
|
|
|
65
65
|
const typography = size === CARD_SIZE.SM
|
|
66
66
|
? TYPOGRAPHY_TYPE.HEADLINE_SMALL
|
|
67
67
|
: TYPOGRAPHY_TYPE.HEADLINE_MEDIUM;
|
|
68
|
-
return (_jsxs(Group, Object.assign({}, anchorElementProps, { type: GROUP_TYPE.GROUP, role: onClick ? 'button' : 'group', onClick: onClick, onKeyDown: (e) => {
|
|
68
|
+
return (_jsxs(Group, Object.assign({}, anchorElementProps, { type: headline || heading ? GROUP_TYPE.REGION : GROUP_TYPE.GROUP, role: onClick ? 'button' : 'group', onClick: onClick, onKeyDown: (e) => {
|
|
69
69
|
if (onClick && e.key === KEY_CODES.ENTER) {
|
|
70
70
|
onClick();
|
|
71
71
|
}
|
|
72
|
-
}, tabIndex: onClick ? 0 : undefined, sx: Object.assign({ boxShadow: raised ? theme.boxShadow.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
}, tabIndex: onClick ? 0 : undefined, sx: Object.assign({ boxShadow: raised || heading ? theme.boxShadow.NORMAL : undefined, width: !isVertical && '100%', borderBottom: 'solid 2px', borderColor: COLOR.TRANSPARENT, cursor: onClick ? 'pointer' : undefined, display: 'flex', flexDirection: layout === CARD_LAYOUT.HORIZONTAL ? 'row' : 'column', alignItems: 'flex-start', ':hover,:focus': onClick
|
|
73
|
+
? {
|
|
74
|
+
transform: 'scale(1.01)',
|
|
75
|
+
borderColor: COLOR.ND_SKY_BLUE_DARK,
|
|
76
|
+
backgroundColor: COLOR.ND_SKY_BLUE,
|
|
77
|
+
}
|
|
78
|
+
: {} }, sx) }, { children: [image && (_jsx("img", { src: image, style: {
|
|
77
79
|
width: isVertical ? '100%' : 'auto',
|
|
78
80
|
height: isVertical ? 'auto' : '100%',
|
|
79
|
-
} })), displayDate && _jsx(DateDisplay, { date: displayDate }),
|
|
81
|
+
} })), displayDate && _jsx(DateDisplay, { date: displayDate }), heading && (_jsxs(Row, Object.assign({ sx: Object.assign({ bg: COLOR.PRIMARY, color: COLOR.WHITE, width: '100%', px: contentPaddingX, py: 3, justifyContent: 'space-between', alignItems: 'center' }, headingStyles) }, { children: [_jsxs(Row, { children: [headingIcon && (_jsx(Icon, { icon: headingIcon, size: FONT_SIZE.LG, color: COLOR.WHITE, sx: { mr: 2 } })), _jsx(Heading, Object.assign({ size: HEADING_SIZE.SM, sx: {
|
|
82
|
+
color: COLOR.WHITE,
|
|
83
|
+
whiteSpace: 'nowrap',
|
|
84
|
+
} }, { children: heading }))] }), _jsx(Row, { children: headingAction && headingAction })] }))), _jsx(Row, Object.assign({ sx: { px: contentPaddingX, py: contentPaddingY } }, { children: _jsxs(Column, Object.assign({ justify: "center" }, { children: [headline && (_jsx(Heading, Object.assign({ typography: typography, sx: { textAlign: 'justify' } }, { children: truncateHeadlineAfter ? (_jsx(ReadMore, Object.assign({ lines: truncateHeadlineAfter, typography: typography, sx: { bg: activeBackground } }, { children: headline }))) : (headline) }))), children && (_jsx(Box, Object.assign({ sx: { mt: headline && !heading ? 2 : 0 } }, { children: typeof children === 'function'
|
|
80
85
|
? children({ isHovered, activeBackground })
|
|
81
86
|
: children })))] })) }))] })));
|
|
82
87
|
};
|
|
@@ -10,13 +10,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
-
import
|
|
13
|
+
import _SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
14
14
|
import { Row } from '../../elements/layout/Row';
|
|
15
15
|
import { Column } from '../../elements/layout/Column';
|
|
16
16
|
import { PARAGRAPH_SIZE, Paragraph } from '../../elements/text/Paragraph';
|
|
17
17
|
import { COLOR } from '../../../theme/colors';
|
|
18
18
|
import { Icon } from '../../elements/Icon';
|
|
19
19
|
import { FONT_SIZE } from '../../../theme/typography';
|
|
20
|
+
import { importedDefaultComponentShim } from '../../../utils/misc';
|
|
21
|
+
const SearchOffIcon = importedDefaultComponentShim(_SearchOffIcon);
|
|
20
22
|
export const DEFAULT_MESSAGE = 'No results found.';
|
|
21
23
|
export const EmptyState = (_a) => {
|
|
22
24
|
var { icon, message, sx } = _a, rest = __rest(_a, ["icon", "message", "sx"]);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowLink } from '.';
|
|
3
|
+
import { Column } from '../layout/Column';
|
|
4
|
+
import { Box } from '../layout/Box';
|
|
5
|
+
const meta = {
|
|
6
|
+
title: 'Elements/ArrowLink',
|
|
7
|
+
component: ArrowLink,
|
|
8
|
+
};
|
|
9
|
+
export default meta;
|
|
10
|
+
export const Default = {
|
|
11
|
+
render: () => (_jsx(Column, { children: _jsx(Box, { children: _jsx(ArrowLink, Object.assign({ to: "/" }, { children: "Click Me" })) }) })),
|
|
12
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '../../../utils/test';
|
|
3
|
+
import { ArrowLink } from '.';
|
|
4
|
+
import { DefaultLink } from '../../providers/componentConfig';
|
|
5
|
+
const CUSTOM_INTERNAL_TEST_ID = 'internal-link-test-id';
|
|
6
|
+
const CUSTOM_EXTERNAL_TEST_ID = 'external-link-test-id';
|
|
7
|
+
const CustomInternalLink = (props) => {
|
|
8
|
+
return _jsx(DefaultLink, Object.assign({ "data-testid": CUSTOM_INTERNAL_TEST_ID }, props));
|
|
9
|
+
};
|
|
10
|
+
const CustomExternalLink = (props) => {
|
|
11
|
+
return _jsx(DefaultLink, Object.assign({ "data-testid": CUSTOM_EXTERNAL_TEST_ID }, props));
|
|
12
|
+
};
|
|
13
|
+
describe('ArrowLink', () => {
|
|
14
|
+
it('renders default external link component without throwing', () => {
|
|
15
|
+
const { getByRole } = render(_jsx(ArrowLink, Object.assign({ to: "https://google.com" }, { children: "Foo" })));
|
|
16
|
+
expect(getByRole('link')).toBeInTheDocument();
|
|
17
|
+
});
|
|
18
|
+
it('renders default internal link component without throwing', () => {
|
|
19
|
+
const { getByRole } = render(_jsx(ArrowLink, Object.assign({ to: "/test/path" }, { children: "Foo" })));
|
|
20
|
+
expect(getByRole('link')).toBeInTheDocument();
|
|
21
|
+
});
|
|
22
|
+
it('passes styles to custom component', () => {
|
|
23
|
+
const { getByTestId } = render(_jsxs(_Fragment, { children: [_jsx(ArrowLink, Object.assign({ to: "https://google.com", sx: { mt: 1 } }, { children: "Foo" })), _jsx(ArrowLink, Object.assign({ to: "/test/route", sx: { mt: 1 } }, { children: "Foo" }))] }), {
|
|
24
|
+
components: {
|
|
25
|
+
link: {
|
|
26
|
+
externalLinkComponent: CustomExternalLink,
|
|
27
|
+
internalLinkComponent: CustomInternalLink,
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
expect(getByTestId(CUSTOM_EXTERNAL_TEST_ID)).toHaveStyle(`margin-top: 0.25rem`);
|
|
32
|
+
expect(getByTestId(CUSTOM_INTERNAL_TEST_ID)).toHaveStyle(`margin-top: 0.25rem`);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/** @jsxImportSource theme-ui */
|
|
3
|
+
import { StyledElementProps } from '../../../theme';
|
|
4
|
+
type ArrowLinkProps = StyledElementProps<HTMLLinkElement, {
|
|
5
|
+
to: string;
|
|
6
|
+
}>;
|
|
7
|
+
export declare const ArrowLink: React.FC<ArrowLinkProps>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
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 "theme-ui/jsx-runtime";
|
|
13
|
+
import { COLOR } from '../../../theme/colors';
|
|
14
|
+
import { Link } from '../Link';
|
|
15
|
+
export const ArrowLink = (_a) => {
|
|
16
|
+
var { to, children, sx } = _a, rest = __rest(_a, ["to", "children", "sx"]);
|
|
17
|
+
return (_jsxs(Link, Object.assign({ to: to }, rest, { sx: Object.assign({ display: 'inline-flex', whiteSpace: 'nowrap', padding: 0, flexGrow: 0, position: 'relative', boxSizing: 'border-box', bg: COLOR.WHITE, color: COLOR.PRIMARY, ':hover': {
|
|
18
|
+
transform: 'scale(1.02)',
|
|
19
|
+
bg: COLOR.EXTRA_EXTRA_LIGHT_GRAY,
|
|
20
|
+
}, ':hover>svg': {
|
|
21
|
+
fill: COLOR.EXTRA_EXTRA_LIGHT_GRAY,
|
|
22
|
+
}, '>svg': {
|
|
23
|
+
fill: COLOR.WHITE,
|
|
24
|
+
} }, sx) }, { children: [_jsx("div", Object.assign({ sx: {
|
|
25
|
+
position: 'relative',
|
|
26
|
+
border: '1px solid #a7a7a7',
|
|
27
|
+
'border-width': '1px 0 2px 1px',
|
|
28
|
+
boxSizing: 'border-box',
|
|
29
|
+
padding: '0.125rem 1.5rem 0.125rem 0.5rem',
|
|
30
|
+
height: '100%',
|
|
31
|
+
flex: '1 1 auto',
|
|
32
|
+
} }, { children: children })), _jsxs("svg", Object.assign({ viewBox: "0 0 16 1", preserveAspectRatio: "none", sx: {
|
|
33
|
+
width: '16px',
|
|
34
|
+
right: '-16px',
|
|
35
|
+
top: '0px',
|
|
36
|
+
position: 'absolute',
|
|
37
|
+
height: '100%',
|
|
38
|
+
} }, { children: [_jsx("path", { d: "M0,0 0,0 16,0.5 0,1 0,1z" }), _jsx("line", { x1: "0", x2: "16", y1: "0", y2: "0.5", stroke: "#a7a7a7", strokeWidth: "0.05", strokeLinecap: "butt" }), _jsx("line", { x1: "0", x2: "16", y1: "1", y2: "0.5", stroke: "#a7a7a7", strokeWidth: "0.1", strokeLinecap: "butt" })] }))] })));
|
|
39
|
+
};
|
|
@@ -28,7 +28,7 @@ type ButtonProps = StyledElementProps<HTMLButtonElement, {
|
|
|
28
28
|
export declare const Button: React.ForwardRefExoticComponent<{
|
|
29
29
|
sx?: import("../../../theme").StylesProp | undefined;
|
|
30
30
|
children?: React.ReactNode;
|
|
31
|
-
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "children"> & {
|
|
31
|
+
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "children" | "onChange"> & {
|
|
32
32
|
size?: BUTTON_SIZE | undefined;
|
|
33
33
|
type?: BUTTON_TYPE | undefined;
|
|
34
34
|
color?: COLOR | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { AutoComplete } from '.';
|
|
3
|
+
import { Paragraph, PARAGRAPH_SIZE } from '../../text/Paragraph';
|
|
4
|
+
import { HEADING_SIZE, Heading } from '../../text/Heading';
|
|
5
|
+
import { Column } from '../../layout/Column';
|
|
6
|
+
import { Row } from '../../layout/Row';
|
|
7
|
+
const options = [
|
|
8
|
+
{
|
|
9
|
+
label: 'Cucumber',
|
|
10
|
+
value: 'Cucumber',
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
label: 'Egg Plant',
|
|
14
|
+
value: 'Egg Plant',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: 'Napa',
|
|
18
|
+
value: 'Napa',
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
label: 'Cabbage',
|
|
22
|
+
value: 'Cabbage',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
label: 'Broccoli',
|
|
26
|
+
value: 'Broccoli',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
label: 'Radish',
|
|
30
|
+
value: 'Radish',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: 'Cauliflower',
|
|
34
|
+
value: 'Cauliflower',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: 'Beet',
|
|
38
|
+
value: 'Beet',
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
label: 'Tomato',
|
|
42
|
+
value: 'Tomato',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
label: 'Zuchinni',
|
|
46
|
+
value: 'Zuchinni',
|
|
47
|
+
},
|
|
48
|
+
];
|
|
49
|
+
function onSelect() {
|
|
50
|
+
return console.log('clicked');
|
|
51
|
+
}
|
|
52
|
+
const meta = {
|
|
53
|
+
title: 'Elements/Fields/AutoComplete',
|
|
54
|
+
component: AutoComplete,
|
|
55
|
+
tags: ['autodocs'],
|
|
56
|
+
};
|
|
57
|
+
export default meta;
|
|
58
|
+
export const Default = {
|
|
59
|
+
render: () => (_jsx(_Fragment, { children: _jsx(Row, Object.assign({ justify: "space-between" }, { children: _jsxs(Column, { children: [_jsx(Heading, Object.assign({ size: HEADING_SIZE.LG }, { children: "Vegetables" })), _jsx("br", {}), _jsx(AutoComplete, { options: options, value: "cucumber", onSelect: onSelect }), _jsx("br", {}), _jsx(Paragraph, Object.assign({ size: PARAGRAPH_SIZE.LG }, { children: "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris ultrices venenatis purus at porta. Etiam congue sapien leo, sed malesuada justo commodo in. Nunc consequat, massa non cursus posuere, magna eros lacinia lectus, eget lobortis mi erat ut justo. Maecenas nisi mi, mollis sed ornare vitae, pharetra sed augue. Curabitur mollis orci risus, sed imperdiet nisi aliquet et. Ut non elit nec magna rhoncus maximus sit amet ut dui. Mauris sit amet eleifend lectus. Aliquam consectetur posuere libero eu ultricies. Etiam rutrum non orci nec vulputate. Sed vel accumsan diam. Cras aliquet eros eros, sit amet pharetra eros tincidunt ut. Vestibulum est erat, eleifend dapibus eros vel, elementum vehicula risus. Etiam blandit condimentum sodales. Donec non libero in orci aliquam egestas fringilla eget purus. Suspendisse pellentesque at ligula ut accumsan." }))] }) })) })),
|
|
60
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface Option {
|
|
2
|
+
label: string;
|
|
3
|
+
value: string;
|
|
4
|
+
}
|
|
5
|
+
interface AutoCompleteProps {
|
|
6
|
+
value: string;
|
|
7
|
+
options: Option[];
|
|
8
|
+
onSelect: (option: string) => any;
|
|
9
|
+
}
|
|
10
|
+
export declare const AutoComplete: ({ value, options, onSelect, }: AutoCompleteProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default AutoComplete;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { COLOR } from '../../../../theme/colors';
|
|
4
|
+
import { ListBox } from '../../ListBox';
|
|
5
|
+
import { TextInput } from '../../Fields/TextInput';
|
|
6
|
+
export const AutoComplete = ({ value, options, onSelect, }) => {
|
|
7
|
+
const [inputValue, setInputValue] = useState(value);
|
|
8
|
+
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
9
|
+
const [showOptions, setShowOptions] = useState(false);
|
|
10
|
+
const handleChange = (value) => {
|
|
11
|
+
setInputValue(value);
|
|
12
|
+
const newFilteredOptions = options.filter((option) => option.label.toLowerCase().includes(value.toLowerCase()));
|
|
13
|
+
setFilteredOptions(newFilteredOptions);
|
|
14
|
+
setShowOptions(true);
|
|
15
|
+
};
|
|
16
|
+
const handleSelect = (selectedOption) => {
|
|
17
|
+
setShowOptions(false);
|
|
18
|
+
setInputValue(selectedOption.label);
|
|
19
|
+
onSelect(selectedOption.value);
|
|
20
|
+
};
|
|
21
|
+
return (_jsxs("div", { children: [_jsx(TextInput, { value: inputValue, onChange: handleChange }), showOptions && (_jsx(ListBox, { options: filteredOptions, selectOption: handleSelect, sx: {
|
|
22
|
+
bg: COLOR.PRIMARY,
|
|
23
|
+
marginTop: 2,
|
|
24
|
+
} }))] }));
|
|
25
|
+
};
|
|
26
|
+
export default AutoComplete;
|
|
@@ -130,8 +130,8 @@ export function Select({ size: sizeParam, placeholder, leftIcon, value, onSelect
|
|
|
130
130
|
boxShadow: theme.boxShadow.NORMAL,
|
|
131
131
|
}, ':focus': {
|
|
132
132
|
boxShadow: theme.boxShadow.NORMAL,
|
|
133
|
-
} }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (
|
|
134
|
-
onSelectOption && onSelectOption(value);
|
|
133
|
+
} }, typographyStyles), sx), leftIcon: leftIcon, rightIcon: ArrowDropDownIcon }, { children: currentOption ? renderOptionLabel(currentOption) : placeholder })), isOpen && (_jsx(ListBox, { id: listboxId, options: options, selected: value, focused: stagedOptionValue, selectOption: (option) => {
|
|
134
|
+
onSelectOption && onSelectOption(option.value);
|
|
135
135
|
close();
|
|
136
136
|
}, ref: refs.setFloating, renderOption: renderOption, style: Object.assign(Object.assign({ minWidth: dropdownMinWidth }, floatingStyles), { zIndex: 1 }) }))] }));
|
|
137
137
|
}
|
|
@@ -17,7 +17,7 @@ export type TextInputProps = StyledElementProps<HTMLInputElement, {
|
|
|
17
17
|
export declare const TextInput: React.ForwardRefExoticComponent<{
|
|
18
18
|
sx?: import("../../../../theme").StylesProp | undefined;
|
|
19
19
|
children?: string | undefined;
|
|
20
|
-
} & Omit<React.HTMLAttributes<HTMLInputElement>, "children"> & {
|
|
20
|
+
} & Omit<React.HTMLAttributes<HTMLInputElement>, "children" | "onChange"> & {
|
|
21
21
|
size?: INPUT_SIZE | undefined;
|
|
22
22
|
leftIcon?: React.FC<any> | undefined;
|
|
23
23
|
inline?: boolean | undefined;
|
|
@@ -7,7 +7,7 @@ type ListBoxProps<Value extends Key, Option extends BasicOption<Value>> = Styled
|
|
|
7
7
|
renderOption?: RenderOption<Value, Option>;
|
|
8
8
|
selected?: Value;
|
|
9
9
|
focused?: Value;
|
|
10
|
-
selectOption?: (
|
|
10
|
+
selectOption?: (option: Option) => void;
|
|
11
11
|
onDownPress?: () => void;
|
|
12
12
|
onUpPress?: () => void;
|
|
13
13
|
onSelect?: () => void;
|
|
@@ -16,12 +16,12 @@ type ListBoxProps<Value extends Key, Option extends BasicOption<Value>> = Styled
|
|
|
16
16
|
export declare const ListBox: <Value extends React.Key = string, Option extends BasicOption<Value> = any>(props: {
|
|
17
17
|
sx?: import("../../../theme").StylesProp | undefined;
|
|
18
18
|
children?: React.ReactNode;
|
|
19
|
-
} & Omit<React.HTMLAttributes<HTMLDivElement>, "children"> & {
|
|
19
|
+
} & Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> & {
|
|
20
20
|
options: Option[];
|
|
21
21
|
renderOption?: RenderOption<Value, Option> | undefined;
|
|
22
22
|
selected?: Value | undefined;
|
|
23
23
|
focused?: Value | undefined;
|
|
24
|
-
selectOption?: ((
|
|
24
|
+
selectOption?: ((option: Option) => void) | undefined;
|
|
25
25
|
onDownPress?: (() => void) | undefined;
|
|
26
26
|
onUpPress?: (() => void) | undefined;
|
|
27
27
|
onSelect?: (() => void) | undefined;
|
|
@@ -21,7 +21,7 @@ function ListBoxInner(_a, ref) {
|
|
|
21
21
|
const typography = getTypographyStyles(TYPOGRAPHY_TYPE.PARAGRAPH_MEDIUM);
|
|
22
22
|
return (_jsx("div", Object.assign({ role: "listbox", ref: ref, sx: Object.assign(Object.assign({ border: 'solid 1px', borderRadius: '4px', borderColor: COLOR.LIGHT_GRAY, backgroundColor: COLOR.BACKGROUND, boxShadow: '0px 0px 8px 2px #dddddd' }, typography), sx), onKeyDown: (e) => {
|
|
23
23
|
console.log(e);
|
|
24
|
-
} }, rest, { children: options.map((option) => (_jsx("div", Object.assign({ id: getOptionId(option.value), "aria-selected": selected === option.value, role: "option", onClick: option.onClick, onMouseDown: () => selectOption && selectOption(option
|
|
24
|
+
} }, rest, { children: options.map((option) => (_jsx("div", Object.assign({ id: getOptionId(option.value), "aria-selected": selected === option.value, role: "option", onClick: option.onClick, onMouseDown: () => selectOption && selectOption(option), sx: {
|
|
25
25
|
px: 4,
|
|
26
26
|
py: 3,
|
|
27
27
|
backgroundColor: focused === option.value
|
|
@@ -12,7 +12,7 @@ export declare enum PILL_TYPE {
|
|
|
12
12
|
export declare const Pill: React.ForwardRefExoticComponent<{
|
|
13
13
|
sx?: import("../../../theme").StylesProp | undefined;
|
|
14
14
|
children?: React.ReactNode;
|
|
15
|
-
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "children"> & {
|
|
15
|
+
} & Omit<React.HTMLAttributes<HTMLButtonElement>, "children" | "onChange"> & {
|
|
16
16
|
size?: PILL_SIZE | undefined;
|
|
17
17
|
type?: PILL_TYPE | undefined;
|
|
18
18
|
color?: COLOR | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export { COLOR } from './theme/colors';
|
|
|
3
3
|
export { TYPOGRAPHY_TYPE, FONT, FONT_SIZE, FONT_WEIGHT, LINE_HEIGHT, } from './theme/typography';
|
|
4
4
|
export { GlobalStyles } from './theme/GlobalStyles';
|
|
5
5
|
export { Alert, Alerts } from './components/elements/Alerts';
|
|
6
|
+
export { ArrowLink } from './components/elements/ArrowLink';
|
|
6
7
|
export { BrandingBar } from './components/elements/BrandingBar';
|
|
7
8
|
export { Button, BUTTON_SIZE, BUTTON_TYPE, LinkButton, } from './components/elements/Button';
|
|
8
9
|
export { Heading, HEADING_SIZE } from './components/elements/text/Heading';
|
package/dist/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { COLOR } from './theme/colors';
|
|
|
3
3
|
export { TYPOGRAPHY_TYPE, FONT, FONT_SIZE, FONT_WEIGHT, LINE_HEIGHT, } from './theme/typography';
|
|
4
4
|
export { GlobalStyles } from './theme/GlobalStyles';
|
|
5
5
|
export { Alert, Alerts } from './components/elements/Alerts';
|
|
6
|
+
export { ArrowLink } from './components/elements/ArrowLink';
|
|
6
7
|
export { BrandingBar } from './components/elements/BrandingBar';
|
|
7
8
|
export { Button, BUTTON_SIZE, BUTTON_TYPE, LinkButton, } from './components/elements/Button';
|
|
8
9
|
export { Heading, HEADING_SIZE } from './components/elements/text/Heading';
|
package/dist/theme/colors.d.ts
CHANGED
package/dist/theme/colors.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export var COLOR;
|
|
2
2
|
(function (COLOR) {
|
|
3
3
|
COLOR["TEXT"] = "text";
|
|
4
|
+
COLOR["LIGHT_TEXT"] = "lightText";
|
|
4
5
|
COLOR["BACKGROUND"] = "background";
|
|
5
6
|
COLOR["TRANSPARENT"] = "transparent";
|
|
6
7
|
COLOR["PRIMARY"] = "primary";
|
|
@@ -48,6 +49,7 @@ export var COLOR;
|
|
|
48
49
|
})(COLOR || (COLOR = {}));
|
|
49
50
|
export const colors = {
|
|
50
51
|
[COLOR.TEXT]: '#333333',
|
|
52
|
+
[COLOR.LIGHT_TEXT]: '#767676',
|
|
51
53
|
[COLOR.BACKGROUND]: '#ffffff',
|
|
52
54
|
[COLOR.TRANSPARENT]: 'rgba(0,0,0,0)',
|
|
53
55
|
[COLOR.PRIMARY]: '#0c2340',
|
|
@@ -59,7 +61,7 @@ export const colors = {
|
|
|
59
61
|
[COLOR.WHITE]: '#ffffff',
|
|
60
62
|
[COLOR.BLACK]: '#000000',
|
|
61
63
|
[COLOR.DARK_GRAY]: '#333333',
|
|
62
|
-
[COLOR.GRAY]: '#
|
|
64
|
+
[COLOR.GRAY]: '#767676',
|
|
63
65
|
[COLOR.LIGHT_GRAY]: '#d2d2d2',
|
|
64
66
|
[COLOR.EXTRA_LIGHT_GRAY]: '#e2e2e2',
|
|
65
67
|
[COLOR.EXTRA_EXTRA_LIGHT_GRAY]: '#f2f2f2',
|
package/dist/theme/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export declare const SPACING: string[];
|
|
|
8
8
|
export declare const theme: {
|
|
9
9
|
colors: {
|
|
10
10
|
text: string;
|
|
11
|
+
lightText: string;
|
|
11
12
|
background: string;
|
|
12
13
|
transparent: string;
|
|
13
14
|
primary: string;
|
|
@@ -96,10 +97,11 @@ export type StylesProp = ThemeUICSSObject & {
|
|
|
96
97
|
export type StyledElementProps<E extends Element, CustomProps = object, Children = React.ReactNode> = {
|
|
97
98
|
sx?: StylesProp;
|
|
98
99
|
children?: Children;
|
|
99
|
-
} & Omit<React.HTMLAttributes<E>, 'children'> & CustomProps;
|
|
100
|
+
} & Omit<React.HTMLAttributes<E>, 'children' | 'onChange'> & CustomProps;
|
|
100
101
|
export declare const useTheme: () => {
|
|
101
102
|
colors: {
|
|
102
103
|
text: string;
|
|
104
|
+
lightText: string;
|
|
103
105
|
background: string;
|
|
104
106
|
transparent: string;
|
|
105
107
|
primary: string;
|