Skip to content

Commit

Permalink
go back to old component analyzer
Browse files Browse the repository at this point in the history
  • Loading branch information
JesmoDev committed Aug 23, 2024
1 parent 74dded7 commit 44f6704
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 370 deletions.
49 changes: 49 additions & 0 deletions .storybook/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,55 @@ WebComponentFormatter(customElements);
setCustomElementsManifest(customElements);

function WebComponentFormatter(customElements) {
for (let tag of customElements.tags || []) {
// Hide all attributes, since we only use props for storybook
tag.attributes = [];

// Hide all 'styles' and 'formAssociated' entries for properties
for (let prop in tag.properties || []) {
if (
tag.properties[prop].name === 'styles' ||
tag.properties[prop].name === 'formAssociated'
) {
delete tag.properties[prop];
}
}

// Run through all CSS Custom Properties and clean them a bit
for (let cssProp of tag.cssProperties || []) {
// If the property does not have a type, set it to string
if (!cssProp.type) {
cssProp.type = 'string';
}
}

// Find all names of properties
const propertyNames = (tag.properties || []).map(p => p.name);

// Run through all slots to clean them up a bit
for (let slot of tag.slots || []) {
// Replace the name of the default slot so Storybook will show it
if (typeof slot.name === 'string' && slot.name.length === 0) {
slot.name = 'slot';
}

// If the slot has the same name as a property, then add the word 'slot' to the name
// Bug reported to Storybook here: https://github.com/storybookjs/storybook/issues/17733
if (propertyNames.includes(slot.name)) {
slot.name = `${slot.name} slot`;
}

// Set type of slots
if (typeof slot.type === 'undefined' || slot.type.length === 0) {
slot.type = 'HTMLElement';
}
}
}

return customElements;
}

function WebComponentFormatterNew(customElements) {
(customElements.modules ?? [])
.flatMap(module => module.declarations ?? [])
.forEach(declaration => {
Expand Down
Loading

0 comments on commit 44f6704

Please sign in to comment.