textInputs.js.flow 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @flow
  2. import statefulSelectors from '../internalHelpers/_statefulSelectors'
  3. import type { InteractionState } from '../types/interactionState'
  4. const stateMap = [undefined, null, 'active', 'focus', 'hover']
  5. function template(state: string): string {
  6. return `input[type="color"]${state},
  7. input[type="date"]${state},
  8. input[type="datetime"]${state},
  9. input[type="datetime-local"]${state},
  10. input[type="email"]${state},
  11. input[type="month"]${state},
  12. input[type="number"]${state},
  13. input[type="password"]${state},
  14. input[type="search"]${state},
  15. input[type="tel"]${state},
  16. input[type="text"]${state},
  17. input[type="time"]${state},
  18. input[type="url"]${state},
  19. input[type="week"]${state},
  20. input:not([type])${state},
  21. textarea${state}`
  22. }
  23. /**
  24. * Populates selectors that target all text inputs. You can pass optional states to append to the selectors.
  25. * @example
  26. * // Styles as object usage
  27. * const styles = {
  28. * [textInputs('active')]: {
  29. * 'border': 'none'
  30. * }
  31. * }
  32. *
  33. * // styled-components usage
  34. * const div = styled.div`
  35. * > ${textInputs('active')} {
  36. * border: none;
  37. * }
  38. * `
  39. *
  40. * // CSS in JS Output
  41. *
  42. * 'input[type="color"]:active,
  43. * input[type="date"]:active,
  44. * input[type="datetime"]:active,
  45. * input[type="datetime-local"]:active,
  46. * input[type="email"]:active,
  47. * input[type="month"]:active,
  48. * input[type="number"]:active,
  49. * input[type="password"]:active,
  50. * input[type="search"]:active,
  51. * input[type="tel"]:active,
  52. * input[type="text"]:active,
  53. * input[type="time"]:active,
  54. * input[type="url"]:active,
  55. * input[type="week"]:active,
  56. * input:not([type]):active,
  57. * textarea:active': {
  58. * 'border': 'none'
  59. * }
  60. */
  61. export default function textInputs(...states: Array<InteractionState>): string {
  62. return statefulSelectors(states, template, stateMap)
  63. }