Skip to content

Commit 2b049ec

Browse files
authored
th-249: Redesign UI table (#262)
* th-249: * update table styles * th-249: * update pagination and dropdown styles * th-249: + edit&delete icon and ability to sort columns * th-249: * changed props name * th-249: + add manualSorting parameter * th-249: + add helper for checking icon cell * th-249: * refactored table and helper * th-249: * splits table.tsx into different files * th-249: - removes unused props * th-249: * changed types and types' names
1 parent 0fe77e4 commit 2b049ec

File tree

17 files changed

+449
-137
lines changed

17 files changed

+449
-137
lines changed

frontend/src/assets/css/fonts.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
@font-face {
22
font-weight: 400;
33
font-family: "Plus Jakarta Sans";
4-
src: url("fonts/plusjakartasans-regular.woff2");
4+
src: url("/fonts/plusjakartasans-regular.woff2");
55
}
66

77
@font-face {
88
font-weight: 600;
99
font-family: "Plus Jakarta Sans";
10-
src: url("fonts/plusjakartasans-semibold.woff2");
10+
src: url("/fonts/plusjakartasans-semibold.woff2");
1111
}
1212

1313
@font-face {
@@ -19,5 +19,5 @@
1919
@font-face {
2020
font-weight: 800;
2121
font-family: "Plus Jakarta Sans";
22-
src: url("fonts/plusjakartasans-extrabold.woff2");
22+
src: url("/fonts/plusjakartasans-extrabold.woff2");
2323
}

frontend/src/assets/css/vars.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ $white: #ffffff;
55
$red-light: #ff437b;
66
$red: #ee2a64;
77
$red-dark: #d51a52;
8+
$white-blue: #adc2ff;
89
$blue-light: #527efe;
910
$blue: #507ceb;
1011
$blue-dark: #3563e9;
12+
$blue-extra-dark: #000b6a;
1113
$black-blue: #1a202c;
1214
$grey-extra-light: #ebf3ff;
1315
$grey-border: #e7eef6;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import styles from './styles.module.scss';
77

88
type Properties = {
99
className?: Parameters<typeof getValidClassNames>[0];
10-
label: string;
10+
label: string | number;
1111
type?: 'button' | 'submit';
1212
size?: 'sm' | 'md';
1313
variant?: 'contained' | 'outlined' | 'text';

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

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,44 @@ type Properties<T extends FieldValues> = {
2828
placeholder?: string;
2929
field?: ControllerRenderProps<T, FieldPath<T>>;
3030
className?: string;
31+
isCustomValueContainer?: boolean;
3132
};
3233

33-
const getClassNames = (
34-
isMenuOpen: boolean,
35-
): ClassNamesConfig<SelectOption, false, GroupBase<SelectOption>> => ({
36-
container: () => styles.container,
37-
control: () => styles.control,
38-
option: () => styles.option,
39-
menu: () => styles.singleValue,
40-
placeholder: () => styles.placeholder,
41-
singleValue: () => styles.singleValue,
42-
valueContainer: () => styles.valueContainer,
43-
dropdownIndicator: () =>
44-
isMenuOpen
45-
? getValidClassNames(styles.dropdownIndicator, styles.upside)
46-
: styles.dropdownIndicator,
47-
indicatorSeparator: () => styles.indicatorSeparator,
48-
});
34+
type GetClassNamesArguments = {
35+
isMenuOpen: boolean;
36+
isCustomValueContainer: boolean;
37+
};
38+
39+
const getClassNames = ({
40+
isMenuOpen,
41+
isCustomValueContainer,
42+
}: GetClassNamesArguments): ClassNamesConfig<
43+
SelectOption,
44+
false,
45+
GroupBase<SelectOption>
46+
> => {
47+
const commonStylesConfig: ClassNamesConfig<
48+
SelectOption,
49+
false,
50+
GroupBase<SelectOption>
51+
> = {
52+
container: () => styles.container,
53+
control: () => styles.control,
54+
option: () => styles.option,
55+
menu: () => styles.singleValue,
56+
placeholder: () => styles.placeholder,
57+
singleValue: () => styles.singleValue,
58+
dropdownIndicator: () =>
59+
isMenuOpen
60+
? getValidClassNames(styles.dropdownIndicator, styles.upside)
61+
: styles.dropdownIndicator,
62+
indicatorSeparator: () => styles.indicatorSeparator,
63+
};
64+
65+
return isCustomValueContainer
66+
? commonStylesConfig
67+
: { ...commonStylesConfig, valueContainer: () => styles.valueContainer };
68+
};
4969

5070
const Dropdown = <T extends FieldValues>({
5171
options,
@@ -56,6 +76,7 @@ const Dropdown = <T extends FieldValues>({
5676
onChange,
5777
className,
5878
placeholder,
79+
isCustomValueContainer = false,
5980
}: Properties<T>): JSX.Element => {
6081
const [isMenuOpen, setIsMenuOpen] = useState(false);
6182

@@ -68,8 +89,8 @@ const Dropdown = <T extends FieldValues>({
6889
}, []);
6990

7091
const classNamesConfig = useMemo(
71-
() => getClassNames(isMenuOpen),
72-
[isMenuOpen],
92+
() => getClassNames({ isMenuOpen, isCustomValueContainer }),
93+
[isMenuOpen, isCustomValueContainer],
7394
);
7495

7596
const findOptionByValue = (

frontend/src/libs/components/icon/maps/icon-name-to-svg.map.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
faCheck,
77
faChevronDown,
88
faChevronLeft,
9+
faChevronUp,
910
faClockRotateLeft,
1011
faCloudUploadAlt,
1112
faEye,
@@ -14,9 +15,11 @@ import {
1415
faListUl,
1516
faLocationDot,
1617
faMap,
18+
faPen,
1719
faPlus,
1820
faRightFromBracket,
1921
faStar,
22+
faTrashCan,
2023
faTruckPickup,
2124
faUserPen,
2225
faUsers,
@@ -32,6 +35,8 @@ const iconNameToSvg: Record<ValueOf<typeof IconName>, IconDefinition> = {
3235
[IconName.CARET_DOWN]: faCaretDown,
3336
[IconName.CHEVRON_DOWN]: faChevronDown,
3437
[IconName.CHEVRON_LEFT]: faChevronLeft,
38+
[IconName.CHEVRON_UP]: faChevronUp,
39+
[IconName.EDIT]: faPen,
3540
[IconName.GEAR]: faGear,
3641
[IconName.STAR]: faStar,
3742
[IconName.LOCATION_DOT]: faLocationDot,
@@ -45,6 +50,7 @@ const iconNameToSvg: Record<ValueOf<typeof IconName>, IconDefinition> = {
4550
[IconName.CLOCK_ROTATE_LEFT]: faClockRotateLeft,
4651
[IconName.USER_PEN]: faUserPen,
4752
[IconName.RIGHT_FROM_BRACKET]: faRightFromBracket,
53+
[IconName.TRASH]: faTrashCan,
4854
[IconName.TRUCK]: faTruckPickup,
4955
[IconName.USERS]: faUsers,
5056
[IconName.XMARK]: faXmark,

frontend/src/libs/components/pagination/pagination.tsx

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type SingleValue } from 'react-select';
22

3-
import { getValidClassNames } from '~/libs/helpers/helpers.js';
43
import { useCallback } from '~/libs/hooks/hooks.js';
54
import { type SelectOption } from '~/libs/types/select-option.type.js';
65

@@ -81,15 +80,13 @@ const Pagination: React.FC<Properties> = ({
8180
const buttons: JSX.Element[] = [];
8281

8382
for (let index = startIndex; index <= endIndex; index++) {
84-
const buttonClass = getValidClassNames(styles.btn, {
85-
[styles.active]: index === pageIndex,
86-
});
8783
buttons.push(
8884
<Button
89-
className={buttonClass}
90-
onClick={handlePageClick}
9185
key={index}
86+
className={styles.btn}
9287
label={`${convertToNumber(index)}`}
88+
variant={index === pageIndex ? 'outlined' : 'text'}
89+
onClick={handlePageClick}
9390
></Button>,
9491
);
9592
}
@@ -122,17 +119,41 @@ const Pagination: React.FC<Properties> = ({
122119
<div className={styles.container}>
123120
<div className={styles.pagination}>
124121
<Button
122+
className={styles['text-btn']}
125123
label="Prev"
126124
size="sm"
125+
variant="text"
127126
onClick={handlePreviousClick}
128127
isDisabled={isFirstPage}
129128
/>
130-
{isHiddenFirstPage ? <div className={styles.dots}>...</div> : null}
129+
{isHiddenFirstPage && (
130+
<>
131+
<Button
132+
className={styles.btn}
133+
label="1"
134+
variant="text"
135+
onClick={handlePageClick}
136+
></Button>
137+
<div className={styles.dots}>...</div>
138+
</>
139+
)}
131140
{showButtons()}
132-
{isHiddenLastPage ? <div className={styles.dots}>...</div> : null}
141+
{isHiddenLastPage && (
142+
<>
143+
<div className={styles.dots}>...</div>
144+
<Button
145+
className={styles.btn}
146+
label={pageCount}
147+
variant="text"
148+
onClick={handlePageClick}
149+
></Button>
150+
</>
151+
)}
133152
<Button
153+
className={styles['text-btn']}
134154
label="Next"
135155
size="sm"
156+
variant="text"
136157
onClick={handleNextClick}
137158
isDisabled={isLastPage}
138159
/>
@@ -143,6 +164,7 @@ const Pagination: React.FC<Properties> = ({
143164
<Dropdown
144165
options={createOptions([5, 10, 20, 50, 100])}
145166
defaultValue={createOption(pageSize)}
167+
isCustomValueContainer
146168
onChange={handleChangePageSize}
147169
/>
148170
</div>

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

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
display: flex;
55
flex-direction: column;
66
align-items: center;
7-
gap: 20px;
7+
gap: 25px;
88
margin-top: 20px;
99
}
1010

@@ -14,27 +14,62 @@
1414
}
1515

1616
.dots {
17+
display: flex;
18+
align-items: center;
1719
margin: 0 5px;
18-
color: $red-dark;
20+
color: $blue-extra-dark;
1921
font-size: 22px;
22+
cursor: default;
23+
user-select: none;
24+
}
25+
26+
.btn,
27+
.text-btn {
28+
color: $blue-extra-dark;
2029
}
2130

2231
.btn {
2332
min-width: 22px;
2433
margin: 1px;
25-
padding: 5px;
26-
color: $red-dark;
27-
background-color: $white;
28-
border: 1px solid $red-dark;
34+
padding: 8px 12px;
35+
border-width: 1px;
36+
border-color: $blue-extra-dark;
37+
38+
&:hover {
39+
color: $blue-extra-dark;
40+
border-color: $blue-extra-dark;
41+
}
42+
43+
&:focus {
44+
color: $blue-extra-dark;
45+
border-color: $blue-extra-dark;
46+
}
2947
}
3048

31-
.active {
32-
color: white;
33-
background-color: $red;
49+
.text-btn {
50+
margin-inline: 12px;
51+
text-transform: capitalize;
52+
53+
&:hover,
54+
&:focus {
55+
color: $blue-extra-dark;
56+
}
57+
58+
&:disabled {
59+
color: $grey;
60+
61+
&:hover {
62+
color: $grey;
63+
}
64+
}
3465
}
3566

3667
.size {
37-
color: $red-dark;
68+
display: flex;
69+
align-items: center;
70+
gap: 12px;
71+
color: $white-blue;
72+
font-weight: 700;
3873
}
3974

4075
.select {
@@ -44,3 +79,10 @@
4479
border-radius: 4px;
4580
outline: none;
4681
}
82+
83+
.dropdown {
84+
padding-inline: 5px;
85+
text-align: center;
86+
border: 1px solid $grey-light;
87+
border-radius: 8px;
88+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export { Tbody } from './tbody.js';
2+
export { Thead } from './thead.js';

0 commit comments

Comments
 (0)