-
Notifications
You must be signed in to change notification settings - Fork 4
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
add BIMDataList component #358
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<template> | ||
<div | ||
class="bimdata-list" | ||
@scroll="computeIndexes" | ||
:style="`--bimdata-list--item-height: ${itemHeight}px`" | ||
> | ||
<div | ||
class="bimdata-list__placeholder" | ||
:style="`height: ${items.length * itemHeight}px;`" | ||
></div> | ||
<div | ||
class="bimdata-list__element" | ||
v-for="(item, index) in displayedItems" | ||
:key="itemKey ? item[itemKey] : item" | ||
:style="`height: ${itemHeight}px; top: ${ | ||
(offsetedStartIndex + index) * itemHeight | ||
}px`" | ||
> | ||
<slot :item="item"> | ||
{{ item }} | ||
</slot> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: "BIMDataList", | ||
props: { | ||
items: { | ||
type: Array, | ||
required: true, | ||
}, | ||
itemHeight: { | ||
type: Number, | ||
default: 30, | ||
}, | ||
offset: { | ||
type: Number, | ||
default: 20, | ||
}, | ||
itemKey: { | ||
type: String, | ||
default: null, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
startIndex: 0, | ||
endIndex: 0, | ||
}; | ||
}, | ||
computed: { | ||
offsetedStartIndex() { | ||
return Math.max(this.startIndex - this.offset, 0); | ||
}, | ||
offsetedEndIndex() { | ||
return Math.min(this.endIndex + this.offset, this.items.length); | ||
}, | ||
displayedItems() { | ||
return this.items.slice( | ||
this.offsetedStartIndex, | ||
this.offsetedEndIndex + 1 | ||
); | ||
}, | ||
}, | ||
mounted() { | ||
this.computeIndexes(); | ||
}, | ||
methods: { | ||
computeIndexes() { | ||
const { itemHeight, items, $el } = this; | ||
const { scrollTop, clientHeight } = $el; | ||
|
||
const startIndex = Math.floor(scrollTop / itemHeight); | ||
|
||
const endIndex = Math.min( | ||
startIndex + Math.ceil(clientHeight / itemHeight) + 1, | ||
items.length | ||
); | ||
|
||
this.startIndex = startIndex; | ||
this.endIndex = endIndex; | ||
}, | ||
}, | ||
}; | ||
</script> | ||
|
||
<style scoped lang="scss"> | ||
.bimdata-list { | ||
margin: 0; | ||
padding: 0; | ||
list-style: none; | ||
border: 1px solid #ccc; | ||
|
||
width: 100%; | ||
height: 100%; | ||
overflow: auto; | ||
|
||
position: relative; | ||
|
||
&__element { | ||
overflow: hidden; | ||
position: absolute; | ||
width: 100%; | ||
} | ||
|
||
&__placeholder { | ||
background: repeating-linear-gradient( | ||
#ffffff, | ||
#ffffff calc(var(--bimdata-list--item-height, 30px) - 1px), | ||
var(--color-silver, #000000) | ||
calc(var(--bimdata-list--item-height, 30px) - 1px), | ||
var(--color-silver, #000000) var(--bimdata-list--item-height, 30px) | ||
); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<template> | ||
<main class="article"> | ||
<div class="article-wrapper"> | ||
<BIMDataText component="h1" color="color-primary"> | ||
{{ $route.name }} | ||
</BIMDataText> | ||
<ComponentCode | ||
:componentTitle="$route.name" | ||
language="javascript" | ||
githubLink="https://github.com/bimdata/design-system/blob/develop/src/BIMDataComponents/BIMDataList/BIMDataList.vue" | ||
> | ||
<template #module> | ||
<div style="width: 100%; height: 400px"> | ||
<BIMDataList | ||
:items="items" | ||
:itemHeight="+itemHeight" | ||
:offset="+offset" | ||
> | ||
<template #default="{ item }"> | ||
{{ item }} | ||
</template> | ||
</BIMDataList> | ||
</div> | ||
</template> | ||
|
||
<template #parameters> | ||
<BIMDataInput | ||
margin="24px 0" | ||
type="number" | ||
placeholder="Item height" | ||
v-model="itemHeight" | ||
/> | ||
<BIMDataInput | ||
margin="24px 0" | ||
type="number" | ||
placeholder="List size" | ||
v-model="size" | ||
/> | ||
<BIMDataInput | ||
margin="24px 0" | ||
type="number" | ||
placeholder="Offset" | ||
v-model="offset" | ||
/> | ||
</template> | ||
|
||
<template #import> | ||
import BIMDataList from | ||
"@bimdata/design-system/src/BIMDataComponents/BIMDataList/BIMDataList.vue" | ||
</template> | ||
|
||
<template #code> | ||
<pre> | ||
<BIMDataList | ||
:items="items" | ||
:itemHeight="{{ +itemHeight }}" | ||
:offset="{{ +offset }}" | ||
/> | ||
<template #default="{ item }"> | ||
{{ item }} | ||
</template> | ||
</BIMDataList> | ||
</pre> | ||
</template> | ||
</ComponentCode> | ||
|
||
<div class="m-t-12"> | ||
<BIMDataText component="h5" margin="15px 0 0" color="color-primary"> | ||
Props: | ||
</BIMDataText> | ||
<BIMDataTable :columns="propsData[0]" :rows="propsData.slice(1)" /> | ||
</div> | ||
</div> | ||
</main> | ||
</template> | ||
|
||
<script> | ||
import propsData from "./props-data.js"; | ||
|
||
import ComponentCode from "../../Elements/ComponentCode/ComponentCode.vue"; | ||
|
||
const getData = (size = 100) => | ||
Array.from({ length: size }, (_, i) => `Item ${i + 1}`); | ||
|
||
export default { | ||
components: { | ||
ComponentCode, | ||
}, | ||
data() { | ||
return { | ||
size: 1000, | ||
itemHeight: 30, | ||
offset: 20, | ||
// Data | ||
propsData, | ||
}; | ||
}, | ||
computed: { | ||
items() { | ||
return getData(+this.size); | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint-disable */ | ||
export default [ | ||
[ "Props", "Type", "Default value", "Description" ], | ||
[ | ||
"items", | ||
"any", | ||
"REQUIRED", | ||
"Items to display in the list.", | ||
], | ||
[ | ||
"itemHeight", | ||
"Number", | ||
"30", | ||
"The height of each item in pixels.", | ||
], | ||
[ | ||
"offset", | ||
"Number", | ||
"20", | ||
"The number of items to render outside the visible area to improve scrolling smoothness.", | ||
], | ||
[ | ||
"itemKey", | ||
"String", | ||
"null", | ||
"The key to use for looping on each item.", | ||
] | ||
]; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.