@ndla/ui 55.0.18-alpha.0 → 55.0.19
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/panda.buildinfo.json +1 -0
- package/dist/styles.css +4 -0
- package/es/AudioPlayer/SpeechControl.js +1 -0
- package/es/BlogPost/BlogPost.js +1 -0
- package/es/CampaignBlock/CampaignBlock.js +33 -27
- package/es/ContactBlock/ContactBlock.js +2 -0
- package/es/CopyParagraphButton/CopyParagraphButton.js +9 -11
- package/es/Embed/AudioEmbed.js +3 -1
- package/es/Embed/BrightcoveEmbed.js +1 -0
- package/es/Embed/CodeEmbed.js +1 -0
- package/es/Embed/ConceptEmbed.js +8 -9
- package/es/Embed/ConceptListEmbed.js +1 -0
- package/es/Embed/ContentLinkEmbed.js +1 -0
- package/es/Embed/CopyrightEmbed.js +1 -0
- package/es/Embed/EmbedErrorPlaceholder.js +1 -0
- package/es/Embed/ExternalEmbed.js +2 -0
- package/es/Embed/FootnoteEmbed.js +1 -0
- package/es/Embed/GlossEmbed.js +1 -0
- package/es/Embed/H5pEmbed.js +2 -0
- package/es/Embed/IframeEmbed.js +2 -0
- package/es/Embed/ImageEmbed.js +1 -0
- package/es/Embed/UnknownEmbed.js +1 -0
- package/es/Embed/UuDisclaimerEmbed.js +1 -0
- package/es/ErrorMessage/ErrorResourceAccessDenied.js +2 -3
- package/es/FactBox/FactBox.js +1 -0
- package/es/LinkBlock/LinkBlock.js +1 -0
- package/es/RelatedArticleList/RelatedArticleList.js +2 -0
- package/es/ResourceBox/ResourceBox.js +1 -0
- package/es/TreeStructure/AddFolderButton.js +25 -28
- package/es/index.js +0 -1
- package/es/styles.css +4 -0
- package/lib/AudioPlayer/SpeechControl.js +1 -0
- package/lib/BlogPost/BlogPost.js +1 -0
- package/lib/CampaignBlock/CampaignBlock.js +33 -27
- package/lib/ContactBlock/ContactBlock.js +2 -0
- package/lib/CopyParagraphButton/CopyParagraphButton.js +9 -11
- package/lib/Embed/AudioEmbed.js +3 -1
- package/lib/Embed/BrightcoveEmbed.js +1 -0
- package/lib/Embed/CodeEmbed.js +1 -0
- package/lib/Embed/ConceptEmbed.js +7 -8
- package/lib/Embed/ConceptListEmbed.js +1 -0
- package/lib/Embed/ContentLinkEmbed.js +1 -0
- package/lib/Embed/CopyrightEmbed.js +1 -0
- package/lib/Embed/EmbedErrorPlaceholder.js +1 -0
- package/lib/Embed/ExternalEmbed.js +2 -0
- package/lib/Embed/FootnoteEmbed.js +1 -0
- package/lib/Embed/GlossEmbed.js +1 -0
- package/lib/Embed/H5pEmbed.js +2 -0
- package/lib/Embed/IframeEmbed.js +2 -0
- package/lib/Embed/ImageEmbed.js +1 -0
- package/lib/Embed/UnknownEmbed.js +1 -0
- package/lib/Embed/UuDisclaimerEmbed.js +1 -0
- package/lib/ErrorMessage/ErrorResourceAccessDenied.js +2 -3
- package/lib/FactBox/FactBox.js +1 -0
- package/lib/LinkBlock/LinkBlock.js +1 -0
- package/lib/RelatedArticleList/RelatedArticleList.js +2 -0
- package/lib/ResourceBox/ResourceBox.js +1 -0
- package/lib/TreeStructure/AddFolderButton.js +25 -28
- package/lib/index.d.ts +0 -2
- package/lib/index.js +0 -25
- package/lib/styles.css +4 -0
- package/package.json +8 -11
- package/src/AudioPlayer/SpeechControl.tsx +1 -1
- package/src/BlogPost/BlogPost.tsx +1 -1
- package/src/CampaignBlock/CampaignBlock.tsx +3 -1
- package/src/ContactBlock/ContactBlock.tsx +2 -1
- package/src/CopyParagraphButton/CopyParagraphButton.tsx +4 -7
- package/src/Embed/AudioEmbed.tsx +3 -2
- package/src/Embed/BrightcoveEmbed.tsx +1 -1
- package/src/Embed/CodeEmbed.tsx +1 -1
- package/src/Embed/ConceptEmbed.tsx +4 -6
- package/src/Embed/ConceptListEmbed.tsx +1 -1
- package/src/Embed/ContentLinkEmbed.tsx +1 -1
- package/src/Embed/CopyrightEmbed.tsx +1 -1
- package/src/Embed/EmbedErrorPlaceholder.tsx +1 -1
- package/src/Embed/ExternalEmbed.tsx +8 -2
- package/src/Embed/FootnoteEmbed.tsx +1 -1
- package/src/Embed/GlossEmbed.tsx +1 -1
- package/src/Embed/H5pEmbed.tsx +2 -2
- package/src/Embed/IframeEmbed.tsx +2 -2
- package/src/Embed/ImageEmbed.tsx +5 -1
- package/src/Embed/UnknownEmbed.tsx +1 -1
- package/src/Embed/UuDisclaimerEmbed.tsx +1 -1
- package/src/ErrorMessage/ErrorResourceAccessDenied.tsx +3 -3
- package/src/FactBox/FactBox.tsx +1 -1
- package/src/LinkBlock/LinkBlock.tsx +1 -1
- package/src/RelatedArticleList/RelatedArticleList.tsx +2 -2
- package/src/ResourceBox/ResourceBox.tsx +1 -0
- package/src/TreeStructure/AddFolderButton.tsx +25 -27
- package/src/TreeStructure/TreeStructure.stories.tsx +5 -5
- package/src/index.ts +0 -2
- package/es/SnackBar/DefaultSnackbar.js +0 -50
- package/es/SnackBar/SnackbarProvider.js +0 -120
- package/es/SnackBar/index.js +0 -10
- package/lib/SnackBar/DefaultSnackbar.d.ts +0 -10
- package/lib/SnackBar/DefaultSnackbar.js +0 -57
- package/lib/SnackBar/SnackbarProvider.d.ts +0 -32
- package/lib/SnackBar/SnackbarProvider.js +0 -130
- package/lib/SnackBar/index.d.ts +0 -10
- package/lib/SnackBar/index.js +0 -32
- package/src/SnackBar/DefaultSnackbar.tsx +0 -62
- package/src/SnackBar/Snack.stories.tsx +0 -105
- package/src/SnackBar/SnackbarProvider.tsx +0 -146
- package/src/SnackBar/index.ts +0 -11
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022-present, NDLA.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { useCallback, useMemo, createContext, ReactNode, useState, useContext, useEffect } from "react";
|
|
10
|
-
import { keyframes } from "@emotion/react";
|
|
11
|
-
import styled from "@emotion/styled";
|
|
12
|
-
import { spacing, stackOrder } from "@ndla/core";
|
|
13
|
-
import DefaultSnack from "./DefaultSnackbar";
|
|
14
|
-
|
|
15
|
-
export interface Snack {
|
|
16
|
-
content?: ReactNode;
|
|
17
|
-
duration?: number;
|
|
18
|
-
render?: (id: string, onClose?: () => void) => ReactNode;
|
|
19
|
-
id: string;
|
|
20
|
-
icon?: ReactNode;
|
|
21
|
-
closable?: boolean;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface SnackContext {
|
|
25
|
-
addSnack: (snack: Snack) => void;
|
|
26
|
-
removeSnack: (id: string) => void;
|
|
27
|
-
clearSnacks: () => void;
|
|
28
|
-
closeSnack: (snack: Snack) => void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const SnackbarContext = createContext<SnackContext | undefined>(undefined);
|
|
32
|
-
|
|
33
|
-
export const useSnack = () => {
|
|
34
|
-
const context = useContext(SnackbarContext);
|
|
35
|
-
if (!context) {
|
|
36
|
-
throw new Error("useSnack can only be used within a SnackbarProvider!");
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return context;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
interface Props {
|
|
43
|
-
children: ReactNode;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export const SnackbarProvider = ({ children }: Props) => {
|
|
47
|
-
const [snacks, setSnacks] = useState<Snack[]>([]);
|
|
48
|
-
|
|
49
|
-
const addSnack = useCallback((snack: Snack) => {
|
|
50
|
-
setSnacks((prev) => prev.filter((s) => s.id !== snack.id).concat(snack));
|
|
51
|
-
}, []);
|
|
52
|
-
|
|
53
|
-
const removeSnack = useCallback((snackId: string) => {
|
|
54
|
-
setSnacks((prev) => prev.filter(({ id }) => snackId !== id));
|
|
55
|
-
}, []);
|
|
56
|
-
|
|
57
|
-
const closeSnack = useCallback((snack: Snack) => {
|
|
58
|
-
setSnacks((prev) => prev.map((p) => (p.id === snack.id ? { ...p, duration: 0 } : p)));
|
|
59
|
-
}, []);
|
|
60
|
-
|
|
61
|
-
const clearSnacks = useCallback(() => setSnacks([]), []);
|
|
62
|
-
|
|
63
|
-
const value = useMemo(
|
|
64
|
-
() => ({ addSnack, removeSnack, clearSnacks, closeSnack }),
|
|
65
|
-
[addSnack, removeSnack, clearSnacks, closeSnack],
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
return (
|
|
69
|
-
<SnackbarContext.Provider value={value}>
|
|
70
|
-
{children}
|
|
71
|
-
<SnackbarContainer snacks={snacks} />
|
|
72
|
-
</SnackbarContext.Provider>
|
|
73
|
-
);
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
interface BaseSnackProps extends Snack {
|
|
77
|
-
children: ReactNode;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
interface BaseSnackContainerProps {
|
|
81
|
-
expired: boolean;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const snackbarInAnimation = keyframes({
|
|
85
|
-
"0%": { transform: `translateY(${spacing.medium})`, opacity: 0 },
|
|
86
|
-
"100%": { opacity: 1 },
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const snackbarOutAnimation = keyframes({
|
|
90
|
-
"0%": { opacity: 1 },
|
|
91
|
-
"100%": { transform: `translateY(${spacing.medium})`, opacity: 0 },
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const BaseSnackContainer = styled.li<BaseSnackContainerProps>`
|
|
95
|
-
display: flex;
|
|
96
|
-
flex-direction: column;
|
|
97
|
-
align-items: center;
|
|
98
|
-
animation: ${(p) => (p.expired ? snackbarOutAnimation : snackbarInAnimation)} 200ms ease-in-out;
|
|
99
|
-
animation-fill-mode: forwards;
|
|
100
|
-
`;
|
|
101
|
-
|
|
102
|
-
export const BaseSnack = ({ duration = 5000, id, children }: BaseSnackProps) => {
|
|
103
|
-
const { removeSnack } = useSnack();
|
|
104
|
-
const [expired, setExpired] = useState(false);
|
|
105
|
-
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
const timeout = setTimeout(() => setExpired(true), duration);
|
|
108
|
-
return () => clearTimeout(timeout);
|
|
109
|
-
}, [duration]);
|
|
110
|
-
|
|
111
|
-
return (
|
|
112
|
-
<BaseSnackContainer expired={expired} onAnimationEnd={() => expired && removeSnack(id)}>
|
|
113
|
-
{children}
|
|
114
|
-
</BaseSnackContainer>
|
|
115
|
-
);
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
interface SnackbarContainerProps {
|
|
119
|
-
snacks: Snack[];
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const StyledSnackList = styled.ul`
|
|
123
|
-
position: fixed;
|
|
124
|
-
z-index: ${stackOrder.toast};
|
|
125
|
-
display: flex;
|
|
126
|
-
flex-direction: column;
|
|
127
|
-
pointer-events: none;
|
|
128
|
-
padding: 0;
|
|
129
|
-
bottom: env(safe-area-inset-bottom, 40px);
|
|
130
|
-
right: env(safe-area-inset-right, 0px);
|
|
131
|
-
left: env(safe-area-inset-left, 0px);
|
|
132
|
-
`;
|
|
133
|
-
|
|
134
|
-
const SnackbarContainer = ({ snacks }: SnackbarContainerProps) => {
|
|
135
|
-
return (
|
|
136
|
-
<StyledSnackList aria-live="polite" role="region">
|
|
137
|
-
{snacks.map((snack) => (
|
|
138
|
-
<BaseSnack key={snack.id} {...snack}>
|
|
139
|
-
{snack.render?.(snack.id) ?? <DefaultSnack {...snack} />}
|
|
140
|
-
</BaseSnack>
|
|
141
|
-
))}
|
|
142
|
-
</StyledSnackList>
|
|
143
|
-
);
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export default SnackbarProvider;
|
package/src/SnackBar/index.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) 2022-present, NDLA.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
export type { Snack, SnackContext } from "./SnackbarProvider";
|
|
10
|
-
export { SnackbarProvider, useSnack, BaseSnack } from "./SnackbarProvider";
|
|
11
|
-
export { default as DefaultSnackbar } from "./DefaultSnackbar";
|