Skip to content

Commit

Permalink
Add TextArea component to TextField
Browse files Browse the repository at this point in the history
  • Loading branch information
psirenny authored Jun 9, 2024
1 parent 78486bc commit 8ff1f32
Show file tree
Hide file tree
Showing 4 changed files with 2,157 additions and 1,906 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-bats-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@spear-ai/ui": minor
---

Added TextArea component to TextField.
31 changes: 24 additions & 7 deletions packages/storybook/src/components/text-field/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ import {
TextFieldError,
TextFieldInput,
TextFieldLabel,
TextFieldTextArea,
} from "@spear-ai/ui/components/text-field";
import type { Meta, StoryObj } from "@storybook/react";
import { Form } from "react-aria-components";
import { useIntl } from "react-intl";

const PreviewTextField = (properties: {
canResizeTextArea: boolean;
hasLabel: boolean;
hasLabelDescription: boolean;
isDisabled: boolean;
isInvalid: boolean;
isSquished: boolean;
isTextArea: boolean;
}) => {
const { hasLabel, hasLabelDescription, isDisabled, isInvalid, isSquished } = properties;
const { canResizeTextArea, hasLabel, hasLabelDescription, isDisabled, isInvalid, isSquished, isTextArea } =
properties;
const intl = useIntl();

return (
Expand Down Expand Up @@ -46,12 +50,23 @@ const PreviewTextField = (properties: {
})}
</TextFieldDescription>
) : null}
<TextFieldInput
placeholder={intl.formatMessage({
defaultMessage: "[email protected]",
id: "SvELQW",
})}
/>
{isTextArea ? (
<TextFieldTextArea
className={canResizeTextArea ? "resize-y" : undefined}
placeholder={intl.formatMessage({
defaultMessage: "[email protected]",
id: "SvELQW",
})}
rows={4}
/>
) : (
<TextFieldInput
placeholder={intl.formatMessage({
defaultMessage: "[email protected]",
id: "SvELQW",
})}
/>
)}
<TextFieldError>
{intl.formatMessage({ defaultMessage: "Email address is invalid", id: "sVgB+Q" })}
</TextFieldError>
Expand All @@ -69,11 +84,13 @@ type Story = StoryObj<typeof meta>;

export const Standard: Story = {
args: {
canResizeTextArea: false,
hasLabel: true,
hasLabelDescription: true,
isDisabled: false,
isInvalid: false,
isSquished: false,
isTextArea: false,
},
parameters: {
layout: "centered",
Expand Down
16 changes: 15 additions & 1 deletion packages/ui/src/components/text-field.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
FieldError as FieldErrorPrimitive,
Input as InputPrimitive,
Label as LabelPrimitive,
TextArea as TextAreaPrimitive,
TextField as TextFieldPrimitive,
} from "react-aria-components";
import { cx } from "@/helpers/cx";
Expand Down Expand Up @@ -47,14 +48,27 @@ export const TextFieldInput = forwardRef<
ComponentPropsWithoutRef<typeof InputPrimitive> & { className?: string | undefined }
>(({ className, ...properties }, reference) => {
const mergedClassName = cx(
"bg-white-a-3 text-neutral-12 outline-neutral-a-7 placeholder:text-neutral-10 theme-dfs:bg-canvas-1 theme-galapago:bg-white invalid:outline-x-negative-a-7 focus-visible:outline-primary-a-8 group-disabled:bg-neutral-a-3 group-disabled:text-neutral-a-8 group-disabled:outline-neutral-a-6 theme-dfs:group-disabled:bg-neutral-a-3 theme-forerunner:group-disabled:bg-neutral-a-3 theme-galapago:group-disabled:bg-neutral-a-3 group-invalid:group-disabled:outline-x-negative-a-6 dark:bg-white-a-3 theme-dfs:dark:bg-white-a-3 theme-forerunner:dark:bg-black-a-3 theme-galapago:dark:bg-black-a-3 h-9 w-full rounded-lg border-none pe-2 ps-3.5 text-base leading-none shadow outline -outline-offset-1 focus-visible:outline-offset-0 group-disabled:pointer-events-none sm:ps-3 sm:text-sm",
"bg-white-a-3 text-neutral-12 outline-neutral-a-7 placeholder:text-neutral-10 theme-dfs:bg-canvas-1 theme-galapago:bg-white invalid:outline-x-negative-a-7 focus-visible:outline-primary-a-8 group-disabled:bg-neutral-a-3 group-disabled:text-neutral-a-8 group-disabled:outline-neutral-a-6 theme-dfs:group-disabled:bg-neutral-a-3 theme-forerunner:group-disabled:bg-neutral-a-3 theme-galapago:group-disabled:bg-neutral-a-3 group-invalid:group-disabled:outline-x-negative-a-6 dark:bg-white-a-3 theme-dfs:dark:bg-white-a-3 theme-forerunner:dark:bg-black-a-3 theme-galapago:dark:bg-black-a-3 w-full rounded-lg border-none py-1.5 pe-2 ps-3.5 text-base leading-6 shadow outline -outline-offset-1 focus-visible:outline-offset-0 group-disabled:pointer-events-none sm:ps-3 sm:text-sm sm:leading-6",
className,
);
return <InputPrimitive className={mergedClassName} {...properties} ref={reference} />;
});

TextFieldInput.displayName = "TextFieldInput";

export const TextFieldTextArea = forwardRef<
ElementRef<typeof TextAreaPrimitive>,
ComponentPropsWithoutRef<typeof TextAreaPrimitive> & { className?: string | undefined }
>(({ className, ...properties }, reference) => {
const mergedClassName = cx(
"bg-white-a-3 text-neutral-12 outline-neutral-a-7 placeholder:text-neutral-10 theme-dfs:bg-canvas-1 theme-galapago:bg-white invalid:outline-x-negative-a-7 focus-visible:outline-primary-a-8 group-disabled:bg-neutral-a-3 group-disabled:text-neutral-a-8 group-disabled:outline-neutral-a-6 theme-dfs:group-disabled:bg-neutral-a-3 theme-forerunner:group-disabled:bg-neutral-a-3 theme-galapago:group-disabled:bg-neutral-a-3 group-invalid:group-disabled:outline-x-negative-a-6 dark:bg-white-a-3 theme-dfs:dark:bg-white-a-3 theme-forerunner:dark:bg-black-a-3 theme-galapago:dark:bg-black-a-3 w-full resize-none rounded-lg border-none py-1.5 pe-2 ps-3.5 text-base leading-6 shadow outline -outline-offset-1 focus-visible:outline-offset-0 group-disabled:pointer-events-none sm:ps-3 sm:text-sm sm:leading-6",
className,
);
return <TextAreaPrimitive className={mergedClassName} {...properties} ref={reference} />;
});

TextFieldTextArea.displayName = "TextFieldTextArea";

export const TextFieldError = forwardRef<
ElementRef<typeof FieldErrorPrimitive>,
ComponentPropsWithoutRef<typeof FieldErrorPrimitive> & { className?: string | undefined }
Expand Down
Loading

0 comments on commit 8ff1f32

Please sign in to comment.