Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storybook: Add BlockImage component (as well as Fancybox) #38

Merged
merged 8 commits into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dist/css/explorer-1.min.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/explorer-1.min.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"dependencies": {
"@tailwindcss/forms": "^0.2.1",
"swiper": "^6.6.2",
"tailwindcss": "^2.0.3"
"tailwindcss": "^2.0.3",
"@fancyapps/ui": "^4.0.0-beta.2"
},
"devDependencies": {
"@babel/core": "^7.13.8",
Expand Down
1 change: 1 addition & 0 deletions src/js/scripts.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('./_lazysizes.js')
require('./_swiper.js')
// add more scripts here
require('@fancyapps/ui')
6 changes: 6 additions & 0 deletions src/scss/_vendors.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Vendor provided styles
@import '@fancyapps/ui/dist/fancybox.css';
@import 'swiper/swiper-bundle.css';

// vendor overrides
@import 'vendors/fancybox_customizations';
2 changes: 1 addition & 1 deletion src/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// end tailwind ----------------

// vendors / node_modules
@import 'swiper/swiper-bundle.css'; // manually added
@import 'vendors';

// main elements
@import 'hover'; // manually added
Expand Down
13 changes: 13 additions & 0 deletions src/scss/vendors/_fancybox_customizations.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// overrides for fancybox
.fancybox__slide {
padding: 36px;
@screen lg {
padding: 64px;
}
}
.fancybox__content {
padding: 18px;
@screen lg {
padding: 36px;
}
}
71 changes: 41 additions & 30 deletions storybook/stories/components/BaseButton/BaseButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IconFacebookTemplate } from '../Icons/IconFacebook'
import { IconTwitterTemplate } from '../Icons/IconTwitter'
import { IconInstagramTemplate } from '../Icons/IconInstagram'
import { IconYoutubeTemplate } from '../Icons/IconYoutube'
import { IconExpandTemplate } from '../Icons/IconExpand'

export const BaseButtonTemplate = ({
label,
Expand All @@ -14,57 +15,67 @@ export const BaseButtonTemplate = ({
disabled,
icon,
cssClass,
fancybox,
}) => {
// TODO: make sure the full variant class names are written out somewhere for purging
let computedClass = '-' + variant
let tag = disabled ? 'button' : 'link'
fancybox = fancybox ? fancybox : ''
let ariaLabel = label
let caretHtml = ''
let iconTemplate = ''
let computedClass = ''

if (icon === 'next') {
caretHtml = IconNextTemplate()
} else if (icon === 'facebook') {
caretHtml = IconFacebookTemplate()
} else if (icon === 'twitter') {
caretHtml = IconTwitterTemplate()
} else if (icon === 'instagram') {
caretHtml = IconInstagramTemplate()
} else if (icon === 'youtube') {
caretHtml = IconYoutubeTemplate()
} else if (caret) {
caretHtml = IconCaretTemplate()
}
if (icon == 'next') iconTemplate = IconNextTemplate()
else if (icon == 'expand') iconTemplate = IconExpandTemplate()
else if (icon == 'facebook') iconTemplate = IconFacebookTemplate()
else if (icon == 'twitter') iconTemplate = IconTwitterTemplate()
else if (icon == 'instagram') iconTemplate = IconInstagramTemplate()
else if (icon == 'youtube') iconTemplate = IconYoutubeTemplate()
else if (caret) iconTemplate = IconCaretTemplate()

if (compact) {
computedClass += ' -compact'
}
// setup classnames
if (variant == 'primary') computedClass = '-primary'
else if (variant == 'secondary') computedClass = '-secondary'
laespinoza marked this conversation as resolved.
Show resolved Hide resolved
else if (variant == 'dark') computedClass = '-dark'
else if (variant == 'social') computedClass = '-social'

if (compact) computedClass += ' -compact'
if (cssClass) computedClass += ' ' + cssClass
if (icon) {
computedClass += ' -icon-only'
label = ''
}

if (cssClass) {
computedClass += ' ' + cssClass
}

if (tag === 'link') {
if (disabled) {
return `
<button
disabled="disabled"
class="BaseButton text-contrast-none inline-block ${computedClass}"
aria-label="${ariaLabel}"
>
<span class="label block">
${label}${iconTemplate}
</span>
</button>
`
} else if (link) {
return `
<a href="${link}" class="BaseButton text-contrast-none ${computedClass} inline-block">
<a
href="${link}"
class="BaseButton text-contrast-none inline-block ${computedClass}"
aria-label="${ariaLabel}"
>
<span class="label block">
${label}${caretHtml}
${label}${iconTemplate}
</span>
</a>
`
} else {
return `
<button
class="BaseButton text-contrast-none inline-block ${computedClass}"
aria-label="${ariaLabel}"
disabled="disabled"
class="BaseButton text-contrast-none ${computedClass} inline-block"
${fancybox}
>
<span class="label block">
${label}${caretHtml}
${label}${iconTemplate}
</span>
</button>
`
Expand Down
16 changes: 16 additions & 0 deletions storybook/stories/components/BlockImage/BlockImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { BlockImageFullBleedTemplate } from './BlockImageFullBleed'
import { BlockImageStandardTemplate } from './BlockImageStandard'

export const BlockImageTemplate = ({ fullBleed, image }) => {
if (fullBleed) {
return BlockImageFullBleedTemplate({ image })
} else {
return `
<div class="BaseGrid container mx-auto">
<div class="lg:col-start-2 lg:col-end-12 col-start-1 col-end-13 lg:px-0 px-4 relative">
${BlockImageStandardTemplate({ image })}
</div>
</div>
`
}
}
64 changes: 64 additions & 0 deletions storybook/stories/components/BlockImage/BlockImage.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { BlockImageTemplate } from './BlockImage'
import { BlockImageFullBleedTemplate } from './BlockImageFullBleed'
import { BlockImageStandardTemplate } from './BlockImageStandard'

export default {
title: 'Components/Blocks/BlockImage',
argTypes: {
fullBleed: {
control: { type: 'boolean' },
},
},
excludeStories: /.*Data$/,
parameters: {
viewMode: 'docs',
docs: {
description: {
component: `
## Usage notes
The "Streamfield Block" markup includes layout assumptions. If \`BlockImage\` needs to be used in a custom layout, then the "Standalone" versions could be used instead, as their markup does not contain any layout assumptions. Alternatively, users can modify the \`col-start-\` and \`col-end-\` classes in \`BlockImage\` to match their layouts.
`,
},
},
},
}

export const BlockImageData = {
fullBleed: false,
image: {
alt: 'Fourth image',
caption:
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel porttitor urna. Maecenas at est laoreet, sagittis risus a, rutrum ipsum. Quisque tincidunt lacus nunc, dapibus facilisis felis scelerisque sit amet. </p>',
credit: 'NASA/JPL',
detailUrl: '/image/placeholder/',
original: 'https://placekitten.com/869/700',
src: {
height: 700,
url: 'https://placekitten.com/869/700',
width: 869,
},
srcSet:
'https://placekitten.com/320/258 320w, https://placekitten.com/869/700 1024w',
},
imageFullBleed: {
alt: 'Fourth image',
caption:
'<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed vel porttitor urna. Maecenas at est laoreet, sagittis risus a, rutrum ipsum. Quisque tincidunt lacus nunc, dapibus facilisis felis scelerisque sit amet. </p>',
credit: 'NASA/JPL',
detailUrl: '/image/placeholder/',
src: {
width: 1800,
height: 900,
url: 'https://picsum.photos/1800/900',
},
},
}

export const StreamfieldBlock = BlockImageTemplate.bind({})
StreamfieldBlock.args = BlockImageData

export const StandaloneFullBleed = BlockImageFullBleedTemplate.bind({})
StandaloneFullBleed.args = { image: BlockImageData.imageFullBleed }

export const StandaloneStandard = BlockImageStandardTemplate.bind({})
StandaloneStandard.args = { image: BlockImageData.image }
44 changes: 44 additions & 0 deletions storybook/stories/components/BlockImage/BlockImageFullBleed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { BaseImagePlaceholderTemplate } from '../BaseImagePlaceholder/BaseImagePlaceholder'
import { BaseImageCaptionTemplate } from '../BaseImageCaption/BaseImageCaption'
import { BlockImageLightboxTemplate } from './BlockImageLightbox'

export const BlockImageFullBleedTemplate = ({ image, fancyboxGallery }) => {
let blockImageLightbox = BlockImageLightboxTemplate({
image,
fancyboxGallery,
})

let baseImagePlaceholder = BaseImagePlaceholderTemplate({
theme: 'dark-theme',
src: image.src.url,
srcset: image.src.url,
alt: image.alt,
width: image.src.width,
height: image.src.height,
wrapperClass: 'aspect-ratio-sixteen-nine lg:aspect-ratio-two-one',
objectFitClass: 'object-cover',
})

let baseImageCaption = ''
if (image.caption || image.credit) {
let baseImageCaptionTemplate = BaseImageCaptionTemplate({
caption: image.caption,
credit: image.credit,
url: image.url,
linkText: image.linkText,
})
baseImageCaption = `<div class="max-w-screen-3xl p-4 pb-0 mx-auto">${baseImageCaptionTemplate}</div>`
}

return `
<div>
<div class="bg-gray-light">
<div class="max-w-screen-3xl mx-auto group relative">
${blockImageLightbox}
${baseImagePlaceholder}
</div>
</div>
${baseImageCaption}
</div>
`
}
17 changes: 17 additions & 0 deletions storybook/stories/components/BlockImage/BlockImageLightbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { FancyboxButtonTemplate } from '../FancyboxButton/FancyboxButton'

export const BlockImageLightboxTemplate = (image, fancyboxGallery) => {
let fancyboxButton = FancyboxButtonTemplate({
variant: 'primary',
fancyboxGallery,
image: image.image,
icon: 'expand',
label: 'View in lightbox',
})

return `
<div class="lg:opacity-0 transition-opacity absolute z-20 top-0 right-0 can-hover:group-hover:opacity-100 focus-within:opacity-100">
${fancyboxButton}
</div>
`
}
42 changes: 42 additions & 0 deletions storybook/stories/components/BlockImage/BlockImageStandard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { BaseImagePlaceholderTemplate } from '../BaseImagePlaceholder/BaseImagePlaceholder'
import { BaseImageCaptionTemplate } from '../BaseImageCaption/BaseImageCaption'
import { BlockImageLightboxTemplate } from './BlockImageLightbox'

export const BlockImageStandardTemplate = ({ image, fancyboxGallery }) => {
let blockImageLightbox = BlockImageLightboxTemplate({
image,
fancyboxGallery,
})

let baseImagePlaceholder = BaseImagePlaceholderTemplate({
theme: 'dark-theme',
src: image.src.url,
srcset: image.src.url,
alt: image.alt,
width: image.src.width,
height: image.src.height,
wrapperClass: 'aspect-ratio-sixteen-nine',
objectFitClass: 'object-contain',
})

let baseImageCaption = ''
if (image.caption || image.credit) {
let baseImageCaptionTemplate = BaseImageCaptionTemplate({
caption: image.caption,
credit: image.credit,
url: image.url,
linkText: image.linkText,
})
baseImageCaption = `<div class="lg:px-0 p-4 pb-0">${baseImageCaptionTemplate}</div>`
}

return `
<div>
<div class="group relative">
${blockImageLightbox}
${baseImagePlaceholder}
</div>
${baseImageCaption}
</div>
`
}
30 changes: 30 additions & 0 deletions storybook/stories/components/FancyboxButton/FancyboxButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { BaseButtonTemplate } from '../BaseButton/BaseButton'

export const FancyboxButtonTemplate = ({
laespinoza marked this conversation as resolved.
Show resolved Hide resolved
variant,
fancyboxGallery,
image,
icon,
label,
}) => {
let fancybox = `data-fancybox`
if (fancyboxGallery) {
fancybox += `="${fancyboxGallery}"`
}
if (image.credit || image.caption) {
fancybox += ` data-caption="`
if (image.caption) fancybox += image.caption
if (image.credit) fancybox += `Credit: ${image.credit}`
fancybox += `"`
}
fancybox += ` data-src="${image.src.url}"`

let baseButton = BaseButtonTemplate({
variant,
icon,
label,
fancybox,
})

return baseButton
}
Loading