Skip to content

Commit 2f2a702

Browse files
Merge pull request #1515 from ASU/uds-1958
Uds 1958
2 parents 9c8e652 + 26cc48e commit 2f2a702

File tree

81 files changed

+1153
-874
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1153
-874
lines changed

packages/unity-bootstrap-theme/.storybook/decorators.jsx

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
import React, { useEffect } from "react";
1+
import { useEffect } from "react";
2+
3+
export const windowLoadEvent = (storyFn) => {
4+
const mount = () => {
5+
// console.log("sb mounting");
6+
7+
// custom events created by eventSpy.js to allow storybook to dispatch load events after the page is loaded
8+
document.dispatchEvent(new Event("sb_DOMContentLoaded"));
9+
window.dispatchEvent(new Event('sb_load'));
10+
}
11+
12+
const unmount = () => {
13+
// console.log("sb unmounting");
14+
15+
// bootstrap script has functionality initiated with window load event,
16+
// so we need to reload the page every time we unmount the story.
17+
// We set the opacity to 0 to avoid flickering.
18+
document.body.style.opacity = "0";
19+
20+
// variable to prevent calling mount function before the page is reloaded
21+
window.unloading = true;
22+
window.location.reload();
23+
}
224

3-
export const forceReloadOfStory = (storyFn, context) => {
425
useEffect(() => {
5-
setTimeout(() => {
6-
context.globals.shouldReload = true;
7-
}, 100);
8-
return () => {
9-
if (context.globals.shouldReload) {
10-
window.location.reload();
11-
}
12-
};
26+
if (!window.unloading) {
27+
mount()
28+
}
29+
return unmount
1330
}, []);
1431

1532
return storyFn();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var originalAddEventListener = EventTarget.prototype.addEventListener;
2+
EventTarget.prototype.addEventListener = function (type, listener, options) {
3+
if(listener.uidEvent && (type === "load" || type === "DOMContentLoaded")) {
4+
/**
5+
* Used by storybook windowLoadEvent decorator
6+
* creates custom events sb_load and sb_DOMContentLoaded
7+
* to allow storybook to dispatch load events after the page is loaded
8+
* */
9+
originalAddEventListener.call(this, `sb_${type}`, listener, options);
10+
}
11+
12+
originalAddEventListener.call(this, type, listener, options);
13+
};

packages/unity-bootstrap-theme/.storybook/local-addon/addon.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react';
22
import { AddonPanel } from '@storybook/components';
3-
import { Source } from '@storybook/blocks';
43
import { addons, types } from '@storybook/addons';
5-
import { formatWithBabelParser } from './helpers';
64
import { Toggle } from '../../../../.storybook-config/Toggle'
75

86
addons.register('local-addon', (api) => {
@@ -12,13 +10,12 @@ addons.register('local-addon', (api) => {
1210
type: types.PANEL,
1311
paramKey: 'initFunc',
1412
render: ({active, key}) => {
15-
const data = api.getCurrentStoryData();
16-
const initFunc = data?.parameters?.initFunc?.code || '';
17-
const code = formatWithBabelParser(`${initFunc}`);
18-
1913
return(
2014
<AddonPanel key={key} active={!!active}>
21-
<Source code={`${code}`} language='js' format={true} />
15+
<div style={{ padding: '20px', fontSize: '1rem'}}>
16+
This component requires Javascript. <br/><br/>
17+
View the documentation on <a href="./index.html?path=/docs/get-started-get-started--docs#-including-unity-in-your-project">including unity in your project</a>
18+
</div>
2219
</AddonPanel>
2320
)},
2421
});

packages/unity-bootstrap-theme/.storybook/local-addon/decorators/withFooter.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
1-
import React, { useEffect, useRef} from 'react';
1+
import React from 'react';
22
import { makeDecorator } from '@storybook/addons';
3-
43
import { GlobalElementsOnly as Footer } from "../../../stories/organisms/global-footer/global-footer.templates";
5-
import { initFooterGA } from "../../../stories/organisms/global-footer/global-footer"
64

75
export const withFooter = makeDecorator({
86
name: 'withFooter',
97
parameterName: 'footer',
108
skipIfNoParametersOrOptions: true,
119
wrapper: (storyFn, context) => {
12-
const loaded = useRef(0);
13-
useEffect(()=>{
14-
if(document.readyState !== "loading") {
15-
initFooterGA()
16-
}
17-
},[loaded.current]);
18-
loaded.current++;
19-
2010
const { globals, parameters } = context;
21-
2211
const footer = parameters?.footer;
2312
const isFooterActive = (globals.footer == true && footer?.disable !== true) || footer.forced == true;
24-
2513
const isStory = context.viewMode === 'story';
2614

2715
return <>

packages/unity-bootstrap-theme/.storybook/local-addon/decorators/withHeader.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
1-
import React, { useEffect, useRef} from 'react';
1+
import React from 'react';
22
import { makeDecorator } from '@storybook/addons';
33

4-
import { Basic as Header } from "../../../stories/organisms/global-header/global-header.templates";
5-
6-
import { initGlobalHeader } from "../../../src/js/storybook-global-header";
4+
import { Basic as Header } from "../../../stories/organisms/global-header/global-header.templates.jsx";
75

86
export const withHeader = makeDecorator({
97
name: 'withHeader',
108
parameterName: 'header',
119
skipIfNoParametersOrOptions: true,
1210
wrapper: (storyFn, context) => {
13-
const loaded = useRef(0);
14-
useEffect(()=>{
15-
if(document.readyState !== "loading") {
16-
initGlobalHeader()
17-
}
18-
},[loaded.current]);
19-
loaded.current++;
20-
2111
const { globals, parameters } = context;
22-
2312
const header = parameters?.header;
2413
const isHeaderActive = (globals.header == true && header?.disable !== true) || header.forced === true;
25-
2614
const isStory = context.viewMode === 'story';
2715

2816
return <>

packages/unity-bootstrap-theme/.storybook/local-addon/decorators/withInitFunc.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

packages/unity-bootstrap-theme/.storybook/local-addon/decorators/withLoadEvent.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

packages/unity-bootstrap-theme/.storybook/local-addon/entry.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import {
55

66
import { withFooter } from './decorators/withFooter';
77
import { withHeader } from './decorators/withHeader';
8-
import { withInitFunc } from './decorators/withInitFunc';
9-
import { withLoadEvent } from './decorators/withLoadEvent';
10-
11-
import "../../src/js/data-layer.js";
128

139
export const parameters = {
1410
header: {
@@ -21,8 +17,7 @@ export const parameters = {
2117
disable: false
2218
},
2319
initFunc: {
24-
disable: true,
25-
code: null
20+
disable: true
2621
},
2722
docs:{
2823
source: {
@@ -40,8 +35,6 @@ export const globals = {
4035
footer: false
4136
}
4237
export const decorators = [
43-
withLoadEvent,
44-
withInitFunc,
4538
withHeader,
4639
withFooter,
4740
]

packages/unity-bootstrap-theme/.storybook/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default {
44
staticDirs: ['../dist'],
55
stories: ["../stories/**/*.stories.mdx", "../stories/**/*.stories.@(js|jsx|ts|tsx)"],
66
addons: [
7+
"./local-addon",
78
"../../../.storybook-config",
89
"../../../.storybook-config/dataLayerListener",
910
"@whitespace/storybook-addon-html",

packages/unity-bootstrap-theme/.storybook/preview.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import "./eventSpy.js";
12
import "../src/scss/unity-bootstrap-theme.bundle.scss";
3+
import { default as bootstrap } from "bootstrap/js/index.umd.js";
4+
globalThis.bootstrap = bootstrap;
5+
import { default as udsBootstrap } from "../src/js/unity-bootstrap.js";
6+
globalThis.udsBootstrap = udsBootstrap;
7+
28
import { removeFontAwesomeChanges } from "./local-addon/helpers";
39

4-
// Import all the Bootstrap bundle
5-
import "../../../node_modules/bootstrap/dist/js/bootstrap.bundle.min";
10+
import { windowLoadEvent } from "./decorators.jsx";
611

712
const parameters = {
813
options: {
@@ -58,7 +63,8 @@ const parameters = {
5863

5964
/** @type { import('@storybook/react').Preview } */
6065
const preview = {
61-
parameters
66+
parameters,
67+
decorators: [windowLoadEvent],
6268
};
6369

6470
export default preview;

0 commit comments

Comments
 (0)