Skip to content

Commit 58a0eba

Browse files
committed
fix: improved storybook rendering, put stories in dedicated folders
1 parent e179b63 commit 58a0eba

File tree

172 files changed

+32894
-21629
lines changed

Some content is hidden

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

172 files changed

+32894
-21629
lines changed

templates/storybook/.storybook/preview.ts

Lines changed: 51 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,46 +48,69 @@ const preview: Preview = {
4848
const anchorContainer = document.querySelector('.sb-anchor');
4949
const controlsContainer = document.querySelector('.css-14m39zm, .docblock-argstable');
5050

51-
if (anchorContainer && controlsContainer) {
51+
// If no controls container, find the docs story div as fallback
52+
const docsStory = document.querySelector('.docs-story');
53+
const insertionPoint = controlsContainer || (docsStory?.parentElement?.parentElement);
54+
55+
if (anchorContainer && insertionPoint) {
5256
// Remove any existing custom sections to avoid duplicates
5357
const existingArgs = document.getElementById('custom-args-section');
5458
const existingHTML = document.getElementById('custom-html-section');
5559
if (existingArgs) existingArgs.remove();
5660
if (existingHTML) existingHTML.remove();
5761

58-
// Create Args JSON section
59-
const argsSection = document.createElement('div');
60-
argsSection.id = 'custom-args-section';
61-
argsSection.style.cssText = 'margin: 2rem 0;';
62-
63-
const argsTitle = document.createElement('span');
64-
argsTitle.className = 'custom-subtitle';
65-
argsTitle.textContent = 'Current Args';
66-
argsSection.appendChild(argsTitle);
67-
68-
const argsCodeBlock = document.createElement('div');
69-
argsCodeBlock.className = 'custom-code-block sb-unstyled theme-atom-one-dark';
70-
const argsPre = document.createElement('pre');
71-
argsPre.className = 'sb-unstyled';
72-
const argsCode = document.createElement('code');
73-
argsCode.className = 'language-json sb-unstyled';
74-
argsCode.textContent = JSON.stringify(context.args, null, 2);
75-
argsPre.appendChild(argsCode);
76-
argsCodeBlock.appendChild(argsPre);
77-
argsSection.appendChild(argsCodeBlock);
78-
79-
// Apply syntax highlighting
80-
hljs.highlightElement(argsCode);
62+
// Check if args object is not empty
63+
const hasArgs = context.args && Object.keys(context.args).length > 0;
64+
65+
// Create Args JSON section only if args exist
66+
let argsSection: HTMLDivElement | null = null;
67+
if (hasArgs) {
68+
argsSection = document.createElement('div');
69+
argsSection.id = 'custom-args-section';
70+
argsSection.style.cssText = 'margin: 2rem 0;';
71+
72+
const argsTitle = document.createElement('span');
73+
argsTitle.className = 'custom-subtitle';
74+
argsTitle.textContent = 'Current Args';
75+
argsSection.appendChild(argsTitle);
76+
77+
const argsCodeBlock = document.createElement('div');
78+
argsCodeBlock.className = 'custom-code-block sb-unstyled theme-atom-one-dark';
79+
const argsPre = document.createElement('pre');
80+
argsPre.className = 'sb-unstyled';
81+
const argsCode = document.createElement('code');
82+
argsCode.className = 'language-json sb-unstyled';
83+
argsCode.textContent = JSON.stringify(context.args, null, 2);
84+
argsPre.appendChild(argsCode);
85+
argsCodeBlock.appendChild(argsPre);
86+
argsSection.appendChild(argsCodeBlock);
87+
88+
// Apply syntax highlighting
89+
hljs.highlightElement(argsCode);
90+
}
8191

8292
// Create HTML Output section
8393
const htmlSection = document.createElement('div');
8494
htmlSection.id = 'custom-html-section';
8595
htmlSection.style.cssText = 'margin: 2rem 0;';
8696

87-
// Insert sections before the controls container
88-
if (controlsContainer.parentNode) {
89-
controlsContainer.parentNode.insertBefore(htmlSection, controlsContainer);
90-
controlsContainer.parentNode.insertBefore(argsSection, controlsContainer);
97+
// Insert sections after the insertion point
98+
if (controlsContainer) {
99+
// If controls exist, insert before them
100+
if (controlsContainer.parentNode) {
101+
controlsContainer.parentNode.insertBefore(htmlSection, controlsContainer);
102+
if (argsSection) {
103+
controlsContainer.parentNode.insertBefore(argsSection, controlsContainer);
104+
}
105+
}
106+
} else if (insertionPoint) {
107+
// If no controls, insert after the grandparent of docs-story
108+
if (argsSection) {
109+
insertionPoint.insertAdjacentElement('afterend', argsSection);
110+
argsSection.insertAdjacentElement('afterend', htmlSection);
111+
} else {
112+
insertionPoint.insertAdjacentElement('afterend', htmlSection);
113+
}
91114
}
92115

93116
// Format HTML with Prettier

0 commit comments

Comments
 (0)