@grantbii/design-system 1.0.55 → 1.0.57

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.
@@ -1,15 +1,14 @@
1
1
  import { GrantMatchQuery } from "@grantbii/ui-base/match/models";
2
+ type GrantMatchProps = GrantMatchQueryProps & {
3
+ isModalFullScreen?: boolean;
4
+ };
5
+ declare const GrantMatch: ({ query, updateQuery, removeQueryFile, removeQueryText, resetQuery, isModalFullScreen, }: GrantMatchProps) => import("react/jsx-runtime").JSX.Element;
6
+ export default GrantMatch;
2
7
  type GrantMatchQueryProps = {
3
8
  query: GrantMatchQuery;
4
- updateQueryFiles: (newFiles: File[]) => void;
9
+ updateQuery: (newQuery: GrantMatchQuery) => void;
5
10
  removeQueryFile: (fileName: string) => void;
6
- updateQueryText: (newText: string) => void;
7
11
  removeQueryText: () => void;
8
12
  resetQuery: () => void;
9
13
  };
10
- type GrantMatchProps = GrantMatchQueryProps & {
11
- isModalFullScreen?: boolean;
12
- };
13
- declare const GrantMatch: ({ query, updateQueryFiles, removeQueryFile, updateQueryText, removeQueryText, resetQuery, isModalFullScreen, }: GrantMatchProps) => import("react/jsx-runtime").JSX.Element;
14
- export default GrantMatch;
15
- export declare const useGrantMatchQueryItems: () => GrantMatchQueryProps;
14
+ export declare const useGrantMatchQueryItems: (performGrantMatch: (newQuery: GrantMatchQuery) => void, resetGrantMatch: () => void) => GrantMatchQueryProps;
@@ -5,38 +5,64 @@ import styled from "styled-components";
5
5
  import { Badge, Button, Textarea } from "../atoms";
6
6
  import { Colors, Icons } from "../foundations";
7
7
  import { FileDrop, Modal, useFileDrop, useModal } from "../molecules";
8
- const GrantMatch = ({ query, updateQueryFiles, removeQueryFile, updateQueryText, removeQueryText, resetQuery, isModalFullScreen, }) => {
8
+ const GrantMatch = ({ query, updateQuery, removeQueryFile, removeQueryText, resetQuery, isModalFullScreen, }) => {
9
9
  const { showModal, openModal, closeModal } = useModal();
10
10
  const isActive = isGrantMatchActive(query);
11
- const performGrantMatch = (newFiles, newText) => {
12
- updateQueryFiles(newFiles);
13
- updateQueryText(newText);
11
+ const updateActiveQuery = (newQuery) => {
12
+ updateQuery(newQuery);
14
13
  closeModal();
15
14
  };
16
- return (_jsxs(Container, { children: [_jsx(GrantMatchButtons, { isActive: isActive, onClickMatch: () => openModal(), onClickReset: () => resetQuery() }), isActive ? (_jsx(QueryItems, { queryFiles: query.files, removeQueryFile: removeQueryFile, queryText: query.text, removeQueryText: removeQueryText })) : (_jsx(_Fragment, {})), showModal ? (_jsx(GrantMatchModal, { activeFiles: query.files, activeText: query.text, performGrantMatch: performGrantMatch, onClickCancel: () => closeModal(), isFullScreen: isModalFullScreen })) : (_jsx(_Fragment, {}))] }));
15
+ return (_jsxs(BaseGrantMatch, { children: [_jsx(GrantMatchButtons, { isActive: isActive, onClickMatch: () => openModal(), onClickReset: () => resetQuery() }), isActive ? (_jsx(QueryItems, { activeQuery: query, removeQueryFile: removeQueryFile, removeQueryText: removeQueryText })) : (_jsx(_Fragment, {})), showModal ? (_jsx(GrantMatchModal, { activeQuery: query, updateActiveQuery: updateActiveQuery, onClickCancel: () => closeModal(), isFullScreen: isModalFullScreen })) : (_jsx(_Fragment, {}))] }));
17
16
  };
18
17
  export default GrantMatch;
19
- const BLANK_GRANT_MATCH_QUERY = { files: [], text: "" };
20
- export const useGrantMatchQueryItems = () => {
18
+ export const useGrantMatchQueryItems = (performGrantMatch, resetGrantMatch) => {
21
19
  const [query, setQuery] = useState(() => (Object.assign({}, BLANK_GRANT_MATCH_QUERY)));
22
- const updateQueryFiles = (files) => setQuery(({ text }) => ({ files, text }));
23
- const removeQueryFile = (fileName) => setQuery(({ files, text }) => ({
24
- files: files.filter((file) => file.name !== fileName),
25
- text,
26
- }));
27
- const updateQueryText = (text) => setQuery(({ files }) => ({ files, text }));
28
- const removeQueryText = () => setQuery(({ files }) => ({ files, text: "" }));
29
- const resetQuery = () => setQuery(Object.assign({}, BLANK_GRANT_MATCH_QUERY));
20
+ const updateQuery = (newQuery) => {
21
+ setQuery(Object.assign({}, newQuery));
22
+ if (isGrantMatchActive(newQuery)) {
23
+ performGrantMatch(newQuery);
24
+ }
25
+ else {
26
+ resetGrantMatch();
27
+ }
28
+ };
29
+ const removeQueryFile = (fileName) => {
30
+ const newQuery = {
31
+ files: query.files.filter((file) => file.name !== fileName),
32
+ text: query.text,
33
+ };
34
+ updateQuery(newQuery);
35
+ if (isGrantMatchActive(newQuery)) {
36
+ performGrantMatch(newQuery);
37
+ }
38
+ else {
39
+ resetGrantMatch();
40
+ }
41
+ };
42
+ const removeQueryText = () => {
43
+ const newQuery = { files: query.files, text: "" };
44
+ updateQuery(newQuery);
45
+ if (isGrantMatchActive(newQuery)) {
46
+ performGrantMatch(newQuery);
47
+ }
48
+ else {
49
+ resetGrantMatch();
50
+ }
51
+ };
52
+ const resetQuery = () => {
53
+ setQuery(Object.assign({}, BLANK_GRANT_MATCH_QUERY));
54
+ resetGrantMatch();
55
+ };
30
56
  return {
31
57
  query,
32
- updateQueryFiles,
58
+ updateQuery,
33
59
  removeQueryFile,
34
- updateQueryText,
35
60
  removeQueryText,
36
61
  resetQuery,
37
62
  };
38
63
  };
39
- const Container = styled.div `
64
+ const BLANK_GRANT_MATCH_QUERY = { files: [], text: "" };
65
+ const BaseGrantMatch = styled.div `
40
66
  display: flex;
41
67
  flex-direction: column;
42
68
  gap: 8px;
@@ -70,10 +96,10 @@ const BaseGrantMatchButton = styled.button `
70
96
  border: 1px solid
71
97
  ${({ $isActive }) => $isActive ? Colors.accent.yellow1 : Colors.neutral.grey3};
72
98
  `;
73
- const QueryItems = ({ queryFiles, removeQueryFile, queryText, removeQueryText, }) => (_jsxs(BaseQueryItems, { children: [queryFiles.map((file) => {
99
+ const QueryItems = ({ activeQuery, removeQueryFile, removeQueryText, }) => (_jsxs(BaseQueryItems, { children: [activeQuery.files.map((file) => {
74
100
  var _a;
75
101
  return (_jsx(Badge, { text: file.name, Icon: (_a = FILE_TYPE_ICON_MAP[file.type]) !== null && _a !== void 0 ? _a : Icons.FileIcon, onClickClose: () => removeQueryFile(file.name), textWidthPixels: 160 }, file.name));
76
- }), queryText === "" ? (_jsx(_Fragment, {})) : (_jsx(Badge, { text: "Additional Information", Icon: Icons.TextAaIcon, onClickClose: () => removeQueryText(), textWidthPixels: 180 }, "additional-information-query-item"))] }));
102
+ }), activeQuery.text === "" ? (_jsx(_Fragment, {})) : (_jsx(Badge, { text: "Additional Information", Icon: Icons.TextAaIcon, onClickClose: () => removeQueryText(), textWidthPixels: 180 }, "additional-information-query-item"))] }));
77
103
  const BaseQueryItems = styled.div `
78
104
  display: flex;
79
105
  align-items: center;
@@ -91,11 +117,10 @@ const BaseQueryItems = styled.div `
91
117
  const FILE_TYPE_ICON_MAP = {
92
118
  "application/pdf": Icons.FilePdfIcon,
93
119
  };
94
- const GrantMatchModal = ({ activeFiles, activeText, performGrantMatch, onClickCancel, isFullScreen, }) => {
95
- const { files, uploadFiles, removeFile } = useFileDrop(activeFiles);
96
- const [queryText, setQueryText] = useState(activeText);
97
- const updateQueryText = (newText) => setQueryText(newText);
98
- return (_jsx(Modal, { header: _jsx(Header, {}), content: _jsx(Content, { files: files, uploadFiles: uploadFiles, removeFile: removeFile, queryText: queryText, updateQueryText: updateQueryText }), footer: _jsx(Button, { text: "Find My Grants", onClick: () => performGrantMatch(files, queryText), backgroundColor: Colors.accent.yellow1 }), onClickCancel: onClickCancel, isFullScreen: isFullScreen }));
120
+ const GrantMatchModal = ({ activeQuery, updateActiveQuery, onClickCancel, isFullScreen, }) => {
121
+ const { files, uploadFiles, removeFile } = useFileDrop(activeQuery.files);
122
+ const [text, setText] = useState(activeQuery.text);
123
+ return (_jsx(Modal, { header: _jsx(Header, {}), content: _jsx(Content, { files: files, uploadFiles: uploadFiles, removeFile: removeFile, queryText: text, updateQueryText: (newText) => setText(newText) }), footer: _jsx(Button, { text: "Find My Grants", onClick: () => updateActiveQuery({ files, text }), backgroundColor: Colors.accent.yellow1 }), onClickCancel: onClickCancel, isFullScreen: isFullScreen }));
99
124
  };
100
125
  const Header = () => (_jsxs(BaseHeader, { children: [_jsx(Icons.GrantMatchIcon, { size: 24 }), _jsx("div", { children: "Grant Match" })] }));
101
126
  const BaseHeader = styled.div `
@@ -103,10 +128,8 @@ const BaseHeader = styled.div `
103
128
  align-items: center;
104
129
  gap: 12px;
105
130
  `;
106
- const Content = ({ files, uploadFiles, removeFile, queryText, updateQueryText, }) => {
107
- const additionalInformationId = "grant-match-additional-information";
108
- return (_jsxs(BaseContent, { children: [_jsx(FileDrop, { uploadedFiles: files, uploadFiles: uploadFiles, removeFile: removeFile }), _jsxs(QueryText, { children: [_jsx("label", { htmlFor: additionalInformationId, children: "Additional Information" }), _jsx(Textarea, { id: additionalInformationId, value: queryText, onChange: (event) => updateQueryText(event.target.value) })] })] }));
109
- };
131
+ const Content = ({ files, uploadFiles, removeFile, queryText, updateQueryText, }) => (_jsxs(BaseContent, { children: [_jsx(FileDrop, { uploadedFiles: files, uploadFiles: uploadFiles, removeFile: removeFile }), _jsxs(QueryText, { children: [_jsx("label", { htmlFor: ADDITIONAL_INFORMATION_ID, children: "Additional Information" }), _jsx(Textarea, { id: ADDITIONAL_INFORMATION_ID, value: queryText, onChange: (event) => updateQueryText(event.target.value) })] })] }));
132
+ const ADDITIONAL_INFORMATION_ID = "grant-match-additional-information";
110
133
  const BaseContent = styled.div `
111
134
  display: flex;
112
135
  flex-direction: column;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grantbii/design-system",
3
- "version": "1.0.55",
3
+ "version": "1.0.57",
4
4
  "description": "Grantbii's Design System",
5
5
  "homepage": "https://design.grantbii.com",
6
6
  "repository": {
@@ -1,12 +1,26 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
2
2
  import { GrantMatch } from "@/.";
3
3
  import { useGrantMatchQueryItems } from "@/core/organisms/GrantMatch";
4
+ import { useState } from "react";
4
5
  import styled from "styled-components";
5
6
  const GrantMatchExample = ({ isModalFullScreen }) => {
6
- const grantMatchProps = useGrantMatchQueryItems();
7
- return (_jsx(Container, { children: _jsx(GrantMatch, Object.assign({}, grantMatchProps, { isModalFullScreen: isModalFullScreen })) }));
7
+ const [status, setStatus] = useState("Pending input");
8
+ const performGrantMatch = (newQuery) => {
9
+ const fileNames = newQuery.files.map((file) => file.name).join(", ");
10
+ setStatus(`Finding grants using files [${fileNames}] and text [${newQuery.text}]`);
11
+ setTimeout(() => setStatus("Found grants"), 3000);
12
+ };
13
+ const resetGrantMatch = () => setStatus("Pending input");
14
+ const grantMatchQueryProps = useGrantMatchQueryItems(performGrantMatch, resetGrantMatch);
15
+ return (_jsxs(Container, { children: [_jsxs(GrantMatchStatus, { children: ["Status: ", status] }), _jsx(GrantMatch, Object.assign({}, grantMatchQueryProps, { isModalFullScreen: isModalFullScreen }))] }));
8
16
  };
17
+ const GrantMatchStatus = styled.p `
18
+ margin: 0px 16px;
19
+ `;
9
20
  const Container = styled.div `
21
+ display: flex;
22
+ flex-direction: column;
23
+
10
24
  width: 90vw;
11
25
  `;
12
26
  const meta = {