-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} />; | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters