Skip to content

Commit

Permalink
Merge pull request #138 from SwitchDreams/fix/size-of-support-message
Browse files Browse the repository at this point in the history
♻️ Refactor ErrorMessage to SupportOrErrorMessage
  • Loading branch information
PedroAugustoRamalhoDuarte authored Oct 15, 2024
2 parents cbde741 + c0830a9 commit cd577fd
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 29 deletions.
4 changes: 2 additions & 2 deletions src/components/CheckBox/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cva, type VariantProps } from "class-variance-authority";
import { HTMLProps } from "react";
import ErrorMessage from "src/internal/ErrorMessage";
import FormLabel from "src/internal/FormLabel";
import SupportOrErrorMessage from "src/internal/SupportOrErrorMessage";
import { twMerge } from "tailwind-merge";

export interface ICheckBox {
Expand Down Expand Up @@ -139,7 +139,7 @@ export const CheckBox = ({
</svg>
</label>
</div>
<ErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
<SupportOrErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
</div>
);
};
4 changes: 2 additions & 2 deletions src/components/RadioButton/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cva, type VariantProps } from "class-variance-authority";
import { ChangeEvent, HTMLProps, useState } from "react";
import ErrorMessage from "src/internal/ErrorMessage";
import FormLabel from "src/internal/FormLabel";
import SupportOrErrorMessage from "src/internal/SupportOrErrorMessage";
import { twMerge } from "tailwind-merge";

export interface IRadioButton {
Expand Down Expand Up @@ -75,7 +75,7 @@ export const RadioButton = ({
></input>
<FormLabel label={label} name={name} className={labelClassName} />
</div>
<ErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
<SupportOrErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
</>
);
};
4 changes: 2 additions & 2 deletions src/components/Select/AsyncSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ElementType } from "react";
import ReactAsyncSelect, { AsyncProps } from "react-select/async";
import ErrorMessage from "src/internal/ErrorMessage";
import FormLabel from "src/internal/FormLabel";
import SupportOrErrorMessage from "src/internal/SupportOrErrorMessage";

import { DropdownIndicator, selectClassName, selectStyles } from "./styles";

Expand Down Expand Up @@ -62,7 +62,7 @@ export const AsyncSelect = ({
classNames={selectClassName({ size, error, className })}
{...rest}
/>
{<ErrorMessage error={error} supportText={supportText} errorMsg={errorMsg} />}
{<SupportOrErrorMessage error={error} supportText={supportText} errorMsg={errorMsg} />}
</>
);
};
4 changes: 2 additions & 2 deletions src/components/Select/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ElementType } from "react";
import ReactSelect, { Props } from "react-select";
import ErrorMessage from "src/internal/ErrorMessage";
import FormLabel from "src/internal/FormLabel";
import SupportOrErrorMessage from "src/internal/SupportOrErrorMessage";

import { Control, DropdownIndicator, selectClassName, selectStyles } from "./styles";

Expand Down Expand Up @@ -61,7 +61,7 @@ export const Select = ({
classNames={selectClassName({ size, error, className })}
{...rest}
/>
{<ErrorMessage error={error} supportText={supportText} errorMsg={errorMsg} />}
{<SupportOrErrorMessage error={error} supportText={supportText} errorMsg={errorMsg} />}
</>
);
};
4 changes: 2 additions & 2 deletions src/components/SelectBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "@heroicons/react/24/outline";
import { cva, type VariantProps } from "class-variance-authority";
import { ElementType, Fragment, ReactNode, useEffect, useState } from "react";
import ErrorMessage from "src/internal/ErrorMessage";
import SupportOrErrorMessage from "src/internal/SupportOrErrorMessage";
import { twMerge } from "tailwind-merge";

type Options = {
Expand Down Expand Up @@ -221,7 +221,7 @@ function SelectBox({
</>
)}
</Listbox>
<ErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
<SupportOrErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
</div>
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/TextField/TextFieldBase.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { cva, VariantProps } from "class-variance-authority";
import React, { ElementType, forwardRef } from "react";
import InputMask from "react-input-mask";
import ErrorMessage from "src/internal/ErrorMessage";
import SupportOrErrorMessage from "src/internal/SupportOrErrorMessage";
import { twMerge } from "tailwind-merge";

import FormLabel from "../../internal/FormLabel";
Expand Down Expand Up @@ -148,7 +148,7 @@ export const TextFieldBase = /* @__PURE__ */ forwardRef(
/>
)}
</div>
<ErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
<SupportOrErrorMessage error={error} errorMsg={errorMsg} supportText={supportText} />
</div>
);
},
Expand Down
17 changes: 0 additions & 17 deletions src/internal/ErrorMessage.tsx

This file was deleted.

24 changes: 24 additions & 0 deletions src/internal/SupportOrErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";
import { Text } from "src/components/Text";

interface ErrorMsgProps {
error: boolean;
supportText?: string;
errorMsg?: string;
}

export const SupportOrErrorMessage = ({ error, supportText, errorMsg }: ErrorMsgProps) => {
return error && errorMsg ? (
<Text size="xs" as="span" className="text-error-500">
{errorMsg}
</Text>
) : (
supportText && (
<Text size="xs" as="span" className="text-coolGray-600">
{supportText}
</Text>
)
);
};

export default SupportOrErrorMessage;

0 comments on commit cd577fd

Please sign in to comment.