buttons.js.flow 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 `button${state},
  7. input[type="button"]${state},
  8. input[type="reset"]${state},
  9. input[type="submit"]${state}`
  10. }
  11. /**
  12. * Populates selectors that target all buttons. You can pass optional states to append to the selectors.
  13. * @example
  14. * // Styles as object usage
  15. * const styles = {
  16. * [buttons('active')]: {
  17. * 'border': 'none'
  18. * }
  19. * }
  20. *
  21. * // styled-components usage
  22. * const div = styled.div`
  23. * > ${buttons('active')} {
  24. * border: none;
  25. * }
  26. * `
  27. *
  28. * // CSS in JS Output
  29. *
  30. * 'button:active,
  31. * 'input[type="button"]:active,
  32. * 'input[type=\"reset\"]:active,
  33. * 'input[type=\"submit\"]:active: {
  34. * 'border': 'none'
  35. * }
  36. */
  37. export default function buttons(...states: Array<InteractionState>): string {
  38. return statefulSelectors(states, template, stateMap)
  39. }