Allow custom styles to be passed to embedded iframe (#1522)

* Allow custom styles to be passed to embedded iframe

* Changelog
pull/1523/head
Uku Taht 5 years ago committed by GitHub
parent 05a89ab130
commit 7d37208d52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,6 +10,7 @@ All notable changes to this project will be documented in this file.
- The `u` option can now be used in the `manual` extension to specify a URL when triggering events.
- Delete a site and all related data through the Sites API
- Subscribed users can see their Paddle invoices from the last 12 months under the user settings
- Allow custom styles to be passed to embedded iframe plausible/analytics#1522
### Fixed
- UI fix where multi-line text in pills would not be underlined properly on small screens.

@ -326,3 +326,7 @@ iframe[hidden] {
}
}
/* This class is used for styling embedded dashboards. Do not remove. */
/* stylelint-disable */
.date-option-group { }

@ -319,29 +319,25 @@ class DatePicker extends React.Component {
>
<div
className="rounded-md shadow-lg bg-white dark:bg-gray-800 ring-1 ring-black ring-opacity-5
font-medium text-gray-800 dark:text-gray-200"
font-medium text-gray-800 dark:text-gray-200 date-options"
>
<div className="py-1">
<div className="py-1 border-b border-gray-200 dark:border-gray-500 date-option-group">
{this.renderLink("day", "Today")}
{this.renderLink("realtime", "Realtime")}
</div>
<div className="border-t border-gray-200 dark:border-gray-500"></div>
<div className="py-1">
<div className="py-1 border-b border-gray-200 dark:border-gray-500 date-option-group">
{this.renderLink("7d", "Last 7 days")}
{this.renderLink("30d", "Last 30 days")}
</div>
<div className="border-t border-gray-200 dark:border-gray-500"></div>
<div className="py-1">
<div className="py-1 border-b border-gray-200 dark:border-gray-500 date-option-group">
{ this.renderLink('month', 'Month to Date') }
{ this.renderLink('month', 'Last month', {date: lastMonth(this.props.site)}) }
</div>
<div className="border-t border-gray-200 dark:border-gray-500"></div>
<div className="py-1">
<div className="py-1 border-b border-gray-200 dark:border-gray-500 date-option-group">
{this.renderLink("6mo", "Last 6 months")}
{this.renderLink("12mo", "Last 12 months")}
</div>
<div className="border-t border-gray-200 dark:border-gray-500"></div>
<div className="py-1">
<div className="py-1 date-option-group">
<span
onClick={() => this.setState({mode: 'calendar'}, this.openCalendar)}
onKeyPress={() => this.setState({mode: 'calendar'}, this.openCalendar)}

@ -1 +1,16 @@
import 'iframe-resizer/js/iframeResizer.contentWindow'
window.iFrameResizer = {
onMessage: function(msg) {
if (msg.type === 'load-custom-styles') {
addCustomStyles(msg.opts)
}
}
}
function addCustomStyles(opts) {
var style = document.createElement('style');
style.innerHTML = opts.styles
document.head.appendChild(style);
}

@ -1,3 +1,20 @@
import iframeResize from 'iframe-resizer/js/iframeResizer'
iframeResize({heightCalculationMethod: 'taggedElement'}, '[plausible-embed]')
var iframes = iframeResize({
heightCalculationMethod: 'taggedElement',
onInit: onInit
}, '[plausible-embed]')
function onInit() {
var iframe = iframes[0]
var styles = iframe.getAttribute('styles')
if (styles) {
iframe.iFrameResizer.sendMessage({
type: 'load-custom-styles',
opts: {
styles: styles
}
})
}
}

Loading…
Cancel
Save