TextInput.tsx 1.8 KB

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