forked from scratchfoundation/scratch-paint
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge-upstream: dynamic icon recoloring
- Loading branch information
1 parent
bba8c9f
commit d3500a2
Showing
7 changed files
with
84 additions
and
32 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 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 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 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 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 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,18 @@ | ||
/* eslint-disable import/no-commonjs */ | ||
|
||
const OLD_PRIMARY_COLOR = '#855cd6'; | ||
|
||
const loader = source => ` | ||
const original = ${JSON.stringify(source)}; | ||
const getSRC = () => { | ||
const recolored = typeof Recolor === 'object' ? ( | ||
original.replace(/${OLD_PRIMARY_COLOR}/gi, Recolor.primary) | ||
) : original; | ||
return 'data:image/svg+xml;,' + encodeURIComponent(recolored); | ||
}; | ||
export default getSRC; | ||
`; | ||
|
||
module.exports = loader; |
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,30 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {connect} from 'react-redux'; | ||
|
||
// This is a wrapper around <img> that forces re-render when theme state updates. | ||
|
||
const TWRenderRecoloredImage = ({ | ||
src, | ||
...props | ||
}) => ( | ||
<img | ||
src={typeof src === 'function' ? src() : src} | ||
{...props} | ||
/> | ||
); | ||
|
||
TWRenderRecoloredImage.propTypes = { | ||
src: PropTypes.oneOfType([PropTypes.string, PropTypes.func]) | ||
}; | ||
|
||
const mapStateToProps = state => ({ | ||
theme: state.scratchGui ? state.scratchGui.theme.theme : '' | ||
}); | ||
|
||
const mapDispatchToProps = () => ({}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(TWRenderRecoloredImage); |