From 9d777ec912422fdb95d11ee5fd93308b229bc712 Mon Sep 17 00:00:00 2001 From: thollander Date: Sun, 5 May 2019 22:23:01 +0200 Subject: [PATCH] Add copy button for individual story - Resolves #6708 --- lib/ui/package.json | 1 + .../__snapshots__/preview.stories.storyshot | 56 ++++++++++++++----- lib/ui/src/components/preview/preview.js | 19 +++++++ 3 files changed, 62 insertions(+), 14 deletions(-) diff --git a/lib/ui/package.json b/lib/ui/package.json index c73a9202787f..99b5bf046c95 100644 --- a/lib/ui/package.json +++ b/lib/ui/package.json @@ -30,6 +30,7 @@ "@storybook/router": "5.1.0-alpha.39", "@storybook/theming": "5.1.0-alpha.39", "core-js": "^2.6.5", + "copy-to-clipboard": "^3.0.8", "fast-deep-equal": "^2.0.1", "fuse.js": "^3.4.4", "global": "^4.3.2", diff --git a/lib/ui/src/components/preview/__snapshots__/preview.stories.storyshot b/lib/ui/src/components/preview/__snapshots__/preview.stories.storyshot index 79ccb7dd928e..eb44f7aaf073 100644 --- a/lib/ui/src/components/preview/__snapshots__/preview.stories.storyshot +++ b/lib/ui/src/components/preview/__snapshots__/preview.stories.storyshot @@ -2,7 +2,7 @@ exports[`Storyshots UI|Preview/Preview no tabs 1`] = ` Array [ - .emotion-22 { + .emotion-25 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -39,7 +39,7 @@ Array [ margin-left: 15px; } -.emotion-21 { +.emotion-24 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -54,7 +54,7 @@ Array [ margin-left: 30px; } -.emotion-21 > * { +.emotion-24 > * { margin-right: 15px; } @@ -70,7 +70,7 @@ Array [ fill: currentColor; } -.emotion-23 { +.emotion-26 { overflow-y: hidden; overflow-x: auto; color: #999999; @@ -133,7 +133,7 @@ Array [ }
+
@@ -339,7 +353,7 @@ Array [ exports[`Storyshots UI|Preview/Preview with tabs 1`] = ` Array [ - .emotion-28 { + .emotion-31 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -474,7 +488,7 @@ Array [ border-bottom-color: #1EA7FD; } -.emotion-27 { +.emotion-30 { display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; @@ -489,7 +503,7 @@ Array [ margin-left: 30px; } -.emotion-27 > * { +.emotion-30 > * { margin-right: 15px; } @@ -505,7 +519,7 @@ Array [ fill: currentColor; } -.emotion-29 { +.emotion-32 { overflow-y: hidden; overflow-x: auto; color: #999999; @@ -575,7 +589,7 @@ Array [ }
+
diff --git a/lib/ui/src/components/preview/preview.js b/lib/ui/src/components/preview/preview.js index 51226ec6aeca..646dd338d8df 100644 --- a/lib/ui/src/components/preview/preview.js +++ b/lib/ui/src/components/preview/preview.js @@ -2,6 +2,7 @@ import window from 'global'; import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import memoize from 'memoizerific'; +import copy from 'copy-to-clipboard'; import { styled } from '@storybook/theming'; import { SET_CURRENT_STORY } from '@storybook/core-events'; @@ -160,6 +161,24 @@ const getTools = memoize(10)( ), }, + { + match: p => p.viewMode === 'story', + render: () => ( + + copy( + `${window.location.origin}${ + window.location.pathname + }${baseUrl}?id=${storyId}${stringifyQueryParams(queryParams)}` + ) + } + title="Copy canvas link" + > + + + ), + }, ]); const filter = item =>