-
Notifications
You must be signed in to change notification settings - Fork 47.7k
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
Yellow Box for react-dom #7360
Closed
Closed
Yellow Box for react-dom #7360
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cb6a2aa
added Yellow Box components
4b9a856
added reactShowWarningDOM, the main entry for `warning` (fbjs) to call
23ed419
installed the `__showWarning` global hook in ReactDOM for `warning` (…
98477e9
changed reactShowWarningDOM's input type
048d428
reordered snooze options (instance first)
79ce1df
removed unused count param
82b764e
renamed imports
9ddf9e3
make it yellow
keyz 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 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
44 changes: 44 additions & 0 deletions
44
src/renderers/dom/client/showWarningDOM/components/ReactDOMYellowBoxDialogBody.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,44 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMYellowBoxDialogBody | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const React = require('React'); | ||
|
||
const ReactDOMYellowBoxMessage = require('ReactDOMYellowBoxMessage'); | ||
|
||
import type {Format, Instance, Milliseconds, InstanceInfo} from 'reactShowWarningDOM'; | ||
|
||
const styles = { | ||
root: { | ||
height: '90%', | ||
overflowY: 'auto', | ||
}, | ||
}; | ||
|
||
const ReactDOMYellowBoxDialogBody = ({data, onSnoozeByType, onSnoozeByInstance}: { | ||
data: Array<InstanceInfo>, | ||
onSnoozeByType: (format: Format) => (snoozeDuration: Milliseconds) => void, | ||
onSnoozeByInstance: (instance: Instance) => (snoozeDuration: Milliseconds) => void, | ||
}) => ( | ||
<div style={styles.root}> | ||
{data.map(({instance, format}) => | ||
<ReactDOMYellowBoxMessage | ||
key={instance} | ||
onSnoozeByType={onSnoozeByType(format)} | ||
onSnoozeByInstance={onSnoozeByInstance(instance)} | ||
instance={instance} | ||
/> | ||
)} | ||
</div> | ||
); | ||
|
||
module.exports = ReactDOMYellowBoxDialogBody; |
54 changes: 54 additions & 0 deletions
54
src/renderers/dom/client/showWarningDOM/components/ReactDOMYellowBoxDialogHeader.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,54 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMYellowBoxDialogHeader | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const React = require('React'); | ||
|
||
const styles = { | ||
root: { | ||
paddingBottom: '15px', | ||
borderBottom: '1px solid rgba(0, 0, 0, 0.10)', | ||
}, | ||
closeButton: { | ||
color: 'inherit', | ||
textDecoration: 'none', | ||
}, | ||
closeButtonContainer: { | ||
float: 'right', | ||
}, | ||
}; | ||
|
||
const ReactDOMYellowBoxDialogHeader = ({onIgnoreAll}: { | ||
onIgnoreAll: () => void, | ||
}) => { | ||
const onClick = (evt) => { | ||
evt.preventDefault(); | ||
onIgnoreAll(); | ||
}; | ||
|
||
return ( | ||
<div style={styles.root}> | ||
<div style={styles.closeButtonContainer}> | ||
<a | ||
style={styles.closeButton} | ||
href="#" | ||
onClick={onClick} | ||
> | ||
✕ | ||
</a> | ||
</div> | ||
React Warnings | ||
</div> | ||
); | ||
}; | ||
|
||
module.exports = ReactDOMYellowBoxDialogHeader; |
94 changes: 94 additions & 0 deletions
94
src/renderers/dom/client/showWarningDOM/components/ReactDOMYellowBoxMessage.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,94 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMYellowBoxMessage | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const React = require('React'); | ||
|
||
import type {Instance, Milliseconds} from 'reactShowWarningDOM'; | ||
|
||
const MS_FOR_10_MINS: Milliseconds = 10 * 60 * 1000; | ||
const MS_FOR_24_HOURS: Milliseconds = 24 * 3600 * 1000; | ||
|
||
const styles = { | ||
root: { | ||
fontSize: '13px', | ||
borderBottom: '1px solid rgba(0, 0, 0, 0.05)', | ||
padding: '20px 0px', | ||
}, | ||
snoozeButtonContainer: { | ||
float: 'right', | ||
}, | ||
snoozeSelect: { | ||
width: '70px', | ||
}, | ||
messageContainer: { | ||
fontFamily: 'Menlo, Consolas, monospace', | ||
whiteSpace: 'pre-wrap', | ||
}, | ||
}; | ||
|
||
const ReactDOMYellowBoxMessage = ({onSnoozeByType, onSnoozeByInstance, instance}: { | ||
onSnoozeByType: (snoozeDuration: Milliseconds) => void, | ||
onSnoozeByInstance: (snoozeDuration: Milliseconds) => void, | ||
instance: Instance, | ||
}) => { | ||
const onSelectChange = (evt: SyntheticEvent): void => { | ||
evt.preventDefault(); | ||
|
||
if (!(evt.target instanceof HTMLSelectElement)) { // make flow happy | ||
return; | ||
} | ||
|
||
switch (evt.target.value) { | ||
case 'type-10-mins': | ||
onSnoozeByType(MS_FOR_10_MINS); | ||
break; | ||
case 'type-24-hrs': | ||
onSnoozeByType(MS_FOR_24_HOURS); | ||
break; | ||
case 'instance-10-mins': | ||
onSnoozeByInstance(MS_FOR_10_MINS); | ||
break; | ||
case 'instance-24-hrs': | ||
onSnoozeByInstance(MS_FOR_24_HOURS); | ||
break; | ||
default: | ||
break; | ||
} | ||
}; | ||
|
||
return ( | ||
<div style={styles.root}> | ||
<div style={styles.snoozeButtonContainer}> | ||
<select defaultValue="noop" | ||
style={styles.snoozeSelect} | ||
onChange={onSelectChange} | ||
> | ||
<option value="noop" disabled={true}>Snooze</option> | ||
<optgroup label="Snooze this warning instance for..."> | ||
<option value="instance-10-mins">10 mins</option> | ||
<option value="instance-24-hrs">24 hours</option> | ||
</optgroup> | ||
<optgroup label="Snooze this type of warning for..."> | ||
<option value="type-10-mins">10 minutes</option> | ||
<option value="type-24-hrs">24 hours</option> | ||
</optgroup> | ||
</select> | ||
</div> | ||
<div style={styles.messageContainer}> | ||
{instance} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
module.exports = ReactDOMYellowBoxMessage; |
71 changes: 71 additions & 0 deletions
71
src/renderers/dom/client/showWarningDOM/components/ReactDOMYellowBoxRoot.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,71 @@ | ||
/** | ||
* Copyright 2013-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @providesModule ReactDOMYellowBoxRoot | ||
* @flow | ||
*/ | ||
'use strict'; | ||
|
||
const React = require('React'); | ||
|
||
const ReactDOMYellowBoxDialogHeader = require('ReactDOMYellowBoxDialogHeader'); | ||
const ReactDOMYellowBoxDialogBody = require('ReactDOMYellowBoxDialogBody'); | ||
|
||
import type {Format, Instance, Milliseconds, InstanceInfo} from 'reactShowWarningDOM'; | ||
|
||
const styles = { | ||
root: { | ||
position: 'fixed', | ||
top: 0, | ||
right: 0, | ||
bottom: 0, | ||
left: 0, | ||
pointerEvents: 'none', | ||
zIndex: 2147483647, | ||
}, | ||
dialogRoot: { | ||
position: 'absolute', | ||
height: '45%', | ||
width: '75%', | ||
top: '50%', | ||
left: '50%', | ||
transform: 'translate(-50%, -50%)', | ||
MozTransform: 'translate(-50%, -50%)', | ||
msTransform: 'translate(-50%, -50%)', | ||
WebkitTransform: 'translate(-50%, -50%)', | ||
padding: '15px 30px', | ||
pointerEvents: 'auto', | ||
overflowY: 'hidden', | ||
backgroundColor: 'rgb(254, 243, 161)', | ||
border: '1px solid rgba(0, 0, 0, 0.10)', | ||
borderRadius: '2px', | ||
boxShadow: '0px 0px 5px rgba(0, 0, 0, 0.10)', | ||
fontFamily: 'Helvetica, Arial, sans-serif', | ||
fontSize: '15px', | ||
}, | ||
}; | ||
|
||
const ReactDOMYellowBoxRoot = ({data, onIgnoreAll, onSnoozeByType, onSnoozeByInstance}: { | ||
data: Array<InstanceInfo>, | ||
onIgnoreAll: () => void, | ||
onSnoozeByType: (format: Format) => (snoozeDuration: Milliseconds) => void, | ||
onSnoozeByInstance: (instance: Instance) => (snoozeDuration: Milliseconds) => void, | ||
}) => ( | ||
<div style={styles.root}> | ||
<div style={styles.dialogRoot}> | ||
<ReactDOMYellowBoxDialogHeader onIgnoreAll={onIgnoreAll} /> | ||
<ReactDOMYellowBoxDialogBody | ||
data={data} | ||
onSnoozeByType={onSnoozeByType} | ||
onSnoozeByInstance={onSnoozeByInstance} | ||
/> | ||
</div> | ||
</div> | ||
); | ||
|
||
module.exports = ReactDOMYellowBoxRoot; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends on a later commit. :\
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry didn't notice that :|