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

Nick Berens GridList Component Test #10

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
44d3aa8
add initial GalleryList component and story
nickberens360 Sep 16, 2021
e8cb625
add data object and import mock data into story
nickberens360 Sep 16, 2021
ff89a94
add component logic and default story
nickberens360 Sep 16, 2021
af3d1eb
add 404 error story
nickberens360 Sep 16, 2021
379d4eb
add comment
nickberens360 Sep 16, 2021
425eb7d
add logic to check for multiple error types
nickberens360 Sep 17, 2021
74c513e
group galler-item css rules
nickberens360 Sep 17, 2021
26a72ba
group remaining css properties
nickberens360 Sep 17, 2021
9d1cbcf
import WpImage into story and component
nickberens360 Sep 17, 2021
4c012d5
optimize lodash import
nickberens360 Sep 17, 2021
5182ca7
move mock-api-error.json data into story
nickberens360 Sep 17, 2021
f3f0572
fix merge conflict after sync
nickberens360 Sep 18, 2021
97556e2
change caption styling to have darker background and white text
nickberens360 Sep 18, 2021
82a6153
import font into the component because it doesn't appear to set globally
nickberens360 Sep 18, 2021
97fc015
change status class names to be more consistent with fuxthaus convent…
nickberens360 Sep 19, 2021
2af9596
move font-size from item-title into link
nickberens360 Sep 19, 2021
b09394a
move hover events to h3 and make display-inline to trigger bg only wh…
nickberens360 Sep 19, 2021
7181598
decrease ul/li nesting
nickberens360 Sep 19, 2021
5469a33
check if caption exists in data if not use item title
nickberens360 Sep 19, 2021
6384735
add comment about importing font
nickberens360 Sep 19, 2021
bad1633
change caption value in story to null instead of empty string to matc…
nickberens360 Sep 19, 2021
0190563
remove WpImage import from component
nickberens360 Sep 19, 2021
c3a8647
remove list class from gallery-list
nickberens360 Sep 19, 2021
a3966a8
lighten caption background a smidge
nickberens360 Sep 19, 2021
c755240
remove WpImage from storybook file
nickberens360 Nov 13, 2021
f515b27
remove WpImage import
nickberens360 Nov 13, 2021
d2fdc77
refactor loop structure
nickberens360 Nov 13, 2021
33eb2cb
remove unused .item-main class
nickberens360 Nov 13, 2021
8962200
use fuxt package.json and nuxt.config.js because storybook was failin…
nickberens360 Nov 14, 2021
86ecdd7
remove font import from component
nickberens360 Nov 14, 2021
9cbbf83
move shapeListData to utils
nickberens360 Nov 14, 2021
5a78120
remove commented out shapeListData method
nickberens360 Nov 14, 2021
18428d1
decrease mobile caption size
nickberens360 Nov 14, 2021
fcbd842
remove component import from story
nickberens360 Nov 14, 2021
5c6f184
remove alt tag which is handled by WpImage
nickberens360 Nov 14, 2021
573a07e
add .env.example back in
nickberens360 Nov 14, 2021
6231703
uncomment mouseout
nickberens360 Nov 14, 2021
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
262 changes: 262 additions & 0 deletions components/gallery/List.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
<template>
<div class="gallery-list">
<nav class="list-main">
<ul
v-for="(main) in preparedList"
class="list"
>
<li
v-for="(item) in main.listItems"
:key="item.id"
class="item"
>
<h3
class="item-title"
@mouseout="mouseOut()"
@mouseover="mouseOver(item)"
>
<nuxt-link
:to="item.uri"
class="link"
>
{{ item.title }}
</nuxt-link>
</h3>
</li>
</ul>
</nav>

<transition
mode="out-in"
name="fade"
>
<wp-image
v-if="image"
:key="image.id"
:caption="caption"
:class="imageClasses"
:image="image"
mode="fullbleed"
@error-video="videoError"
@error-image="imageError"
@loaded-image="imageLoaded"
@loaded-video="videoLoaded"
/>
</transition>
</div>
</template>
<script>



import _shapeListData from "~/utils/_shapeListData"

export default {
name: "List",
props: {
items: {
type: Array,
default: () => []
},
},
data() {
return {
isImageLoaded: false,
isVideoLoaded: false,
isImageError: false,
isVideoError: false,
caption: '',
image: null
}
},
computed: {
imageClasses() {
return [
{
'has-loaded-media': this.isImageLoaded || this.isVideoLoaded,
'has-full-media-error': this.isVideoError && this.isImageError && !this.isImageLoaded && !this.isVideoLoaded,
Comment on lines +76 to +77
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were just trying to show off classes, then cool.

But I think wp-image adds error and loading classes to itself already.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WpImage adds the class has-error if there is a video error OR image error. So if the video fails to load but the image fallback does load WpImage still adds the class had-error. I needed to add a class based on whether or not one of the two media types loaded successfully .has-loaded-media. I also needed a way to add a class based on whether or not both the image and video fully errored .has-full-media-error and then show the caption if so.

}
]

},
preparedList() {
let tempData = this.items
let {right, left} = _shapeListData(tempData, 3)
let trimmed = _shapeListData(left, 2)

return [
{
listItems: trimmed.left
},
{
listItems: trimmed.right
},
{
listItems: right
}
]
},

},
methods: {
videoLoaded() {
this.isVideoLoaded = true
},
imageLoaded() {
this.isImageLoaded = true
},
videoError() {
this.isVideoError = true
},
imageError() {
this.isImageError = true
},

mouseOver(item) {
this.caption = item.featuredImage.node.caption !== null ? item.featuredImage.node.caption : `Who the fuxt is ${item.title}?`
this.image = item.featuredImage.node
},
mouseOut() {
this.isVideoLoaded = false
this.isImageLoaded = false
this.isVideoError = false
this.isImageError = false
this.caption = ''
this.image = null
},
}

}
</script>


<style lang="scss" scoped>

.gallery-list {
position: relative;
z-index: 0;

max-width: 1280px;
min-height: var(--unit-100vh);
margin: 0 auto;
padding: 0 var(--unit-gap);
box-sizing: border-box;

display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

font-family: var(--font-primary);

.list {
margin: 0;
padding: 0;
list-style: none;
}

.list-main {
position: relative;
z-index: 20;

max-width: 1180px;
width: 100%;
height: 100%;
box-sizing: border-box;
margin: 0 auto;

display: flex;
justify-content: space-between;
}


.item-title {
display: inline-block;

margin: 0;
}

.link {
padding: 17px 0;

display: block;

font-size: 24px;
color: var(--color-yellow);
}

.wp-image {
position: absolute;
z-index: 10;

max-width: 960px;
width: 100%;
max-height: 540px;
height: 100%;
margin: auto;
overflow: hidden;
box-sizing: border-box;

&.has-loaded-media {
// don't hide media if video has 404 but item still has an image
/deep/ .media {
opacity: 1;
}
}

&.has-full-media-error {
// set overflow to visible in case the item name is long
overflow: visible;
// hide the sizer so the broken image icon isn't visible on 404 images
/deep/ .sizer {
visibility: hidden;
}

// display the caption
/deep/ .caption {
opacity: 1;
}
}
}

/deep/ .caption {
height: 100%;

display: flex;
flex-direction: column;
justify-content: center;

background: #212121;
text-align: right;
font-size: 8vw;
line-height: 1;
text-transform: uppercase;
color: #FFFFFFFF;
opacity: 0;

transition: opacity .4s ease-in-out;
transition-delay: .4s; // add slight delay so you don't see a flash of the caption on items that have image 404s but still have videos
}


@media #{$has-hover} {
.link {
&:hover {
color: var(--color-white);
}
}
}

@media #{$lt-phone} {
.list-main {
display: block;

text-align: center;
}

/deep/ .caption {
font-size: 18vw;
}
}
}
</style>
Loading