Skip to content

Commit 041ff68

Browse files
allow toolbar options customization
1 parent 206ee14 commit 041ff68

File tree

5 files changed

+41
-34
lines changed

5 files changed

+41
-34
lines changed

Diff for: modules/components/src/Table/CountDisplay/CountDisplay.tsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { css } from '@emotion/react';
22
import cx from 'classnames';
33
import pluralize from 'pluralize';
44

5-
import Spinner from '#Loader/index.js';
65
import { useTableContext } from '#Table/helpers/index.js';
76
import { useThemeContext } from '#ThemeContext/index.js';
87
import { emptyObj } from '#utils/noops.js';
@@ -13,12 +12,7 @@ import type { CountDisplayProps } from './types.js';
1312
const CountDisplay = ({
1413
className: customClassName,
1514
css: customCSS,
16-
theme: {
17-
fontColor: customFontColor,
18-
fontSize: customFontSize,
19-
hideLoader: customHideLoader,
20-
Loader: customSpinnerProps = emptyObj,
21-
} = emptyObj,
15+
theme: { fontColor: customFontColor, fontSize: customFontSize, spacing: customSpacing } = emptyObj,
2216
}: CountDisplayProps) => {
2317
const { currentPage, documentType, isLoading, pageSize, missingProvider, total } = useTableContext({
2418
callerName: 'Table - CountDisplay',
@@ -30,17 +24,16 @@ const CountDisplay = ({
3024
CountDisplay: {
3125
className: themeClassName,
3226
css: themeCSS,
33-
hideLoader: themeHideLoader,
3427
fontColor: themeFontColor = colors?.grey?.[700],
3528
fontSize: themeFontSize = '0.8rem',
36-
Spinner: themeSpinnerProps = emptyObj,
29+
spacing: themeSpacing = '0.2rem',
3730
} = emptyObj,
31+
Toolbar: { spacing: themeToolbarSpacing } = emptyObj,
3832
} = emptyObj,
3933
} = emptyObj,
4034
} = useThemeContext({ callerName: 'Table - CountDisplay' });
4135

4236
const hasData = total > 0;
43-
const hideLoader = customHideLoader || themeHideLoader;
4437

4538
const oneOrManyDocuments =
4639
missingProvider || pluralize(documentType, isPlural({ total, pageSize, currentPage }) ? 2 : 1);
@@ -52,13 +45,17 @@ const CountDisplay = ({
5245
themeCSS,
5346
css`
5447
align-items: center;
55-
color: ${customFontColor || themeFontColor};
48+
color: ${customFontColor ?? themeFontColor};
5649
display: flex;
5750
flex-grow: 1;
58-
font-size: ${customFontSize || themeFontSize};
51+
font-size: ${customFontSize ?? themeFontSize};
5952
6053
> * {
6154
flex: 0 0 auto;
55+
56+
&:not(:first-of-type) {
57+
margin-left: ${customSpacing ?? themeSpacing ?? themeToolbarSpacing};
58+
}
6259
}
6360
`,
6461
customCSS,

Diff for: modules/components/src/Table/CountDisplay/types.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ import type { LoaderThemeProps } from '#Loader/types.js';
22
import type { ThemeCommon } from '#ThemeContext/types/index.js';
33
import type { RecursivePartial } from '#utils/types.js';
44

5-
export interface CountDisplayThemeProps extends ThemeCommon.FontProperties {
5+
export type CountDisplayThemeProps = {
66
hideLoader: boolean;
77

88
// Child components
99
Loader: LoaderThemeProps;
10-
}
10+
spacing: string;
11+
} & ThemeCommon.FontProperties;
1112

12-
export interface CountDisplayProps extends ThemeCommon.CustomCSS {
13+
export type CountDisplayProps = {
1314
theme?: RecursivePartial<CountDisplayThemeProps>;
14-
}
15+
} & ThemeCommon.CustomCSS;

Diff for: modules/components/src/Table/Toolbar/Toolbar.tsx

+9-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { ToolbarProps } from './types.js';
1515
const Toolbar = ({
1616
css: customCSS,
1717
className: customClassName,
18-
theme: { CountDisplay: customCountDisplayProps } = emptyObj,
18+
theme: { CountDisplay: customCountDisplayProps, spacing: customSpacing, tools: customTools } = emptyObj,
1919
}: ToolbarProps) => {
2020
const {
2121
components: {
@@ -24,10 +24,13 @@ const Toolbar = ({
2424
className: themeClassName,
2525
css: themeCSS,
2626
CountDisplay: themeCountDisplayProps = emptyObj,
27+
spacing: themeSpacing = '0.4rem',
28+
tools: themeTools = [ColumnSelectButton, DownloadButton],
2729
} = emptyObj,
2830
} = emptyObj,
2931
} = emptyObj,
3032
} = useThemeContext({ callerName: 'Table - Toolbar' });
33+
const tools = customTools ?? themeTools;
3134
const className = cx('Toolbar', customClassName, themeClassName);
3235
const countDisplayTheme = merge({}, themeCountDisplayProps, customCountDisplayProps);
3336

@@ -49,17 +52,12 @@ const Toolbar = ({
4952
css={css`
5053
flex-shrink: 0;
5154
margin: 0.3rem 0 0 0.3rem;
52-
53-
.Spinner {
54-
justify-content: space-between;
55-
width: 65%;
56-
}
5755
`}
5856
theme={countDisplayTheme}
5957
/>
6058

6159
<ul
62-
className="buttons"
60+
className="tools"
6361
css={css`
6462
display: flex;
6563
flex-wrap: wrap;
@@ -69,22 +67,21 @@ const Toolbar = ({
6967
padding: 0;
7068
`}
7169
>
72-
{/* TODO: Allow adding buttons here */}
73-
{[ColumnSelectButton, DownloadButton].map((Component) => (
70+
{tools.map((Component, index) => (
7471
<li
7572
css={css`
76-
margin-left: 0.3rem;
73+
margin-left: ${customSpacing ?? themeSpacing};
7774
margin-bottom: 0.3rem;
7875
`}
79-
key={getDisplayName(Component)}
76+
key={`${getDisplayName(Component)}-${index}`}
8077
>
8178
<Component />
8279
</li>
8380
))}
8481
</ul>
8582
</section>
8683
),
87-
[className, countDisplayTheme, customCSS, themeCSS],
84+
[className, countDisplayTheme, customCSS, customSpacing, themeCSS, themeSpacing, tools],
8885
);
8986
};
9087

Diff for: modules/components/src/Table/Toolbar/types.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import type { ElementType } from 'react';
2+
13
import type { CountDisplayThemeProps } from '#Table/CountDisplay/types.js';
24
import type { ThemeCommon } from '#ThemeContext/types/index.js';
35
import type { RecursivePartial } from '#utils/types.js';
46

5-
export interface ToolbarThemeProps extends ThemeCommon.FontProperties, ThemeCommon.CustomCSS {
7+
export type ToolbarThemeProps = {
8+
spacing: string;
9+
tools: ElementType[];
610
CountDisplay: CountDisplayThemeProps;
7-
}
11+
} & ThemeCommon.FontProperties &
12+
ThemeCommon.CustomCSS;
813

9-
export interface ToolbarProps extends ThemeCommon.CustomCSS {
14+
export type ToolbarProps = {
1015
theme?: RecursivePartial<ToolbarThemeProps>;
11-
}
16+
} & ThemeCommon.CustomCSS;
+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import type { FC } from 'react';
22

3-
const getDisplayName = <P extends object>(Component: P) =>
4-
(Component as FC<P>)?.displayName || (Component as FC<P>)?.name || 'UnnamedComponent';
3+
import { DEBUG } from './config.js';
4+
5+
const getDisplayName = <P extends object>(Component: P) => {
6+
const displayName = (Component as FC<P>)?.displayName ?? (Component as FC<P>)?.name;
7+
8+
displayName || (DEBUG && console.log("Component doesn't have a name", Component));
9+
10+
return displayName ?? 'UnnamedComponent';
11+
};
512

613
export default getDisplayName;

0 commit comments

Comments
 (0)