diff --git a/src/components/ebay-accordion/accordion.stories.ts b/src/components/ebay-accordion/accordion.stories.ts index 9568d5e30..b87b1e04a 100644 --- a/src/components/ebay-accordion/accordion.stories.ts +++ b/src/components/ebay-accordion/accordion.stories.ts @@ -53,8 +53,8 @@ export default { }, }, }, - item: { - name: "@item", + details: { + name: "@details", description: "Represents an element to be used as part of the group. Allowed attributes are `open`, `as`, `text` and `renderBody`", table: { @@ -71,6 +71,16 @@ export default { }, }, }, + onClick: { + action: "on-click", + description: "Triggered on click of details", + table: { + category: "Events", + defaultValue: { + summary: "{ originalEvent }", + }, + }, + }, }, }; diff --git a/src/components/ebay-accordion/component-browser.ts b/src/components/ebay-accordion/component-browser.ts index 128a0452a..6fb3f53c1 100644 --- a/src/components/ebay-accordion/component-browser.ts +++ b/src/components/ebay-accordion/component-browser.ts @@ -6,10 +6,11 @@ export interface AccordionInput extends Omit, `on${string}`> { size?: "regular" | "large"; "auto-collapse"?: AttrBoolean; "a11y-role-description"?: AttrString; - item?: Marko.AttrTag< + details?: Marko.AttrTag< Omit >; "on-toggle"?: (event: { originalEvent: Event; open: boolean }) => void; + "on-click"?: (event: { originalEvent: MouseEvent }) => void; } export interface Input extends WithNormalizedProps {} @@ -17,16 +18,26 @@ class Accordion extends Marko.Component { handleToggle(event: { originalEvent: Event; open: boolean }) { const { autoCollapse } = this.input; - if(autoCollapse && event.open) { - const accordion = this.getEl("accordion-root") as HTMLUListElement; - const detailsElements = accordion.querySelectorAll("details"); + const accordion = this.getEl("accordion-root") as HTMLUListElement; + const detailsElements = Array.from(accordion.querySelectorAll("details")); + const index = detailsElements.indexOf( + event.originalEvent.target as HTMLDetailsElement, + ); + + if (autoCollapse && event.open) { detailsElements.forEach((details: HTMLDetailsElement) => { // Close the
element by setting its open attribute to false if (details !== event.originalEvent.target) { details.open = false; - } - }); + } + }); } + + this.emit("toggle", { + originalEvent: event.originalEvent, + open: (event.originalEvent.target as HTMLDetailsElement).open, + index, + }); } } diff --git a/src/components/ebay-accordion/examples/autoCollapsed.marko b/src/components/ebay-accordion/examples/autoCollapsed.marko index 4e4b4b41a..6c3863ae9 100644 --- a/src/components/ebay-accordion/examples/autoCollapsed.marko +++ b/src/components/ebay-accordion/examples/autoCollapsed.marko @@ -1,11 +1,14 @@ - <@item text="Item 1"> + <@details> + <@summary>Item 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 2"> + + <@details> + <@summary>Item 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 3"> + + <@details> + <@summary>Item 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - + diff --git a/src/components/ebay-accordion/examples/default.marko b/src/components/ebay-accordion/examples/default.marko index 7e3e3425e..d93307d13 100644 --- a/src/components/ebay-accordion/examples/default.marko +++ b/src/components/ebay-accordion/examples/default.marko @@ -1,11 +1,14 @@ - <@item text="Item 1"> + <@details> + <@summary>Item 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 2"> + + <@details> + <@summary>Item 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 3"> + + <@details> + <@summary>Item 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - + diff --git a/src/components/ebay-accordion/examples/large.marko b/src/components/ebay-accordion/examples/large.marko index 6ad85223e..e417152cb 100644 --- a/src/components/ebay-accordion/examples/large.marko +++ b/src/components/ebay-accordion/examples/large.marko @@ -1,11 +1,14 @@ - <@item text="Item 1"> + <@details> + <@summary>Item 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 2"> + + <@details> + <@summary>Item 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 3"> + + <@details> + <@summary>Item 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - + diff --git a/src/components/ebay-accordion/examples/opened.marko b/src/components/ebay-accordion/examples/opened.marko index 974d1ce6f..d8b9cadf6 100644 --- a/src/components/ebay-accordion/examples/opened.marko +++ b/src/components/ebay-accordion/examples/opened.marko @@ -1,11 +1,14 @@ - <@item text="Item 1" open> + <@details open> + <@summary>Item 1 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 2"> + + <@details> + <@summary>Item 2 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - - <@item text="Item 3"> + + <@details> + <@summary>Item 3 Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - + diff --git a/src/components/ebay-accordion/index.marko b/src/components/ebay-accordion/index.marko index 46a63eb6c..0e8fe9b87 100644 --- a/src/components/ebay-accordion/index.marko +++ b/src/components/ebay-accordion/index.marko @@ -5,7 +5,7 @@ static function noop() {} $ const { class: inputClass, size, - item: items = [], + details: items = [], autoCollapse, a11yRoleDescription, ...htmlInput @@ -25,6 +25,7 @@ $ (input as any).toJSON = noop; ...item layout="accordion" on-toggle("handleToggle") + on-click("emit", "click") > <${item.renderBody} /> diff --git a/src/components/ebay-accordion/marko-tag.json b/src/components/ebay-accordion/marko-tag.json index daa4dc664..d2a2fea37 100644 --- a/src/components/ebay-accordion/marko-tag.json +++ b/src/components/ebay-accordion/marko-tag.json @@ -11,14 +11,13 @@ "@as": "string", "@auto-collapse": "boolean", "@a11y-role-description": "string", - "@item []": { + "@details
[]": { "attribute-groups": ["html-attributes"], "@*": { "targetProperty": null, "type": "expression" }, - "@html-attributes": "expression", - "@text": "string" + "@html-attributes": "expression" }, "description": "[view documentation](https://ebay.github.io/ebayui-core/?path=/story/navigation-disclosure-ebay-accordion)" } diff --git a/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap b/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap index 42929f653..562ee588d 100644 --- a/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap +++ b/src/components/ebay-accordion/test/__snapshots__/test.server.js.snap @@ -28,11 +28,11 @@ exports[`accordion > renders accordion with auto-collapse true 1`] = `    renders accordion with auto-collapse true 1`] = `    renders accordion with auto-collapse true 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -100,7 +100,7 @@ exports[`accordion > renders accordion with auto-collapse true 1`] = `   renders accordion with auto-collapse true 1`] = `   renders accordion with auto-collapse true 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -148,7 +148,7 @@ exports[`accordion > renders accordion with auto-collapse true 1`] = `   renders accordion with auto-collapse true 1`] = `   renders accordion with auto-collapse true 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -207,11 +207,11 @@ exports[`accordion > renders accordion with large size 1`] = `    renders accordion with large size 1`] = `    renders accordion with large size 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -279,7 +279,7 @@ exports[`accordion > renders accordion with large size 1`] = `   renders accordion with large size 1`] = `   renders accordion with large size 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -327,7 +327,7 @@ exports[`accordion > renders accordion with large size 1`] = `   renders accordion with large size 1`] = `   renders accordion with large size 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -386,11 +386,11 @@ exports[`accordion > renders accordion with localized role description 1`] = `    renders accordion with localized role description 1`] = `    renders accordion with localized role description 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -458,7 +458,7 @@ exports[`accordion > renders accordion with localized role description 1`] = `   renders accordion with localized role description 1`] = `   renders accordion with localized role description 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -506,7 +506,7 @@ exports[`accordion > renders accordion with localized role description 1`] = `   renders accordion with localized role description 1`] = `   renders accordion with localized role description 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -565,11 +565,11 @@ exports[`accordion > renders default accordion 1`] = `    renders default accordion 1`] = `    renders default accordion 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -637,7 +637,7 @@ exports[`accordion > renders default accordion 1`] = `   renders default accordion 1`] = `   renders default accordion 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  @@ -685,7 +685,7 @@ exports[`accordion > renders default accordion 1`] = `   renders default accordion 1`] = `   renders default accordion 1`] = `   Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.  diff --git a/src/components/ebay-accordion/test/mock/index.js b/src/components/ebay-accordion/test/mock/index.js index fa4f6e359..a6fafc438 100644 --- a/src/components/ebay-accordion/test/mock/index.js +++ b/src/components/ebay-accordion/test/mock/index.js @@ -2,21 +2,27 @@ import { createRenderBody } from "../../../../common/test-utils/shared"; export const Default_Accordion = { - item: [ + details: [ { - text: "Item 1", + summary: { + renderBody: createRenderBody("Item 1"), + }, renderBody: createRenderBody( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", ), }, { - text: "Item 2", + summary: { + renderBody: createRenderBody("Item 2"), + }, renderBody: createRenderBody( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", ), }, { - text: "Item 3", + summary: { + renderBody: createRenderBody("Item 3"), + }, renderBody: createRenderBody( "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", ), diff --git a/src/components/ebay-accordion/test/test.browser.js b/src/components/ebay-accordion/test/test.browser.js index 2c6d957da..c46b37ebd 100644 --- a/src/components/ebay-accordion/test/test.browser.js +++ b/src/components/ebay-accordion/test/test.browser.js @@ -17,6 +17,8 @@ afterAll(() => fastAnimations.stop()); afterEach(cleanup); let component; +const getSectionText = (item) => item.summary.renderBody.text; + describe("given the accordion in the default state", () => { const input = mock.Default_Accordion; @@ -25,25 +27,32 @@ describe("given the accordion in the default state", () => { }); it("should render all sections collapsed", () => { - input.item.forEach((item) => { + input.details.forEach((item) => { expect( - component.getByText(item.text).closest("details").open, + component.getByText(getSectionText(item)).closest("details") + .open, ).to.equal(false); }); }); describe("when first section toggled", () => { beforeEach(async () => { - await fireEvent.click(component.getByText(input.item[0].text)); + await fireEvent.click( + component.getByText(getSectionText(input.details[0])), + ); }); it("should open the clicked section", async () => { - const firstSection = component.getByText(input.item[0].text); + const firstSection = component.getByText( + getSectionText(input.details[0]), + ); expect(firstSection.closest("details").open).to.equal(true); }); it("should close an open section when clicked again", async () => { - const firstSection = component.getByText(input.item[0].text); + const firstSection = component.getByText( + getSectionText(input.details[0]), + ); expect(firstSection.closest("details").open).to.equal(true); await fireEvent.click(firstSection); expect(firstSection.closest("details").open).to.equal(false); @@ -60,20 +69,30 @@ describe("given the accordion with autocollapse enabled", () => { it("should collapse previous section when new section is opened", async () => { // Open first section - await fireEvent.click(component.getByText(input.item[0].text)); + await fireEvent.click( + component.getByText(getSectionText(input.details[0])), + ); expect( - component.getByText(input.item[0].text).closest("details").open, + component + .getByText(getSectionText(input.details[0])) + .closest("details").open, ).to.equal(true); // Open second section - await fireEvent.click(component.getByText(input.item[1].text)); + await fireEvent.click( + component.getByText(getSectionText(input.details[1])), + ); // Verify first section closed and second section opened expect( - component.getByText(input.item[0].text).closest("details").open, + component + .getByText(getSectionText(input.details[0])) + .closest("details").open, ).to.equal(false); expect( - component.getByText(input.item[1].text).closest("details").open, + component + .getByText(getSectionText(input.details[1])) + .closest("details").open, ).to.equal(true); }); }); diff --git a/src/components/ebay-details/component-browser.ts b/src/components/ebay-details/component-browser.ts index b52da7e7e..80bc70f6d 100644 --- a/src/components/ebay-details/component-browser.ts +++ b/src/components/ebay-details/component-browser.ts @@ -1,7 +1,8 @@ import type { WithNormalizedProps } from "../../global"; -export interface DetailsInput extends Omit { - text: string; +export interface DetailsInput + extends Omit, `on${string}`> { + summary?: Marko.AttrTag>; size?: "regular" | "small"; alignment?: "regular" | "center"; layout?: "regular" | "accordion"; diff --git a/src/components/ebay-details/details.stories.ts b/src/components/ebay-details/details.stories.ts index 1e30441d5..97908dc26 100644 --- a/src/components/ebay-details/details.stories.ts +++ b/src/components/ebay-details/details.stories.ts @@ -1,16 +1,12 @@ import { Story } from "@storybook/marko"; import { tagToString } from "../../common/storybook/storybook-code-source"; +import { addRenderBodies } from "../../common/storybook/utils"; import Readme from "./README.md"; import Details from "./index.marko"; import type { Input } from "./component-browser"; const Template: Story = (args) => ({ - input: { - ...args, - renderBody: function (out: any) { - out.html(args.renderBody); - } as any, - }, + input: addRenderBodies(args), }); export default { @@ -26,6 +22,13 @@ export default { argTypes: { renderBody: {}, + summary: { + name: "@summary", + description: "The body which will be wrapped as the details summary", + table: { + category: "@attribute tags", + }, + }, alignment: { type: "options", description: "The position of the details", @@ -89,12 +92,14 @@ export default { export const Standard = Template.bind({}); Standard.args = { renderBody: - `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.` as any, - text: "Show me the details!", + `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.`, + summary: { + renderBody: `Show me details!`, + }, size: "regular", open: false, as: "p", -}; +} as any; Standard.parameters = { docs: { diff --git a/src/components/ebay-details/examples/centered.marko b/src/components/ebay-details/examples/centered.marko index 9a05ede48..799e42753 100644 --- a/src/components/ebay-details/examples/centered.marko +++ b/src/components/ebay-details/examples/centered.marko @@ -1,3 +1,4 @@ - + + <@summary>details Sample content inside of details diff --git a/src/components/ebay-details/examples/default.marko b/src/components/ebay-details/examples/default.marko index c49d811a1..5829c0142 100644 --- a/src/components/ebay-details/examples/default.marko +++ b/src/components/ebay-details/examples/default.marko @@ -1,4 +1,5 @@ - + + <@summary>details Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. diff --git a/src/components/ebay-details/examples/div-root.marko b/src/components/ebay-details/examples/div-root.marko index 410e00ce9..2d21b1aee 100644 --- a/src/components/ebay-details/examples/div-root.marko +++ b/src/components/ebay-details/examples/div-root.marko @@ -1,6 +1,7 @@ class {} - + + <@summary>details
Block content
diff --git a/src/components/ebay-details/examples/multiple-options.marko b/src/components/ebay-details/examples/multiple-options.marko index 338952c6f..29c767496 100644 --- a/src/components/ebay-details/examples/multiple-options.marko +++ b/src/components/ebay-details/examples/multiple-options.marko @@ -1,5 +1,6 @@ class {} - console.log('toggle', ev.open)) > + console.log('toggle', ev.open)) > + <@summary>details Sample content inside of details diff --git a/src/components/ebay-details/examples/opened.marko b/src/components/ebay-details/examples/opened.marko index 0091f48bb..374aa8a9a 100644 --- a/src/components/ebay-details/examples/opened.marko +++ b/src/components/ebay-details/examples/opened.marko @@ -1,3 +1,4 @@ - + + <@summary>details Sample content inside of details diff --git a/src/components/ebay-details/examples/small.marko b/src/components/ebay-details/examples/small.marko index abe0a9da3..99d415d43 100644 --- a/src/components/ebay-details/examples/small.marko +++ b/src/components/ebay-details/examples/small.marko @@ -1,3 +1,4 @@ - + + <@summary>details Sample content inside of details diff --git a/src/components/ebay-details/index.marko b/src/components/ebay-details/index.marko index 416b3e51e..bf9761ee7 100644 --- a/src/components/ebay-details/index.marko +++ b/src/components/ebay-details/index.marko @@ -7,7 +7,7 @@ $ const { open, alignment, size, - text, + summary, renderBody, layout, as: inputAs, @@ -23,22 +23,24 @@ $ (input as any).toJSON = noop; key="root" onToggle("toggleDetails") onClick("clickDetails")> - - ${text} - - + + + <${summary.renderBody}/> + + + <${inputAs || "div"} class=layout === "accordion" && "details__content"> <${renderBody}/> diff --git a/src/components/ebay-details/marko-tag.json b/src/components/ebay-details/marko-tag.json index aa30238e6..24e237dec 100644 --- a/src/components/ebay-details/marko-tag.json +++ b/src/components/ebay-details/marko-tag.json @@ -11,7 +11,13 @@ "@size": { "enum": ["regular", "small"] }, - "@text": "string", + "@summary": { + "@*": { + "targetProperty": null, + "type": "expression" + }, + "@html-attributes": "expression" + }, "@as": "string", "@open": "boolean", "description": "[view documentation](https://ebay.github.io/ebayui-core/?path=/story/navigation-disclosure-ebay-details)" diff --git a/src/components/ebay-details/test/__snapshots__/test.server.js.snap b/src/components/ebay-details/test/__snapshots__/test.server.js.snap index 1bc0e5cf3..9408687e3 100644 --- a/src/components/ebay-details/test/__snapshots__/test.server.js.snap +++ b/src/components/ebay-details/test/__snapshots__/test.server.js.snap @@ -10,44 +10,8 @@ exports[`details > passes through additional html attributes 1`] = ` style="color:red" type="number" > - - - -
`; @@ -62,44 +26,8 @@ exports[`details > passes through additional html attributes 2`] = ` style="color:red" type="number" > - - - -
`; @@ -126,11 +54,11 @@ exports[`details > renders as div version 1`] = `    renders as div version 1`] = `    body content  @@ -178,11 +106,11 @@ exports[`details > renders basic version 1`] = `    renders basic version 1`] = `    body content  @@ -230,11 +158,11 @@ exports[`details > renders center version 1`] = `    renders center version 1`] = `    body content  @@ -282,11 +210,11 @@ exports[`details > renders in open state 1`] = `    renders in open state 1`] = `    body content  @@ -334,11 +262,11 @@ exports[`details > renders small version 1`] = `    renders small version 1`] = `    body content  diff --git a/src/components/ebay-details/test/mock/index.js b/src/components/ebay-details/test/mock/index.js index a9a077d1b..2de91616d 100644 --- a/src/components/ebay-details/test/mock/index.js +++ b/src/components/ebay-details/test/mock/index.js @@ -2,7 +2,9 @@ import { createRenderBody } from "../../../../common/test-utils/shared"; export const Default_Details = { - text: "open", + summary: { + renderBody: createRenderBody("open"), + }, renderBody: createRenderBody("body content"), }; diff --git a/src/components/ebay-details/test/test.browser.js b/src/components/ebay-details/test/test.browser.js index d20960ee0..7237f31cb 100644 --- a/src/components/ebay-details/test/test.browser.js +++ b/src/components/ebay-details/test/test.browser.js @@ -26,7 +26,9 @@ describe("given the details is in the default state", () => { it("should render with open false", () => { expect( - component.getByText(input.text).closest("details").open, + component + .getByText(input.summary.renderBody.text) + .closest("details").open, ).to.equal(false); }); }); @@ -40,14 +42,16 @@ describe("given the details is in the open state", () => { it("should render with open false", () => { expect( - component.getByText(input.text).closest("details").open, + component + .getByText(input.summary.renderBody.text) + .closest("details").open, ).to.equal(true); }); }); describe("given the details is in the default state and click is triggered", () => { const input = mock.Default_Details; - const detailsText = input.text; + const detailsText = input.summary.renderBody.text; beforeEach(async () => { component = await render(template, input); @@ -67,7 +71,7 @@ describe("given the details is in the default state and click is triggered", () describe("given the details is in the open state and click is triggered", () => { const input = mock.Open_Details; - const detailsText = input.text; + const detailsText = input.summary.renderBody.text; beforeEach(async () => { component = await render(template, input);