This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+23
View File
@@ -0,0 +1,23 @@
@import './_variables.scss'
.v-responsive
position: relative
overflow: hidden
flex: 1 0 auto
max-width: 100%
display: flex
&__content
flex: 1 0 0px
max-width: 100%
&__sizer ~ &__content
+ltr()
margin-left: -100%
+rtl()
margin-right: -100%
&__sizer
transition: padding-bottom 0.2s map-get($transition, 'swing')
flex: 1 0 0px
+57
View File
@@ -0,0 +1,57 @@
import './VResponsive.sass'
// Mixins
import Measurable, { NumberOrNumberString } from '../../mixins/measurable'
// Types
import { VNode } from 'vue'
// Utils
import mixins from '../../util/mixins'
/* @vue/component */
export default mixins(Measurable).extend({
name: 'v-responsive',
props: {
aspectRatio: [String, Number] as NumberOrNumberString,
},
computed: {
computedAspectRatio (): number {
return Number(this.aspectRatio)
},
aspectStyle (): object | undefined {
return this.computedAspectRatio
? { paddingBottom: (1 / this.computedAspectRatio) * 100 + '%' }
: undefined
},
__cachedSizer (): VNode | [] {
if (!this.aspectStyle) return []
return this.$createElement('div', {
style: this.aspectStyle,
staticClass: 'v-responsive__sizer',
})
},
},
methods: {
genContent (): VNode {
return this.$createElement('div', {
staticClass: 'v-responsive__content',
}, this.$slots.default)
},
},
render (h): VNode {
return h('div', {
staticClass: 'v-responsive',
style: this.measurableStyles,
on: this.$listeners,
}, [
this.__cachedSizer,
this.genContent(),
])
},
})
@@ -0,0 +1,47 @@
// Components
import VResponsive from '../VResponsive'
// Utilities
import {
mount,
Wrapper,
} from '@vue/test-utils'
describe('VResponsive.ts', () => {
type Instance = InstanceType<typeof VResponsive>
let mountFunction: (options?: object) => Wrapper<Instance>
beforeEach(() => {
mountFunction = (options = {}) => {
return mount(VResponsive, {
...options,
})
}
})
it('should force aspect ratio', () => {
const wrapper = mountFunction({
propsData: { aspectRatio: 16 / 9 },
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should render content', () => {
const wrapper = mountFunction({
slots: {
default: { render: h => h('div', ['content']) },
},
})
expect(wrapper.html()).toMatchSnapshot()
})
it('should set height', () => {
const wrapper = mountFunction({
propsData: { height: 100, maxHeight: 200 },
})
expect(wrapper.html()).toMatchSnapshot()
})
})
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`VResponsive.ts should force aspect ratio 1`] = `
<div class="v-responsive">
<div class="v-responsive__sizer"
style="padding-bottom: 56.25%;"
>
</div>
<div class="v-responsive__content">
</div>
</div>
`;
exports[`VResponsive.ts should render content 1`] = `
<div class="v-responsive">
<div class="v-responsive__content">
<div>
content
</div>
</div>
</div>
`;
exports[`VResponsive.ts should set height 1`] = `
<div class="v-responsive"
style="height: 100px; max-height: 200px;"
>
<div class="v-responsive__content">
</div>
</div>
`;
+3
View File
@@ -0,0 +1,3 @@
@import '../../styles/styles.sass';
$responsive-transition: padding-bottom 0.2s map-get($transition, 'swing') !default;
+4
View File
@@ -0,0 +1,4 @@
import VResponsive from './VResponsive'
export { VResponsive }
export default VResponsive