Skip to content

Commit

Permalink
test(Button): render states descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
zhzz committed Mar 29, 2019
1 parent 14b5b19 commit 48fb5ca
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 35 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -299,21 +299,21 @@ const ButtonsTable = (props: {
const { rows = [], cols = [], presetState = {}, children = 'Button' } = props;
return (
<table style={{ width: '100%', borderSpacing: 10, marginBottom: 20 }}>
<caption style={{ captionSide: 'bottom' }}>{stateToString(presetState)}</caption>
<caption style={{ captionSide: 'bottom' }}>{renderStateDesc(presetState)}</caption>
<thead>
<tr>
<th />
{cols.map((state, i) => (
<th style={{ whiteSpace: 'nowrap' }} key={i}>
{stateToString(state)}
{renderStateDesc(state)}
</th>
))}
</tr>
</thead>
<tbody>
{rows.map((rowState, rowIndex) => (
<tr key={rowIndex}>
<td style={{ whiteSpace: 'nowrap' }}>{stateToString(rowState)}</td>
<td style={{ whiteSpace: 'nowrap' }}>{renderStateDesc(rowState)}</td>
{cols.map((colState, colIndex) => (
<td key={colIndex}>
<Button children={children} {...rowState} {...colState} {...presetState} />
Expand All @@ -326,7 +326,7 @@ const ButtonsTable = (props: {
);
};

const stateToString = (state: ButtonState): string => {
const renderStateDesc = (state: ButtonState): React.ReactNode => {
return Object.keys(state)
.map(key => {
// @ts-ignore
Expand All @@ -336,11 +336,20 @@ const stateToString = (state: ButtonState): string => {
return key + (value ? '' : ': false');
case 'string':
return `${key}: "${value}"`;
case 'object':
if (React.isValidElement(value)) {
return React.createElement('span', {}, [`${key}: `, value]);
}
return `${key}: ${JSON.stringify(value)}`;
default:
return `${key}: ${value}`;
}
})
.join(', ');
.map((node: React.ReactNode, index: number, nodes: React.ReactNode[]) => (
<span key={index}>
{node} {index + 1 < nodes.length ? ', ' : null}
</span>
));
};

class StatesCombinator extends React.Component<
Expand Down

0 comments on commit 48fb5ca

Please sign in to comment.