-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(storybook): adds matrix builder, and use it in button stories
- Loading branch information
1 parent
cb3b1b0
commit a3fd187
Showing
5 changed files
with
116 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import {Card, Text} from '../../../src/primitives' | ||
|
||
interface MatrixBuilderProps<Rows extends string[], Cols extends string[]> { | ||
scheme: 'light' | 'dark' | ||
columns: Cols | ||
rows: Rows | ||
title: string | ||
renderItem: ({row, column}: {row: Rows[number]; column: Cols[number]}) => React.ReactNode | ||
} | ||
|
||
/** | ||
* Creates a two dimensions matrix if components, to be used in Storybook when having a component | ||
* that has multiple styles that can be combined. | ||
*/ | ||
export function MatrixBuilder<Rows extends string[], Cols extends string[]>({ | ||
scheme, | ||
columns, | ||
rows, | ||
title, | ||
renderItem, | ||
}: MatrixBuilderProps<Rows, Cols>): JSX.Element { | ||
return ( | ||
<Card scheme={scheme} padding={4} border marginBottom={4}> | ||
<table | ||
style={{ | ||
borderCollapse: 'collapse', | ||
tableLayout: 'fixed', | ||
width: '100%', | ||
borderSpacing: '10px 10px', | ||
}} | ||
> | ||
<thead> | ||
<tr> | ||
<th> | ||
<Text weight="semibold">{title}</Text> | ||
</th> | ||
{columns.map((column) => ( | ||
<th key={column + 'head'}> | ||
<Text weight="semibold" style={{textTransform: 'capitalize'}}> | ||
{column} | ||
</Text> | ||
</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody style={{borderTop: '16px solid transparent'}}> | ||
{rows.map((row) => ( | ||
<tr | ||
key={row} | ||
style={{ | ||
borderBottom: '16px solid transparent', | ||
}} | ||
> | ||
<td style={{verticalAlign: 'middle', textAlign: 'center'}}> | ||
<Text | ||
style={{ | ||
textTransform: 'capitalize', | ||
}} | ||
> | ||
{row} | ||
</Text> | ||
</td> | ||
{columns.map((column) => ( | ||
<td key={column + row} style={{verticalAlign: 'middle', textAlign: 'center'}}> | ||
{renderItem({column, row})} | ||
</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</Card> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function capitalize(str: string): string { | ||
if (!str || typeof str !== 'string') { | ||
return '' | ||
} | ||
|
||
return str.charAt(0).toUpperCase() + str.slice(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters