@qoretechnologies/reqore 0.34.2 → 0.34.4

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 (66) hide show
  1. package/__tests__/button.test.tsx +30 -1
  2. package/__tests__/containers/paging.test.tsx +1 -1
  3. package/__tests__/drawer.test.tsx +1 -1
  4. package/__tests__/heading.test.tsx +58 -0
  5. package/__tests__/hooks/useReqorePaging.test.tsx +16 -0
  6. package/__tests__/pagination.test.tsx +104 -3
  7. package/__tests__/panel.test.tsx +23 -2
  8. package/dist/components/Button/index.d.ts +3 -1
  9. package/dist/components/Button/index.d.ts.map +1 -1
  10. package/dist/components/Button/index.js +9 -7
  11. package/dist/components/Button/index.js.map +1 -1
  12. package/dist/components/Collection/index.js +1 -2
  13. package/dist/components/Collection/index.js.map +1 -1
  14. package/dist/components/ControlGroup/index.d.ts.map +1 -1
  15. package/dist/components/ControlGroup/index.js +3 -3
  16. package/dist/components/ControlGroup/index.js.map +1 -1
  17. package/dist/components/Drawer/index.d.ts.map +1 -1
  18. package/dist/components/Drawer/index.js +3 -10
  19. package/dist/components/Drawer/index.js.map +1 -1
  20. package/dist/components/Dropdown/list.js +1 -1
  21. package/dist/components/Dropdown/list.js.map +1 -1
  22. package/dist/components/Header/index.d.ts +3 -3
  23. package/dist/components/Header/index.d.ts.map +1 -1
  24. package/dist/components/Header/index.js +5 -2
  25. package/dist/components/Header/index.js.map +1 -1
  26. package/dist/components/Paging/index.d.ts +2 -1
  27. package/dist/components/Paging/index.d.ts.map +1 -1
  28. package/dist/components/Paging/index.js +41 -7
  29. package/dist/components/Paging/index.js.map +1 -1
  30. package/dist/components/Panel/NonResponsiveActions.d.ts +18 -0
  31. package/dist/components/Panel/NonResponsiveActions.d.ts.map +1 -0
  32. package/dist/components/Panel/NonResponsiveActions.js +47 -0
  33. package/dist/components/Panel/NonResponsiveActions.js.map +1 -0
  34. package/dist/components/Panel/index.d.ts +5 -1
  35. package/dist/components/Panel/index.d.ts.map +1 -1
  36. package/dist/components/Panel/index.js +32 -19
  37. package/dist/components/Panel/index.js.map +1 -1
  38. package/dist/components/Tag/group.js +4 -1
  39. package/dist/components/Tag/group.js.map +1 -1
  40. package/dist/containers/Paging.d.ts +3 -3
  41. package/dist/containers/Paging.d.ts.map +1 -1
  42. package/dist/containers/Paging.js +6 -6
  43. package/dist/containers/Paging.js.map +1 -1
  44. package/dist/hooks/usePaging.d.ts +5 -0
  45. package/dist/hooks/usePaging.d.ts.map +1 -1
  46. package/dist/hooks/usePaging.js +7 -1
  47. package/dist/hooks/usePaging.js.map +1 -1
  48. package/package.json +1 -1
  49. package/src/components/Button/index.tsx +19 -14
  50. package/src/components/Collection/index.tsx +2 -2
  51. package/src/components/ControlGroup/index.tsx +2 -3
  52. package/src/components/Drawer/index.tsx +4 -10
  53. package/src/components/Dropdown/list.tsx +1 -1
  54. package/src/components/Header/index.tsx +9 -3
  55. package/src/components/Paging/index.tsx +46 -6
  56. package/src/components/Panel/NonResponsiveActions.tsx +79 -0
  57. package/src/components/Panel/index.tsx +128 -75
  58. package/src/components/Tag/group.tsx +1 -1
  59. package/src/containers/Paging.tsx +83 -37
  60. package/src/hooks/usePaging.ts +14 -0
  61. package/src/stories/Drawer/Drawer.stories.tsx +6 -1
  62. package/src/stories/Dropdown/Dropdown.stories.tsx +1 -0
  63. package/src/stories/Header/Header.stories.tsx +6 -8
  64. package/src/stories/Paging/Paging.stories.tsx +22 -2
  65. package/src/stories/Panel/Panel.stories.tsx +13 -3
  66. package/tests.json +1 -1
@@ -1,26 +1,64 @@
1
1
  import { memo, useMemo } from 'react';
2
- import { IReqorePaginationProps, ReqorePagination } from '../components/Paging';
2
+ import {
3
+ IReqorePaginationComponentProps,
4
+ IReqorePaginationProps,
5
+ ReqorePagination,
6
+ } from '../components/Paging';
3
7
  import { ReqoreVerticalSpacer } from '../components/Spacer';
4
8
  import {
9
+ getPaginationOptionsFromType,
5
10
  TReqorePaginationType,
6
11
  TReqorePaginationTypeResult,
7
- getPaginationOptionsFromType,
8
12
  } from '../constants/paging';
9
13
  import { PADDING_FROM_SIZE, TSizes } from '../constants/sizes';
10
- import { useReqorePaging } from '../hooks/usePaging';
14
+ import { IReqorePagingResult, useReqorePaging } from '../hooks/usePaging';
11
15
 
12
16
  export interface IReqorePagingContainerProps<T> {
13
17
  type?: TReqorePaginationType<T>;
14
18
  items: T[];
15
- scrollContainer?: HTMLElement;
19
+ scrollContainer?: IReqorePaginationComponentProps['scrollContainer'];
16
20
  children: (
17
21
  items: T[],
18
- Controls: React.FC<Partial<IReqorePaginationProps<T>>>,
22
+ Controls: JSX.Element,
19
23
  options: TReqorePaginationTypeResult<T>
20
24
  ) => React.ReactNode;
21
25
  size?: TSizes;
22
26
  }
23
27
 
28
+ function PagingControls<T>({
29
+ withSpacer,
30
+ position,
31
+ pagingData,
32
+ componentOptions,
33
+ scrollContainer,
34
+ size,
35
+ ...pagingProps
36
+ }: Partial<IReqorePaginationProps<T>> &
37
+ Partial<TReqorePaginationTypeResult<T>> & {
38
+ withSpacer?: boolean;
39
+ position?: 'top' | 'bottom';
40
+ pagingData: Omit<IReqorePagingResult<T>, 'items'>;
41
+ }) {
42
+ return pagingData.renderControls ? (
43
+ <>
44
+ {withSpacer && position === 'bottom' ? (
45
+ <ReqoreVerticalSpacer height={PADDING_FROM_SIZE[size]} />
46
+ ) : null}
47
+ <ReqorePagination
48
+ key={`reqore-pagination-${position}`}
49
+ size={size}
50
+ {...pagingData}
51
+ {...componentOptions}
52
+ scrollContainer={scrollContainer}
53
+ {...pagingProps}
54
+ />
55
+ {withSpacer && position === 'top' ? (
56
+ <ReqoreVerticalSpacer height={PADDING_FROM_SIZE[size]} />
57
+ ) : null}
58
+ </>
59
+ ) : null;
60
+ }
61
+
24
62
  function PagingContainer<T>({
25
63
  type,
26
64
  items,
@@ -42,46 +80,54 @@ function PagingContainer<T>({
42
80
  enabled: !!type,
43
81
  });
44
82
 
45
- const Controls = ({
46
- withSpacer,
47
- position,
48
- ...pagingProps
49
- }: Partial<IReqorePaginationProps<T>> & { withSpacer?: boolean; position?: 'top' | 'bottom' }) =>
50
- pagingData.renderControls ? (
51
- <>
52
- {withSpacer && position === 'bottom' ? (
53
- <ReqoreVerticalSpacer height={PADDING_FROM_SIZE[size]} />
54
- ) : null}
55
- <ReqorePagination
56
- size={size}
57
- {...pagingData}
58
- {...componentOptions}
59
- scrollContainer={scrollContainer}
60
- {...pagingProps}
61
- />
62
- {withSpacer && position === 'top' ? (
63
- <ReqoreVerticalSpacer height={PADDING_FROM_SIZE[size]} />
64
- ) : null}
65
- </>
66
- ) : null;
67
-
68
83
  return (
69
84
  <>
70
85
  {includeTopControls && (pageControlsPosition === 'top' || pageControlsPosition === 'both') ? (
71
- <Controls autoLoadMore={false} scrollOnLoadMore={false} position='top' withSpacer />
86
+ <PagingControls<T>
87
+ key='top-paging'
88
+ position='top'
89
+ withSpacer
90
+ scrollContainer={scrollContainer}
91
+ size={size}
92
+ pagingData={pagingData}
93
+ pagingOptions={pagingOptions}
94
+ componentOptions={componentOptions}
95
+ autoLoadMore={false}
96
+ scrollOnLoadMore={false}
97
+ />
72
98
  ) : null}
73
99
 
74
- {children(finalItems, Controls, {
75
- pagingOptions,
76
- componentOptions,
77
- pageControlsPosition,
78
- includeTopControls,
79
- includeBottomControls,
80
- })}
100
+ {children(
101
+ finalItems,
102
+ <PagingControls
103
+ key='custom-paging'
104
+ scrollContainer={scrollContainer}
105
+ size={size}
106
+ pagingData={pagingData}
107
+ pagingOptions={pagingOptions}
108
+ componentOptions={componentOptions}
109
+ />,
110
+ {
111
+ pagingOptions,
112
+ componentOptions,
113
+ pageControlsPosition,
114
+ includeTopControls,
115
+ includeBottomControls,
116
+ }
117
+ )}
81
118
 
82
119
  {includeBottomControls &&
83
120
  (pageControlsPosition === 'bottom' || pageControlsPosition === 'both') ? (
84
- <Controls position='bottom' withSpacer />
121
+ <PagingControls<T>
122
+ key='bottom-paging'
123
+ position='bottom'
124
+ withSpacer
125
+ scrollContainer={scrollContainer}
126
+ size={size}
127
+ pagingData={pagingData}
128
+ pagingOptions={pagingOptions}
129
+ componentOptions={componentOptions}
130
+ />
85
131
  ) : null}
86
132
  </>
87
133
  );
@@ -3,6 +3,11 @@ import { useEffect, useMemo } from 'react';
3
3
  import { useUpdateEffect } from 'react-use';
4
4
  import usePagination, { usePaginationReturn } from 'react-use-pagination-hook';
5
5
 
6
+ export interface IReqorePageChangeData {
7
+ isFirst?: boolean;
8
+ isLast?: boolean;
9
+ }
10
+
6
11
  export interface IReqorePagingOptions<T> {
7
12
  items: T[];
8
13
  startPage?: number;
@@ -10,6 +15,7 @@ export interface IReqorePagingOptions<T> {
10
15
  itemsPerPage?: number;
11
16
  infinite?: boolean;
12
17
  enabled?: boolean;
18
+ onPageChange?: (page: number, info: IReqorePageChangeData) => void;
13
19
  }
14
20
 
15
21
  export interface IReqorePagingResult<T>
@@ -46,6 +52,7 @@ export const useReqorePaging = <T>(
46
52
  pagesToShow,
47
53
  startPage,
48
54
  enabled = true,
55
+ onPageChange,
49
56
  }: IReqorePagingOptions<T> = merge({}, defaultPagingOptions, options);
50
57
  const allPageCount = useMemo(() => Math.ceil(size(items) / itemsPerPage), [items, itemsPerPage]);
51
58
  const { pagelist, currentPage, setPage, setTotalPage, goNext, goBefore } = usePagination({
@@ -57,6 +64,13 @@ export const useReqorePaging = <T>(
57
64
  setPage(startPage || 1);
58
65
  }, [startPage]);
59
66
 
67
+ useUpdateEffect(() => {
68
+ onPageChange?.(currentPage, {
69
+ isFirst: currentPage === 1,
70
+ isLast: currentPage === allPageCount,
71
+ });
72
+ }, [currentPage]);
73
+
60
74
  useUpdateEffect(() => {
61
75
  setPage(1);
62
76
  setTotalPage(Math.ceil(size(items) / itemsPerPage));
@@ -10,12 +10,17 @@ import {
10
10
  ReqoreTabsContent,
11
11
  useReqoreProperty,
12
12
  } from '../../index';
13
- import { FlatArg, IntentArg, argManager } from '../utils/args';
13
+ import { argManager, FlatArg, IntentArg } from '../utils/args';
14
14
 
15
15
  const { createArg } = argManager<IReqoreDrawerProps>();
16
16
 
17
17
  export default {
18
18
  title: 'Components/Drawer',
19
+ parameters: {
20
+ chromatic: {
21
+ viewports: [450, 600, 1440],
22
+ },
23
+ },
19
24
  argTypes: {
20
25
  ...FlatArg,
21
26
  ...createArg('floating', {
@@ -229,6 +229,7 @@ export const WithPaging: Story<IReqoreDropdownProps> = Template.bind({});
229
229
  WithPaging.args = {
230
230
  paging: {
231
231
  itemsPerPage: 50,
232
+ changePageOnScroll: 'horizontal',
232
233
  },
233
234
  label: 'Dropdown with paging',
234
235
  };
@@ -1,6 +1,6 @@
1
1
  import { Meta, Story } from '@storybook/react/types-6-0';
2
2
  import { IReqoreHeadingProps } from '../../components/Header';
3
- import { ReqoreHeading, ReqoreVerticalSpacer } from '../../index';
3
+ import { ReqoreControlGroup, ReqoreHeading } from '../../index';
4
4
  import { IntentArg } from '../utils/args';
5
5
 
6
6
  export default {
@@ -12,31 +12,29 @@ export default {
12
12
 
13
13
  const Template: Story<IReqoreHeadingProps> = (args) => {
14
14
  return (
15
- <>
15
+ <ReqoreControlGroup gapSize='big' vertical>
16
16
  <ReqoreHeading size={1} {...args}>
17
17
  This is a heading
18
18
  </ReqoreHeading>
19
- <ReqoreVerticalSpacer height={10} />
20
19
  <ReqoreHeading size={2} {...args}>
21
20
  This is a heading
22
21
  </ReqoreHeading>
23
- <ReqoreVerticalSpacer height={10} />
24
22
  <ReqoreHeading size={3} {...args}>
25
23
  This is a heading
26
24
  </ReqoreHeading>
27
- <ReqoreVerticalSpacer height={10} />
28
25
  <ReqoreHeading size={4} {...args}>
29
26
  This is a heading
30
27
  </ReqoreHeading>
31
- <ReqoreVerticalSpacer height={10} />
32
28
  <ReqoreHeading size={5} {...args}>
33
29
  This is a heading
34
30
  </ReqoreHeading>
35
- <ReqoreVerticalSpacer height={10} />
36
31
  <ReqoreHeading size={6} {...args}>
37
32
  This is a heading
38
33
  </ReqoreHeading>
39
- </>
34
+ <ReqoreHeading size={1} {...args} tooltip={{ content: 'Nice tooltip', openOnMount: true }}>
35
+ This is a heading with tooltip
36
+ </ReqoreHeading>
37
+ </ReqoreControlGroup>
40
38
  );
41
39
  };
42
40
 
@@ -20,11 +20,17 @@ const Template: Story<IReqorePaginationProps<any> & { pagingOptions?: IReqorePag
20
20
  });
21
21
 
22
22
  return (
23
- <ReqoreControlGroup vertical fluid>
23
+ <ReqoreControlGroup vertical fluid key='paging-wrapper'>
24
24
  {paging.items.map((item) => (
25
25
  <ReqoreTag fixed='key' labelKey={item.id} label={`${item.firstName} ${item.lastName}`} />
26
26
  ))}
27
- <ReqorePagination<any> {...paging} {...args} scrollContainer={scrollContainer} />
27
+ <ReqorePagination<any>
28
+ {...paging}
29
+ {...args}
30
+ scrollContainer={
31
+ args.scrollToTopOnPageChange || !!args.changePageOnScroll ? scrollContainer : undefined
32
+ }
33
+ />
28
34
  </ReqoreControlGroup>
29
35
  );
30
36
  };
@@ -138,6 +144,20 @@ WithLabels.args = {
138
144
  } as IReqorePagingOptions<any>,
139
145
  };
140
146
 
147
+ export const NextPageOnVerticalScroll: Story<
148
+ IReqorePaginationProps<any> & { pagingOptions?: IReqorePagingOptions<any> }
149
+ > = Template.bind({});
150
+ NextPageOnVerticalScroll.args = {
151
+ changePageOnScroll: 'vertical',
152
+ };
153
+
154
+ export const NextPageOnHorizontalScroll: Story<
155
+ IReqorePaginationProps<any> & { pagingOptions?: IReqorePagingOptions<any> }
156
+ > = Template.bind({});
157
+ NextPageOnHorizontalScroll.args = {
158
+ changePageOnScroll: 'horizontal',
159
+ };
160
+
141
161
  export const ScrollToTop: Story<
142
162
  IReqorePaginationProps<any> & { pagingOptions?: IReqorePagingOptions<any> }
143
163
  > = Template.bind({});
@@ -3,12 +3,17 @@ import { noop } from 'lodash';
3
3
  import ReqoreInput, { IReqoreInputProps } from '../../components/Input';
4
4
  import { IReqorePanelAction, IReqorePanelProps, ReqorePanel } from '../../components/Panel';
5
5
  import { ReqoreVerticalSpacer } from '../../components/Spacer';
6
- import { FlatArg, IconArg, IntentArg, SizeArg, argManager } from '../utils/args';
6
+ import { argManager, FlatArg, IconArg, IntentArg, SizeArg } from '../utils/args';
7
7
 
8
8
  const { createArg } = argManager<IReqorePanelProps>();
9
9
 
10
10
  export default {
11
11
  title: 'Components/Panel',
12
+ parameters: {
13
+ chromatic: {
14
+ viewports: [450, 600, 1440],
15
+ },
16
+ },
12
17
  argTypes: {
13
18
  ...IntentArg,
14
19
  ...FlatArg,
@@ -373,13 +378,18 @@ NoLabel.args = {
373
378
  badge: undefined,
374
379
  };
375
380
 
376
- export const ImageAsIcon: Story<IReqorePanelProps> = Template.bind({});
377
- ImageAsIcon.args = {
381
+ export const ImageAsIconLinkAsHeader: Story<IReqorePanelProps> = Template.bind({});
382
+ ImageAsIconLinkAsHeader.args = {
378
383
  iconImage:
379
384
  'https://avatars.githubusercontent.com/u/44835090?s=400&u=371120ce0755102d2e432f11ad9aa0378c871b45&v=4',
380
385
  iconProps: {
381
386
  size: '30px',
382
387
  },
388
+ headerProps: {
389
+ as: 'a',
390
+ href: 'https://qoretechnologies.com',
391
+ target: '_blank',
392
+ } as React.HTMLAttributes<HTMLAnchorElement>,
383
393
  };
384
394
 
385
395
  export const ContentSize: Story<IReqorePanelProps> = Template.bind({});