11import { Args } from '@storybook/web-components' ;
2- import { html , nothing , TemplateResult } from 'lit' ;
2+ import { nothing , TemplateResult } from 'lit' ;
3+ import { unsafeHTML } from 'lit/directives/unsafe-html.js' ;
34
45/**
56 * Render a list of slots, filtering out any null or undefined slots to prevent empty lines.
67 * Accepts an array of TemplateResults or an Args object. If an Args object is provided, it will render any properties that end with 'slot'.
78 */
89// TODO: add a way to control the new lines. Eg exclude newlines: before, after, between as an array
9- function renderSlots ( args : Args ) : TemplateResult | typeof nothing ;
10- function renderSlots (
11- param : TemplateResult [ ] | Args ,
12- ) : TemplateResult | typeof nothing {
10+ function renderSlots ( args : Args ) : TemplateResult [ ] | typeof nothing ;
11+ function renderSlots ( param : TemplateResult [ ] | Args ) {
1312 let slots : TemplateResult [ ] = [ ] ;
1413
1514 // if param is array, set slots to param
@@ -34,13 +33,14 @@ function renderSlots(
3433
3534 // Join slots with consistent formatting; no extra line breaks between them
3635 const spacing = ' ' ;
37- const formattedSlots = validSlots . map (
38- ( slot , index ) =>
39- // eslint-disable-next-line lit/no-useless-template-literals
40- html `${ '\n' } ${ spacing } ${ slot } ${ index === slots . length - 1 ? '\n' : '' } ` ,
41- ) ;
42-
43- // Return the combined template results
44- return html `${ formattedSlots } ` ;
36+
37+ const stringSlots = validSlots . map ( slot => slot . strings [ 0 ] ) ;
38+ const stringSlotsJoined = stringSlots . join ( '\n' ) ;
39+ const stringSlotsJoinedWithSpacing = stringSlotsJoined
40+ . split ( '\n' )
41+ . map ( line => spacing + line )
42+ . join ( '\n' ) ;
43+
44+ return unsafeHTML ( stringSlotsJoinedWithSpacing ) ;
4545}
4646export { renderSlots } ;
0 commit comments