You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { REDUCER_KEY } from './constants';
  2. /**
  3. * Generates a class attribute value.
  4. *
  5. * @param {Iterable<string>} args - String iterable.
  6. * @returns {string} Class attribute value.
  7. */
  8. export const classList = (...args) => args.filter(Boolean).join(' ');
  9. /**
  10. * Find the first styled ancestor component of an element.
  11. *
  12. * @param {Element} target - Element to look up.
  13. * @param {StyledComponentClass} component - Styled component reference.
  14. * @returns {Element|null} Ancestor.
  15. */
  16. export const findStyledAncestor = (target, component) => {
  17. if (!target || target.matches(`.${component.styledComponentId}`)) {
  18. return target;
  19. }
  20. return findStyledAncestor(target.parentElement, component);
  21. };
  22. /**
  23. * Get a style property from a style declaration as a float.
  24. *
  25. * @param {CSSStyleDeclaration} styles - Style declaration.
  26. * @param {string} name - Property name.
  27. * @returns {number} Float value.
  28. */
  29. export const getFloatStyleProperty = (styles, name) =>
  30. parseFloat(styles.getPropertyValue(name));
  31. /**
  32. * Gets the outer height of an element, including margins.
  33. *
  34. * @param {Element} element - Target element.
  35. * @returns {number} Computed height.
  36. */
  37. export const getComputedOuterHeight = element => {
  38. const computedStyle = getComputedStyle(element);
  39. return element.offsetHeight
  40. + getFloatStyleProperty(computedStyle, 'margin-top')
  41. + getFloatStyleProperty(computedStyle, 'margin-bottom');
  42. };
  43. /**
  44. * Returns this feature's root state.
  45. *
  46. * @param {Object} state - Global state.
  47. * @returns {Object} Feature state.
  48. */
  49. const getState = state => state[REDUCER_KEY];
  50. /**
  51. * Is the participants pane open.
  52. *
  53. * @param {Object} state - Global state.
  54. * @returns {boolean} Is the participants pane open.
  55. */
  56. export const getParticipantsPaneOpen = state => Boolean(getState(state).isOpen);