2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2022-01-27 11:21:12 +00:00
|
|
|
import { helper } from '@ember/component/helper';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Conditionally maps classInfos (classes) to a string ready for typical DOM
|
|
|
|
* usage (i.e. space delimited)
|
|
|
|
*
|
|
|
|
* @typedef {([string, boolean] | [string])} classInfo
|
|
|
|
* @param {(classInfo | string)[]} entries - An array of 'entry-like' arrays of `classInfo`s to map
|
|
|
|
*/
|
2022-09-15 08:43:17 +00:00
|
|
|
const classMap = (entries) => {
|
2022-01-27 11:21:12 +00:00
|
|
|
const str = entries
|
2022-03-07 09:51:47 +00:00
|
|
|
.filter(Boolean)
|
2022-09-15 08:43:17 +00:00
|
|
|
.filter((entry) => (typeof entry === 'string' ? true : entry[entry.length - 1]))
|
|
|
|
.map((entry) => (typeof entry === 'string' ? entry : entry[0]))
|
2022-01-27 11:21:12 +00:00
|
|
|
.join(' ');
|
|
|
|
return str.length > 0 ? str : undefined;
|
|
|
|
};
|
|
|
|
export default helper(classMap);
|