Last active
October 8, 2020 15:08
-
-
Save infelipe13/00a40fcef45945b5ef192b97a922c556 to your computer and use it in GitHub Desktop.
CSS module + Tailwind CSS
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
import { useId } from "@reach/auto-id"; | |
import clsx from "clsx"; | |
import style from "src/components/Input/style.module.css"; | |
export const Input = ({ errorMessage = "", id, label, ...otherProps }) => { | |
const inputId = useId(id); | |
const inputClassName = clsx(style.input, errorMessage && style.inputError); | |
const ErrorMessage = () => { | |
return errorMessage ? <p className={style.errorMessage}>{errorMessage}</p> : null; | |
}; | |
return ( | |
<div className="space-y-1"> | |
<label htmlFor={inputId}>{label}</label> | |
<input id={inputId} className={inputClassName} {...otherProps} /> | |
<ErrorMessage /> | |
</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
.label { | |
@apply text-sm leading-6 font-medium text-gray-900; | |
} | |
.input { | |
@apply p-4 bg-gray-100 text-sm leading-6 text-gray-800 border-2 border-gray-300 border-b-solid; | |
} | |
.input:hover { | |
@apply bg-gray-200 border-gray-600; | |
} | |
.input:focus { | |
@apply bg-blue-200 border-blue-600; | |
} | |
.inputError { | |
@apply bg-red-100 border-red-300; | |
} | |
.inputError:hover, .inputError:focus { | |
@apply bg-red-200 border-red-600; | |
} | |
.errorMessage { | |
@apply text-red-800 text-xs leading-5; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment