diff --git a/package.json b/package.json index 55eb91251..387ca946b 100644 --- a/package.json +++ b/package.json @@ -74,11 +74,7 @@ "prettier": "^2.3.0", "typescript": "4.3.4" }, - "husky": { - "hooks": { - "pre-commit": "lint-staged" - } - }, + "lint-staged": { "**/*.{js,jsx,ts,tsx}": [ "prettier --write", diff --git a/pages/index.tsx b/pages/index.tsx index 0005eacd0..9c9942636 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,21 +1,31 @@ -import { ButtonCommon, Layout } from 'src/components/common' -import { IconBuy } from 'src/components/icons' -import { ButonType, ButtonSize } from 'src/utils/constanst.utils' +import { useEffect, useRef } from 'react'; +import { Inputcommon, Layout } from 'src/components/common' +import { InputType } from 'src/utils/constanst.utils' export default function Home() { + + const inputElementRef = useRef(null); + + useEffect(() => { + setTimeout(() =>{ + inputElementRef.current?.focus() + }, 1000) + }, []) + + const onEnter = (value: string | number) => { + + } + return ( <>
This is home page
- Button default - {ButonType.light} - Button light - {ButonType.light} - Button light - {ButonType.light} - Button light - }>{ButtonSize.large} - Button default large - } disabled isIconSuffix={true}>Button with icon disabled - } type={ButonType.light}>Button with icon

Go to pages/index.tsx to get your hand dirty!

Go to src/components to make your awesome component!

Go to src/styles to find global styles!

+ + + + ) } diff --git a/src/components/common/InputCommon/InputCommon.module.scss b/src/components/common/InputCommon/InputCommon.module.scss new file mode 100644 index 000000000..8909a6a7f --- /dev/null +++ b/src/components/common/InputCommon/InputCommon.module.scss @@ -0,0 +1,5 @@ +@import "../../../styles/utilities"; + +.inputCommon { + @apply custom-border-radius bg-primary transition-all duration-200 text-white font-bold; +} diff --git a/src/components/common/InputCommon/InputCommon.tsx b/src/components/common/InputCommon/InputCommon.tsx new file mode 100644 index 000000000..e0ca5ff95 --- /dev/null +++ b/src/components/common/InputCommon/InputCommon.tsx @@ -0,0 +1,52 @@ +import React, { forwardRef, RefObject, useImperativeHandle, useRef } from 'react'; +import { InputType, KEY } from 'src/utils/constanst.utils'; +import s from './InputCommon.module.scss' + +type Ref = { + focus: () => void +} | null; + +interface Props { + children?: React.ReactNode, + value?: string | number, + placeholder?: string, + type?: InputType, + onChange?: (value: string | number) => void, + onEnter?: (value: string | number) => void, +} + +const InputCommon = forwardRef(({ value, placeholder, type, onChange, onEnter }: Props, ref) => { + const inputElementRef = useRef(null); + + useImperativeHandle(ref, () => ({ + focus: () => { + inputElementRef.current?.focus(); + }, + })); + + const handleChange = (e: React.ChangeEvent) => { + onChange && onChange(e.target.value) + } + + const handleKeyDown = (e: any) => { + if (e.key === KEY.ENTER && onEnter) { + const value = inputElementRef.current?.value || '' + onEnter(value) + } + } + + return ( + + ) + +}) + +export default InputCommon diff --git a/src/components/common/index.ts b/src/components/common/index.ts index 8144b0de0..4e9637e6c 100644 --- a/src/components/common/index.ts +++ b/src/components/common/index.ts @@ -3,4 +3,5 @@ export { default as Layout } from './Layout/Layout' export { default as Head } from './Head/Head' export { default as ViewAllItem} from './ViewAllItem/ViewAllItem' export { default as ItemWishList} from './ItemWishList/ItemWishList' -export { default as Logo} from './Logo/Logo' \ No newline at end of file +export { default as Logo} from './Logo/Logo' +export { default as Inputcommon} from './InputCommon/InputCommon' diff --git a/src/utils/constanst.utils.ts b/src/utils/constanst.utils.ts index 538cfe306..110af9a7e 100644 --- a/src/utils/constanst.utils.ts +++ b/src/utils/constanst.utils.ts @@ -10,3 +10,11 @@ export enum ButtonSize { large = 'large', } +export enum InputType { + text = 'text', + number = 'number', +} + +export const KEY = { + ENTER: 'Enter', +}