TextInput.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import styled from "styled-components";
  2. import { withProp, prop } from "styled-tools";
  3. import { Flex, BoxProps } from "reflexbox/styled-components";
  4. import { fadeIn } from "../helpers/animations";
  5. interface Props extends BoxProps {
  6. autoFocus?: boolean;
  7. name?: string;
  8. id?: string;
  9. type?: string;
  10. value?: string;
  11. required?: boolean;
  12. small?: boolean;
  13. onChange?: any;
  14. tiny?: boolean;
  15. placeholderSize?: number[];
  16. br?: string;
  17. bbw?: string;
  18. }
  19. const TextInput = styled(Flex).attrs({
  20. as: "input"
  21. })<Props>`
  22. position: relative;
  23. box-sizing: border-box;
  24. letter-spacing: 0.05em;
  25. color: #444;
  26. background-color: white;
  27. box-shadow: 0 10px 35px hsla(200, 15%, 70%, 0.2);
  28. border: none;
  29. border-radius: ${prop("br", "100px")};
  30. border-bottom: 5px solid #f5f5f5;
  31. border-bottom-width: ${prop("bbw", "5px")};
  32. animation: ${fadeIn} 0.5s ease-out;
  33. transition: all 0.5s ease-out;
  34. :focus {
  35. outline: none;
  36. box-shadow: 0 20px 35px hsla(200, 15%, 70%, 0.4);
  37. }
  38. ::placeholder {
  39. font-size: ${withProp("placeholderSize", s => s[0] || 14)};
  40. letter-spacing: 0.05em;
  41. color: #888;
  42. }
  43. @media screen and (min-width: 64em) {
  44. ::placeholder {
  45. font-size: ${withProp("placeholderSize", s => s[3] || 16)}px;
  46. }
  47. }
  48. @media screen and (min-width: 52em) {
  49. letter-spacing: 0.1em;
  50. border-bottom-width: ${prop("bbw", "6px")};
  51. ::placeholder {
  52. font-size: ${withProp("placeholderSize", s => s[2] || 15)}px;
  53. }
  54. }
  55. @media screen and (min-width: 40em) {
  56. ::placeholder {
  57. font-size: ${withProp("placeholderSize", s => s[1] || 15)}px;
  58. }
  59. }
  60. `;
  61. TextInput.defaultProps = {
  62. value: "",
  63. small: false,
  64. tiny: false,
  65. height: [56, 72],
  66. py: 0,
  67. pr: [48, 84],
  68. pl: [32, 40],
  69. fontSize: [14, 16],
  70. placeholderSize: []
  71. };
  72. export default TextInput;