Skip to content

Commit be66a15

Browse files
committed
Upgrade ui-components
1 parent 7fee251 commit be66a15

File tree

7 files changed

+968
-854
lines changed

7 files changed

+968
-854
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@openstax/highlighter": "https://github.com/openstax/highlighter#v1.14.2",
1313
"@openstax/open-search-client": "0.1.0-build.7",
1414
"@openstax/ts-utils": "1.6.0",
15-
"@openstax/ui-components": "https://github.com/openstax/ui-components#1.3.4-post2",
15+
"@openstax/ui-components": "openstax/ui-components#1.6.4",
1616
"@sentry/integrations": "^7.54.0",
1717
"@sentry/react": "^7.54.0",
1818
"color": "^3.1.2",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import { ToastData, ToastContainer } from '@openstax/ui-components';
3+
4+
const ctx = React.createContext({});
5+
const defaultToastData: Omit<ToastData, 'message'> = {
6+
title: '',
7+
variant: 'success',
8+
dismissAfterMs: 4000,
9+
};
10+
type ConfirmationToastData = Partial<ToastData> & Pick<ToastData, 'message'>;
11+
12+
function useConfirmationToastContext() {
13+
return React.useContext(ctx) as (data: ConfirmationToastData) => void;
14+
}
15+
16+
function ConfirmationToastProvider({ children }: React.PropsWithChildren<{}>) {
17+
const [toastData, setToastData] = React.useState<ToastData[]>([]);
18+
const showToast = React.useCallback(
19+
(data: ConfirmationToastData) =>
20+
setToastData([
21+
{
22+
...defaultToastData,
23+
...data,
24+
onDismiss() {
25+
setToastData([]);
26+
},
27+
},
28+
]),
29+
[]
30+
);
31+
32+
return (
33+
<ctx.Provider value={showToast}>
34+
<ToastContainer toasts={toastData} />
35+
{children}
36+
</ctx.Provider>
37+
);
38+
}
39+
40+
export { useConfirmationToastContext, ConfirmationToastProvider };

src/app/content/components/Content.tsx

+16-12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import PrevNextBar from './PrevNextBar';
3535

3636
import Navigation from './Navigation';
3737
import Topbar from './Topbar';
38+
import { ConfirmationToastProvider } from './ConfirmationToast';
3839
import Wrapper from './Wrapper';
3940

4041
// tslint:disable-next-line:variable-name
@@ -71,6 +72,7 @@ const OuterWrapper = styled.div`
7172
}
7273
`;
7374

75+
7476
// tslint:disable-next-line:variable-name
7577
const Content = ({mobileExpanded, book}: {mobileExpanded: boolean; book: Book}) => <Layout>
7678
<ScrollOffset
@@ -96,18 +98,20 @@ const Content = ({mobileExpanded, book}: {mobileExpanded: boolean; book: Book})
9698
<OuterWrapper>
9799
<Topbar />
98100
<Wrapper>
99-
<Navigation />
100-
<ContentPane>
101-
<ContentNotifications mobileExpanded={mobileExpanded} />
102-
<ContentWarning book={book} />
103-
<Page>
104-
<PrevNextBar />
105-
<LabsCTA />
106-
<BuyBook />
107-
</Page>
108-
<Attribution />
109-
<Footer />
110-
</ContentPane>
101+
<ConfirmationToastProvider>
102+
<Navigation />
103+
<ContentPane>
104+
<ContentNotifications mobileExpanded={mobileExpanded} />
105+
<ContentWarning book={book} />
106+
<Page>
107+
<PrevNextBar />
108+
<LabsCTA />
109+
<BuyBook />
110+
</Page>
111+
<Attribution />
112+
<Footer />
113+
</ContentPane>
114+
</ConfirmationToastProvider>
111115
</Wrapper>
112116
</OuterWrapper>
113117
</ErrorBoundary>

0 commit comments

Comments
 (0)