joinClasses.js.flow 827 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @providesModule joinClasses
  8. * @typechecks static-only
  9. */
  10. 'use strict';
  11. /**
  12. * Combines multiple className strings into one.
  13. * http://jsperf.com/joinclasses-args-vs-array
  14. *
  15. * @param {...?string} className
  16. * @return {string}
  17. */
  18. function joinClasses(className /*, ... */) {
  19. if (!className) {
  20. className = '';
  21. }
  22. let nextClass;
  23. const argLength = arguments.length;
  24. if (argLength > 1) {
  25. for (let ii = 1; ii < argLength; ii++) {
  26. nextClass = arguments[ii];
  27. if (nextClass) {
  28. className = (className ? className + ' ' : '') + nextClass;
  29. }
  30. }
  31. }
  32. return className;
  33. }
  34. module.exports = joinClasses;