Skip to content

Commit

Permalink
Add support for using style CSS separately to avoid CSP style-src sec…
Browse files Browse the repository at this point in the history
…urity flags.
  • Loading branch information
Brian T. Rice committed Nov 4, 2016
1 parent 3f3417e commit 82e3f88
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 76 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class | data-class | String | | extra custom class, can use !important to
html | data-html | Bool | true, false | `<p data-tip="<p>HTML tooltip</p>" data-html={true}></p>` or `<ReactTooltip html={true} />`
delayHide | data-delay-hide | Number | | `<p data-tip="tooltip" data-delay-hide='1000'></p>` or `<ReactTooltip delayHide={1000} />`
delayShow | data-delay-show | Number | | `<p data-tip="tooltip" data-delay-show='1000'></p>` or `<ReactTooltip delayShow={1000} />`
insecure | null | Bool | true, false | Whether to inject the style header into the page dynamically (violates CSP style-src but is a convenient default)
border | data-border | Bool | true, false | Add one pixel white border
getContent | null | Func or Array | () => {}, [() => {}, Interval] | Generate the tip content dynamically
afterShow | null | Func | () => {} | Function that will be called after tooltip show
Expand Down
13 changes: 10 additions & 3 deletions bin/transferSass.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ function transferSass () {
console.log(err)
return
}
fs.writeFile(path.resolve(__dirname, '../src/style.js'), "export default '" + result.css.toString().replace(/\n/g, '') + "'", function (err) {
var cssSource = result.css.toString()
fs.writeFile(path.resolve(__dirname, '../src/style.js'), "export default '" + cssSource.replace(/\n/g, '') + "'", function (err) {
if (err) {
console.error(err)
}
console.log('css file has been transformed successful')
process.exit()
console.log('css file has been transformed to JS successful')
fs.writeFile(path.resolve(__dirname, '../src/style.css'), cssSource, function (err) {
if (err) {
console.error(err)
}
console.log('css file has been transformed successful')
process.exit()
})
})
})
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"dist/",
"standalone/",
"src/style.js",
"src/style.css",
"example/"
]
},
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ReactTooltip extends Component {
offset: PropTypes.object,
multiline: PropTypes.bool,
border: PropTypes.bool,
insecure: PropTypes.bool,
class: PropTypes.string,
id: PropTypes.string,
html: PropTypes.bool,
Expand All @@ -48,6 +49,7 @@ class ReactTooltip extends Component {
};

static defaultProps = {
insecure: true,
resizeHide: true
};

Expand Down Expand Up @@ -100,9 +102,12 @@ class ReactTooltip extends Component {
}

componentDidMount () {
this.setStyleHeader() // Set the style to the <link>
const { insecure, resizeHide } = this.props
if (insecure) {
this.setStyleHeader() // Set the style to the <link>
}
this.bindListener() // Bind listener for tooltip
this.bindWindowEvents(this.props.resizeHide) // Bind global event for static method
this.bindWindowEvents(resizeHide) // Bind global event for static method
}

componentWillReceiveProps (props) {
Expand Down
1 change: 1 addition & 0 deletions src/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 82e3f88

Please sign in to comment.