Add copy to HTML feature for storybook (#14599)

* Add copy to HTML feature for storybook, inc fix for article markup

* remove html stories no longer needed
This commit is contained in:
Suzanne Aitchison 2021-08-27 16:09:21 +01:00 committed by GitHub
parent 62e2e0b898
commit bfb4f00aae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 76 additions and 415 deletions

View file

@ -203,7 +203,7 @@ function buildArticleHTML(article) {
</a>
</div>
<div>
<p>
<div>
<a href="/${profileUsername}" class="crayons-story__secondary fw-medium ${
isArticle ? 'm:hidden' : ''
}">${filterXSS(article.user.name)}</a>
@ -213,7 +213,7 @@ function buildArticleHTML(article) {
: ''
}
${forOrganization}
</p>
</div>
<a href="${
article.path
}" class="crayons-story__tertiary fs-xs">${publishDate}</a>

View file

@ -13,6 +13,7 @@ module.exports = {
'@storybook/addon-links',
'@storybook/addon-a11y',
'@storybook/addon-notes/register-panel',
'@whitespace/storybook-addon-html',
{
name: '@storybook/addon-storysource',
loaderOptions: {

View file

@ -61,7 +61,7 @@ const themeSwitcherDecorator = (storyFn) => {
))}
</select>
</label>
{storyFn()}
<div id="story-content">{storyFn()}</div>
</div>
);
};
@ -103,4 +103,7 @@ export const parameters = {
],
},
},
html: {
root: '#story-content',
},
};

View file

@ -57,7 +57,7 @@ Object {
</a>
</div>
<div>
<p>
<div>
<a
class="crayons-story__secondary fw-medium m:hidden"
href="/Emil99"
@ -126,7 +126,7 @@ Object {
</div>
</div>
</div>
</p>
</div>
<a
class="crayons-story__tertiary fs-xs"
href="/some-post/path"
@ -305,7 +305,7 @@ Object {
</a>
</div>
<div>
<p>
<div>
<a
class="crayons-story__secondary fw-medium m:hidden"
href="/Emil99"
@ -374,7 +374,7 @@ Object {
</div>
</div>
</div>
</p>
</div>
<a
class="crayons-story__tertiary fs-xs"
href="/some-post/path"

View file

@ -44,7 +44,7 @@ export const Meta = ({ article, organization }) => {
</a>
</div>
<div>
<p>
<div>
<a
href={`/${article.user.username}`}
className="crayons-story__secondary fw-medium m:hidden"
@ -55,6 +55,7 @@ export const Meta = ({ article, organization }) => {
: article.user.name,
)}
</a>
<MinimalProfilePreviewCard
triggerId={`story-author-preview-trigger-${article.id}`}
contentId={`story-author-preview-content-${article.id}`}
@ -77,7 +78,7 @@ export const Meta = ({ article, organization }) => {
</a>
</span>
)}
</p>
</div>
<a href={article.path} className="crayons-story__tertiary fs-xs">
<PublishDate
readablePublishDate={article.readable_publish_date}

View file

@ -1,180 +0,0 @@
import { h } from 'preact';
import '../../storybook-utilities/designSystem.scss';
import notes from './buttons.md';
export default {
title: 'Components/Buttons/HTML',
parameters: {
notes,
},
};
export const Primary = () => (
<button type="button" className="crayons-btn">
Button label
</button>
);
Primary.story = {
name: 'primary',
};
export const Secondary = () => (
<button type="button" className="crayons-btn crayons-btn--secondary">
Secondary Button label
</button>
);
Secondary.story = {
name: 'Secondary',
};
export const Outlined = () => (
<button type="button" className="crayons-btn crayons-btn--outlined">
Outlined Button label
</button>
);
Outlined.story = {
name: 'Outlined',
};
export const Danger = () => (
<button type="button" className="crayons-btn crayons-btn--danger">
Danger Button label
</button>
);
Danger.story = {
name: 'Danger',
};
export const Ghost = () => (
<button type="button" className="crayons-btn crayons-btn--ghost">
Ghost Button label
</button>
);
Ghost.story = {
name: 'Ghost',
};
export const GhostDimmed = () => (
<button type="button" className="crayons-btn crayons-btn--ghost-dimmed">
Ghost Dimmed Button label
</button>
);
Ghost.story = {
name: 'Ghost Dimmed',
};
export const GhostBrand = () => (
<button type="button" className="crayons-btn crayons-btn--ghost-brand">
Ghost Brand Button label
</button>
);
GhostBrand.story = {
name: 'Ghost Brand',
};
export const GhostSuccess = () => (
<button type="button" className="crayons-btn crayons-btn--ghost-success">
Ghost Success Button label
</button>
);
GhostSuccess.story = {
name: 'Ghost Success',
};
export const GhostWarning = () => (
<button type="button" className="crayons-btn crayons-btn--ghost-warning">
Ghost Warning Button label
</button>
);
GhostWarning.story = {
name: 'Ghost Warning',
};
export const GhostDanger = () => (
<button type="button" className="crayons-btn crayons-btn--ghost-danger">
Ghost Danger Button label
</button>
);
GhostDanger.story = {
name: 'Ghost Danger',
};
export const IconLeft = () => (
<button type="button" className="crayons-btn crayons-btn--icon-left">
<svg
width="24"
height="24"
xmlns="http://www.w3.org/2000/svg"
className="crayons-icon"
>
<path d="M9.99999 15.172L19.192 5.979L20.607 7.393L9.99999 18L3.63599 11.636L5.04999 10.222L9.99999 15.172Z" />
</svg>
Button
</button>
);
IconLeft.story = {
name: 'Icon to the left',
};
export const IconRight = () => (
<button type="button" className="crayons-btn crayons-btn--icon-right">
Button
<svg
width="24"
height="24"
xmlns="http://www.w3.org/2000/svg"
className="crayons-icon"
>
<path d="M9.99999 15.172L19.192 5.979L20.607 7.393L9.99999 18L3.63599 11.636L5.04999 10.222L9.99999 15.172Z" />
</svg>
</button>
);
IconRight.story = {
name: 'Icon to the right',
};
export const IconAlone = () => (
<button type="button" className="crayons-btn crayons-btn--icon">
<svg
width="24"
height="24"
xmlns="http://www.w3.org/2000/svg"
className="crayons-icon"
>
<path d="M9.99999 15.172L19.192 5.979L20.607 7.393L9.99999 18L3.63599 11.636L5.04999 10.222L9.99999 15.172Z" />
</svg>
</button>
);
IconAlone.story = {
name: 'Icon alone',
};
export const IconRounded = () => (
<button type="button" className="crayons-btn crayons-btn--icon-rounded">
<svg
width="24"
height="24"
xmlns="http://www.w3.org/2000/svg"
className="crayons-icon"
>
<path d="M9.99999 15.172L19.192 5.979L20.607 7.393L9.99999 18L3.63599 11.636L5.04999 10.222L9.99999 15.172Z" />
</svg>
</button>
);
IconRounded.story = {
name: 'Icon rounded',
};

View file

@ -1,50 +0,0 @@
import { h } from 'preact';
import '../../storybook-utilities/designSystem.scss';
import notes from './buttons.md';
export default {
title: 'Components/Buttons/HTML',
parameter: {
notes,
},
};
export const Default = () => (
<button type="button" className="crayons-btn">
Button label
</button>
);
Default.story = {
name: 'Default',
};
export const Small = () => (
<button type="button" className="crayons-btn crayons-btn--s">
Small Button label
</button>
);
Small.story = {
name: 'Small',
};
export const Large = () => (
<button type="button" className="crayons-btn crayons-btn--l">
Large Button label
</button>
);
Large.story = {
name: 'Large',
};
export const XLarge = () => (
<button type="button" className="crayons-btn crayons-btn--xl">
Extra Large Button label
</button>
);
XLarge.story = {
name: 'Extra Large',
};

View file

@ -1,54 +0,0 @@
import { h } from 'preact';
import { useLayoutEffect } from 'preact/hooks';
import notes from './dropdowns.md';
import { initializeDropdown } from '@utilities/dropdownUtils';
import '../../storybook-utilities/designSystem.scss';
export default {
title: 'Components/Dropdowns/HTML',
parameters: { notes },
};
const DropdownWithActivator = ({ additionalDropdownClasses = '' }) => {
useLayoutEffect(() => {
initializeDropdown({
triggerElementId: 'storybook-dropdown-trigger',
dropdownContentId: 'storybook-dropdown',
});
}, []);
return (
<div className="dropdown-trigger-container">
<button
id="storybook-dropdown-trigger"
className="crayons-btn dropdown-trigger"
>
Click to trigger dropdown
</button>
<div
id="storybook-dropdown"
className={`crayons-dropdown ${additionalDropdownClasses}`}
>
<p>
Hey, I&apos;m a dropdown content! Lorem ipsum dolor sit amet,
consectetur adipisicing elit.
</p>
<a href="/">Sequi ea voluptates</a>
</div>
</div>
);
};
export const Default = () => <DropdownWithActivator />;
Default.story = {
name: 'default',
};
export const AdditonalCssClasses = () => (
<DropdownWithActivator additionalDropdownClasses="p-6" />
);
AdditonalCssClasses.story = {
name: 'additional CSS classes',
};

View file

@ -1,62 +0,0 @@
/* eslint-disable jsx-a11y/no-static-element-interactions */
/* eslint-disable jsx-a11y/click-events-have-key-events */
// Disabled for the file due to issues disabling for individual JSX lines.
// These are disabled to allow the "click outside to close" functionality
import { h } from 'preact';
import { useState, useEffect } from 'preact/hooks';
import notes from './drawers.md';
import '../../storybook-utilities/designSystem.scss';
export default {
title: 'Components/MobileDrawer/HTML',
parameters: { notes },
};
export const Default = () => {
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
useEffect(() => {
const keyupListener = (e) => {
if (e.key === 'Escape') {
setIsDrawerOpen(false);
}
};
document.addEventListener('keyup', keyupListener);
return () => document.removeEventListener('keyup', keyupListener);
}, []);
return (
<div>
<button className="crayons-btn" onClick={() => setIsDrawerOpen(true)}>
Open drawer
</button>
{isDrawerOpen && (
<div class="crayons-mobile-drawer">
<div
class="crayons-mobile-drawer__overlay"
onClick={() => setIsDrawerOpen(false)}
/>
<div
aria-label="Example MobileDrawer"
aria-modal="true"
class="crayons-mobile-drawer__content"
role="dialog"
>
<h2 className="mb-4">Lorem ipsum</h2>
<button
className="crayons-btn"
onClick={() => setIsDrawerOpen(false)}
>
OK
</button>
</div>
</div>
)}
</div>
);
};
Default.story = {
name: 'default',
};

View file

@ -1,54 +0,0 @@
import { h } from 'preact';
import '../../storybook-utilities/designSystem.scss';
import notes from './modals.md';
export default {
title: 'Components/Modals/HTML',
parameters: { notes },
};
export const Default = () => (
<div className="crayons-modal">
Hey, I&apos;m a Default Modal content! Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Sequi ea voluptates quaerat eos consequuntur
temporibus.
</div>
);
Default.story = {
name: 'default',
};
export const Small = () => (
<div className="crayons-modal crayons-modal--s">
Hey, I&apos;m a Small Modal content! Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Sequi ea voluptates quaerat eos consequuntur temporibus.
</div>
);
Small.story = {
name: 'small',
};
export const Large = () => (
<div className="crayons-modal crayons-modal--l">
Hey, I&apos;m a Large Modal content! Lorem ipsum dolor sit amet, consectetur
adipisicing elit. Sequi ea voluptates quaerat eos consequuntur temporibus.
</div>
);
Large.story = {
name: 'large',
};
export const NoPadding = () => (
<div className="crayons-modal crayons-modal--padding-0">
Hey, I&apos;m a modal content with no padding! Lorem ipsum dolor sit amet,
consectetur adipisicing elit. Sequi ea voluptates quaerat eos consequuntur
temporibus.
</div>
);
NoPadding.story = {
name: 'no padding',
};

View file

@ -34,7 +34,7 @@
</a>
</div>
<div>
<p>
<div>
<a href="/<%= story.cached_user.username %>" class="crayons-story__secondary fw-medium m:hidden">
<%= story.cached_user.name %>
</a>
@ -81,7 +81,7 @@
<a href="/<%= story.cached_organization.slug %>" class="crayons-story__secondary fw-medium"><%= story.cached_organization.name %></a>
</span>
<% end %>
</p>
</div>
<a href="<%= story.path %>" class="crayons-story__tertiary fs-xs"><time datetime="<%= story.published_timestamp %>"><%= story.readable_publish_date %></time><span class="time-ago-indicator-initial-placeholder" data-seconds="<%= story.published_at_int %>"></span></a>
</div>
</div>

View file

@ -92,6 +92,7 @@
"@testing-library/preact": "^2.0.1",
"@testing-library/preact-hooks": "^1.1.0",
"@testing-library/user-event": "^13.2.1",
"@whitespace/storybook-addon-html": "^5.0.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.6.3",

View file

@ -71,7 +71,7 @@
semver "^6.3.0"
source-map "^0.5.0"
"@babel/generator@^7.12.11", "@babel/generator@^7.12.5", "@babel/generator@^7.15.0":
"@babel/generator@^7.12.11", "@babel/generator@^7.12.5", "@babel/generator@^7.13.9", "@babel/generator@^7.15.0":
version "7.15.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.15.0.tgz#a7d0c172e0d814974bad5aa77ace543b97917f15"
integrity sha512-eKl4XdMrbpYvuB505KTta4AV9g+wWzmVBW69tX0H2NwKVKd2YJbKgyK6M8j/rgLbmHOYJn6rUklV677nOyJrEQ==
@ -405,6 +405,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.2.tgz#08d4ffcf90d211bf77e7cc7154c6f02d468d2b1d"
integrity sha512-bMJXql1Ss8lFnvr11TZDH4ArtwlAS5NG9qBmdiFW2UHHm6MVoR+GDc5XE2b9K938cyjc9O6/+vjjcffLDtfuDg==
"@babel/parser@^7.13.12":
version "7.15.3"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.3.tgz#3416d9bea748052cfcb63dbcc27368105b1ed862"
integrity sha512-O0L6v/HvqbdJawj0iBEfVQMc3/6WP+AeOsovsIgBFyJaG+W2w7eqvZB7puddATmWuARlm1SX7DwxJ/JJUnDpEA==
"@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining@^7.14.5":
version "7.14.5"
resolved "https://registry.yarnpkg.com/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/-/plugin-bugfix-v8-spread-parameters-in-optional-chaining-7.14.5.tgz#4b467302e1548ed3b1be43beae2cc9cf45e0bb7e"
@ -2151,7 +2156,7 @@
ts-dedent "^2.0.0"
util-deprecate "^1.0.2"
"@storybook/api@6.3.7":
"@storybook/api@6.3.7", "@storybook/api@^6.1.21":
version "6.3.7"
resolved "https://registry.yarnpkg.com/@storybook/api/-/api-6.3.7.tgz#88b8a51422cd0739c91bde0b1d65fb6d8a8485d0"
integrity sha512-57al8mxmE9agXZGo8syRQ8UhvGnDC9zkuwkBPXchESYYVkm3Mc54RTvdAOYDiy85VS4JxiGOywHayCaRwgUddQ==
@ -2508,7 +2513,7 @@
ts-dedent "^2.0.0"
util-deprecate "^1.0.2"
"@storybook/components@6.3.7":
"@storybook/components@6.3.7", "@storybook/components@^6.1.21":
version "6.3.7"
resolved "https://registry.yarnpkg.com/@storybook/components/-/components-6.3.7.tgz#42b1ca6d24e388e02eab82aa9ed3365db2266ecc"
integrity sha512-O7LIg9Z18G0AJqXX7Shcj0uHqwXlSA5UkHgaz9A7mqqqJNl6m6FwwTWcxR1acUfYVNkO+czgpqZHNrOF6rky1A==
@ -3743,6 +3748,18 @@
"@webassemblyjs/wast-parser" "1.9.0"
"@xtuc/long" "4.2.2"
"@whitespace/storybook-addon-html@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@whitespace/storybook-addon-html/-/storybook-addon-html-5.0.0.tgz#4fd009c1625c909218f2a1a2e6e10524feb05fe6"
integrity sha512-1OkgqEGNcXFzeOCGtJsEcPPswVy+mDRgDOFClXWX/f2SG/JBfkltXoFnCj2EfGwhIQaVGxjT7k1gqANKy5VeJQ==
dependencies:
"@babel/generator" "^7.13.9"
"@babel/parser" "^7.13.12"
"@storybook/api" "^6.1.21"
"@storybook/components" "^6.1.21"
prettier "^2.2.1"
react-syntax-highlighter "^15.4.3"
"@xtuc/ieee754@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@xtuc/ieee754/-/ieee754-1.2.0.tgz#eef014a3145ae477a1cbc00cd1e552336dceb790"
@ -8232,6 +8249,11 @@ highlight.js@^10.1.1, highlight.js@~10.6.0:
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.6.0.tgz#0073aa71d566906965ba6e1b7be7b2682f5e18b6"
integrity sha512-8mlRcn5vk/r4+QcqerapwBYTe+iPL5ih6xrNylxrnBdHQiijDETfXX7VIxC3UiCRiINBJfANBAsPzAvRQj8RpQ==
highlight.js@^10.4.1, highlight.js@~10.7.0:
version "10.7.3"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-10.7.3.tgz#697272e3991356e40c3cac566a74eef681756531"
integrity sha512-tzcUFauisWKNHaRkN4Wjl/ZA07gENAjFl3J/c480dprkGTg5EQstgaNFqBfUqCq54kZRIEcreTsAgF/m2quD7A==
highlight.js@~9.13.0:
version "9.13.1"
resolved "https://registry.yarnpkg.com/highlight.js/-/highlight.js-9.13.1.tgz#054586d53a6863311168488a0f58d6c505ce641e"
@ -10190,6 +10212,14 @@ lowlight@^1.14.0:
fault "^1.0.0"
highlight.js "~10.6.0"
lowlight@^1.17.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/lowlight/-/lowlight-1.20.0.tgz#ddb197d33462ad0d93bf19d17b6c301aa3941888"
integrity sha512-8Ktj+prEb1RoCPkEOrPMYUN/nCggB7qAWe3a7OpMjWQkh3l2RD5wKRQ+o8Q8YuI9RG/xs95waaI/E6ym/7NsTw==
dependencies:
fault "^1.0.0"
highlight.js "~10.7.0"
lowlight@~1.11.0:
version "1.11.0"
resolved "https://registry.yarnpkg.com/lowlight/-/lowlight-1.11.0.tgz#1304d83005126d4e8b1dc0f07981e9b689ec2efc"
@ -12650,7 +12680,7 @@ prescribe@>=1.1.2:
resolved "https://registry.yarnpkg.com/prescribe/-/prescribe-1.1.3.tgz#8d3122445f3fbaf4c4c5817ea527a17fc8139ee6"
integrity sha1-jTEiRF8/uvTExYF+pSehf8gTnuY=
prettier@^2.3.2:
prettier@^2.2.1, prettier@^2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.3.2.tgz#ef280a05ec253712e486233db5c6f23441e7342d"
integrity sha512-lnJzDfJ66zkMy58OL5/NY5zp70S7Nz6KqcKkXYzn2tMVrNxvbqaBpg7H3qHaLxCJ5lNMsGuM8+ohS7cZrthdLQ==
@ -12695,6 +12725,11 @@ prismjs@^1.21.0, prismjs@^1.8.4, prismjs@~1.23.0:
optionalDependencies:
clipboard "^2.0.0"
prismjs@^1.22.0, prismjs@~1.24.0:
version "1.24.1"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.24.1.tgz#c4d7895c4d6500289482fa8936d9cdd192684036"
integrity sha512-mNPsedLuk90RVJioIky8ANZEwYm5w9LcvCXrxHlwf4fNVSn8jEipMybMkWUyyF0JhnC+C4VcOVSBuHRKs1L5Ow==
prismjs@~1.17.0:
version "1.17.1"
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.17.1.tgz#e669fcbd4cdd873c35102881c33b14d0d68519be"
@ -13193,6 +13228,17 @@ react-syntax-highlighter@^13.5.3:
prismjs "^1.21.0"
refractor "^3.1.0"
react-syntax-highlighter@^15.4.3:
version "15.4.4"
resolved "https://registry.yarnpkg.com/react-syntax-highlighter/-/react-syntax-highlighter-15.4.4.tgz#dc9043f19e7bd063ff3ea78986d22a6eaa943b2a"
integrity sha512-PsOFHNTzkb3OroXdoR897eKN5EZ6grht1iM+f1lJSq7/L0YVnkJaNVwC3wEUYPOAmeyl5xyer1DjL6MrumO6Zw==
dependencies:
"@babel/runtime" "^7.3.1"
highlight.js "^10.4.1"
lowlight "^1.17.0"
prismjs "^1.22.0"
refractor "^3.2.0"
react-textarea-autosize@^7.1.0:
version "7.1.2"
resolved "https://registry.yarnpkg.com/react-textarea-autosize/-/react-textarea-autosize-7.1.2.tgz#70fdb333ef86bcca72717e25e623e90c336e2cda"
@ -13367,6 +13413,15 @@ refractor@^3.1.0:
parse-entities "^2.0.0"
prismjs "~1.23.0"
refractor@^3.2.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/refractor/-/refractor-3.4.0.tgz#62bd274b06c942041f390c371b676eb67cb0a678"
integrity sha512-dBeD02lC5eytm9Gld2Mx0cMcnR+zhSnsTfPpWqFaMgUMJfC9A6bcN3Br/NaXrnBJcuxnLFR90k1jrkaSyV8umg==
dependencies:
hastscript "^6.0.0"
parse-entities "^2.0.0"
prismjs "~1.24.0"
regenerate-unicode-properties@^8.2.0:
version "8.2.0"
resolved "https://registry.yarnpkg.com/regenerate-unicode-properties/-/regenerate-unicode-properties-8.2.0.tgz#e5de7111d655e7ba60c057dbe9ff37c87e65cdec"