| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { applyFilters } from '@wordpress/hooks'; |
| 4 |
|
| 5 |
/** |
| 6 |
* Returns the ready to use className for grid column. |
| 7 |
* |
| 8 |
* @param {Object} props - block properties. |
| 9 |
* |
| 10 |
* @return {string} Classname for Grid container. |
| 11 |
*/ |
| 12 |
export default function getColClass(props) { |
| 13 |
const { attributes } = props; |
| 14 |
let result = 'ghostkit-col'; |
| 15 |
|
| 16 |
// Responsive classes. |
| 17 |
Object.keys(attributes).forEach((key) => { |
| 18 |
if (attributes[key]) { |
| 19 |
let prefix = key.split('_')[0]; |
| 20 |
let type = key.split('_')[1]; |
| 21 |
|
| 22 |
if (!type) { |
| 23 |
type = prefix; |
| 24 |
prefix = ''; |
| 25 |
} |
| 26 |
|
| 27 |
if ( |
| 28 |
type && |
| 29 |
(type === 'size' || |
| 30 |
type === 'order' || |
| 31 |
type === 'verticalAlign') |
| 32 |
) { |
| 33 |
prefix = prefix && `-${prefix}`; |
| 34 |
|
| 35 |
switch (type) { |
| 36 |
case 'size': |
| 37 |
type = ''; |
| 38 |
break; |
| 39 |
case 'order': |
| 40 |
type = `-${type}`; |
| 41 |
break; |
| 42 |
case 'verticalAlign': |
| 43 |
type = '-align-self'; |
| 44 |
break; |
| 45 |
// no default |
| 46 |
} |
| 47 |
|
| 48 |
result = classnames( |
| 49 |
result, |
| 50 |
`ghostkit-col${type}${prefix || ''}${ |
| 51 |
attributes[key] !== 'auto' ? `-${attributes[key]}` : '' |
| 52 |
}` |
| 53 |
); |
| 54 |
} |
| 55 |
} |
| 56 |
}); |
| 57 |
|
| 58 |
// Sticky content. |
| 59 |
if ( |
| 60 |
attributes.stickyContent && |
| 61 |
typeof attributes.stickyContentOffset !== 'undefined' |
| 62 |
) { |
| 63 |
result = classnames( |
| 64 |
result, |
| 65 |
`ghostkit-col-sticky-${attributes.stickyContent}` |
| 66 |
); |
| 67 |
} |
| 68 |
|
| 69 |
result = applyFilters('ghostkit.editor.className', result, props); |
| 70 |
|
| 71 |
return result; |
| 72 |
} |
| 73 |
|