Skip to content

Commit

Permalink
feat: add TextArea
Browse files Browse the repository at this point in the history
  • Loading branch information
receter committed Nov 11, 2024
1 parent 674e878 commit 818116f
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/ui/fixtures/textArea.fixture.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useState } from "react";

import { TextArea } from "../lib/main";

export default function Fixture() {
const [textAreaValue, setTextAreaValue] = useState("Hello, world!");
return (
<div style={{ padding: "2rem" }}>
<TextArea
onChange={(e) => setTextAreaValue(e.target.value)}
value={textAreaValue}
/>
</div>
);
}
14 changes: 14 additions & 0 deletions packages/ui/lib/TextArea/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { forwardRef } from "react";

import { TextAreaProps, useTextArea } from "./useTextArea";

export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>(
(props, ref) => {
const { textAreaProps, textAreaRef } = useTextArea({
props,
forwardedRef: ref,
});

return <textarea ref={textAreaRef} {...textAreaProps} />;
},
);
23 changes: 23 additions & 0 deletions packages/ui/lib/TextArea/styles.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.textArea {
box-sizing: border-box;
font-size: 1em;
line-height: var(--sys42-input-text-line-height);
background: var(--sys42-input-text-background);
border: var(--sys42-input-text-border-width) solid
var(--sys42-input-text-border-color);
border-radius: var(--sys42-input-text-border-radius);
padding: calc(
var(--sys42-input-text-padding-vert) -
var(--sys42-input-text-border-width)
)
calc(
var(--sys42-input-text-padding-horiz) -
var(--sys42-input-text-border-width)
);
}

.textArea:focus,
.textArea:focus-visible {
outline: var(--sys42-focus-outline);
outline-offset: var(--sys42-focus-outline-offset);
}
28 changes: 28 additions & 0 deletions packages/ui/lib/TextArea/useBaseTextArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from "react";

// Define specific props for the component
interface TextAreaProps {}

export type BaseTextAreaProps = Sys42Props<
TextAreaProps,
React.ComponentProps<"textarea">
>;

export type UseBaseTextAreaOptions<Props> = {
props: Props;
forwardedRef: React.ForwardedRef<HTMLTextAreaElement>;
};

export function useBaseTextArea<Props extends BaseTextAreaProps>({
props,
forwardedRef,
}: UseBaseTextAreaOptions<Props>) {
const textAreaProps: React.ComponentProps<"textarea"> = {
...props,
};

return {
textAreaProps,
textAreaRef: forwardedRef,
};
}
22 changes: 22 additions & 0 deletions packages/ui/lib/TextArea/useTextArea.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { cn } from "@sys42/utils";

import {
BaseTextAreaProps,
useBaseTextArea,
UseBaseTextAreaOptions,
} from "./useBaseTextArea";

import styles from "./styles.module.css";

export type TextAreaProps = BaseTextAreaProps;

export function useTextArea(options: UseBaseTextAreaOptions<TextAreaProps>) {
const textArea = useBaseTextArea(options);

textArea.textAreaProps.className = cn(
styles.textArea,
textArea.textAreaProps.className,
);

return textArea;
}
3 changes: 3 additions & 0 deletions packages/ui/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ export { FormField } from "./FormField";
export { Label } from "./Label";
export { OverflowMenu } from "./OverflowMenu";
export { Stack } from "./Stack";
export { TextArea } from "./TextArea";
export { TextLink, TextLinkButton } from "./TextLink";
export { TextInput } from "./TextInput";

export { useButton } from "./Button/useButton";
export { useFormField } from "./FormField/useFormField";
export { useLabel } from "./Label/useLabel";
export { useStack } from "./Stack/useStack";
export { useTextArea } from "./TextArea/useTextArea";
export { useTextLink } from "./TextLink/useTextLink";
export { useTextInput } from "./TextInput/useTextInput";

Expand All @@ -18,6 +20,7 @@ export { useBaseFormField } from "./FormField/useBaseFormField";
export { useBaseLabel } from "./Label/useBaseLabel";
export { useBaseOverflowMenu } from "./OverflowMenu/useBaseOverflowMenu";
export { useBaseStack } from "./Stack/useBaseStack";
export { useBaseTextArea } from "./TextArea/useBaseTextArea";
export { useBaseTextLink } from "./TextLink/useBaseTextLink";
export { useBaseTextInput } from "./TextInput/useBaseTextInput";

Expand Down

0 comments on commit 818116f

Please sign in to comment.