From a228953aff4489e4659c179ccbfe4f926cb0dcea Mon Sep 17 00:00:00 2001 From: Oksamies Date: Wed, 8 Nov 2023 12:26:36 +0200 Subject: [PATCH] temp2 --- .../CreateTeamForm/CreateTeamForm.module.css | 4 +- .../Forms/CreateTeamForm/CreateTeamForm.tsx | 44 ++++++++++++++----- .../components/TextInput/TextInput.module.css | 40 +++++++++++++---- .../src/components/TextInput/TextInput.tsx | 30 +++++++------ 4 files changed, 83 insertions(+), 35 deletions(-) diff --git a/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.module.css b/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.module.css index 2dffb9493..fe2ec743a 100644 --- a/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.module.css +++ b/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.module.css @@ -13,9 +13,9 @@ .footer { display: flex; - flex-direction: row; + flex-direction: row-reverse; gap: var(--gap--16); justify-content: space-between; - padding: var(--space--16) var(--space--24); + padding-top: var(--space--16); border-top: var(--border); } diff --git a/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx b/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx index 492859677..24d41db9c 100644 --- a/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx +++ b/packages/cyberstorm/src/components/Forms/CreateTeamForm/CreateTeamForm.tsx @@ -4,6 +4,33 @@ import * as Button from "../../Button"; import { TextInput } from "../../TextInput/TextInput"; import { useForm, useController, UseControllerProps } from "react-hook-form"; +type FormValues = { + teamName: string; +}; + +function Input(props: UseControllerProps) { + const { field, fieldState } = useController(props); + + return ( +
+ + + +

{fieldState.isTouched && "Touched"}

+
+ ); +} + /** * Form for creating a team */ @@ -17,14 +44,6 @@ export function CreateTeamForm() { const onSubmit = (data: { teamName: string }) => console.log(data); - const controllerProps = { - control: control, - name: "teamName", - rules: { required: true }, - } as UseControllerProps<{ teamName: string }>; - - const { field, fieldState } = useController(controllerProps); - return (
@@ -32,10 +51,11 @@ export function CreateTeamForm() { Enter the name of the team you wish to create. Team names can contain the characters a-z A-Z 0-9 _ and must not start or end with an _
- -

{fieldState.isTouched && "Touched"}

-

{fieldState.isDirty && "Dirty"}

-

{fieldState.invalid ? "invalid" : "valid"}

+
diff --git a/packages/cyberstorm/src/components/TextInput/TextInput.module.css b/packages/cyberstorm/src/components/TextInput/TextInput.module.css index 5e07ef9da..8377670ca 100644 --- a/packages/cyberstorm/src/components/TextInput/TextInput.module.css +++ b/packages/cyberstorm/src/components/TextInput/TextInput.module.css @@ -5,7 +5,7 @@ color: var(--color-text--tertiary); } -.input { +.root > input { display: flex; flex-direction: row; align-items: center; @@ -23,27 +23,51 @@ --border-color: transparent; } -.hasLeftIcon { - padding-left: 2.875rem; -} - -.input:hover { +.root > input:hover { --border-color: var(--color-border--highlight); transition: ease-out 80ms; } -.input:focus-within { +.root > input:focus-within { color: var(--color-text--default); background-color: var(--color-black); --border-color: var(--color-border--highlight); } -.input::placeholder { +.root > input::placeholder { color: var(--color-text--tertiary); } +.root > input[data-state="invalid"] { + --border-color: var(--color-red--5); + + transition: ease-out 80ms; +} + +.root > input[data-state="invalid"]:hover { + --border-color: var(--color-red--3); + + transition: ease-out 80ms; +} + +.root > input[data-state="valid"] { + --border-color: var(--color-cyber-green--50); + + transition: ease-out 80ms; +} + +.root > input[data-state="valid"]:hover { + --border-color: var(--color-cyber-green--80); + + transition: ease-out 80ms; +} + +.hasLeftIcon { + padding-left: 2.875rem; +} + .leftIcon { position: absolute; width: 1em; diff --git a/packages/cyberstorm/src/components/TextInput/TextInput.tsx b/packages/cyberstorm/src/components/TextInput/TextInput.tsx index 1027393ed..9956e6301 100644 --- a/packages/cyberstorm/src/components/TextInput/TextInput.tsx +++ b/packages/cyberstorm/src/components/TextInput/TextInput.tsx @@ -1,10 +1,11 @@ "use client"; -import React from "react"; +import React, { ReactNode, cloneElement } from "react"; import styles from "./TextInput.module.css"; import { Icon } from "../Icon/Icon"; import { classnames } from "../../utils/utils"; export interface TextInputProps { + children?: ReactNode; placeHolder?: string; leftIcon?: JSX.Element; id?: string; @@ -13,6 +14,7 @@ export interface TextInputProps { value?: string; setValue?: React.Dispatch>; enterHook?: (value: string) => string | void; + asChild?: boolean; } /** @@ -20,6 +22,7 @@ export interface TextInputProps { */ export function TextInput(props: TextInputProps) { const { + children, placeHolder, id, type = "text", @@ -28,6 +31,7 @@ export function TextInput(props: TextInputProps) { value = "", setValue, enterHook, + asChild = false, } = props; const onEnter = (e: React.KeyboardEvent) => { @@ -43,18 +47,18 @@ export function TextInput(props: TextInputProps) { {leftIcon} ) : null} - setValue && setValue(event.target.value)} - value={value} - onKeyDown={(e) => onEnter(e)} - /> + {asChild ? ( + children + ) : ( + setValue && setValue(event.target.value)} + value={value} + onKeyDown={(e) => onEnter(e)} + /> + )} {rightIcon ? ( {rightIcon}