From efb719b530d68463466ba6b9bcef927a30be641e Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Mon, 15 Apr 2024 16:57:40 +0200 Subject: [PATCH] refactor: render stories/grid in iframe only, related to #339 --- docs/examples/vue3/single-stories.md | 12 +- docs/guide/svelte3/stories.md | 7 +- docs/guide/vue2/stories.md | 7 +- docs/guide/vue3/stories.md | 7 +- docs/reference/svelte3/story.md | 2 - docs/reference/vue3/story.md | 2 - .../nuxt3/components/BaseButtonLink.story.vue | 1 - examples/nuxt3/cypress/e2e/render-story.cy.js | 2 +- .../svelte4/cypress/e2e/render-story.cy.js | 11 +- examples/svelte4/cypress/e2e/state-sync.cy.js | 9 - examples/svelte4/src/NoIframe.story.svelte | 36 ---- .../vue3/cypress/e2e/toolbar-background.cy.js | 15 +- examples/vue3/src/LongFile1.story.md | 5 +- .../src/components/ComplexParameter.story.vue | 2 +- .../vue3/src/components/Responsive.story.vue | 1 - .../app/components/story/StoryVariantGrid.vue | 171 ++++++++--------- .../story/StoryVariantGridIframe.vue | 174 ++++++++++++++++++ .../components/story/StoryVariantGridItem.vue | 66 +++---- ...emote.vue => StoryVariantSingleIframe.vue} | 0 .../story/StoryVariantSinglePreviewNative.vue | 66 ------- .../story/StoryVariantSingleView.vue | 11 +- .../src/app/components/story/StoryView.vue | 8 +- .../src/app/components/story/StoryViewer.vue | 4 +- packages/histoire-app/src/app/sandbox.ts | 108 ++++++++--- packages/histoire-app/src/app/stores/story.ts | 7 +- packages/histoire-app/src/app/style/main.pcss | 5 - .../histoire-app/src/app/style/sandbox.css | 5 - packages/histoire-app/src/app/util/const.ts | 2 + packages/histoire-app/src/app/util/events.ts | 4 + packages/histoire-app/src/app/util/sandbox.ts | 9 +- .../src/components/button/HstButton.story.vue | 2 +- .../button/HstButtonGroup.story.vue | 1 - .../components/checkbox/HstCheckbox.story.vue | 1 - .../checkbox/HstCheckboxList.story.vue | 1 - .../checkbox/HstSimpleCheckbox.story.vue | 1 - .../colorselect/HstColorSelect.story.vue | 1 - .../src/components/json/HstJson.story.vue | 1 - .../src/components/radio/HstRadio.story.vue | 1 - .../src/components/slider/HstSlider.story.vue | 1 - packages/histoire-shared/src/types/story.ts | 1 - .../node/builtin-plugins/pinceau-tokens.ts | 2 +- .../node/builtin-plugins/tailwind-tokens.ts | 2 +- .../vanilla-support/collect.ts | 2 +- packages/histoire/src/node/collect/index.ts | 2 +- 44 files changed, 417 insertions(+), 361 deletions(-) delete mode 100644 examples/svelte4/src/NoIframe.story.svelte create mode 100644 packages/histoire-app/src/app/components/story/StoryVariantGridIframe.vue rename packages/histoire-app/src/app/components/story/{StoryVariantSinglePreviewRemote.vue => StoryVariantSingleIframe.vue} (100%) delete mode 100644 packages/histoire-app/src/app/components/story/StoryVariantSinglePreviewNative.vue diff --git a/docs/examples/vue3/single-stories.md b/docs/examples/vue3/single-stories.md index 6e481ce1..9a731611 100644 --- a/docs/examples/vue3/single-stories.md +++ b/docs/examples/vue3/single-stories.md @@ -1,10 +1,6 @@ # Single stories -Here are some pattern examples to test your component without any variant. This is the simplest way to get you started. - -## Within an iframe - -This will display your component inside an iframe to be able to test the responsiveness correctly. The iframe is needed for CSS media queries to work properly. +The default way to display stories and variants is inside an iframe that renders a single variant. The iframe is needed for CSS media queries to work properly and to isolate your application's styles. ```vue - - - No iframe story content - -
{content}
-
- -
- - - - -
- - diff --git a/examples/vue3/cypress/e2e/toolbar-background.cy.js b/examples/vue3/cypress/e2e/toolbar-background.cy.js index 91502fb7..2e5179b7 100644 --- a/examples/vue3/cypress/e2e/toolbar-background.cy.js +++ b/examples/vue3/cypress/e2e/toolbar-background.cy.js @@ -23,17 +23,6 @@ describe('background color', () => { 'rgb(0, 81, 66)', ] - it('should provide background and contrast color (no iframe)', () => { - cy.visit('/story/src-components-complexparameter-story-vue?variantId=_default') - cy.get('[data-test-id="toolbar-background"]').click() - cy.get('[data-test-id="background-popper"]').should('be.visible').find('button').should('have.length', 6).each(($el, index) => { - cy.wrap($el).click() - cy.get('[data-test-id="responsive-preview-bg"]').should('have.css', 'background-color', backgroundColorShouldBe[index]) - cy.get('[data-test-id="story-variant-single-view"] .native-story').should('have.css', 'color', contrastColorShouldBe[index]) - cy.get('[data-test-id="toolbar-background"]').click() - }) - }) - it('should provide background and contrast color (with iframe)', () => { cy.visit('story/src-components-contrastcolor-story-vue?variantId=_default') cy.get('[data-test-id="toolbar-background"]').click() @@ -49,8 +38,8 @@ describe('background color', () => { cy.get('[data-test-id="toolbar-background"]').click() cy.get('[data-test-id="background-popper"]').should('be.visible').find('button').should('have.length', 6).each(($el, index) => { cy.wrap($el).click() - cy.get('[data-test-id="responsive-preview-bg"]').should('have.css', 'background-color', backgroundColorShouldBe[index]) - cy.get('.histoire-generic-render-story .text').should('have.css', 'color', contrastColorShouldBe[index]) + getIframeBody().find('[data-test-id="responsive-preview-bg"]').should('have.css', 'background-color', backgroundColorShouldBe[index]) + getIframeBody().find('.histoire-generic-render-story .text').should('have.css', 'color', contrastColorShouldBe[index]) cy.get('[data-test-id="toolbar-background"]').click() }) }) diff --git a/examples/vue3/src/LongFile1.story.md b/examples/vue3/src/LongFile1.story.md index 237575bc..67d411c6 100644 --- a/examples/vue3/src/LongFile1.story.md +++ b/examples/vue3/src/LongFile1.story.md @@ -66,14 +66,11 @@ You can change the layout of the variant by using the `layout` prop with an obje This is the default layout, displaying one variant at a time. The default behavior is to isolate the story with an iframe. -Additional `layout` properties: -- `iframe`: (default: `true`) enables the iframe, useful when your CSS has media queries for responsive design. - ```vue{4}