forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add storybooks for number-format and time-format (#93)
* add number format storybook * Add explanation * add time-format storybook
- Loading branch information
1 parent
473a690
commit 18537af
Showing
6 changed files
with
252 additions
and
0 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
1 change: 1 addition & 0 deletions
1
...nd/temporary_superset_ui/superset-ui/packages/superset-ui-demo/storybook/stories/index.js
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
124 changes: 124 additions & 0 deletions
124
...rset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-number-format/Stories.jsx
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,124 @@ | ||
/* eslint-disable no-magic-numbers, jsx-a11y/label-has-for, jsx-a11y/label-has-associated-control */ | ||
|
||
import React from 'react'; | ||
import { formatNumber } from '@superset-ui/number-format'; | ||
|
||
const propTypes = {}; | ||
const defaultProps = {}; | ||
|
||
class NumberFormatValidator extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
formatString: '.3~s', | ||
testValues: [ | ||
987654321, | ||
12345.6789, | ||
3000, | ||
400.14, | ||
70.00002, | ||
1, | ||
0, | ||
-1, | ||
-70.00002, | ||
-400.14, | ||
-3000, | ||
-12345.6789, | ||
-987654321, | ||
Number.POSITIVE_INFINITY, | ||
Number.NEGATIVE_INFINITY, | ||
NaN, | ||
null, | ||
undefined, | ||
], | ||
}; | ||
|
||
this.handleFormatChange = this.handleFormatChange.bind(this); | ||
} | ||
|
||
handleFormatChange(event) { | ||
this.setState({ | ||
formatString: event.target.value, | ||
}); | ||
} | ||
|
||
render() { | ||
const { formatString, testValues } = this.state; | ||
|
||
return ( | ||
<div className="container"> | ||
<div className="row" style={{ margin: '40px 20px 0 20px' }}> | ||
<div className="col-sm"> | ||
<p> | ||
This <code>@superset-ui/number-format</code> package enriches <code>d3-format</code>{' '} | ||
to handle invalid formats as well as edge case values. Use the validator below to | ||
preview outputs from the specified format string. See{' '} | ||
<a | ||
href="https://github.com/d3/d3-format#locale_format" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
D3 Format Reference | ||
</a>{' '} | ||
for how to write a D3 format string. | ||
</p> | ||
</div> | ||
</div> | ||
<div className="row" style={{ margin: '10px 0 30px 0' }}> | ||
<div className="col-sm" /> | ||
<div className="col-sm-8"> | ||
<div className="form"> | ||
<div className="form-group"> | ||
<label>Enter D3 format string: </label> | ||
<input | ||
id="formatString" | ||
className="form-control form-control-lg" | ||
type="text" | ||
value={formatString} | ||
onChange={this.handleFormatChange} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="col-sm" /> | ||
</div> | ||
<div className="row"> | ||
<div className="col-sm"> | ||
<table className="table table-striped table-sm"> | ||
<thead> | ||
<tr> | ||
<th>Input (number)</th> | ||
<th>Formatted output (string)</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{testValues.map(v => ( | ||
<tr key={v}> | ||
<td> | ||
<code>{`${v}`}</code> | ||
</td> | ||
<td> | ||
<code>"{formatNumber(formatString, v)}"</code> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
NumberFormatValidator.propTypes = propTypes; | ||
NumberFormatValidator.defaultProps = defaultProps; | ||
|
||
export default [ | ||
{ | ||
renderStory: () => <NumberFormatValidator />, | ||
storyName: 'Validator', | ||
storyPath: '@superset-ui/number-format', | ||
}, | ||
]; |
5 changes: 5 additions & 0 deletions
5
...uperset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-number-format/index.js
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,5 @@ | ||
import Stories from './Stories'; | ||
|
||
export default { | ||
examples: [...Stories], | ||
}; |
113 changes: 113 additions & 0 deletions
113
...perset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-time-format/Stories.jsx
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,113 @@ | ||
/* eslint-disable no-magic-numbers, jsx-a11y/label-has-for, jsx-a11y/label-has-associated-control */ | ||
|
||
import React from 'react'; | ||
import { formatTime } from '@superset-ui/time-format'; | ||
|
||
const propTypes = {}; | ||
const defaultProps = {}; | ||
|
||
class TimeFormatValidator extends React.PureComponent { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
formatString: '%Y-%m-%d %H:%M:%S', | ||
testValues: [ | ||
new Date(Date.UTC(1986, 5, 14, 8, 30, 53)), | ||
new Date(Date.UTC(2001, 9, 27, 13, 45, 2, 678)), | ||
new Date(Date.UTC(2009, 1, 1, 0, 0, 0)), | ||
new Date(Date.UTC(2018, 1, 1, 10, 20, 33)), | ||
0, | ||
null, | ||
undefined, | ||
], | ||
}; | ||
|
||
this.handleFormatChange = this.handleFormatChange.bind(this); | ||
} | ||
|
||
handleFormatChange(event) { | ||
this.setState({ | ||
formatString: event.target.value, | ||
}); | ||
} | ||
|
||
render() { | ||
const { formatString, testValues } = this.state; | ||
|
||
return ( | ||
<div className="container"> | ||
<div className="row" style={{ margin: '40px 20px 0 20px' }}> | ||
<div className="col-sm"> | ||
<p> | ||
This <code>@superset-ui/time-format</code> package enriches{' '} | ||
<code>d3-time-format</code> to handle invalid formats as well as edge case values. Use | ||
the validator below to preview outputs from the specified format string. See{' '} | ||
<a | ||
href="https://github.com/d3/d3-time-format#locale_format" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
D3 Time Format Reference | ||
</a>{' '} | ||
for how to write a D3 time format string. | ||
</p> | ||
</div> | ||
</div> | ||
<div className="row" style={{ margin: '10px 0 30px 0' }}> | ||
<div className="col-sm" /> | ||
<div className="col-sm-8"> | ||
<div className="form"> | ||
<div className="form-group"> | ||
<label>Enter D3 time format string: </label> | ||
<input | ||
id="formatString" | ||
className="form-control form-control-lg" | ||
type="text" | ||
value={formatString} | ||
onChange={this.handleFormatChange} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="col-sm" /> | ||
</div> | ||
<div className="row"> | ||
<div className="col-sm"> | ||
<table className="table table-striped table-sm"> | ||
<thead> | ||
<tr> | ||
<th>Input (time)</th> | ||
<th>Formatted output (string)</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{testValues.map(v => ( | ||
<tr key={v}> | ||
<td> | ||
<code>{v instanceof Date ? v.toUTCString() : `${v}`}</code> | ||
</td> | ||
<td> | ||
<code>"{formatTime(formatString, v)}"</code> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
TimeFormatValidator.propTypes = propTypes; | ||
TimeFormatValidator.defaultProps = defaultProps; | ||
|
||
export default [ | ||
{ | ||
renderStory: () => <TimeFormatValidator />, | ||
storyName: 'Validator', | ||
storyPath: '@superset-ui/time-format', | ||
}, | ||
]; |
5 changes: 5 additions & 0 deletions
5
.../superset-ui/packages/superset-ui-demo/storybook/stories/superset-ui-time-format/index.js
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,5 @@ | ||
import Stories from './Stories'; | ||
|
||
export default { | ||
examples: [...Stories], | ||
}; |