@awsui/components-react
Version:
On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en
43 lines • 2.01 kB
JavaScript
export function getItemGridColumns(layout, itemIndex) {
let i = 0;
for (const row of layout.rows) {
let gridColumnStart = 1;
for (const columnWidth of row) {
if (i === itemIndex) {
return { gridColumnStart, gridColumnEnd: gridColumnStart + columnWidth };
}
else {
gridColumnStart += columnWidth;
}
i++;
}
}
return { gridColumnStart: 1, gridColumnEnd: 1 };
}
export function getRemoveButtonGridColumns(layout, previousGridColumnEnd) {
var _a, _b;
const maxColumns = layout.rows.reduce((max, columns) => Math.max(max, columns.reduce((sum, col) => sum + col, 0)), 0);
if (isRemoveButtonOnSameLine(layout)) {
const removeButtonWidth = typeof ((_a = layout.removeButton) === null || _a === void 0 ? void 0 : _a.width) === 'number' ? (_b = layout.removeButton) === null || _b === void 0 ? void 0 : _b.width : 1;
return {
gridColumnStart: previousGridColumnEnd,
gridColumnEnd: previousGridColumnEnd + removeButtonWidth,
};
}
return { gridColumnStart: 1, gridColumnEnd: maxColumns + 1 };
}
export function isRemoveButtonOnSameLine(layout) {
var _a;
return layout.rows.length === 1 && !((_a = layout.removeButton) === null || _a === void 0 ? void 0 : _a.ownRow);
}
export function getGridTemplateColumns(layout) {
var _a, _b, _c;
const totalColumnUnits = layout.rows.reduce((maxCols, row) => Math.max(maxCols, row.reduce((cols, col) => cols + col, 0)), 0);
const removeButtonColumn = isRemoveButtonOnSameLine(layout)
? ((_a = layout.removeButton) === null || _a === void 0 ? void 0 : _a.width) === 'auto'
? 'max-content'
: `${(_c = (_b = layout.removeButton) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 1}fr`
: '';
return `repeat(${totalColumnUnits}, 1fr) ${removeButtonColumn}`;
}
//# sourceMappingURL=utils.js.map