Skip to content

Commit

Permalink
fix: remove orientation prop
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 3, 2024
1 parent a2b816c commit 36415d9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 133 deletions.
68 changes: 0 additions & 68 deletions examples/orientation.ts

This file was deleted.

43 changes: 0 additions & 43 deletions src/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ export function Table<T extends Record<string, unknown>>(props: TableOptions<T>)
horizontalAlignment = 'left',
maxWidth,
noStyle = false,
orientation = 'horizontal',
overflow = 'truncate',
padding = 1,
sort,
Expand Down Expand Up @@ -237,48 +236,6 @@ export function Table<T extends Record<string, unknown>>(props: TableOptions<T>)
skeleton: BORDER_SKELETONS[config.borderStyle].separator,
})

if (orientation === 'vertical') {
return (
<Box flexDirection="column" width={determineWidthToUse(columns, config.maxWidth)} paddingBottom={1}>
{title && <Text {...titleOptions}>{title}</Text>}
{processedData.map((row, index) => {
// Calculate the hash of the row based on its value and position
const key = `row-${sha1(row)}-${index}`
const maxKeyLength = Math.max(...Object.values(headings).map((c) => c.length))
// Construct a row.
return (
<Box
key={key}
borderTop
borderBottom={false}
borderLeft={false}
borderRight={false}
flexDirection="column"
borderStyle={noStyle ? undefined : 'single'}
borderColor={borderColor}
>
{/* print all data in key:value pairs */}
{columns.map((column) => {
const value = (row[column.column] ?? '').toString()
const keyName = (headings[column.key] ?? column.key).toString()
const keyPadding = ' '.repeat(maxKeyLength - keyName.length + padding)
return (
<Box key={`${key}-cell-${column.key}`} flexWrap="wrap">
<Text {...config.headerOptions}>
{keyName}
{keyPadding}
</Text>
<Text wrap={overflow}>{value}</Text>
</Box>
)
})}
</Box>
)
})}
</Box>
)
}

return (
<Box flexDirection="column" width={determineWidthToUse(columns, config.maxWidth)}>
{title && <Text {...titleOptions}>{title}</Text>}
Expand Down
25 changes: 3 additions & 22 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,15 @@ export type TableOptions<T extends Record<string, unknown>> = {
*/
headerOptions?: HeaderOptions
/**
* Border style for the table. Defaults to 'all'. Only applies to horizontal orientation.
* Border style for the table. Defaults to 'all'.
*/
borderStyle?: BorderStyle
/**
* Color of the table border. Defaults to 'white' in dark terminals and 'black' in light terminals.
*/
borderColor?: SupportedColor
/**
* Align data in columns. Defaults to 'left'. Only applies to horizontal orientation.
* Align data in columns. Defaults to 'left'.
*/
horizontalAlignment?: HorizontalAlignment
/**
Expand Down Expand Up @@ -170,26 +170,7 @@ export type TableOptions<T extends Record<string, unknown>> = {
*/
sort?: Sort<T>
/**
* The orientation of the table. Defaults to 'horizontal'.
*
* If 'vertical', individual records will be displayed vertically in key:value pairs.
*
* @example
* ```
* ─────────────
* Name Alice
* Id 36329
* Age 20
* ─────────────
* Name Bob
* Id 49032
* Age 21
* ─────────────
* ```
*/
orientation?: 'horizontal' | 'vertical'
/**
* Vertical alignment of cell content. Defaults to 'top'. Only applies to horizontal orientation.
* Vertical alignment of cell content. Defaults to 'top'.
*/
verticalAlignment?: VerticalAlignment
/**
Expand Down

0 comments on commit 36415d9

Please sign in to comment.