diff --git a/@stellar/design-system-website/docs/components/inputs/textarea.mdx b/@stellar/design-system-website/docs/components/inputs/textarea.mdx new file mode 100644 index 00000000..411adb12 --- /dev/null +++ b/@stellar/design-system-website/docs/components/inputs/textarea.mdx @@ -0,0 +1,19 @@ +--- +slug: /textarea +--- + +# Textarea + + + +## Example + +```tsx live + + + +``` + +## Props + + diff --git a/@stellar/design-system-website/src/componentPreview/textareaPreview.tsx b/@stellar/design-system-website/src/componentPreview/textareaPreview.tsx new file mode 100644 index 00000000..c7e0885f --- /dev/null +++ b/@stellar/design-system-website/src/componentPreview/textareaPreview.tsx @@ -0,0 +1,104 @@ +import { ComponentPreview } from "@site/src/components/PreviewBlock"; + +export const textareaPreview: ComponentPreview = { + options: [ + { + type: "select", + prop: "label", + customValue: "Label", + options: [ + { + value: "", + label: "No label", + }, + { + value: "label", + label: "Label", + }, + ], + }, + { + type: "select", + prop: "placeholder", + customValue: "Placeholder", + options: [ + { + value: "", + label: "No placeholder", + }, + { + value: "placeholder", + label: "Placeholder", + }, + ], + }, + { + type: "select", + prop: "fieldSize", + options: [ + { + value: "md", + label: "MD", + }, + { + value: "sm", + label: "SM", + }, + { + value: "xs", + label: "XS", + }, + ], + }, + { + type: "checkbox", + prop: "disabled", + label: "Disabled", + }, + { + type: "checkbox", + prop: "isLabelUppercase", + label: "Uppercase label", + }, + { + type: "checkbox", + prop: "isError", + label: "Error", + }, + { + type: "checkbox", + prop: "isExtraPadding", + label: "Extra padding", + }, + { + type: "select", + prop: "note", + customValue: "Note message", + options: [ + { + value: "", + label: "No note", + }, + { + value: "note", + label: "Note", + }, + ], + }, + { + type: "select", + prop: "error", + customValue: "Error message", + options: [ + { + value: "", + label: "No error", + }, + { + value: "error", + label: "Error", + }, + ], + }, + ], +}; diff --git a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx index fbfb92ca..daf26e60 100644 --- a/@stellar/design-system-website/src/components/PreviewBlock/index.tsx +++ b/@stellar/design-system-website/src/components/PreviewBlock/index.tsx @@ -21,6 +21,7 @@ import { paragraphPreview } from "@site/src/componentPreview/paragraphPreview"; import { profilePreview } from "@site/src/componentPreview/profilePreview"; import { projectLogoPreview } from "@site/src/componentPreview/projectLogoPreview"; import { selectPreview } from "@site/src/componentPreview/selectPreview"; +import { textareaPreview } from "@site/src/componentPreview/textareaPreview"; import { titlePreview } from "@site/src/componentPreview/titlePreview"; import { tooltipPreview } from "@site/src/componentPreview/tooltipPreview"; @@ -43,6 +44,7 @@ const previews: { [key: string]: ComponentPreview } = { Profile: profilePreview, ProjectLogo: projectLogoPreview, Select: selectPreview, + Textarea: textareaPreview, Title: titlePreview, Tooltip: tooltipPreview, }; diff --git a/@stellar/design-system-website/src/components/PreviewBlock/styles.css b/@stellar/design-system-website/src/components/PreviewBlock/styles.css index 2c314621..44eb8371 100644 --- a/@stellar/design-system-website/src/components/PreviewBlock/styles.css +++ b/@stellar/design-system-website/src/components/PreviewBlock/styles.css @@ -85,7 +85,8 @@ margin: 0 !important; } +.PreviewBlock .Input, .PreviewBlock .Select, -.PreviewBlock .Input { +.PreviewBlock .Textarea { max-width: 24rem; } diff --git a/@stellar/design-system/src/components/Textarea/index.tsx b/@stellar/design-system/src/components/Textarea/index.tsx index 884e53b6..aa7ef5f5 100644 --- a/@stellar/design-system/src/components/Textarea/index.tsx +++ b/@stellar/design-system/src/components/Textarea/index.tsx @@ -3,22 +3,42 @@ import { Label } from "../Label"; import { FieldNote } from "../utils/FieldNote"; import "./styles.scss"; -interface TextareaProps - extends React.TextareaHTMLAttributes { +/** Including all valid [textarea attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea#attributes) */ +export interface TextareaProps { + /** ID of the textarea should be unique */ id: string; // Note: cannot use "size" here because it's input's native property + /** Size of the textarea */ fieldSize: "md" | "sm" | "xs"; + /** Content of the textarea */ children?: string; + /** Label of the textarea */ label?: string | React.ReactNode; + /** Note message of the textarea */ note?: string | React.ReactNode; + /** Error message of the textarea */ error?: string | React.ReactNode; + /** Textarea error without a message */ isError?: boolean; + /** Make label uppercase */ isLabelUppercase?: boolean; + /** Textarea with extra padding */ isExtraPadding?: boolean; + /** Use a specific textarea rather than a generic HTML textarea (useful for Formik or otherwise controlled inputs) */ customTextarea?: React.ReactElement; } -export const Textarea: React.FC = ({ +interface Props + extends TextareaProps, + React.TextareaHTMLAttributes { + id: string; + children?: string; +} + +/** + * `Textarea` component is a multi-line text input element, which inherits all native HTML `textarea` element attributes. + */ +export const Textarea: React.FC = ({ id, fieldSize, children = "", @@ -32,7 +52,7 @@ export const Textarea: React.FC = ({ spellCheck = false, autoComplete = "off", ...props -}: TextareaProps) => { +}: Props) => { const additionalClasses = [ `Textarea--${fieldSize}`, ...(props.disabled ? ["Textarea--disabled"] : []),