@ttoss/components 1.27.3 → 1.28.1

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,3 +1,4 @@
1
+ import * as React from 'react';
1
2
  import { Button, Flex, Text } from '@ttoss/ui';
2
3
 
3
4
  export type InstallPwaUiProps = {
@@ -33,3 +34,36 @@ export const InstallPwaUi = ({ onInstall }: InstallPwaUiProps) => {
33
34
  </Flex>
34
35
  );
35
36
  };
37
+
38
+ export const InstallPwa = () => {
39
+ const [supportsPwa, setSupportsPwa] = React.useState(false);
40
+ const [promptInstall, setPromptInstall] = React.useState<any>(null);
41
+
42
+ React.useEffect(() => {
43
+ const handler = (e: any) => {
44
+ e.preventDefault();
45
+ setSupportsPwa(true);
46
+ setPromptInstall(e);
47
+ };
48
+
49
+ window.addEventListener('beforeinstallprompt', handler);
50
+
51
+ return () => {
52
+ return window.removeEventListener('transitionend', handler);
53
+ };
54
+ }, []);
55
+
56
+ const onInstall = (e: any) => {
57
+ e.preventDefault();
58
+ if (!promptInstall) {
59
+ return;
60
+ }
61
+ promptInstall.prompt();
62
+ };
63
+
64
+ if (!supportsPwa) {
65
+ return null;
66
+ }
67
+
68
+ return <InstallPwaUi onInstall={onInstall} />;
69
+ };
@@ -1,3 +1,4 @@
1
+ import { css as transformStyleObject } from '@theme-ui/css';
1
2
  import { useResponsiveValue, useTheme } from '@ttoss/ui';
2
3
  import ReactModal from 'react-modal';
3
4
 
@@ -11,33 +12,33 @@ export type ModalProps = ReactModal.Props;
11
12
  export const Modal = (props: ModalProps) => {
12
13
  const { theme } = useTheme();
13
14
 
15
+ const space = theme.space as Record<string, string>;
16
+
14
17
  const padding =
15
- useResponsiveValue([
16
- theme.space?.[2],
17
- theme.space?.[3],
18
- theme.space?.[4],
19
- ]) || 0;
18
+ useResponsiveValue([space?.['lg'], space?.['xl'], space?.['xl']]) || 0;
20
19
 
21
20
  const style: ReactModal.Styles = {
22
- overlay: {
21
+ overlay: transformStyleObject({
23
22
  position: 'fixed',
24
23
  top: 0,
25
24
  left: 0,
26
25
  right: 0,
27
26
  bottom: 0,
28
- backgroundColor: 'rgba(255, 255, 255, 0.5)',
27
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
29
28
  display: 'flex',
30
29
  justifyContent: 'center',
31
30
  alignItems: 'center',
32
- padding,
33
31
  ...props.style?.overlay,
34
- },
35
- content: {
32
+ })(theme) as any,
33
+ content: transformStyleObject({
36
34
  /**
37
35
  * Theme
38
36
  */
39
- backgroundColor: theme.rawColors?.background?.toString() || '#fff',
37
+ backgroundColor: 'surface',
40
38
  padding,
39
+ border: 'default',
40
+ borderColor: 'surface',
41
+ borderRadius: 'default',
41
42
  /**
42
43
  * General
43
44
  */
@@ -48,13 +49,10 @@ export const Modal = (props: ModalProps) => {
48
49
  left: '0px',
49
50
  right: '0px',
50
51
  bottom: '0px',
51
- border: '2px solid',
52
- borderColor: theme.rawColors?.muted?.toString() || '#fff',
53
- display: 'flex',
54
- flexDirection: 'column',
55
- alignItems: 'center',
52
+ maxHeight: '90%',
53
+ maxWidth: '90%',
56
54
  ...props.style?.content,
57
- },
55
+ })(theme) as any,
58
56
  };
59
57
 
60
58
  return <ReactModal {...props} style={style} />;
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+ import { Box } from '@ttoss/ui';
3
+ import {
4
+ ToastContainer as ReactToastifyToastContainer,
5
+ type ToastContainerProps,
6
+ toast,
7
+ } from 'react-toastify';
8
+ import { injectStyle } from 'react-toastify/dist/inject-style';
9
+
10
+ export { toast };
11
+
12
+ export { type ToastContainerProps };
13
+
14
+ export const ToastContainer = (props: ToastContainerProps) => {
15
+ React.useEffect(() => {
16
+ injectStyle();
17
+ }, []);
18
+
19
+ return (
20
+ <Box
21
+ sx={({ colors, fonts }) => {
22
+ return {
23
+ '--toastify-color-light': '#fff',
24
+ '--toastify-color-dark': '#121212',
25
+ '--toastify-color-info': colors?.info || '#3498db',
26
+ '--toastify-color-success': colors?.success || '#07bc0c',
27
+ '--toastify-color-warning': '#f1c40f',
28
+ '--toastify-color-error': '#e74c3c',
29
+ '--toastify-color-progress-light': `linear-gradient(to right, ${colors?.primary}, ${colors?.secondary})`,
30
+ '--toastify-font-family': (fonts as { body: string }).body,
31
+ };
32
+ }}
33
+ >
34
+ <ReactToastifyToastContainer {...props} />
35
+ </Box>
36
+ );
37
+ };
package/src/index.ts CHANGED
@@ -1,4 +1,4 @@
1
- export * from './components/Accordion/Accordion';
2
- export * from './components/InstallPwa/InstallPwa';
3
- export * from './components/Modal/Modal';
4
- export * from './components/Toast/Toast';
1
+ export * from './components/Accordion';
2
+ export * from './components/InstallPwa';
3
+ export * from './components/Modal';
4
+ export * from './components/Toast';
@@ -1,34 +0,0 @@
1
- import * as React from 'react';
2
-
3
- import { InstallPwaUi } from './InstallPwaUi';
4
-
5
- export const InstallPwa = () => {
6
- const [supportsPwa, setSupportsPwa] = React.useState(false);
7
- const [promptInstall, setPromptInstall] = React.useState<any>(null);
8
-
9
- React.useEffect(() => {
10
- const handler = (e: any) => {
11
- e.preventDefault();
12
- setSupportsPwa(true);
13
- setPromptInstall(e);
14
- };
15
-
16
- window.addEventListener('beforeinstallprompt', handler);
17
-
18
- return () => window.removeEventListener('transitionend', handler);
19
- }, []);
20
-
21
- const onInstall = (e: any) => {
22
- e.preventDefault();
23
- if (!promptInstall) {
24
- return;
25
- }
26
- promptInstall.prompt();
27
- };
28
-
29
- if (!supportsPwa) {
30
- return null;
31
- }
32
-
33
- return <InstallPwaUi onInstall={onInstall} />;
34
- };
@@ -1,35 +0,0 @@
1
- import * as React from 'react';
2
- import { Box } from '@ttoss/ui';
3
- import {
4
- ToastContainer as ReactToastifyToastContainer,
5
- ToastContainerProps,
6
- toast,
7
- } from 'react-toastify';
8
- import { injectStyle } from 'react-toastify/dist/inject-style';
9
-
10
- export { toast };
11
-
12
- export { type ToastContainerProps };
13
-
14
- export const ToastContainer = (props: ToastContainerProps) => {
15
- React.useEffect(() => {
16
- injectStyle();
17
- }, []);
18
-
19
- return (
20
- <Box
21
- sx={({ colors, fonts }) => ({
22
- '--toastify-color-light': '#fff',
23
- '--toastify-color-dark': '#121212',
24
- '--toastify-color-info': colors?.info || '#3498db',
25
- '--toastify-color-success': colors?.success || '#07bc0c',
26
- '--toastify-color-warning': '#f1c40f',
27
- '--toastify-color-error': '#e74c3c',
28
- '--toastify-color-progress-light': `linear-gradient(to right, ${colors?.primary}, ${colors?.secondary})`,
29
- '--toastify-font-family': (fonts as { body: string }).body,
30
- })}
31
- >
32
- <ReactToastifyToastContainer {...props} />
33
- </Box>
34
- );
35
- };
@@ -1,11 +0,0 @@
1
- import * as componentsModule from './index';
2
-
3
- test.each([
4
- componentsModule.Accordion,
5
- componentsModule.InstallPwa,
6
- componentsModule.Modal,
7
- componentsModule.ToastContainer,
8
- componentsModule.toast,
9
- ])('should export components %#', (Component) => {
10
- expect(Component).toBeDefined();
11
- });