Skip to content

Commit

Permalink
Merge pull request #72 from fs-jun24-team-3/fix-add-to-cart-button
Browse files Browse the repository at this point in the history
Fixed in cart text. Added selected style.
  • Loading branch information
k-marchuk authored Sep 25, 2024
2 parents 111c265 + 482737a commit 0c98479
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/components/Buttons/MainButton/MainButton.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
}
}

&--selected {
background-color: $white-color;
color: $accent-color;
border: $button-with-color-border;
}

&:hover {
cursor: pointer;
box-shadow: $wide-button-box-shadow-on-hover;
Expand Down
3 changes: 3 additions & 0 deletions src/components/Buttons/MainButton/MainButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ type Props = {
onClick?: () => void;
label: string;
size: Exclude<ButtonSize, ButtonSize.Small>;
isSelected: boolean;
};

export const MainButton: React.FC<Props> = ({
label,
onClick = () => {},
size,
isSelected,
}) => {
return (
<button
className={classNames('button', styles['main-button'], {
[styles['main-button__size--default']]: size === ButtonSize.Default,
[styles['main-button__size--large']]: size === ButtonSize.Large,
[styles['main-button--selected']]: isSelected,
})}
onClick={onClick}
>
Expand Down
7 changes: 4 additions & 3 deletions src/components/ProductActions/ProductActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ProductActions: React.FC<Props> = ({
item,
}) => {
const dispatch = useAppDispatch();
const inCart = useAppSelector(state =>
const isInCart = useAppSelector(state =>
state.cart.cartItems.some(el => el.item.id === item.id),
);

Expand All @@ -40,9 +40,10 @@ export const ProductActions: React.FC<Props> = ({
return (
<div className={styles['product-actions-block']}>
<MainButton
label={inCart ? 'Remove from cart' : 'Add to cart'}
label={isInCart ? 'In cart' : 'Add to cart'}
size={size}
onClick={inCart ? handleRemoveFromCart : handleAddToCart}
isSelected={isInCart}
onClick={isInCart ? handleRemoveFromCart : handleAddToCart}
/>
<FavoriteButton
size={size}
Expand Down

0 comments on commit 0c98479

Please sign in to comment.