TextInput.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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)}px;
  40. letter-spacing: 0.05em;
  41. color: #888;
  42. }
  43. @media screen and (min-width: 64em) {
  44. ::placeholder {
  45. font-size: ${withProp(
  46. "placeholderSize",
  47. s => s[3] || s[2] || s[1] || s[0] || 16
  48. )}px;
  49. }
  50. }
  51. @media screen and (min-width: 52em) {
  52. letter-spacing: 0.1em;
  53. border-bottom-width: ${prop("bbw", "6px")};
  54. ::placeholder {
  55. font-size: ${withProp(
  56. "placeholderSize",
  57. s => s[2] || s[1] || s[0] || 15
  58. )}px;
  59. }
  60. }
  61. @media screen and (min-width: 40em) {
  62. ::placeholder {
  63. font-size: ${withProp("placeholderSize", s => s[1] || s[0] || 15)}px;
  64. }
  65. }
  66. `;
  67. TextInput.defaultProps = {
  68. value: "",
  69. small: false,
  70. tiny: false,
  71. height: [56, 72],
  72. py: 0,
  73. pr: [48, 84],
  74. pl: [32, 40],
  75. fontSize: [14, 16],
  76. placeholderSize: []
  77. };
  78. export default TextInput;