Skip to content

Commit

Permalink
add helper text to Textarea
Browse files Browse the repository at this point in the history
  • Loading branch information
kishkoigor committed Mar 28, 2024
1 parent 0ca7eda commit 9b26a35
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@airdao/ui-library",
"version": "1.4.14",
"version": "1.4.15",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/types.d.ts",
Expand Down
18 changes: 14 additions & 4 deletions src/components/Textarea/Textarea.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { TextareaProps } from './Textarea.types';
import { BottomTextProps, TextareaProps } from './Textarea.types';
import propTypes from 'prop-types';
import s from './textarea.module.css';

Expand All @@ -13,6 +13,7 @@ export function Textarea({
onChange,
disabled,
error,
helperText,
}: TextareaProps) {
return (
<div
Expand All @@ -30,13 +31,22 @@ export function Textarea({
/>
{tailIcon || null}
</div>
{typeof error === 'string' && error && (
<span className={s.error}>{error}</span>
)}
<span className={s.helperText}></span>
<BottomText helperText={helperText} error={error} />
</div>
);
}

function BottomText({ helperText, error }: BottomTextProps) {
if (error && typeof error === 'string') {
return <span className={`${s.helperText} ${s.errorText}`}>{error}</span>;
}
if (helperText) {
return <span className={s.helperText}>{helperText}</span>;
}
return null;
}

Textarea.propTypes = {
className: propTypes.string,
placeholder: propTypes.string,
Expand Down
6 changes: 6 additions & 0 deletions src/components/Textarea/Textarea.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ export interface TextareaProps {
disabled?: boolean;
onChange?: ChangeEventHandler<HTMLTextAreaElement>;
error?: string | boolean;
helperText?: string;
}

export interface BottomTextProps {
helperText?: string;
error?: string | boolean;
}
10 changes: 7 additions & 3 deletions src/components/Textarea/textarea.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,20 @@
letter-spacing: -0.16px;
}

.error {
.helperText {
position: absolute;
bottom: -23px;
color: #FF4747;
bottom: -24px;
color: var(--alpha-black-60, rgba(14, 14, 14, 0.60));
font-family: Inter, sans-serif;
font-size: 14px;
line-height: 20px; /* 142.857% */
letter-spacing: -0.14px;
}

.errorText {
color: #FF4747;
}

.inputError .field {
border: 1px solid #FFD9CD;
color: #FF4747;
Expand Down

0 comments on commit 9b26a35

Please sign in to comment.