Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bender101 committed Jan 16, 2024
1 parent 8764f50 commit 4632d2a
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 107 deletions.
13 changes: 13 additions & 0 deletions json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,12 @@
"userId": "1",
"text": "sss",
"id": "YIjywga"
},
{
"articleId": "3",
"userId": "1",
"text": "sdfsdffds",
"id": "oiKSMac"
}
],
"users": [
Expand Down Expand Up @@ -862,6 +868,13 @@
"rate": 4,
"feedback": "asdfdsfds",
"id": "LGlKc2U"
},
{
"userId": "1",
"articleId": "3",
"rate": 4,
"feedback": "asaff",
"id": "8d_uUBp"
}
]
}
12 changes: 1 addition & 11 deletions src/pages/MainPage/ui/MainPage.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
import React from "react";
import { useTranslation } from "react-i18next";
import { Counter } from "@/entities/Counter";
import { Page } from "@/widgets/Page";
import { RatingCard } from "@/entities/Rating";

const MainPage = () => {
const { t } = useTranslation("main");

return (
<Page data-testid="MainPage">
{t("main")}
<div>
<Counter />
<RatingCard hasFeedback />
</div>
</Page>
);
return <Page data-testid="MainPage">{t("main")}</Page>;
};

export default MainPage;
86 changes: 47 additions & 39 deletions src/shared/ui/redesigned/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ButtonHTMLAttributes, memo, ReactNode } from "react";
import {
ButtonHTMLAttributes,
ForwardedRef,
forwardRef,
ReactNode,
} from "react";
import { classNames, Mods } from "@/shared/lib/classNames/classNames";
import cls from "./Button.module.scss";

Expand Down Expand Up @@ -40,43 +45,46 @@ interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
addonRight?: ReactNode;
}

export const Button = memo((props: ButtonProps) => {
const {
className,
children,
variant = "outline",
square,
disabled,
fullWidth,
size = "m",
addonLeft,
addonRight,
color = "normal",
...otherProps
} = props;
export const Button = forwardRef(
// eslint-disable-next-line @typescript-eslint/no-unused-vars,no-unused-vars
(props: ButtonProps, _ref: ForwardedRef<HTMLButtonElement>) => {
const {
className,
children,
variant = "outline",
square,
disabled,
fullWidth,
size = "m",
addonLeft,
addonRight,
color = "normal",
...otherProps
} = props;

const mods: Mods = {
[cls.square]: square,
[cls.disabled]: disabled,
[cls.fullWidth]: fullWidth,
[cls.withAddon]: Boolean(addonLeft) || Boolean(addonRight),
};
const mods: Mods = {
[cls.square]: square,
[cls.disabled]: disabled,
[cls.fullWidth]: fullWidth,
[cls.withAddon]: Boolean(addonLeft) || Boolean(addonRight),
};

return (
<button
type="button"
className={classNames(cls.Button, mods, [
className,
cls[variant],
cls[size],
cls[color],
])}
disabled={disabled}
{...otherProps}
>
<div className={cls.addonLeft}>{addonLeft}</div>
{children}
<div className={cls.addonRight}>{addonRight}</div>
</button>
);
});
return (
<button
type="button"
className={classNames(cls.Button, mods, [
className,
cls[variant],
cls[size],
cls[color],
])}
disabled={disabled}
{...otherProps}
>
<div className={cls.addonLeft}>{addonLeft}</div>
{children}
<div className={cls.addonRight}>{addonRight}</div>
</button>
);
}
);
111 changes: 54 additions & 57 deletions src/shared/ui/redesigned/Popups/components/ListBox/ListBox.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Fragment, ReactNode, useMemo } from 'react';
import { Listbox as HListBox } from '@headlessui/react';
import { classNames } from '@/shared/lib/classNames/classNames';
import { DropdownDirection } from '@/shared/types/ui';
import { HStack } from '../../../../redesigned/Stack';
import { Button } from '../../../Button/Button';
import cls from './ListBox.module.scss';
import { mapDirectionClass } from '../../styles/consts';
import popupCls from '../../styles/popup.module.scss';
import ArrowIcon from '@/shared/assets/icons/arrow-bottom.svg';
import { Icon } from '../../../Icon';
import { Fragment, ReactNode, useMemo } from "react";
import { Listbox as HListBox } from "@headlessui/react";
import { classNames } from "@/shared/lib/classNames/classNames";
import { DropdownDirection } from "@/shared/types/ui";
import { HStack } from "../../../../redesigned/Stack";
import { Button } from "../../../Button/Button";
import cls from "./ListBox.module.scss";
import { mapDirectionClass } from "../../styles/consts";
import popupCls from "../../styles/popup.module.scss";
import ArrowIcon from "@/shared/assets/icons/arrow-bottom.svg";
import { Icon } from "../../../Icon";

export interface ListBoxItem<T extends string> {
value: T;
Expand All @@ -35,7 +35,7 @@ export function ListBox<T extends string>(props: ListBoxProps<T>) {
defaultValue,
onChange,
readonly,
direction = 'bottom right',
direction = "bottom right",
label,
} = props;

Expand All @@ -46,53 +46,50 @@ export function ListBox<T extends string>(props: ListBoxProps<T>) {
}, [items, value]);

return (
<HStack gap="4">
{label && <span>{`${label}>`}</span>}
<HListBox
disabled={readonly}
as="div"
className={classNames(cls.ListBox, {}, [
className,
popupCls.popup,
])}
value={value}
onChange={onChange}
<HStack gap="4">
{label && <span>{`${label}>`}</span>}
<HListBox
disabled={readonly}
as="div"
className={classNames(cls.ListBox, {}, [className, popupCls.popup])}
value={value}
onChange={onChange}
>
<HListBox.Button
as={Button}
disabled={readonly}
className={cls.trigger}
variant="filled"
addonRight={<Icon Svg={ArrowIcon} />}
>
<HListBox.Button disabled={readonly} className={cls.trigger}>
<Button
variant="filled"
disabled={readonly}
addonRight={<Icon Svg={ArrowIcon} />}
{selectedItem?.content ?? defaultValue}
</HListBox.Button>
<HListBox.Options
className={classNames(cls.options, {}, optionsClasses)}
>
{items?.map((item) => (
<HListBox.Option
key={item.value}
value={item.value}
disabled={item.disabled}
as={Fragment}
>
{selectedItem?.content ?? defaultValue}
</Button>
</HListBox.Button>
<HListBox.Options
className={classNames(cls.options, {}, optionsClasses)}
>
{items?.map((item) => (
<HListBox.Option
key={item.value}
value={item.value}
disabled={item.disabled}
as={Fragment}
{({ active, selected }) => (
<li
className={classNames(cls.item, {
[popupCls.active]: active,
[popupCls.disabled]: item.disabled,
[popupCls.selected]: selected,
})}
>
{({ active, selected }) => (
<li
className={classNames(cls.item, {
[popupCls.active]: active,
[popupCls.disabled]: item.disabled,
[popupCls.selected]: selected,
})}
>
{selected}
{item.content}
</li>
)}
</HListBox.Option>
))}
</HListBox.Options>
</HListBox>
</HStack>
{selected}
{item.content}
</li>
)}
</HListBox.Option>
))}
</HListBox.Options>
</HListBox>
</HStack>
);
}

0 comments on commit 4632d2a

Please sign in to comment.