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

feat(picture): default display style #33

Merged
merged 1 commit into from
Jun 27, 2024
Merged
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
31 changes: 12 additions & 19 deletions components/molecules/VPicture/VPicture.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import type { ExtractPropTypes } from 'vue'
import pick from 'lodash/pick'
import { pictureProps } from '#image/components/nuxt-picture'
import VImg from '~/components/molecules/VImg/VImg.vue'
import { imgProps } from '#image/components/nuxt-img'
import VImg from '~/components/molecules/VImg/VImg.vue'
import VPictureSource from '~/components/molecules/VPicture/VPictureSource.vue'

export const vPictureProps = {
Expand All @@ -21,30 +21,23 @@ export default defineComponent({
// Provide props to children (<sources>)
provide('pictureProps', props)

const $style = useCssModule()
const imgFilteredProps = computed(() => pick(props, Object.keys(imgProps)))
const img = h(VImg, {
...imgFilteredProps.value,
...props.imgAttrs,
})
const sources = computed(() => {
return context.slots.default?.() || h(VPictureSource)
})

return () => h('picture', null, [sources.value, img])
return () =>
h('picture', { class: $style.root }, [
context.slots.default?.() || h(VPictureSource),
h(VImg, {
...imgFilteredProps.value,
...props.imgAttrs,
}),
])
},
})
</script>

<style lang="scss" module>
.root img {
// for switching easily between VImg and VPicture, we use the same css var name
max-width: var(--v-img-max-width, 100%); // responsive image
height: var(--v-img-height, auto); // responsive image
background: var(--v-img-background, var(--v-img-placeholder));
}

.root--loaded img {
// Remove background when image is loaded. This is useful for hiding antialiasing artifacts.
--v-img-background: none;
.root {
display: var(--v-picture-display, fit-content);
}
</style>
Loading