groovinads-ui 1.2.52 → 1.2.53

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "groovinads-ui",
3
3
  "description": "Groovinads UI is a React component library designed exclusively for Groovinads applications. It provides ready-to-use UI elements styled according to Groovinads design guidelines to facilitate rapid development.",
4
- "version": "1.2.52",
4
+ "version": "1.2.53",
5
5
  "keywords": [
6
6
  "css",
7
7
  "sass",
@@ -0,0 +1,49 @@
1
+ import React, { children, useState } from 'react';
2
+ import Toast from 'react-bootstrap/Toast';
3
+ import { Icon } from '../../Labels';
4
+
5
+ function ToastCardComponent({ variant, autoClose, children, className, position }) {
6
+ const [show, setShow] = useState(true);
7
+
8
+ const toggleShow = () => setShow(!show);
9
+
10
+ const variantIcons = {
11
+ info: 'circle-info',
12
+ success: 'circle-check',
13
+ warning: 'triangle-exclamation',
14
+ error: 'circle-xmark',
15
+ };
16
+
17
+ console.log('Hola');
18
+
19
+ return (
20
+ <Toast
21
+ onClose={toggleShow}
22
+ show={show}
23
+ delay={autoClose ? 3500 : null}
24
+ autohide={autoClose}
25
+ className={`${position} ${variant} ${className ? className : ''}`}
26
+ >
27
+ <Toast.Body>
28
+ <div className='toast-wrapper'>
29
+ <div className='toast-type'>
30
+ <Icon
31
+ style={'solid'}
32
+ iconName={variantIcons[variant]}
33
+ scale={1}
34
+ className={'icon'}
35
+ />
36
+ </div>
37
+ <span>{children}</span>
38
+ </div>
39
+ {!autoClose && (
40
+ <button className='btn-close' onClick={toggleShow}>
41
+ <Icon style={'solid'} iconName={'xmark'} scale={1} />
42
+ </button>
43
+ )}
44
+ </Toast.Body>
45
+ </Toast>
46
+ );
47
+ }
48
+
49
+ export default ToastCardComponent;
@@ -1,82 +1,45 @@
1
- import React, { children, useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
4
  // BOOTSTRAP
5
- import Toast from 'react-bootstrap/Toast';
6
5
  import { ToastContainer } from 'react-bootstrap';
7
6
 
8
7
  // COMPONENTS
9
- import Icon from '../Labels/Icon';
8
+ import ToastCardComponent from './Toast/ToastCardComponent';
10
9
 
11
- const ToastComponent = ({
12
- variant = 'info',
13
- autoClose = true,
14
- position = 'bottom-start',
15
- children,
16
- className,
17
- }) => {
18
- const [show, setShow] = useState(true);
10
+ const ToastComponent = ({ toast, position = 'bottom-end' }) => {
11
+ const [toastsHistory, setToastsHistory] = useState([]);
19
12
 
20
- const toggleShow = () => setShow(!show);
21
-
22
- const delay = autoClose ? 3500 : null;
23
- const autohide = autoClose ? true : false;
24
-
25
- const variantIcons = {
26
- info: 'circle-info',
27
- success: 'circle-check',
28
- warning: 'triangle-exclamation',
29
- error: 'circle-xmark',
30
- };
31
-
32
- const iconClass = variantIcons[variant];
13
+ useEffect(() => {
14
+ if (toast) setToastsHistory([...toastsHistory, toast]);
15
+ }, [toast]);
33
16
 
34
17
  return (
35
18
  <ToastContainer position={position}>
36
- <Toast
37
- onClose={toggleShow}
38
- show={show}
39
- delay={delay}
40
- autohide={autohide}
41
- className={`${position} ${variant} ${className ? className : ''}`}
42
- >
43
- <Toast.Body>
44
- <div className='toast-wrapper'>
45
- <div className='toast-type'>
46
- <Icon
47
- style={'solid'}
48
- iconName={iconClass}
49
- scale={1}
50
- className={'icon'}
51
- />
52
- </div>
53
- <span>{children}</span>
54
- </div>
55
- {!autoClose && (
56
- <button className='btn-close' onClick={toggleShow}>
57
- <Icon
58
- style={'solid'}
59
- iconName={'xmark'}
60
- scale={1}
61
- />
62
- </button>
63
- )}
64
- </Toast.Body>
65
- </Toast>
19
+ {toastsHistory.map(
20
+ ({ variant = 'info', autoClose = true, children, className }, i) => (
21
+ <ToastCardComponent
22
+ variant={variant}
23
+ autoClose={autoClose}
24
+ children={children}
25
+ className={className}
26
+ position={position}
27
+ key={children + variant + i}
28
+ />
29
+ ),
30
+ )}
66
31
  </ToastContainer>
67
32
  );
68
33
  };
69
34
 
70
35
  ToastComponent.propTypes = {
71
- variant: PropTypes.oneOf(['info', 'success', 'warning', 'error']),
72
- autoClose: PropTypes.bool,
36
+ toast: PropTypes.object,
73
37
  position: PropTypes.oneOf([
74
38
  'top-start',
75
39
  'top-end',
76
40
  'bottom-start',
77
41
  'bottom-end',
78
42
  ]),
79
- className: PropTypes.string,
80
43
  };
81
44
 
82
- export default ToastComponent;
45
+ export default ToastComponent;
@@ -1,11 +1,62 @@
1
1
  import React, { useState } from 'react';
2
2
  import ToastComponent from '../components/Toasts/ToastComponent';
3
3
 
4
+ import Button from '../components/Button/Button';
5
+
4
6
  export default {
5
- title: 'Toasts/ToastComponent',
6
- component: ToastComponent,
7
+ title: 'Toasts/ToastComponent',
8
+ component: ToastComponent,
7
9
  };
8
10
 
9
- const Template = (args) => <ToastComponent {...args}>ToastComponent</ToastComponent>;
11
+ const Template = (args) => {
12
+
13
+ const [selected, setSelected] = useState(null);
14
+
15
+ const toasts = [
16
+ {
17
+ variant: 'info',
18
+ autoClose: true,
19
+ children: 'Se eliminó',
20
+ // className,
21
+ },
22
+ {
23
+ variant: 'success',
24
+ autoClose: true,
25
+ children: 'Se guardó',
26
+ // className,
27
+ },
28
+ {
29
+ variant: 'warning',
30
+ autoClose: true,
31
+ children: 'Se modificó',
32
+ // className,
33
+ },
34
+ {
35
+ variant: 'error',
36
+ autoClose: true,
37
+ children: 'Error',
38
+ // className,
39
+ },
40
+ {
41
+ variant: 'info',
42
+ autoClose: false,
43
+ children: 'No se puede eliminar',
44
+ // className,
45
+ }
46
+ ]
47
+
48
+ const pushToast = () => {
49
+ setSelected(toasts[Math.floor(Math.random() * toasts.length)]);
50
+ }
51
+
52
+ return (
53
+ <>
54
+ <Button onClick={pushToast}>Nuevo toast</Button>
55
+ <ToastComponent toast={selected} {...args}>
56
+ ToastComponent
57
+ </ToastComponent>
58
+ </>
59
+ );
60
+ };
10
61
 
11
- export const Default = Template.bind({});
62
+ export const Default = Template.bind({});