-
Notifications
You must be signed in to change notification settings - Fork 77
feat: New Busy Indicator component #963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -3,6 +3,6 @@ | |
| name: "Fundamental-React Size", | ||
| webpack: true, | ||
| path: "lib/index.js", | ||
| limit: "190 KB" | ||
| limit: "195 KB" | ||
| } | ||
| ] | ||
This file contains hidden or 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,26 @@ | ||
| import { BusyIndicator } from '../'; | ||
| import path from 'path'; | ||
| import React from 'react'; | ||
| import { ComponentPage, Example } from '../_playground'; | ||
|
|
||
| export const BusyIndicatorComponent = () => { | ||
| return ( | ||
| <ComponentPage | ||
| description={'A **Busy Indicator** informs the user of an ongoing operation.'} | ||
| sourceModulePath={path.join(__dirname, './BusyIndicator')} | ||
| title='Busy Indicator'> | ||
| <Example centered title='Busy Indicator'> | ||
| <BusyIndicator show /> | ||
| </Example> | ||
|
|
||
| <Example | ||
| centered | ||
| description={'There are 3 sizes for Busy Indicator: s, m & l'} | ||
| title='Busy Indicator Sizes'> | ||
| <BusyIndicator show size='s' /> | ||
| <BusyIndicator show /> | ||
| <BusyIndicator show size='l' /> | ||
| </Example> | ||
| </ComponentPage> | ||
| ); | ||
| }; |
This file contains hidden or 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,75 @@ | ||
| import { BUSY_INDICATOR_SIZES } from '../utils/constants'; | ||
| import classnames from 'classnames'; | ||
| import CustomPropTypes from '../utils/CustomPropTypes/CustomPropTypes'; | ||
| import PropTypes from 'prop-types'; | ||
| import React, { useEffect } from 'react'; | ||
|
|
||
| const BusyIndicator = React.forwardRef(({ | ||
| className, | ||
| show, | ||
| size, | ||
| disableStyles, | ||
| localizedText, | ||
| ...props | ||
| }, ref) => { | ||
|
|
||
| useEffect(() => { | ||
| if (!disableStyles) { | ||
| require('fundamental-styles/dist/icon.css'); | ||
| require('fundamental-styles/dist/busy-indicator.css'); | ||
| } | ||
| }, []); | ||
|
|
||
| const busyIndicatorClasses = classnames( | ||
| { | ||
| [`fd-busy-indicator--${size}`]: size === 'm' || size === 'l', | ||
| 'fd-busy-indicator': size === 's' | ||
| }, | ||
| className | ||
| ); | ||
|
|
||
| if (!show) | ||
| return null; | ||
|
|
||
| return ( | ||
| <div | ||
| {...props} | ||
| aria-hidden='false' | ||
| aria-label={localizedText.loading} | ||
| className={busyIndicatorClasses} | ||
| ref={ref} > | ||
| <div className='fd-busy-indicator--circle-0' /> | ||
| <div className='fd-busy-indicator--circle-1' /> | ||
| <div className='fd-busy-indicator--circle-2' /> | ||
| </div> | ||
| ); | ||
| }); | ||
|
|
||
| BusyIndicator.displayName = 'BusyIndicator'; | ||
|
|
||
| BusyIndicator.propTypes = { | ||
| className: PropTypes.string, | ||
| disableStyles: PropTypes.bool, | ||
| localizedText: CustomPropTypes.i18n({ | ||
| loading: PropTypes.string | ||
| }), | ||
| show: PropTypes.bool, | ||
| size: PropTypes.oneOf(BUSY_INDICATOR_SIZES) | ||
| }; | ||
|
|
||
| BusyIndicator.defaultProps = { | ||
| localizedText: { | ||
| loading: 'Loading' | ||
| }, | ||
| size: 'm', | ||
| show: false | ||
| }; | ||
|
|
||
| BusyIndicator.propDescriptions = { | ||
| show: 'Set to **true** to make Busy Indicator visible', | ||
| localizedTextShape: { | ||
skvale marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| loading: 'aria-label for Busy Indicator component' | ||
| } | ||
| }; | ||
|
|
||
| export default BusyIndicator; | ||
This file contains hidden or 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,64 @@ | ||
| import BusyIndicator from './BusyIndicator'; | ||
| import { mount } from 'enzyme'; | ||
| import React from 'react'; | ||
| import renderer from 'react-test-renderer'; | ||
|
|
||
| describe('<BusyIndicator />', () => { | ||
| const showDefaultBusyIndicator = <BusyIndicator show />; | ||
| const smallBusyIndicator = <BusyIndicator show size='s' />; | ||
| const largeBusyIndicator = <BusyIndicator show size='l' />; | ||
| const defaultBusyIndicator = <BusyIndicator />; | ||
| const hideBusyIndicator = <BusyIndicator show={false} />; | ||
|
|
||
| test('create busy indicators', () => { | ||
| // show default busy indicator | ||
| let component = renderer.create(showDefaultBusyIndicator); | ||
| let tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
|
|
||
| // small busy indicator | ||
| component = renderer.create(smallBusyIndicator); | ||
| tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
|
|
||
| // large busy indicator | ||
| component = renderer.create(largeBusyIndicator); | ||
| tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
|
|
||
| // default busy indicator | ||
| component = renderer.create(defaultBusyIndicator); | ||
| tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('hide busy indicator', () => { | ||
| // hide busy indicator | ||
| let component = renderer.create(hideBusyIndicator); | ||
| let tree = component.toJSON(); | ||
| expect(tree).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| describe('Prop spreading', () => { | ||
| test('should allow props to be spread to the Busy Indicator component', () => { | ||
| const element = mount(<BusyIndicator data-sample='Sample' show />); | ||
|
|
||
| expect( | ||
| element.getDOMNode().attributes['data-sample'].value | ||
| ).toBe('Sample'); | ||
| }); | ||
| }); | ||
| test('forwards the ref', () => { | ||
| let ref; | ||
| class Test extends React.Component { | ||
| constructor(props) { | ||
| super(props); | ||
| ref = React.createRef(); | ||
| } | ||
| render = () => <BusyIndicator ref={ref} show />; | ||
| } | ||
| mount(<Test />); | ||
| expect(ref.current.tagName).toEqual('DIV'); | ||
| expect(ref.current.className).toEqual('fd-busy-indicator--m'); | ||
| }); | ||
| }); |
59 changes: 59 additions & 0 deletions
59
src/BusyIndicator/__snapshots__/BusyIndicator.test.js.snap
This file contains hidden or 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,59 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`<BusyIndicator /> create busy indicators 1`] = ` | ||
| <div | ||
| aria-hidden="false" | ||
| aria-label="Loading" | ||
| className="fd-busy-indicator--m" | ||
| > | ||
| <div | ||
| className="fd-busy-indicator--circle-0" | ||
| /> | ||
| <div | ||
| className="fd-busy-indicator--circle-1" | ||
| /> | ||
| <div | ||
| className="fd-busy-indicator--circle-2" | ||
| /> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`<BusyIndicator /> create busy indicators 2`] = ` | ||
| <div | ||
| aria-hidden="false" | ||
| aria-label="Loading" | ||
| className="fd-busy-indicator" | ||
| > | ||
| <div | ||
| className="fd-busy-indicator--circle-0" | ||
| /> | ||
| <div | ||
| className="fd-busy-indicator--circle-1" | ||
| /> | ||
| <div | ||
| className="fd-busy-indicator--circle-2" | ||
| /> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`<BusyIndicator /> create busy indicators 3`] = ` | ||
| <div | ||
| aria-hidden="false" | ||
| aria-label="Loading" | ||
| className="fd-busy-indicator--l" | ||
| > | ||
| <div | ||
| className="fd-busy-indicator--circle-0" | ||
| /> | ||
| <div | ||
| className="fd-busy-indicator--circle-1" | ||
| /> | ||
| <div | ||
| className="fd-busy-indicator--circle-2" | ||
| /> | ||
| </div> | ||
| `; | ||
|
|
||
| exports[`<BusyIndicator /> create busy indicators 4`] = `null`; | ||
|
|
||
| exports[`<BusyIndicator /> hide busy indicator 1`] = `null`; |
This file contains hidden or 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,22 @@ | ||
| import BusyIndicator from '../BusyIndicator'; | ||
| import React from 'react'; | ||
| import { storiesOf } from '@storybook/react'; | ||
| import { withKnobs } from '@storybook/addon-knobs'; | ||
|
|
||
| storiesOf('Components|BusyIndicator', module) | ||
| .addDecorator(withKnobs) | ||
| .add('Default', () => ( | ||
| <BusyIndicator show /> | ||
| )) | ||
| .add('small', () => ( | ||
| <BusyIndicator show size='s' /> | ||
| )) | ||
| .add('large', () => ( | ||
| <BusyIndicator show size='l' /> | ||
| )) | ||
| .add('hidden', () => ( | ||
| <BusyIndicator /> | ||
| )) | ||
| .add('disable styles', () => ( | ||
| <BusyIndicator disableStyles show>Default</BusyIndicator> | ||
| )); |
This file contains hidden or 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 contains hidden or 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 contains hidden or 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
Binary file added
BIN
+3.81 KB
...ts__/storyshots-test-js-storyshots-components-busy-indicator-default-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.17 KB
...oryshots-test-js-storyshots-components-busy-indicator-disable-styles-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.17 KB
...ots__/storyshots-test-js-storyshots-components-busy-indicator-hidden-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+4.74 KB
...hots__/storyshots-test-js-storyshots-components-busy-indicator-large-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.32 KB
...hots__/storyshots-test-js-storyshots-components-busy-indicator-small-1-snap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.