@tecsinapse/react-web-kit 1.5.0 → 1.6.3

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.
Files changed (131) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/components/atoms/Accordion/Accordion.d.ts +9 -0
  3. package/dist/components/atoms/Accordion/Accordion.js +85 -0
  4. package/dist/components/atoms/Accordion/Accordion.js.map +1 -0
  5. package/dist/components/atoms/Accordion/animations.d.ts +41 -0
  6. package/dist/components/atoms/Accordion/animations.js +65 -0
  7. package/dist/components/atoms/Accordion/animations.js.map +1 -0
  8. package/dist/components/atoms/Accordion/index.d.ts +1 -0
  9. package/dist/components/atoms/Accordion/index.js +24 -0
  10. package/dist/components/atoms/Accordion/index.js.map +1 -0
  11. package/dist/components/atoms/Accordion/styled.d.ts +8 -0
  12. package/dist/components/atoms/Accordion/styled.js +53 -0
  13. package/dist/components/atoms/Accordion/styled.js.map +1 -0
  14. package/dist/components/atoms/Badge/index.js +2 -2
  15. package/dist/components/atoms/Button/index.js +2 -2
  16. package/dist/components/atoms/Button/styled.js +5 -3
  17. package/dist/components/atoms/Button/styled.js.map +1 -1
  18. package/dist/components/atoms/Input/index.js +2 -2
  19. package/dist/components/atoms/Modal/Modal.d.ts +8 -0
  20. package/dist/components/atoms/Modal/Modal.js +43 -0
  21. package/dist/components/atoms/Modal/Modal.js.map +1 -0
  22. package/dist/components/atoms/Modal/animations.d.ts +23 -0
  23. package/dist/components/atoms/Modal/animations.js +32 -0
  24. package/dist/components/atoms/Modal/animations.js.map +1 -0
  25. package/dist/components/atoms/Modal/index.d.ts +1 -0
  26. package/dist/components/atoms/Modal/index.js +24 -0
  27. package/dist/components/atoms/Modal/index.js.map +1 -0
  28. package/dist/components/atoms/Modal/styled.d.ts +2 -0
  29. package/dist/components/atoms/Modal/styled.js +39 -0
  30. package/dist/components/atoms/Modal/styled.js.map +1 -0
  31. package/dist/components/atoms/Overlay/Overlay.d.ts +10 -0
  32. package/dist/components/atoms/Overlay/Overlay.js +40 -0
  33. package/dist/components/atoms/Overlay/Overlay.js.map +1 -0
  34. package/dist/components/atoms/Overlay/animations.d.ts +18 -0
  35. package/dist/components/atoms/Overlay/animations.js +27 -0
  36. package/dist/components/atoms/Overlay/animations.js.map +1 -0
  37. package/dist/components/atoms/Overlay/index.d.ts +1 -0
  38. package/dist/components/atoms/Overlay/index.js +16 -0
  39. package/dist/components/atoms/Overlay/index.js.map +1 -0
  40. package/dist/components/atoms/Overlay/styled.d.ts +2 -0
  41. package/dist/components/atoms/Overlay/styled.js +36 -0
  42. package/dist/components/atoms/Overlay/styled.js.map +1 -0
  43. package/dist/components/atoms/Skeleton/index.js +2 -2
  44. package/dist/components/atoms/Table/Toolbar/index.js +2 -2
  45. package/dist/components/atoms/Tag/index.js +2 -2
  46. package/dist/components/molecules/Breadcrumbs/BreadcrumbItem/index.js +2 -2
  47. package/dist/components/molecules/Breadcrumbs/Breadcrumbs.d.ts +3 -3
  48. package/dist/components/molecules/Breadcrumbs/Breadcrumbs.js +3 -3
  49. package/dist/components/molecules/Breadcrumbs/Breadcrumbs.js.map +1 -1
  50. package/dist/components/molecules/Breadcrumbs/index.d.ts +1 -1
  51. package/dist/components/molecules/Breadcrumbs/index.js +8 -2
  52. package/dist/components/molecules/Breadcrumbs/index.js.map +1 -1
  53. package/dist/components/molecules/Drawer/Drawer.js +8 -11
  54. package/dist/components/molecules/Drawer/Drawer.js.map +1 -1
  55. package/dist/components/molecules/Drawer/animations.d.ts +0 -18
  56. package/dist/components/molecules/Drawer/animations.js +1 -21
  57. package/dist/components/molecules/Drawer/animations.js.map +1 -1
  58. package/dist/components/molecules/Drawer/index.js +2 -2
  59. package/dist/components/molecules/Drawer/styled.d.ts +0 -1
  60. package/dist/components/molecules/Drawer/styled.js +2 -21
  61. package/dist/components/molecules/Drawer/styled.js.map +1 -1
  62. package/dist/components/molecules/InputPassword/InputPassword.js +2 -2
  63. package/dist/components/molecules/InputPassword/index.js +2 -2
  64. package/dist/components/molecules/Menubar/MenuBlock/MenuBlock.d.ts +4 -3
  65. package/dist/components/molecules/Menubar/MenuBlock/MenuBlock.js +14 -5
  66. package/dist/components/molecules/Menubar/MenuBlock/MenuBlock.js.map +1 -1
  67. package/dist/components/molecules/Menubar/MenuBlock/MenuItem/MenuItem.d.ts +1 -0
  68. package/dist/components/molecules/Menubar/MenuBlock/MenuItem/MenuItem.js +6 -3
  69. package/dist/components/molecules/Menubar/MenuBlock/MenuItem/MenuItem.js.map +1 -1
  70. package/dist/components/molecules/Menubar/MenuBlock/MenuItem/SubMenuBlock/SubMenuBlock.d.ts +1 -0
  71. package/dist/components/molecules/Menubar/MenuBlock/MenuItem/SubMenuBlock/SubMenuBlock.js +4 -2
  72. package/dist/components/molecules/Menubar/MenuBlock/MenuItem/SubMenuBlock/SubMenuBlock.js.map +1 -1
  73. package/dist/components/molecules/Menubar/Menubar.d.ts +3 -2
  74. package/dist/components/molecules/Menubar/Menubar.js +26 -33
  75. package/dist/components/molecules/Menubar/Menubar.js.map +1 -1
  76. package/dist/components/molecules/Menubar/MostUsed/MostUsed.d.ts +3 -2
  77. package/dist/components/molecules/Menubar/MostUsed/MostUsed.js +6 -3
  78. package/dist/components/molecules/Menubar/MostUsed/MostUsed.js.map +1 -1
  79. package/dist/components/molecules/Menubar/SearchResultItem/SearchResultItem.d.ts +1 -0
  80. package/dist/components/molecules/Menubar/SearchResultItem/SearchResultItem.js +4 -2
  81. package/dist/components/molecules/Menubar/SearchResultItem/SearchResultItem.js.map +1 -1
  82. package/dist/components/molecules/Menubar/animations.d.ts +2 -2
  83. package/dist/components/molecules/Menubar/animations.js +14 -22
  84. package/dist/components/molecules/Menubar/animations.js.map +1 -1
  85. package/dist/components/molecules/Menubar/index.d.ts +1 -0
  86. package/dist/components/molecules/Menubar/index.js +26 -3
  87. package/dist/components/molecules/Menubar/index.js.map +1 -1
  88. package/dist/components/molecules/Menubar/styled.js +5 -2
  89. package/dist/components/molecules/Menubar/styled.js.map +1 -1
  90. package/dist/components/molecules/Menubar/types.js +4 -0
  91. package/dist/components/molecules/Select/index.js +2 -2
  92. package/dist/components/molecules/Snackbar/index.js +2 -2
  93. package/dist/components/molecules/Snackbar/styled.js +2 -2
  94. package/dist/components/organisms/DataGrid/index.js +2 -2
  95. package/dist/components/organisms/DataGrid/types.js +4 -0
  96. package/dist/index.d.ts +6 -3
  97. package/dist/index.js +99 -14
  98. package/dist/index.js.map +1 -1
  99. package/package.json +5 -5
  100. package/src/components/atoms/Accordion/Accordion.stories.tsx +35 -0
  101. package/src/components/atoms/Accordion/Accordion.tsx +99 -0
  102. package/src/components/atoms/Accordion/animations.ts +51 -0
  103. package/src/components/atoms/Accordion/index.ts +1 -0
  104. package/src/components/atoms/Accordion/styled.ts +35 -0
  105. package/src/components/atoms/Button/styled.ts +3 -1
  106. package/src/components/atoms/Modal/Modal.stories.tsx +55 -0
  107. package/src/components/atoms/Modal/Modal.tsx +34 -0
  108. package/src/components/atoms/Modal/animations.ts +12 -0
  109. package/src/components/atoms/Modal/index.ts +1 -0
  110. package/src/components/atoms/Modal/styled.ts +17 -0
  111. package/src/components/atoms/Overlay/Overlay.tsx +40 -0
  112. package/src/components/atoms/Overlay/animations.ts +11 -0
  113. package/src/components/atoms/Overlay/index.ts +1 -0
  114. package/src/components/atoms/Overlay/styled.ts +20 -0
  115. package/src/components/molecules/Breadcrumbs/Breadcrumbs.tsx +5 -5
  116. package/src/components/molecules/Breadcrumbs/index.ts +5 -1
  117. package/src/components/molecules/Drawer/Drawer.stories.tsx +10 -20
  118. package/src/components/molecules/Drawer/Drawer.tsx +3 -15
  119. package/src/components/molecules/Drawer/animations.ts +0 -11
  120. package/src/components/molecules/Drawer/styled.ts +1 -14
  121. package/src/components/molecules/Menubar/MenuBlock/MenuBlock.tsx +38 -31
  122. package/src/components/molecules/Menubar/MenuBlock/MenuItem/MenuItem.tsx +4 -2
  123. package/src/components/molecules/Menubar/MenuBlock/MenuItem/SubMenuBlock/SubMenuBlock.tsx +3 -2
  124. package/src/components/molecules/Menubar/Menubar.stories.tsx +19 -13
  125. package/src/components/molecules/Menubar/Menubar.tsx +48 -57
  126. package/src/components/molecules/Menubar/MostUsed/MostUsed.tsx +4 -2
  127. package/src/components/molecules/Menubar/SearchResultItem/SearchResultItem.tsx +7 -2
  128. package/src/components/molecules/Menubar/animations.ts +14 -21
  129. package/src/components/molecules/Menubar/index.ts +5 -0
  130. package/src/components/molecules/Menubar/styled.ts +3 -2
  131. package/src/index.ts +16 -2
@@ -2,26 +2,26 @@ import React, { ElementType, FC } from 'react';
2
2
  import { StyledContainerBreadcrumbs } from './styled';
3
3
  import { BreadcrumbItem } from './BreadcrumbItem';
4
4
 
5
- type Breadcrumb = {
5
+ export type BreadcrumbType = {
6
6
  title: string;
7
7
  Component: ElementType;
8
- componentProps?: any;
8
+ props?: any;
9
9
  };
10
10
 
11
11
  export interface BreadcrumbsProps {
12
- breadcrumbs: Breadcrumb[];
12
+ breadcrumbs: BreadcrumbType[];
13
13
  }
14
14
 
15
15
  const Breadcrumbs: FC<BreadcrumbsProps> = ({ breadcrumbs }) => {
16
16
  return (
17
17
  <StyledContainerBreadcrumbs>
18
18
  {breadcrumbs.map((item, index) => {
19
- const { componentProps, Component, title } = item;
19
+ const { props, Component = 'a', title } = item;
20
20
  return (
21
21
  <BreadcrumbItem
22
22
  key={index}
23
23
  Component={Component}
24
- props={componentProps}
24
+ props={props}
25
25
  isLast={breadcrumbs.length - 1 === index}
26
26
  title={title}
27
27
  />
@@ -1 +1,5 @@
1
- export { default as Breadcrumbs, BreadcrumbsProps } from './Breadcrumbs';
1
+ export {
2
+ default as Breadcrumbs,
3
+ BreadcrumbsProps,
4
+ BreadcrumbType,
5
+ } from './Breadcrumbs';
@@ -8,35 +8,34 @@ import { default as Drawer, DrawerProps } from './Drawer';
8
8
  export default {
9
9
  title: 'Components/Drawer',
10
10
  component: Drawer,
11
- parameters: {
12
- layout: 'fullscreen',
13
- },
14
11
  };
15
12
 
16
13
  const Template: Story<DrawerProps> = ({ anchorPosition, open }) => {
17
14
  const [isOpen, setOpen] = React.useState<boolean>(open);
18
15
 
19
- const onClose = () => {
16
+ const toggleOpen = () => {
20
17
  setOpen(!isOpen);
21
18
  };
22
19
 
23
20
  return (
24
21
  <>
25
- <Drawer open={isOpen} onClose={onClose} anchorPosition={anchorPosition}>
22
+ <Drawer
23
+ open={isOpen}
24
+ onClose={toggleOpen}
25
+ anchorPosition={anchorPosition}
26
+ >
26
27
  <StyledHeaderDrawerStory>
27
28
  <StyledTextHeader typography="h4">Design System</StyledTextHeader>
28
29
  <StyledHButtonHeaderStory>
29
- <Button size="small" onPress={onClose} variant="text">
30
+ <Button size="small" onPress={toggleOpen} variant="text">
30
31
  <Icon name="close" type="material-community" />
31
32
  </Button>
32
33
  </StyledHButtonHeaderStory>
33
34
  </StyledHeaderDrawerStory>
34
35
  </Drawer>
35
- <StyledContainerButtonStory>
36
- <Button onPress={onClose}>
37
- <StyledTextButton fontColor="light">Open Drawer</StyledTextButton>
38
- </Button>
39
- </StyledContainerButtonStory>
36
+ <Button onPress={toggleOpen}>
37
+ <StyledTextButton fontColor="light">Open Drawer</StyledTextButton>
38
+ </Button>
40
39
  </>
41
40
  );
42
41
  };
@@ -48,15 +47,6 @@ Base.args = {
48
47
  open: false,
49
48
  };
50
49
 
51
- const StyledContainerButtonStory = styled('div')`
52
- display: flex;
53
- flex-direction: row;
54
- align-items: center;
55
- justify-content: center;
56
- width: 100vw;
57
- height: 100vh;
58
- `;
59
-
60
50
  const StyledHeaderDrawerStory = styled('div')`
61
51
  display: flex;
62
52
  flex-direction: row;
@@ -1,13 +1,12 @@
1
1
  import React, { FC } from 'react';
2
- import { StyledContainerDrawer, StyledOverlay } from './styled';
2
+ import { StyledContainerDrawer } from './styled';
3
3
  import { Transition } from 'react-transition-group';
4
+ import { Overlay } from '../../atoms/Overlay';
4
5
  import {
5
6
  transitionStylesTopBottom,
6
7
  defaultStylesTopBottom,
7
8
  defaultStylesLeftRight,
8
- transitionStylesOverlay,
9
9
  transitionStylesLeftRight,
10
- defaultStyleOverlay,
11
10
  } from './animations';
12
11
 
13
12
  export interface DrawerProps {
@@ -43,18 +42,7 @@ const Drawer: FC<DrawerProps> = ({
43
42
 
44
43
  return (
45
44
  <>
46
- <Transition in={open} timeout={300}>
47
- {state => (
48
- <div
49
- style={{
50
- ...defaultStyleOverlay,
51
- ...transitionStylesOverlay[state],
52
- }}
53
- >
54
- <StyledOverlay onClick={open ? onClose : undefined} show={open} />
55
- </div>
56
- )}
57
- </Transition>
45
+ <Overlay timeout={300} open={open} onClose={onClose} zIndex="drawer" />
58
46
  <Transition in={open} timeout={300}>
59
47
  {state => (
60
48
  <StyledContainerDrawer
@@ -1,14 +1,3 @@
1
- export const defaultStyleOverlay = {
2
- transition: `opacity 700ms ease-in-out`,
3
- opacity: 0,
4
- };
5
- export const transitionStylesOverlay = {
6
- entering: { opacity: 1 },
7
- entered: { opacity: 1 },
8
- exiting: { opacity: 0 },
9
- exited: { opacity: 0 },
10
- };
11
-
12
1
  export const transformLeftRigthClose = (anchorPosition: string) =>
13
2
  anchorPosition === 'right' ? 'translateX(100%)' : 'translateX(-100%)';
14
3
 
@@ -3,19 +3,6 @@ import { hex2rgba, StyleProps } from '@tecsinapse/react-core';
3
3
  import { DrawerProps } from './Drawer';
4
4
  import { css } from '@emotion/react';
5
5
 
6
- export const StyledOverlay = styled('div')<
7
- Partial<StyleProps> & { show: boolean }
8
- >`
9
- background: ${({ theme }: StyleProps) =>
10
- hex2rgba(theme.miscellaneous.overlay, 0.5)};
11
- width: 100vw;
12
- height: 100vh;
13
- z-index: ${({ theme, show }: StyleProps & { show: boolean }) =>
14
- show ? theme.zIndex.drawer : theme.zIndex.default};
15
- cursor: ${({ show }) => (show ? 'pointer' : 'default')};
16
- position: absolute;
17
- `;
18
-
19
6
  const anchorLeft = ({ theme, anchorPosition }: StyleProps & DrawerProps) => {
20
7
  return (
21
8
  anchorPosition === 'left' &&
@@ -72,7 +59,7 @@ const baseStyles = ({ theme, anchorPosition }: StyleProps & DrawerProps) => {
72
59
  position: fixed;
73
60
  overflow: hidden;
74
61
  background-color: ${theme.miscellaneous.bodyColor};
75
- z-index: ${theme.zIndex.drawer + 1};
62
+ z-index: ${theme.zIndex.drawer};
76
63
  `;
77
64
  };
78
65
 
@@ -7,42 +7,49 @@ import {
7
7
  StyledLeftComponent,
8
8
  } from './styled';
9
9
  import { ItemsOptions, OptionsType } from '../types';
10
+ import { Masonry } from '../../Masonry';
10
11
 
11
12
  interface MenuBlockProps {
12
- data: OptionsType;
13
+ toggle: () => void;
14
+ options: OptionsType[];
13
15
  }
14
16
 
15
- const MenuBlock: React.FC<MenuBlockProps> = ({ data }) => {
17
+ const MenuBlock: React.FC<MenuBlockProps> = ({ options, toggle }) => {
16
18
  return (
17
- <>
18
- <StyledContainerMenu>
19
- {data.leftComponents && (
20
- <StyledLeftComponent>{data.leftComponents}</StyledLeftComponent>
21
- )}
22
- <Text fontWeight="bold">{data.title}</Text>
23
- </StyledContainerMenu>
24
- <StyledContainerItems>
25
- {data.items.map(
26
- ({
27
- title,
28
- Component,
29
- props,
30
- rightComponents,
31
- items,
32
- }: ItemsOptions) => (
33
- <MenuItem
34
- items={items}
35
- key={title}
36
- title={title}
37
- Component={Component}
38
- rightComponents={rightComponents}
39
- props={props}
40
- />
41
- )
42
- )}
43
- </StyledContainerItems>
44
- </>
19
+ <Masonry columns={4} spacingTop="kilo" spacingLeft="mega">
20
+ {options.map(data => (
21
+ <>
22
+ <StyledContainerMenu>
23
+ {data.leftComponents && (
24
+ <StyledLeftComponent>{data.leftComponents}</StyledLeftComponent>
25
+ )}
26
+ <Text fontWeight="bold">{data.title}</Text>
27
+ </StyledContainerMenu>
28
+ <StyledContainerItems>
29
+ {data.items.map(
30
+ ({
31
+ title,
32
+ Component,
33
+ props,
34
+ rightComponents,
35
+ items,
36
+ }: ItemsOptions) => (
37
+ <MenuItem
38
+ items={items}
39
+ key={title}
40
+ title={title}
41
+ Component={Component}
42
+ rightComponents={rightComponents}
43
+ props={props}
44
+ toggle={toggle}
45
+ />
46
+ )
47
+ )}
48
+ </StyledContainerItems>
49
+ </>
50
+ ))}
51
+ </Masonry>
45
52
  );
46
53
  };
47
54
 
48
- export default MenuBlock;
55
+ export default React.memo(MenuBlock);
@@ -11,6 +11,7 @@ interface MenuItemProps {
11
11
  Component: ElementType;
12
12
  /** Properties spread to wrapping Component */
13
13
  props: any;
14
+ toggle: () => void;
14
15
  rightComponents?: React.ReactNode;
15
16
  items?: ItemsOptions[];
16
17
  }
@@ -21,6 +22,7 @@ const MenuItem: React.FC<MenuItemProps> = ({
21
22
  props = {},
22
23
  rightComponents,
23
24
  items,
25
+ toggle,
24
26
  }) => {
25
27
  const [open, setOpen] = React.useState<boolean>(false);
26
28
 
@@ -34,7 +36,7 @@ const MenuItem: React.FC<MenuItemProps> = ({
34
36
  return (
35
37
  <>
36
38
  <StyledContainerItemText key={title}>
37
- <Component {...props} style={noTextDecoration}>
39
+ <Component {...props} style={noTextDecoration} onClick={toggle}>
38
40
  <Text
39
41
  colorVariant={open ? 'primary' : 'secondary'}
40
42
  colorTone={open ? 'medium' : 'dark'}
@@ -57,7 +59,7 @@ const MenuItem: React.FC<MenuItemProps> = ({
57
59
  </StyledContainerItemText>
58
60
  {open &&
59
61
  items?.map(subItem => (
60
- <SubMenuBlock key={subItem.title} data={subItem} />
62
+ <SubMenuBlock key={subItem.title} data={subItem} toggle={toggle} />
61
63
  ))}
62
64
  </>
63
65
  );
@@ -6,9 +6,10 @@ import { DummyBorder, StyledContainerItem } from './styled';
6
6
 
7
7
  interface SubMenuBlockProps {
8
8
  data: ItemsOptions;
9
+ toggle: () => void;
9
10
  }
10
11
 
11
- const SubMenuBlock: React.FC<SubMenuBlockProps> = ({ data }) => {
12
+ const SubMenuBlock: React.FC<SubMenuBlockProps> = ({ data, toggle }) => {
12
13
  const { Component, props, rightComponents, title } = data;
13
14
 
14
15
  const noTextDecoration = { textDecoration: 'none' };
@@ -16,7 +17,7 @@ const SubMenuBlock: React.FC<SubMenuBlockProps> = ({ data }) => {
16
17
  return (
17
18
  <StyledContainerItem>
18
19
  <DummyBorder />
19
- <Component {...props} style={noTextDecoration}>
20
+ <Component {...props} style={noTextDecoration} onClick={toggle}>
20
21
  <Text colorVariant="secondary" colorTone="medium" typography="sub">
21
22
  <StyledText>{title}</StyledText>
22
23
  </Text>
@@ -2,7 +2,7 @@ import React, { ElementType } from 'react';
2
2
  import Menubar, { MenubarProps } from './Menubar';
3
3
  import { Story } from '@storybook/react';
4
4
  import styled from '@emotion/styled';
5
- import { Icon, Text } from '@tecsinapse/react-core';
5
+ import { Avatar, Icon, Text } from '@tecsinapse/react-core';
6
6
 
7
7
  export default {
8
8
  title: 'Components/Menu Bar',
@@ -253,20 +253,26 @@ const StyledImage = styled('img')`
253
253
  margin-right: 35px;
254
254
  `;
255
255
 
256
- // Import type manually
257
256
  const Template: Story<MenubarProps> = args => {
258
257
  return (
259
- <Menubar
260
- {...args}
261
- options={EXAMPLE_MENU}
262
- mostUsed={MOST_USED}
263
- leftComponents={
264
- <StyledImage
265
- src="https://www.tecsinapse.com.br/wp-content/themes/tecsinapse/img/logo.svg"
266
- alt="TecSinapse"
267
- />
268
- }
269
- />
258
+ <>
259
+ <Menubar
260
+ {...args}
261
+ options={EXAMPLE_MENU}
262
+ mostUsed={MOST_USED}
263
+ leftComponents={
264
+ <StyledImage
265
+ src="https://www.tecsinapse.com.br/wp-content/themes/tecsinapse/img/logo.svg"
266
+ alt="TecSinapse"
267
+ />
268
+ }
269
+ rightComponents={
270
+ <div style={{ marginLeft: 24 }}>
271
+ <Avatar name="Design System" />
272
+ </div>
273
+ }
274
+ />
275
+ </>
270
276
  );
271
277
  };
272
278
 
@@ -1,12 +1,6 @@
1
1
  import React from 'react';
2
- import {
3
- Icon,
4
- Text,
5
- ThemeProp,
6
- useDebouncedState,
7
- } from '@tecsinapse/react-core';
2
+ import { Icon, Text, useDebouncedState } from '@tecsinapse/react-core';
8
3
  import { Transition } from 'react-transition-group';
9
- import { useTheme } from '@emotion/react';
10
4
  import {
11
5
  StyledIconInput,
12
6
  StyledMenuBar,
@@ -17,7 +11,6 @@ import {
17
11
  StyledSearchResultsContainer,
18
12
  StyledSearchTextContainer,
19
13
  } from './styled';
20
- import { Masonry } from '../Masonry';
21
14
  import { MostUsedType, OptionsType } from './types';
22
15
  import { MostUsed } from './MostUsed';
23
16
  import { MenuBlock } from './MenuBlock';
@@ -29,32 +22,35 @@ import {
29
22
  } from './animations';
30
23
 
31
24
  export interface MenubarProps {
25
+ options: OptionsType[];
32
26
  leftComponents?: React.ReactNode;
33
27
  rightComponents?: React.ReactNode;
34
- inputPlaceholder?: string;
35
- options: OptionsType[];
36
28
  /** Limited to first 4 elements */
37
29
  mostUsed?: MostUsedType[];
38
30
  mostUsedLabel?: string;
31
+ searchable?: boolean;
32
+ searchPlaceholder?: string;
39
33
  searchResultsLabel?: string;
40
34
  }
41
35
 
42
36
  const Menubar: React.FC<MenubarProps> = ({
43
37
  leftComponents,
44
38
  rightComponents,
45
- inputPlaceholder = 'O quê você deseja buscar?',
39
+ searchPlaceholder = 'O quê você deseja buscar?',
46
40
  options,
47
41
  mostUsed,
48
42
  mostUsedLabel = 'Mais acessados',
49
43
  searchResultsLabel = 'Resultados da busca',
44
+ searchable = true,
50
45
  }) => {
51
46
  const [search, setSearch] = React.useState<string>('');
52
47
  const [results, setResults] = React.useState<MostUsedType[]>([]);
53
48
  const [input, setInput] = useDebouncedState('', state => setSearch(state));
54
- const [isOpen, setOpen] = React.useState<boolean>(false);
55
- const theme = useTheme() as ThemeProp;
49
+ const [open, setOpen] = React.useState<boolean>(false);
56
50
 
57
- const toggleOpenClose = () => setOpen(!isOpen);
51
+ const toggleOpen = React.useCallback(() => setOpen(state => !state), [
52
+ setOpen,
53
+ ]);
58
54
 
59
55
  React.useEffect(() => {
60
56
  if (search === '') return;
@@ -64,12 +60,8 @@ const Menubar: React.FC<MenubarProps> = ({
64
60
  return (
65
61
  <>
66
62
  <StyledMenuBar>
67
- <StyledMenuButton
68
- variant="filled"
69
- color="primary"
70
- onPress={toggleOpenClose}
71
- >
72
- {!isOpen ? (
63
+ <StyledMenuButton variant="filled" color="primary" onPress={toggleOpen}>
64
+ {!open ? (
73
65
  <Icon
74
66
  size="deca"
75
67
  name="menu"
@@ -86,12 +78,12 @@ const Menubar: React.FC<MenubarProps> = ({
86
78
  )}
87
79
  </StyledMenuButton>
88
80
  {leftComponents}
89
- <Transition in={isOpen} timeout={250}>
81
+ <Transition in={open} timeout={250}>
90
82
  {state => (
91
- <div style={getInputContainerStyles(state, theme)}>
92
- <StyledInputContainer>
83
+ <StyledInputContainer style={getInputContainerStyles(state)}>
84
+ {searchable && (
93
85
  <StyledInput
94
- placeholder={inputPlaceholder}
86
+ placeholder={searchPlaceholder}
95
87
  leftComponent={
96
88
  <StyledIconInput>
97
89
  <Icon name="magnify" type="material-community" />
@@ -100,43 +92,42 @@ const Menubar: React.FC<MenubarProps> = ({
100
92
  value={input}
101
93
  onChange={setInput}
102
94
  />
103
- </StyledInputContainer>
104
- {rightComponents}
105
- </div>
95
+ )}
96
+ </StyledInputContainer>
106
97
  )}
107
98
  </Transition>
99
+ {rightComponents}
108
100
  </StyledMenuBar>
109
- <Transition in={isOpen} timeout={250}>
101
+ <Transition in={open} timeout={250}>
110
102
  {state => (
111
- <div style={getContainerOpenMenuStyles(state, theme)}>
112
- <StyledContainerOpenMenu>
113
- {!search ? (
114
- <div>
115
- {mostUsed && (
116
- <MostUsed label={mostUsedLabel} data={mostUsed} />
117
- )}
118
- <Masonry columns={4} spacingTop="kilo" spacingLeft="mega">
119
- {options.map(option => (
120
- <MenuBlock data={option} key={option.title} />
121
- ))}
122
- </Masonry>
123
- </div>
124
- ) : (
125
- <StyledSearchResultsContainer>
126
- <StyledSearchTextContainer>
127
- <Text fontWeight="bold">{searchResultsLabel}</Text>
128
- </StyledSearchTextContainer>
129
- {results.map(result => (
130
- <SearchResultItem
131
- key={`${result.title}-${result.category}`}
132
- data={result}
133
- searchTerm={search}
134
- />
135
- ))}
136
- </StyledSearchResultsContainer>
137
- )}
138
- </StyledContainerOpenMenu>
139
- </div>
103
+ <StyledContainerOpenMenu style={getContainerOpenMenuStyles(state)}>
104
+ {!search ? (
105
+ <>
106
+ {mostUsed && (
107
+ <MostUsed
108
+ label={mostUsedLabel}
109
+ data={mostUsed}
110
+ toggle={toggleOpen}
111
+ />
112
+ )}
113
+ <MenuBlock options={options} toggle={toggleOpen} />
114
+ </>
115
+ ) : (
116
+ <StyledSearchResultsContainer>
117
+ <StyledSearchTextContainer>
118
+ <Text fontWeight="bold">{searchResultsLabel}</Text>
119
+ </StyledSearchTextContainer>
120
+ {results.map(result => (
121
+ <SearchResultItem
122
+ key={`${result.title}-${result.category}`}
123
+ data={result}
124
+ searchTerm={search}
125
+ toggle={toggleOpen}
126
+ />
127
+ ))}
128
+ </StyledSearchResultsContainer>
129
+ )}
130
+ </StyledContainerOpenMenu>
140
131
  )}
141
132
  </Transition>
142
133
  </>