Skip to content

Commit ede6d58

Browse files
authored
th-80: Table Component (#101)
* th-80: * package.json added tanstack/react-table * th-80: + pagination component * th-80: + table component * th-80: * hooks resolved conflict * th-80: * types resolved conflict * th-80: * pagination removed magical num * th-80: * pagination refactored * th-80: + useAppTable hook * th-80: * pagination * th-80: * pagination fixed imports * th-80: * hooks resolved merge conflict * th-80: * button removed background * th-80: * components fixed conflict
1 parent d3b109e commit ede6d58

27 files changed

+524
-16
lines changed

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@googlemaps/react-wrapper": "1.1.35",
2525
"@hookform/resolvers": "2.9.11",
2626
"@reduxjs/toolkit": "1.9.3",
27+
"@tanstack/react-table": "8.9.3",
2728
"clsx": "2.0.0",
2829
"modern-normalize": "2.0.0",
2930
"react": "18.2.0",

frontend/src/.stylelintrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ rules:
2727
- ignorePseudoClasses:
2828
- global
2929
- export
30+
# allow limit the depth of nesting
31+
max-nesting-depth:
32+
- 2
3033
media-query-no-invalid:
3134
- null
3235

frontend/src/libs/components/badge/badge.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { getValidClassNames } from '~/libs/helpers/helpers.js';
2+
import darkColors from '~/libs/palette/dark-colors.module.scss';
3+
import lightColors from '~/libs/palette/light-colors.module.scss';
4+
import { type DarkColor, type LightColor } from '~/libs/types/types.js';
25

3-
import darkColors from './dark-colors.module.scss';
4-
import lightColors from './light-colors.module.scss';
56
import styles from './styles.module.scss';
6-
import { type DarkColor, type LightColor } from './types/color.type.js';
77

88
type Color = DarkColor | LightColor;
99

frontend/src/libs/components/badge/types/color.type.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

frontend/src/libs/components/badge/types/light-color.type.ts

Lines changed: 0 additions & 2 deletions
This file was deleted.

frontend/src/libs/components/button/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type Properties = {
1616
frontIcon?: ValueOf<typeof IconName>;
1717
backIcon?: ValueOf<typeof IconName>;
1818
children?: JSX.Element;
19-
onClick?: () => void;
19+
onClick?: (() => void) | ((event_: React.MouseEvent) => void);
2020
};
2121

2222
const Button: React.FC<Properties> = ({

frontend/src/libs/components/button/styles.module.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
align-items: center;
88
font-weight: $font-weight-extrabold;
99
line-height: 1.25;
10+
background-color: $red;
1011
border-radius: 4px;
1112
}
1213

@@ -30,7 +31,6 @@
3031

3132
.contained {
3233
color: $white;
33-
background-color: $red;
3434
}
3535

3636
.contained,
@@ -40,6 +40,7 @@
4040

4141
.contained:hover,
4242
.contained:focus {
43+
color: $white;
4344
background-color: $red-light;
4445
}
4546

frontend/src/libs/components/components.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ export { Image } from './image/image.js';
1313
export { Input } from './input/input.js';
1414
export { Link } from './link/link.js';
1515
export { Modal } from './modal/modal.js';
16+
export { Pagination } from './pagination/pagination.js';
1617
export { ProtectedRoute } from './protected-route/protected-route.js';
1718
export { Radio } from './radio/radio.js';
1819
export { Router } from './router/router.jsx';
1920
export { RouterProvider } from './router-provider/router-provider.jsx';
2021
export { Spinner } from './spinner/spinner.js';
22+
export { Table } from './table/table.js';
2123
export { Toggle } from './toggle/toggle.js';
2224
export { Provider as StoreProvider } from 'react-redux';
2325
export { Outlet as RouterOutlet } from 'react-router-dom';

frontend/src/libs/components/dropdown/dropdown.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
import Select, { type StylesConfig } from 'react-select';
1+
import Select, {
2+
type GroupBase,
3+
type SingleValue,
4+
type StylesConfig,
5+
} from 'react-select';
26

37
import { useCallback, useMemo, useState } from '~/libs/hooks/hooks.js';
48
import { type SelectOption } from '~/libs/types/select-option.type.js';
59

610
type Properties = {
711
options: SelectOption[];
12+
defaultValue?: SelectOption;
13+
onChange?: (value: string | undefined) => void;
814
};
915

10-
const getStyles = (isMenuOpen: boolean): StylesConfig => {
16+
const getStyles = (
17+
isMenuOpen: boolean,
18+
): StylesConfig<SelectOption, false, GroupBase<SelectOption>> => {
1119
return {
1220
control: (styles) => ({
1321
...styles,
@@ -47,6 +55,8 @@ const getStyles = (isMenuOpen: boolean): StylesConfig => {
4755

4856
const Dropdown: React.FC<Properties> = ({
4957
options,
58+
defaultValue,
59+
onChange,
5060
}: Properties): JSX.Element => {
5161
const [isMenuOpen, setIsMenuOpen] = useState(false);
5262

@@ -60,15 +70,26 @@ const Dropdown: React.FC<Properties> = ({
6070

6171
const stylesConfig = useMemo(() => getStyles(isMenuOpen), [isMenuOpen]);
6272

73+
const handleChange = useCallback(
74+
(option: SingleValue<SelectOption>) => {
75+
if (onChange) {
76+
onChange(option?.value);
77+
}
78+
},
79+
[onChange],
80+
);
81+
6382
return (
64-
<Select
83+
<Select<SelectOption>
6584
options={options}
6685
classNamePrefix="react-select"
6786
styles={stylesConfig}
6887
isSearchable={false}
6988
menuIsOpen={isMenuOpen}
7089
onMenuOpen={handleOpenMenu}
7190
onMenuClose={handleCloseMenu}
91+
onChange={handleChange}
92+
defaultValue={defaultValue}
7293
/>
7394
);
7495
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const DEFAULT_SIZE = 5;
2+
3+
export { DEFAULT_SIZE };

0 commit comments

Comments
 (0)