0
0
mirror of https://github.com/wagtail/wagtail.git synced 2024-11-29 17:36:49 +01:00
wagtail/client/storybook/preview.js
LB (Ben Johnston) 9a04aefe9a
Disable ESLint prefer-default-export globally (#8577)
- default / named exports are used in varying places and it is not a critical blocker for future code
- disable this rule and in the future it can be re-assessed or moved to the core wagtail eslint config
2022-05-31 22:47:50 +01:00

48 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import '../tests/stubs';
import '../../wagtail/admin/static_src/wagtailadmin/scss/core.scss';
import './preview.scss';
export const parameters = {
controls: {
hideNoControlsWarning: true,
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
};
const cachedIcons = sessionStorage.getItem('WAGTAIL_ICONS');
window.WAGTAIL_ICONS = cachedIcons ? JSON.parse(cachedIcons) : [];
/**
* Loads Wagtails icon sprite into the DOM, similarly to the admin.
*/
const loadIconSprite = () => {
const PATTERN_LIBRARY_SPRITE_URL = '/pattern-library/api/v1/sprite';
window
.fetch(PATTERN_LIBRARY_SPRITE_URL)
.then((res) => res.text())
.then((html) => {
const sprite = document.createElement('div');
sprite.innerHTML = html;
const symbols = Array.from(sprite.querySelectorAll('symbol'));
const icons = symbols.map((elt) => elt.id.replace('icon-', '')).sort();
window.WAGTAIL_ICONS = icons;
sessionStorage.setItem('WAGTAIL_ICONS', JSON.stringify(icons));
if (document.body) {
document.body.appendChild(sprite);
} else {
window.addEventListener('DOMContentLoaded', () => {
document.body.appendChild(sprite);
});
}
});
};
loadIconSprite();