Skip to content

Commit

Permalink
th-249: Redesign UI table (BinaryStudioAcademy#262)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
h0wter committed Sep 18, 2023
1 parent 0fe77e4 commit 2b049ec
Show file tree
Hide file tree
Showing 17 changed files with 449 additions and 137 deletions.
6 changes: 3 additions & 3 deletions frontend/src/assets/css/fonts.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@font-face {
font-weight: 400;
font-family: "Plus Jakarta Sans";
src: url("fonts/plusjakartasans-regular.woff2");
src: url("/fonts/plusjakartasans-regular.woff2");
}

@font-face {
font-weight: 600;
font-family: "Plus Jakarta Sans";
src: url("fonts/plusjakartasans-semibold.woff2");
src: url("/fonts/plusjakartasans-semibold.woff2");
}

@font-face {
Expand All @@ -19,5 +19,5 @@
@font-face {
font-weight: 800;
font-family: "Plus Jakarta Sans";
src: url("fonts/plusjakartasans-extrabold.woff2");
src: url("/fonts/plusjakartasans-extrabold.woff2");
}
2 changes: 2 additions & 0 deletions frontend/src/assets/css/vars.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ $white: #ffffff;
$red-light: #ff437b;
$red: #ee2a64;
$red-dark: #d51a52;
$white-blue: #adc2ff;
$blue-light: #527efe;
$blue: #507ceb;
$blue-dark: #3563e9;
$blue-extra-dark: #000b6a;
$black-blue: #1a202c;
$grey-extra-light: #ebf3ff;
$grey-border: #e7eef6;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/libs/components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import styles from './styles.module.scss';

type Properties = {
className?: Parameters<typeof getValidClassNames>[0];
label: string;
label: string | number;
type?: 'button' | 'submit';
size?: 'sm' | 'md';
variant?: 'contained' | 'outlined' | 'text';
Expand Down
57 changes: 39 additions & 18 deletions frontend/src/libs/components/dropdown/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,44 @@ type Properties<T extends FieldValues> = {
placeholder?: string;
field?: ControllerRenderProps<T, FieldPath<T>>;
className?: string;
isCustomValueContainer?: boolean;
};

const getClassNames = (
isMenuOpen: boolean,
): ClassNamesConfig<SelectOption, false, GroupBase<SelectOption>> => ({
container: () => styles.container,
control: () => styles.control,
option: () => styles.option,
menu: () => styles.singleValue,
placeholder: () => styles.placeholder,
singleValue: () => styles.singleValue,
valueContainer: () => styles.valueContainer,
dropdownIndicator: () =>
isMenuOpen
? getValidClassNames(styles.dropdownIndicator, styles.upside)
: styles.dropdownIndicator,
indicatorSeparator: () => styles.indicatorSeparator,
});
type GetClassNamesArguments = {
isMenuOpen: boolean;
isCustomValueContainer: boolean;
};

const getClassNames = ({
isMenuOpen,
isCustomValueContainer,
}: GetClassNamesArguments): ClassNamesConfig<
SelectOption,
false,
GroupBase<SelectOption>
> => {
const commonStylesConfig: ClassNamesConfig<
SelectOption,
false,
GroupBase<SelectOption>
> = {
container: () => styles.container,
control: () => styles.control,
option: () => styles.option,
menu: () => styles.singleValue,
placeholder: () => styles.placeholder,
singleValue: () => styles.singleValue,
dropdownIndicator: () =>
isMenuOpen
? getValidClassNames(styles.dropdownIndicator, styles.upside)
: styles.dropdownIndicator,
indicatorSeparator: () => styles.indicatorSeparator,
};

return isCustomValueContainer
? commonStylesConfig
: { ...commonStylesConfig, valueContainer: () => styles.valueContainer };
};

const Dropdown = <T extends FieldValues>({
options,
Expand All @@ -56,6 +76,7 @@ const Dropdown = <T extends FieldValues>({
onChange,
className,
placeholder,
isCustomValueContainer = false,
}: Properties<T>): JSX.Element => {
const [isMenuOpen, setIsMenuOpen] = useState(false);

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

const classNamesConfig = useMemo(
() => getClassNames(isMenuOpen),
[isMenuOpen],
() => getClassNames({ isMenuOpen, isCustomValueContainer }),
[isMenuOpen, isCustomValueContainer],
);

const findOptionByValue = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
faCheck,
faChevronDown,
faChevronLeft,
faChevronUp,
faClockRotateLeft,
faCloudUploadAlt,
faEye,
Expand All @@ -14,9 +15,11 @@ import {
faListUl,
faLocationDot,
faMap,
faPen,
faPlus,
faRightFromBracket,
faStar,
faTrashCan,
faTruckPickup,
faUserPen,
faUsers,
Expand All @@ -32,6 +35,8 @@ const iconNameToSvg: Record<ValueOf<typeof IconName>, IconDefinition> = {
[IconName.CARET_DOWN]: faCaretDown,
[IconName.CHEVRON_DOWN]: faChevronDown,
[IconName.CHEVRON_LEFT]: faChevronLeft,
[IconName.CHEVRON_UP]: faChevronUp,
[IconName.EDIT]: faPen,
[IconName.GEAR]: faGear,
[IconName.STAR]: faStar,
[IconName.LOCATION_DOT]: faLocationDot,
Expand All @@ -45,6 +50,7 @@ const iconNameToSvg: Record<ValueOf<typeof IconName>, IconDefinition> = {
[IconName.CLOCK_ROTATE_LEFT]: faClockRotateLeft,
[IconName.USER_PEN]: faUserPen,
[IconName.RIGHT_FROM_BRACKET]: faRightFromBracket,
[IconName.TRASH]: faTrashCan,
[IconName.TRUCK]: faTruckPickup,
[IconName.USERS]: faUsers,
[IconName.XMARK]: faXmark,
Expand Down
38 changes: 30 additions & 8 deletions frontend/src/libs/components/pagination/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { type SingleValue } from 'react-select';

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

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

for (let index = startIndex; index <= endIndex; index++) {
const buttonClass = getValidClassNames(styles.btn, {
[styles.active]: index === pageIndex,
});
buttons.push(
<Button
className={buttonClass}
onClick={handlePageClick}
key={index}
className={styles.btn}
label={`${convertToNumber(index)}`}
variant={index === pageIndex ? 'outlined' : 'text'}
onClick={handlePageClick}
></Button>,
);
}
Expand Down Expand Up @@ -122,17 +119,41 @@ const Pagination: React.FC<Properties> = ({
<div className={styles.container}>
<div className={styles.pagination}>
<Button
className={styles['text-btn']}
label="Prev"
size="sm"
variant="text"
onClick={handlePreviousClick}
isDisabled={isFirstPage}
/>
{isHiddenFirstPage ? <div className={styles.dots}>...</div> : null}
{isHiddenFirstPage && (
<>
<Button
className={styles.btn}
label="1"
variant="text"
onClick={handlePageClick}
></Button>
<div className={styles.dots}>...</div>
</>
)}
{showButtons()}
{isHiddenLastPage ? <div className={styles.dots}>...</div> : null}
{isHiddenLastPage && (
<>
<div className={styles.dots}>...</div>
<Button
className={styles.btn}
label={pageCount}
variant="text"
onClick={handlePageClick}
></Button>
</>
)}
<Button
className={styles['text-btn']}
label="Next"
size="sm"
variant="text"
onClick={handleNextClick}
isDisabled={isLastPage}
/>
Expand All @@ -143,6 +164,7 @@ const Pagination: React.FC<Properties> = ({
<Dropdown
options={createOptions([5, 10, 20, 50, 100])}
defaultValue={createOption(pageSize)}
isCustomValueContainer
onChange={handleChangePageSize}
/>
</div>
Expand Down
62 changes: 52 additions & 10 deletions frontend/src/libs/components/pagination/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
gap: 25px;
margin-top: 20px;
}

Expand All @@ -14,27 +14,62 @@
}

.dots {
display: flex;
align-items: center;
margin: 0 5px;
color: $red-dark;
color: $blue-extra-dark;
font-size: 22px;
cursor: default;
user-select: none;
}

.btn,
.text-btn {
color: $blue-extra-dark;
}

.btn {
min-width: 22px;
margin: 1px;
padding: 5px;
color: $red-dark;
background-color: $white;
border: 1px solid $red-dark;
padding: 8px 12px;
border-width: 1px;
border-color: $blue-extra-dark;

&:hover {
color: $blue-extra-dark;
border-color: $blue-extra-dark;
}

&:focus {
color: $blue-extra-dark;
border-color: $blue-extra-dark;
}
}

.active {
color: white;
background-color: $red;
.text-btn {
margin-inline: 12px;
text-transform: capitalize;

&:hover,
&:focus {
color: $blue-extra-dark;
}

&:disabled {
color: $grey;

&:hover {
color: $grey;
}
}
}

.size {
color: $red-dark;
display: flex;
align-items: center;
gap: 12px;
color: $white-blue;
font-weight: 700;
}

.select {
Expand All @@ -44,3 +79,10 @@
border-radius: 4px;
outline: none;
}

.dropdown {
padding-inline: 5px;
text-align: center;
border: 1px solid $grey-light;
border-radius: 8px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { Tbody } from './tbody.js';
export { Thead } from './thead.js';
Loading

0 comments on commit 2b049ec

Please sign in to comment.