Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propriedade rest para todos componente e Ajustes no Toast #90

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/AccordionMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,16 @@ export interface AccordionMenuProps
extends Omit<AccordionMenuVariantProps, "size">,
AccordionMenuType {}

const AccordionMenu = ({ title, size = "md", children, className }: AccordionMenuProps) => {
const AccordionMenu = ({
title,
size = "md",
children,
className,
...rest
}: AccordionMenuProps) => {
const accordionMenuClasses = twMerge(accordionMenuVariants({ size }), className);
return (
<Disclosure as="div" className="border border-x-0 border-t-0 border-gray-100">
<Disclosure as="div" className="border border-x-0 border-t-0 border-gray-100" {...rest}>
{({ open }) => (
<>
<Disclosure.Button
Expand Down
3 changes: 2 additions & 1 deletion src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const Avatar = ({
avatarUrl,
size = "md",
className,
...rest
}: AvatarProps) => {
const avatarClass = twMerge(avatarVariants({ color, size }), className);
const avatarOnlineClass = twMerge(avatarOnlineVariants({ size }), className);
Expand All @@ -73,7 +74,7 @@ const Avatar = ({

return (
<>
<div className={avatarUrl ? `overflow-hidden ${avatarClass}` : avatarClass}>
<div className={avatarUrl ? `overflow-hidden ${avatarClass}` : avatarClass} {...rest}>
{avatarUrl ? (
<div
style={{
Expand Down
3 changes: 2 additions & 1 deletion src/components/FloatingButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ const FloatingButton = ({
icon: Icon,
className,
onClick,
...rest
}: FloatingButtonProps) => {
const buttonClasses = twMerge(buttonVariants({ variant, size }), className);
return (
<button className={buttonClasses} onClick={onClick}>
<button className={buttonClasses} onClick={onClick} {...rest}>
{<Icon className="h-4 w-4 stroke-2" />}
{label && label}
</button>
Expand Down
27 changes: 14 additions & 13 deletions src/components/Toast/__test__/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ describe("Toast Component", () => {
const { container } = render(compontent("tonal", "primary"));
const toastElement = container.querySelector(".toast-component");
expect(toastElement).toHaveClass("bg-primary-300 text-white");
}),
it("test the primary color with filled variant", () => {
const { container } = render(compontent("filled", "primary"));
const toastElement = container.querySelector(".toast-component");
expect(toastElement).toHaveClass("bg-primary-25 border-primary-100 text-primary-400");
});
});
it("test the primary color with filled variant", () => {
const { container } = render(compontent("filled", "primary"));
const toastElement = container.querySelector(".toast-component");
expect(toastElement).toHaveClass("bg-primary-25 border-primary-100 text-primary-400");
});
it("test the success color with tonal variant", () => {
const { container } = render(compontent("tonal", "success"));
const toastElement = container.querySelector(".toast-component");
expect(toastElement).toHaveClass("bg-success-500 text-gray-950");
}),
it("test the success color with filled variant", () => {
const { container } = render(compontent("filled", "success"));
const toastElement = container.querySelector(".toast-component");
expect(toastElement).toHaveClass("bg-success-50 border-success-200 text-success-700");
});
expect(toastElement).toHaveClass("bg-success-400 text-gray-950");
});
it("test the success color with filled variant", () => {
const { container } = render(compontent("filled", "success"));
const toastElement = container.querySelector(".toast-component");
expect(toastElement).toHaveClass("bg-success-50 border-success-200 text-success-700");
});
it("test the warning color with tonal variant", () => {
const { container } = render(compontent("tonal", "warning"));
const toastElement = container.querySelector(".toast-component");
Expand Down Expand Up @@ -99,6 +99,7 @@ describe("Toast Component", () => {
});
}

expect(onClickMock).toHaveBeenCalled();
expect(toastComponent).toHaveClass("hidden");
});
});
Expand Down
27 changes: 14 additions & 13 deletions src/components/Toast/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { cva, type VariantProps } from "class-variance-authority";
import React, { HTMLAttributes, useState } from "react";
import { twMerge } from "tailwind-merge";

import { Text } from "../Text";

interface ToastType extends HTMLAttributes<any> {
variant?: "tonal" | "filled";
title: string;
Expand Down Expand Up @@ -42,7 +44,7 @@ export const toastVariants = cva(
{
variant: "tonal",
color: "success",
class: "bg-success-500 text-gray-950",
class: "bg-success-400 text-gray-950",
},
{
variant: "tonal",
Expand All @@ -57,6 +59,7 @@ export const toastVariants = cva(
],
},
);

export interface ToastProps extends Omit<ToastVariantProps, "color" | "variant">, ToastType {}

const Toast = ({
Expand All @@ -66,13 +69,14 @@ const Toast = ({
message,
onClose,
className,
...rest
}: ToastProps) => {
const [isClose, setIsClose] = useState(false);
const toastClass = twMerge(toastVariants({ color, variant }), className);

const closeToast = () => {
const closeToast = (e: any) => {
setIsClose(true);
if (onClose) onClose;
if (onClose) onClose(e);
};

const defineIcon = (color: string) => {
Expand All @@ -88,20 +92,17 @@ const Toast = ({
};

return (
<div className={isClose ? "toast-component hidden" : toastClass}>
<div className={isClose ? "toast-component hidden" : toastClass} {...rest}>
{defineIcon(color)}
<div className="w-11/12">
<h1 className="font-semibold">{title}</h1>
<p>{message}</p>
<Text as="h6" className="font-semibold">
{title}
</Text>
<Text size="sm">{message}</Text>
</div>
<div
onClick={() => {
closeToast();
}}
className="close-toast h-5 cursor-pointer"
>
<button onClick={closeToast} className="close-toast h-5 cursor-pointer">
<XMarkIcon className="h-5 w-5" />
</div>
</button>
</div>
);
};
Expand Down
2 changes: 2 additions & 0 deletions src/components/ToggleSwitch/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,15 @@ export const ToggleSwitch = ({
disabled = false,
withIcon = true,
size = "md",
...rest
}: ToggleSwitchProps) => {
return (
<Switch
checked={externalChecked}
onChange={onChange}
as={Fragment}
defaultChecked={externalChecked}
{...rest}
>
{({ checked }) => (
<button
Expand Down