Skip to content

Commit

Permalink
🔀 merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineKM committed Jan 12, 2024
2 parents d9c754b + 7d14a37 commit d1b60fd
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 36 deletions.
5 changes: 0 additions & 5 deletions .changeset/quiet-dryers-double.md

This file was deleted.

12 changes: 12 additions & 0 deletions packages/kitchen/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @tonightpass/kitchen

## 1.10.3

### Patch Changes

- 5f1128e: Set forwardRef to Input component

## 1.10.2

### Patch Changes

- ccdce5a: Add missing scale hoc on select

## 1.10.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/kitchen/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tonightpass/kitchen",
"version": "1.10.1",
"version": "1.10.3",
"description": "Tonight Pass delicious React styled-components UI kit",
"repository": "https://github.com/tonightpass/kitchen",
"bugs": "https://github.com/tonightpass/kitchen/issues",
Expand Down
63 changes: 36 additions & 27 deletions packages/kitchen/src/components/Input/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { forwardRef, useImperativeHandle } from "react";
import { RiCloseCircleLine } from "react-icons/ri";
import styled from "styled-components";

Expand Down Expand Up @@ -47,31 +47,34 @@ export type InputProps = KitchenComponent<
React.InputHTMLAttributes<HTMLInputElement>
>;

const Input = styled(
({
size = "normal",
prefix,
suffix,
disabled = false,
prefixContainer = true,
suffixContainer = true,
prefixStyling = true,
suffixStyling = true,
clearable = false,
value,
initialValue = "",
readOnly = false,
onChange,
width,
onClearClick,
onFocus,
onBlur,
error,
type,
label,
...props
}: InputProps) => {
const inputRef = React.useRef<HTMLInputElement>();
const ForwardedInput = forwardRef<HTMLInputElement, InputProps>(
(
{
size = "normal",
prefix,
suffix,
disabled = false,
prefixContainer = true,
suffixContainer = true,
prefixStyling = true,
suffixStyling = true,
clearable = false,
value,
initialValue = "",
readOnly = false,
onChange,
width,
onClearClick,
onFocus,
onBlur,
error,
type,
label,
...props
}: InputProps,
ref: React.Ref<HTMLInputElement>,
) => {
const inputRef = React.useRef<HTMLInputElement>(null);
const [selfValue, setSelfValue] = React.useState<string>(initialValue);
const [focus, setFocus] = React.useState<boolean>(false);
const [clearIconHover, setClearIconHover] = React.useState<boolean>(false);
Expand All @@ -80,6 +83,8 @@ const Input = styled(
[value],
);

useImperativeHandle(ref, () => inputRef.current as HTMLInputElement);

const Wrapper = label ? "label" : React.Fragment;

const controlledValue = isControlledComponent
Expand Down Expand Up @@ -223,7 +228,11 @@ const Input = styled(
</Wrapper>
);
},
)`
);

ForwardedInput.displayName = "Input";

const Input = styled(ForwardedInput)`
font: inherit;
width: 100%;
min-width: 0;
Expand Down
33 changes: 30 additions & 3 deletions workshop/pages/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,19 @@ type FormData = {
};

const InputPage: NextPage = () => {
const { control, handleSubmit } = useForm<FormData>();
const { control, handleSubmit: handleSubmitControl } = useForm<FormData>();

const onSubmit = handleSubmit((data) => {
const onSubmitControl = handleSubmitControl((data) => {
console.log(data);
});

const {
register,
handleSubmit: handleSubmitRegistered,
formState: { isValid: isValidRegistered },
} = useForm<FormData>();

const onSubmitRegistered = handleSubmitRegistered((data) => {
console.log(data);
});

Expand Down Expand Up @@ -305,11 +315,28 @@ const InputPage: NextPage = () => {
</Container>
</Container>

<Container gap={5}>
<Text>{"registered"}</Text>
<Text>{`is valid : ${isValidRegistered}`}</Text>
<Container row>
<Container align={"flex-start"}>
<form onSubmit={onSubmitRegistered}>
<Input
{...register("name", {
required: true,
maxLength: 20,
})}
/>
</form>
</Container>
</Container>
</Container>

<Container gap={5}>
<Text>{"controlled"}</Text>
<Container row>
<Container align={"flex-start"}>
<form onSubmit={onSubmit}>
<form onSubmit={onSubmitControl}>
<ControlledInput name={"name"} control={control} />
</form>
</Container>
Expand Down

1 comment on commit d1b60fd

@vercel
Copy link

@vercel vercel bot commented on d1b60fd Jan 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

kitchen-workshop – ./workshop

kitchen-workshop-git-master-tonightpass.vercel.app
kitchen-workshop-tonightpass.vercel.app
kitchen-workshop.vercel.app

Please sign in to comment.