Skip to content

Commit

Permalink
🩹 Fix book shelf layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nwingt committed Nov 18, 2023
1 parent f099b67 commit 1dd007c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 4 deletions.
24 changes: 24 additions & 0 deletions src/components/NFTBook/Shelf.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import NFTBookShelf from './Shelf';

export default {
title: 'NFTBookShelf',
argTypes: {
itemCount: {
type: { name: 'number', required: false, min: 1, max: 30, step: 1 },
defaultValue: 4,
},
},
};

export const Default = (_, { argTypes }) => ({
components: {
NFTBookShelf,
},
props: Object.keys(argTypes),
template: `
<NFTBookShelf
:items="Array(this.itemCount).fill('').map((_, index) => ({ classId: \`likernft\${index}\` }))"
:is-dummy="true"
/>
`,
});
40 changes: 36 additions & 4 deletions src/components/NFTBook/Shelf.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
:key="item.classId"
class="max-w-[220px]"
>
<NFTBookItemCard
<component
:is="cardTag"
:class="{ 'h-[290px] w-[216px] bg-medium-gray': isDummy }"
:class-id="item.classId"
preset="shelf"
:shelf-class="[
Expand All @@ -34,8 +36,7 @@
:key="`dummy-${i}`"
:class="[
'hidden',
{ 'sm:block !desktop:hidden': i === 1 && normalizedItems.length % 2 > 0 },
{ 'desktop:block': i === 2 && normalizedItems.length % 3 > 0 },
getDummyResponsiveClass(i),
'relative',
'w-full',
'max-w-[220px]',
Expand Down Expand Up @@ -68,7 +69,8 @@
:id="classId"
:key="classId"
>
<NFTBookItemCard
<component
:is="cardTag"
:class-id="classId"
preset="default"
component-class="!bg-like-cyan-pale"
Expand All @@ -89,13 +91,20 @@ export default {
type: Array,
default: () => [],
},
isDummy: {
type: Boolean,
default: false,
},
},
data() {
return {
dialogNFTClassList: [],
};
},
computed: {
cardTag() {
return this.isDummy ? 'div' : 'NFTBookItemCard';
},
normalizedItems() {
return this.items.map(item => {
const isMultiple =
Expand All @@ -116,6 +125,29 @@ export default {
},
},
methods: {
getDummyResponsiveClass(index) {
const total = this.normalizedItems.length;
switch (total % 3) {
case 1:
if (index === 1 && total % 2 !== 0) {
return 'sm:block';
}
return 'desktop:block';
case 2:
if (index === 1) {
return 'sm:block';
}
return '';
case 0:
default:
if (index === 1 && total % 2 !== 0) {
return 'sm:block desktop:hidden';
}
return '';
}
},
handleClickItem(item) {
if (item.isMultiple) {
this.dialogNFTClassList = item.classIds;
Expand Down

0 comments on commit 1dd007c

Please sign in to comment.