NOTE:
Have a look at the
.storybook/webpack.config.js
diff --git a/examples/angular-cli/src/stories/core/styles/__snapshots__/story-styles.stories.storyshot b/examples/angular-cli/src/stories/core/styles/__snapshots__/story-styles.stories.storyshot
index 9e96c5f03b1b..7307da48a797 100644
--- a/examples/angular-cli/src/stories/core/styles/__snapshots__/story-styles.stories.storyshot
+++ b/examples/angular-cli/src/stories/core/styles/__snapshots__/story-styles.stories.storyshot
@@ -3,7 +3,7 @@
exports[`Storyshots Core / Story host styles With Args 1`] = `
@@ -19,7 +19,7 @@ exports[`Storyshots Core / Story host styles With Args 1`] = `
exports[`Storyshots Core / Story host styles With story template 1`] = `
diff --git a/examples/official-storybook/components/addon-measure/ShadowRoot.js b/examples/official-storybook/components/addon-measure/ShadowRoot.js
new file mode 100644
index 000000000000..665257cf6d6d
--- /dev/null
+++ b/examples/official-storybook/components/addon-measure/ShadowRoot.js
@@ -0,0 +1,65 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+// eslint-disable-next-line import/no-extraneous-dependencies
+import { drawSelectedElement } from '@storybook/addon-measure/dist/cjs/box-model/visualizer';
+// eslint-disable-next-line import/no-extraneous-dependencies
+import { init, destroy } from '@storybook/addon-measure/dist/cjs/box-model/canvas';
+
+export const ShadowRoot = ({ label = 'Hello from shadow DOM', drawMode = 'ROOT' }) => {
+ const ref = React.useRef();
+
+ React.useEffect(() => {
+ if (!ref.current.attachShadow) return;
+
+ ref.current.attachShadow({ mode: 'open' });
+
+ ref.current.shadowRoot.innerHTML = `
+
+ ${label}
+ `;
+
+ init();
+ drawSelectedElement(drawMode === 'ROOT' ? ref.current : ref.current.shadowRoot.children[1]);
+
+ // eslint-disable-next-line consistent-return
+ return () => {
+ destroy();
+ };
+ }, []);
+
+ return
;
+};
+
+ShadowRoot.propTypes = {
+ label: PropTypes.string,
+ drawMode: PropTypes.oneOf(['ROOT', 'NESTED']),
+};
+
+ShadowRoot.defaultProps = {
+ label: 'Hello from shadow DOM',
+ drawMode: 'ROOT',
+};
diff --git a/examples/official-storybook/components/addon-measure/Visualization.js b/examples/official-storybook/components/addon-measure/Visualization.js
new file mode 100644
index 000000000000..bcd10d6a3d1b
--- /dev/null
+++ b/examples/official-storybook/components/addon-measure/Visualization.js
@@ -0,0 +1,36 @@
+import React, { useEffect, useRef } from 'react';
+import PropTypes from 'prop-types';
+// eslint-disable-next-line import/no-extraneous-dependencies
+import { drawSelectedElement } from '@storybook/addon-measure/dist/cjs/box-model/visualizer';
+// eslint-disable-next-line import/no-extraneous-dependencies
+import { init, destroy } from '@storybook/addon-measure/dist/cjs/box-model/canvas';
+
+export const Visualization = ({ render }) => {
+ const element = useRef(null);
+
+ useEffect(() => {
+ if (element.current) {
+ init();
+ drawSelectedElement(element.current);
+ }
+
+ return () => {
+ destroy();
+ };
+ }, [element]);
+
+ return (
+
+ {render(element)}
+
+ );
+};
+
+Visualization.propTypes = {
+ render: PropTypes.func.isRequired,
+};
diff --git a/examples/official-storybook/stories/addon-measure/BoxModel.stories.js b/examples/official-storybook/stories/addon-measure/BoxModel.stories.js
new file mode 100644
index 000000000000..17876cde74b4
--- /dev/null
+++ b/examples/official-storybook/stories/addon-measure/BoxModel.stories.js
@@ -0,0 +1,118 @@
+import React from 'react';
+import { Visualization } from '../../components/addon-measure/Visualization';
+
+export default {
+ title: 'Addons/Measure/BoxModel',
+ parameters: {
+ layout: 'fullscreen',
+ },
+};
+
+const Template = (args) => ;
+
+export const MarginUniform = Template.bind({});
+MarginUniform.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const MarginAsymmetric = Template.bind({});
+MarginAsymmetric.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const PaddingUniform = Template.bind({});
+PaddingUniform.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const PaddingAsymmetric = Template.bind({});
+PaddingAsymmetric.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const BorderUniform = Template.bind({});
+BorderUniform.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const BorderAsymmetric = Template.bind({});
+BorderAsymmetric.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const DecimalSizing = Template.bind({});
+DecimalSizing.args = {
+ render: (ref) => (
+
+ ),
+};
diff --git a/examples/official-storybook/stories/addon-measure/Grid.stories.js b/examples/official-storybook/stories/addon-measure/Grid.stories.js
new file mode 100644
index 000000000000..f9849389bf6d
--- /dev/null
+++ b/examples/official-storybook/stories/addon-measure/Grid.stories.js
@@ -0,0 +1,46 @@
+import React from 'react';
+
+export default {
+ title: 'Addons/Measure/Grid',
+};
+
+const MeasureButton = () => (
+
+
+
+);
+
+export const Basic = () => (
+
+
+ {[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12].map((id) => (
+
+ {id}
+
+ ))}
+
+
+ Click the measure button in the toolbar to enable the addon
+
+
+);
diff --git a/examples/official-storybook/stories/addon-measure/ShadowRoot.stories.js b/examples/official-storybook/stories/addon-measure/ShadowRoot.stories.js
new file mode 100644
index 000000000000..eec397d9d8d7
--- /dev/null
+++ b/examples/official-storybook/stories/addon-measure/ShadowRoot.stories.js
@@ -0,0 +1,26 @@
+import React from 'react';
+
+import { ShadowRoot } from '../../components/addon-measure/ShadowRoot';
+
+export default {
+ title: 'Addons/Measure/ShadowRoot',
+ component: ShadowRoot,
+};
+
+const Template = (args) => (
+
+
+
+);
+
+export const Root = Template.bind({});
+
+export const Nested = Template.bind({});
+Nested.args = {
+ drawMode: 'NESTED',
+};
diff --git a/examples/official-storybook/stories/addon-measure/SmallNode.stories.js b/examples/official-storybook/stories/addon-measure/SmallNode.stories.js
new file mode 100644
index 000000000000..6a38904f5d21
--- /dev/null
+++ b/examples/official-storybook/stories/addon-measure/SmallNode.stories.js
@@ -0,0 +1,73 @@
+import React from 'react';
+import { Visualization } from '../../components/addon-measure/Visualization';
+
+export default {
+ title: 'Addons/Measure/SmallNode',
+ parameters: {
+ layout: 'fullscreen',
+ },
+};
+
+const Template = (args) => ;
+
+export const Everything30px = Template.bind({});
+Everything30px.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const Short = Template.bind({});
+Short.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const Narrow = Template.bind({});
+Narrow.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const Tiny = Template.bind({});
+Tiny.args = {
+ render: (ref) => (
+
+ ),
+};
diff --git a/examples/official-storybook/stories/addon-measure/StackingLabels.stories.js b/examples/official-storybook/stories/addon-measure/StackingLabels.stories.js
new file mode 100644
index 000000000000..cd8197237dec
--- /dev/null
+++ b/examples/official-storybook/stories/addon-measure/StackingLabels.stories.js
@@ -0,0 +1,67 @@
+import React from 'react';
+import { Visualization } from '../../components/addon-measure/Visualization';
+
+export default {
+ title: 'Addons/Measure/StackingLabels',
+ parameters: {
+ layout: 'fullscreen',
+ },
+};
+
+const Template = (args) => ;
+
+export const EverythingUniform = Template.bind({});
+EverythingUniform.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const Asymmetric = Template.bind({});
+Asymmetric.args = {
+ render: (ref) => (
+
+ ),
+};
+
+export const MoreAsymmetric = Template.bind({});
+MoreAsymmetric.args = {
+ render: (ref) => (
+
+ ),
+};
diff --git a/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-dev b/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-dev
index 3acb73c6b296..e655ab5e5c96 100644
--- a/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-dev
+++ b/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-dev
@@ -10,7 +10,7 @@ Object {
"ROOT/addons/actions/dist/esm/register.js",
"ROOT/addons/backgrounds/dist/esm/register.js",
"ROOT/addons/toolbars/dist/esm/register.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/manager.js",
+ "ROOT/addons/measure/dist/esm/register.js",
"ROOT/addons/outline/dist/esm/register.js",
],
"keys": Array [
diff --git a/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-prod b/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-prod
index 05d044eeacde..3960607da817 100644
--- a/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-prod
+++ b/lib/core-server/src/__snapshots__/cra-ts-essentials_manager-prod
@@ -10,7 +10,7 @@ Object {
"ROOT/addons/actions/dist/esm/register.js",
"ROOT/addons/backgrounds/dist/esm/register.js",
"ROOT/addons/toolbars/dist/esm/register.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/manager.js",
+ "ROOT/addons/measure/dist/esm/register.js",
"ROOT/addons/outline/dist/esm/register.js",
],
"keys": Array [
diff --git a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev
index 8ed1c87f02a9..be400084b96b 100644
--- a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev
+++ b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-dev
@@ -12,7 +12,7 @@ Object {
"ROOT/addons/actions/dist/esm/preset/addArgs.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addParameter.js-generated-other-entry.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/preview.js-generated-other-entry.js",
+ "ROOT/addons/measure/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/outline/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/examples/cra-ts-essentials/.storybook/preview.js-generated-config-entry.js",
"ROOT/examples/cra-ts-essentials/.storybook/generated-stories-entry.js",
diff --git a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod
index 43c8930903af..c561f897abfa 100644
--- a/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod
+++ b/lib/core-server/src/__snapshots__/cra-ts-essentials_preview-prod
@@ -12,7 +12,7 @@ Object {
"ROOT/addons/actions/dist/esm/preset/addArgs.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addParameter.js-generated-other-entry.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/preview.js-generated-other-entry.js",
+ "ROOT/addons/measure/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/outline/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/examples/cra-ts-essentials/.storybook/preview.js-generated-config-entry.js",
"ROOT/examples/cra-ts-essentials/.storybook/generated-stories-entry.js",
diff --git a/lib/core-server/src/__snapshots__/vue-3-cli_manager-dev b/lib/core-server/src/__snapshots__/vue-3-cli_manager-dev
index d2c84b977969..be6c5b62a0d3 100644
--- a/lib/core-server/src/__snapshots__/vue-3-cli_manager-dev
+++ b/lib/core-server/src/__snapshots__/vue-3-cli_manager-dev
@@ -12,7 +12,7 @@ Object {
"ROOT/addons/backgrounds/dist/esm/register.js",
"ROOT/addons/viewport/dist/esm/register.js",
"ROOT/addons/toolbars/dist/esm/register.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/manager.js",
+ "ROOT/addons/measure/dist/esm/register.js",
"ROOT/addons/outline/dist/esm/register.js",
],
"keys": Array [
diff --git a/lib/core-server/src/__snapshots__/vue-3-cli_manager-prod b/lib/core-server/src/__snapshots__/vue-3-cli_manager-prod
index b557d6f74789..b86aeecbfb37 100644
--- a/lib/core-server/src/__snapshots__/vue-3-cli_manager-prod
+++ b/lib/core-server/src/__snapshots__/vue-3-cli_manager-prod
@@ -12,7 +12,7 @@ Object {
"ROOT/addons/backgrounds/dist/esm/register.js",
"ROOT/addons/viewport/dist/esm/register.js",
"ROOT/addons/toolbars/dist/esm/register.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/manager.js",
+ "ROOT/addons/measure/dist/esm/register.js",
"ROOT/addons/outline/dist/esm/register.js",
],
"keys": Array [
diff --git a/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev b/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev
index 221bee3241bd..69659043a13f 100644
--- a/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev
+++ b/lib/core-server/src/__snapshots__/vue-3-cli_preview-dev
@@ -13,7 +13,7 @@ Object {
"ROOT/addons/actions/dist/esm/preset/addArgs.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addParameter.js-generated-other-entry.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/preview.js-generated-other-entry.js",
+ "ROOT/addons/measure/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/outline/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/examples/vue-3-cli/.storybook/preview.ts-generated-config-entry.js",
"ROOT/examples/vue-3-cli/.storybook/generated-stories-entry.js",
diff --git a/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod b/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod
index 98ffbef4f8e2..e49eaefc4796 100644
--- a/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod
+++ b/lib/core-server/src/__snapshots__/vue-3-cli_preview-prod
@@ -13,7 +13,7 @@ Object {
"ROOT/addons/actions/dist/esm/preset/addArgs.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/backgrounds/dist/esm/preset/addParameter.js-generated-other-entry.js",
- "NODE_MODULES/@storybook/addon-measure/dist/esm/preset/preview.js-generated-other-entry.js",
+ "ROOT/addons/measure/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/addons/outline/dist/esm/preset/addDecorator.js-generated-other-entry.js",
"ROOT/examples/vue-3-cli/.storybook/preview.ts-generated-config-entry.js",
"ROOT/examples/vue-3-cli/.storybook/generated-stories-entry.js",
diff --git a/nx.json b/nx.json
index 67811749944a..e3dd0270bdff 100644
--- a/nx.json
+++ b/nx.json
@@ -43,6 +43,9 @@
"@storybook/addon-links": {
"implicitDependencies": []
},
+ "@storybook/addon-measure": {
+ "implicitDependencies": []
+ },
"@storybook/addon-outline": {
"implicitDependencies": []
},
diff --git a/package.json b/package.json
index 0cc091d3f6d3..82ee6419212b 100644
--- a/package.json
+++ b/package.json
@@ -134,6 +134,7 @@
"@storybook/addon-essentials": "workspace:*",
"@storybook/addon-jest": "workspace:*",
"@storybook/addon-links": "workspace:*",
+ "@storybook/addon-measure": "workspace:*",
"@storybook/addon-outline": "workspace:*",
"@storybook/addon-storyshots": "workspace:*",
"@storybook/addon-storyshots-puppeteer": "workspace:*",
diff --git a/workspace.json b/workspace.json
index a637596318e5..d342fa8b56c0 100644
--- a/workspace.json
+++ b/workspace.json
@@ -33,6 +33,10 @@
"root": "addons/links",
"type": "library"
},
+ "@storybook/addon-measure": {
+ "root": "addons/measure",
+ "type": "library"
+ },
"@storybook/addon-outline": {
"root": "addons/outline",
"type": "library"
diff --git a/yarn.lock b/yarn.lock
index ed2a2c3ab087..f9f292024d4a 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -5777,7 +5777,7 @@ __metadata:
"@storybook/addon-backgrounds": 6.4.0-alpha.13
"@storybook/addon-controls": 6.4.0-alpha.13
"@storybook/addon-docs": 6.4.0-alpha.13
- "@storybook/addon-measure": ^2.0.0
+ "@storybook/addon-measure": 6.4.0-alpha.13
"@storybook/addon-outline": 6.4.0-alpha.13
"@storybook/addon-toolbars": 6.4.0-alpha.13
"@storybook/addon-viewport": 6.4.0-alpha.13
@@ -5869,15 +5869,19 @@ __metadata:
languageName: unknown
linkType: soft
-"@storybook/addon-measure@npm:^2.0.0":
- version: 2.0.0
- resolution: "@storybook/addon-measure@npm:2.0.0"
+"@storybook/addon-measure@6.4.0-alpha.13, @storybook/addon-measure@workspace:*, @storybook/addon-measure@workspace:addons/measure":
+ version: 0.0.0-use.local
+ resolution: "@storybook/addon-measure@workspace:addons/measure"
+ dependencies:
+ "@storybook/addons": 6.4.0-alpha.13
+ "@storybook/api": 6.4.0-alpha.13
+ "@storybook/client-logger": 6.4.0-alpha.13
+ "@storybook/components": 6.4.0-alpha.13
+ "@storybook/core-events": 6.4.0-alpha.13
+ "@types/webpack-env": ^1.16.0
+ core-js: ^3.8.2
+ global: ^4.4.0
peerDependencies:
- "@storybook/addons": ^6.3.0
- "@storybook/api": ^6.3.0
- "@storybook/components": ^6.3.0
- "@storybook/core-events": ^6.3.0
- "@storybook/theming": ^6.3.0
react: ^16.8.0 || ^17.0.0
react-dom: ^16.8.0 || ^17.0.0
peerDependenciesMeta:
@@ -5885,9 +5889,8 @@ __metadata:
optional: true
react-dom:
optional: true
- checksum: fa701e19ac0806590a24fdc4de75a00e06cee26cc0d909fe03743fee5f92abddafa3756a01def312622ff2ba1dd1fe92c6de5046c4d49363dfdff8120cf231de
- languageName: node
- linkType: hard
+ languageName: unknown
+ linkType: soft
"@storybook/addon-outline@6.4.0-alpha.13, @storybook/addon-outline@workspace:*, @storybook/addon-outline@workspace:addons/outline":
version: 0.0.0-use.local
@@ -7271,6 +7274,7 @@ __metadata:
"@storybook/addon-essentials": "workspace:*"
"@storybook/addon-jest": "workspace:*"
"@storybook/addon-links": "workspace:*"
+ "@storybook/addon-measure": "workspace:*"
"@storybook/addon-outline": "workspace:*"
"@storybook/addon-storyshots": "workspace:*"
"@storybook/addon-storyshots-puppeteer": "workspace:*"