groovinads-ui 1.2.38 → 1.2.40

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.38",
4
+ "version": "1.2.40",
5
5
  "keywords": [
6
6
  "css",
7
7
  "sass",
@@ -32,16 +32,10 @@ const DropdownDatePicker = ({
32
32
  dateTo2,
33
33
  setDateTo2,
34
34
  }) => {
35
- const [activeTab, setActiveTab] = useState(1);
35
+ //const [activeTab, setActiveTab] = useState(1);
36
36
 
37
37
  const [compareDates, setCompareDates] = useState(true);
38
38
 
39
- /* State for dropdowns only visible when selecting 'compare dates' option */
40
- const [period1, setPeriod1] = useState('Custom range');
41
- const [detailLevel1, setDetailLevel1] = useState('Daily');
42
-
43
- const [period2, setPeriod2] = useState('Custom range');
44
- const [detailLevel2, setDetailLevel2] = useState('Daily');
45
39
 
46
40
  /* We have a 'local' state for datepickers inside the dropdown, so the user can cancel the dropdown and go back to previous values. */
47
41
  /* When user confirms selected values, the 'local' state replaces the values previously stored in the DateFilters component. */
@@ -49,9 +43,6 @@ const DropdownDatePicker = ({
49
43
  const [editingDateFrom, setEditingDateFrom] = useState(dateFrom);
50
44
  const [editingDateTo, setEditingDateTo] = useState(dateTo);
51
45
 
52
- const [editingDateFrom2, setEditingDateFrom2] = useState(dateFrom2);
53
- const [editingDateTo2, setEditingDateTo2] = useState(dateTo2);
54
-
55
46
  const [internalShow, setInternalShow] = useState(!!show);
56
47
 
57
48
  const { capitalice } = useTextFormatter();
@@ -64,12 +55,6 @@ const DropdownDatePicker = ({
64
55
  setEditingDateTo(end);
65
56
  };
66
57
 
67
- const onChangeDate2 = (dates) => {
68
- const [start, end] = dates;
69
- setEditingDateFrom2(start);
70
- setEditingDateTo2(end);
71
- };
72
-
73
58
  const internalToggle = () => {
74
59
  setInternalShow((prevShow) => !prevShow);
75
60
  try {
@@ -105,7 +90,7 @@ const DropdownDatePicker = ({
105
90
  return (
106
91
  <Dropdown
107
92
  show={internalShow}
108
- className={`${variant === 'filter' ? 'dropdown-filter' : ''}`}
93
+ className={`${variant === 'filter' ? 'dropdown-filter' : ''} ${className}`}
109
94
  >
110
95
  <Dropdown.Toggle
111
96
  variant='toggle-filter'
@@ -16,11 +16,11 @@ const PillComponent = ({
16
16
  <span>{children}</span>
17
17
  {closeButton && (
18
18
  <button onClick={onClick}>
19
- <Icon
20
- style={'solid'}
21
- iconName={'xmark'}
22
- scale={0.7}
23
- />
19
+ <Icon
20
+ style={'solid'}
21
+ iconName={'xmark'}
22
+ scale={0.7}
23
+ />
24
24
  </button>
25
25
  )}
26
26
  </div>
@@ -11,15 +11,21 @@ import PropTypes from 'prop-types';
11
11
  // COMPONENTES
12
12
  import { Icon } from '../Labels';
13
13
 
14
- const Sidebar = ({ api, customLinks, defaultOpened = true, show, setShow}) => {
15
- const isMobile = useMediaQuery({ query: '(max-width: 992px)' })
14
+ const Sidebar = ({
15
+ api,
16
+ customLinks,
17
+ defaultOpened = true,
18
+ show,
19
+ setShow,
20
+ onNavigate,
21
+ }) => {
22
+ const isMobile = useMediaQuery({ query: '(max-width: 992px)' });
16
23
 
17
24
  const url = window.location.pathname; // to get current url
18
25
 
19
26
  const [sidebarLinks, setSidebarLinks] = useState([]);
20
27
  const [openIndex, setOpenIndex] = useState(null);
21
- console.log('defaultOpened', defaultOpened, isMobile? false : defaultOpened);
22
- const [innerShow, setInnerShow] = useState(isMobile? false : defaultOpened);
28
+ const [innerShow, setInnerShow] = useState(isMobile ? false : defaultOpened);
23
29
 
24
30
  const sidebarRef = useRef(null);
25
31
  const firstOpen = useRef(true);
@@ -43,7 +49,7 @@ const Sidebar = ({ api, customLinks, defaultOpened = true, show, setShow}) => {
43
49
 
44
50
  useEffect(() => {
45
51
  if (isMobile && setShow) setShow(innerShow);
46
- setInnerShow(isMobile ? false : firstOpen.current ? defaultOpened : show)
52
+ setInnerShow(isMobile ? false : firstOpen.current ? defaultOpened : show);
47
53
  firstOpen.current = false;
48
54
  }, []);
49
55
 
@@ -91,31 +97,29 @@ const Sidebar = ({ api, customLinks, defaultOpened = true, show, setShow}) => {
91
97
  <ul className='btn-toggle-nav'>
92
98
  {linkSection.children.map((childSection, x) => (
93
99
  <li key={`childSectionIndex${x}`}>
94
- <a
100
+ <button
95
101
  className={`nav-link ${
96
102
  url === childSection.url ? 'active' : ''
97
103
  }`}
98
- href={childSection.url}
104
+ onClick={() => onNavigate(childSection.url)}
99
105
  >
100
106
  {childSection.name}
101
- </a>
107
+ </button>
102
108
  </li>
103
109
  ))}
104
110
  </ul>
105
111
  </Collapse>
106
112
  </>
107
113
  ) : (
108
- <>
109
- <a
110
- className={`nav-link ${
111
- url === linkSection.url ? 'active' : ''
112
- }`}
113
- href={linkSection.url}
114
- >
115
- <Icon iconName={linkSection.icon} />
116
- {linkSection.name}
117
- </a>
118
- </>
114
+ <button
115
+ className={`nav-link ${
116
+ url === linkSection.url ? 'active' : ''
117
+ }`}
118
+ onClick={() => onNavigate(linkSection.url)}
119
+ >
120
+ <Icon iconName={linkSection.icon} />
121
+ {linkSection.name}
122
+ </button>
119
123
  )}
120
124
  </li>
121
125
  </ul>
@@ -135,6 +139,7 @@ Sidebar.propTypes = {
135
139
  defaultOpened: PropTypes.bool,
136
140
  show: PropTypes.bool, // Add show prop for controlling visibility
137
141
  setShow: PropTypes.func, // Add setShow prop for controlling visibility
142
+ onNavigate: PropTypes.func.isRequired, // Nueva prop para manejar la navegación
138
143
  };
139
144
 
140
145
  export default Sidebar;
@@ -1,4 +1,4 @@
1
- import React, { useState } from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { Nav } from 'react-bootstrap';
4
4
 
@@ -8,19 +8,27 @@ import { Icon } from '../Labels';
8
8
  // HOOKS
9
9
  import useTextFormatter from '../../hooks/useTextFormatter';
10
10
 
11
- function Tabnav({ tabs = [], activeTab = 1, customFunction = false}) {
11
+ function Tabnav({
12
+ tabs = [],
13
+ activeTab = 1,
14
+ navigateTab= false,
15
+ setActiveTab,
16
+ }) {
12
17
  const { toCamelCase } = useTextFormatter();
13
18
 
14
- const handleSelect = (k) => {
15
- if (customFunction){
16
- console.log('custom function');
17
- }else{
18
- const tabIndex = tabs.findIndex((tab) => toCamelCase(tab.tab) === k);
19
- console.log(tabs[tabIndex].url);
20
-
21
- window.location.href = tabs[tabIndex].url;
22
- }
19
+ // initial activeTab (in case it's not sent, it has a default value)
20
+ const [activeTabState, setActiveTabState] = useState(activeTab);
23
21
 
22
+ const handleSelect = (k) => {
23
+ if (navigateTab) {
24
+ const tab = tabs.find((tab) => toCamelCase(tab.tab) === k);
25
+ console.log(tab.url);
26
+ window.location.href = tab.url;
27
+ }else{
28
+ // console.log('Valor de k:', k);
29
+ const tabIndex = tabs.findIndex((tab) => toCamelCase(tab.tab) === k) + 1;
30
+ setActiveTab ? setActiveTab(tabIndex) : setActiveTabState(tabIndex);
31
+ }
24
32
  };
25
33
 
26
34
  const formatTabsName = (tab) => {
@@ -31,32 +39,37 @@ function Tabnav({ tabs = [], activeTab = 1, customFunction = false}) {
31
39
  return tabReplace.charAt(0).toUpperCase() + tabReplace.slice(1);
32
40
  };
33
41
 
42
+ useEffect(() => {
43
+ setActiveTabState(activeTab);
44
+ }, [activeTab]);
45
+
34
46
  return (
35
47
  <Nav
36
48
  variant='tabs'
37
- activeKey={toCamelCase(tabs[activeTab - 1].tab)}
49
+ activeKey={toCamelCase(tabs[activeTabState - 1].tab)}
38
50
  onSelect={handleSelect}
39
51
  >
40
- {tabs.map(({ tab, badgeNumber, warningIcon }, index) => (
41
- <Nav.Item key={index}>
42
- <Nav.Link
43
- eventKey={toCamelCase(tab)}
44
- >
45
- {/* Dia 1 => dia1 */}
46
- {warningIcon && <Icon iconName='triangle-exclamation' />}
47
- {formatTabsName(tab)}
48
- {badgeNumber && <span className='tab-badge'>{badgeNumber}</span>}
49
- </Nav.Link>
50
- </Nav.Item>
51
- ))}
52
+ {tabs.map(({ tab, badgeNumber, warningIcon }, index) => {
53
+ return (
54
+ <Nav.Item key={`tabs.tab: ${index}`}>
55
+ <Nav.Link eventKey={toCamelCase(tab)}>
56
+ {warningIcon && <Icon iconName='triangle-exclamation' />}
57
+ {formatTabsName(tab)}
58
+ {badgeNumber && <span className='tab-badge'>{badgeNumber}</span>}
59
+ </Nav.Link>
60
+ </Nav.Item>
61
+ );
62
+ })}
52
63
  </Nav>
53
64
  );
54
65
  }
55
66
 
56
67
  Tabnav.propTypes = {
57
- tabs: PropTypes.array,
68
+ tabs: PropTypes.array.isRequired,
58
69
  activeTab: PropTypes.number,
59
- customFunction: PropTypes.bool
70
+ customFunction: PropTypes.bool,
71
+ navigateTab: PropTypes.bool,
72
+ setExternalTab: PropTypes.func,
60
73
  };
61
74
 
62
75
  export default Tabnav;
@@ -41,7 +41,7 @@ const Template = (args) => {
41
41
  // onClick={() => handleToggle()}
42
42
  >
43
43
  <span>Add filter</span>
44
- <Icon iconName='fas fa-chevron-down' className='ms-2' />
44
+ <Icon iconName='chevron-down' className='ms-2' />
45
45
  </Button>
46
46
 
47
47
  <DropdownMenu>
@@ -1,5 +1,6 @@
1
- import React, { act, useState } from 'react';
1
+ import React, { useState } from 'react';
2
2
  import Tabnav from '../components/Navigation/Tabnav';
3
+ import { Button } from 'react-bootstrap';
3
4
 
4
5
  export default {
5
6
  title: 'Navigation/Tabnav',
@@ -8,13 +9,47 @@ export default {
8
9
 
9
10
  const Template = (args) => {
10
11
  const tabs = [
11
- { tab: 'hola', badgeNumber: '', url: '/com', warningIcon: true },
12
- { tab: 'tab 2', badgeNumber: '2', url: '/abc', warningIcon: false },
13
- { tab: 'tab 3', badgeNumber: '1', url: '/www', warningIcon: false },
12
+ { tab: 'Tab', badgeNumber: '', url: '/com', warningIcon: true },
13
+ { tab: 'Tab 1', badgeNumber: '1', url: '/abc', warningIcon: false },
14
+ { tab: 'Tab 2', badgeNumber: '2', url: '/www', warningIcon: false },
14
15
  ];
15
- const activeTab = tabs[0].tab;
16
+
17
+ const [activeTab, setActiveTab] = useState(1);
16
18
 
17
- return <Tabnav {...args} tabs={tabs} activeTab={activeTab} />;
19
+ return (
20
+ <>
21
+ {/* test: external Buttons to change */}
22
+ <Button onClick={() => setActiveTab(1)}>1</Button>
23
+ <Button onClick={() => setActiveTab(2)}>2</Button>
24
+ <Button onClick={() => setActiveTab(3)}>3</Button>
25
+
26
+ <Tabnav
27
+ {...args}
28
+ tabs={tabs}
29
+ activeTab={activeTab} // Send the external state
30
+ setActiveTab={setActiveTab} // Send the setter of the external state
31
+ />
32
+ <Tabnav
33
+ {...args}
34
+ tabs={tabs}
35
+ activeTab={2} // Test with the activeTab prop
36
+
37
+ />
38
+
39
+ <Tabnav
40
+ {...args}
41
+ tabs={tabs} // Test without the activeTab prop
42
+ />
43
+
44
+ <Tabnav
45
+ {...args}
46
+ tabs={tabs}
47
+ activeTab={activeTab}
48
+ setActiveTab={setActiveTab}
49
+ navigateTab={true} // Test with navigateTab prop
50
+ />
51
+ </>
52
+ );
18
53
  };
19
54
 
20
55
  export const Default = Template.bind({});