@shopify/cli-kit
Version:
A set of utilities, interfaces, and models that are common across all the platform features
41 lines • 1.71 kB
JavaScript
import { TokenizedText } from './TokenizedText.js';
import { Box, Text } from 'ink';
import React from 'react';
const DOT = '•';
/**
* `List` displays an unordered or ordered list with text aligned with the bullet point
* and wrapped to the container width.
*/
const List = ({ title, items, margin = true, ordered = false, color, bullet = DOT, }) => {
function isCustomListItem(item) {
return item.item !== undefined;
}
function resolveListItem(item, index) {
const resolvedItem = {
index,
color,
bullet,
ordered,
item: item,
};
return isCustomListItem(item)
? {
...resolvedItem,
...item,
}
: resolvedItem;
}
const ListItem = ({ item, color, bullet, index, ordered }) => {
return (React.createElement(Box, { key: index, marginLeft: margin ? 2 : 0 },
React.createElement(Text, { color: color }, ordered ? `${index + 1}.` : bullet),
React.createElement(Box, { flexGrow: 1, marginLeft: 1 },
React.createElement(Text, { color: color },
React.createElement(TokenizedText, { item: item })))));
};
return (React.createElement(Box, { flexDirection: "column" },
title ? (React.createElement(Text, { color: color },
React.createElement(TokenizedText, { item: title }))) : null,
items.map(resolveListItem).map(({ index, item, color, bullet, ordered }) => (React.createElement(ListItem, { key: index, item: item, color: color, bullet: bullet, index: index, ordered: ordered })))));
};
export { List };
//# sourceMappingURL=List.js.map