Refactor #3965 - For ScrollTop

pull/3997/head
Bahadır Sofuoğlu 2023-05-24 13:09:45 +03:00
parent ab3343a751
commit bff2abf68a
6 changed files with 94 additions and 65 deletions

View File

@ -48,7 +48,7 @@ const classes = {
icon: ({ props }) => ['p-avatar-icon', props.icon]
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_divider_style', manual: true });
const { load: loadStyle } = useStyle(styles, { id: 'primevue_avatar_style', manual: true });
export default {
name: 'BaseAvatar',

View File

@ -38,10 +38,10 @@ const classes = {
removeIcon: ({ props }) => ['p-chip-remove-icon', props.removeIcon]
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_divider_style', manual: true });
const { load: loadStyle } = useStyle(styles, { id: 'primevue_chip_style', manual: true });
export default {
name: 'BaseAvatar',
name: 'BaseChip',
extends: BaseComponent,
props: {
label: {

View File

@ -29,10 +29,10 @@ const classes = {
closeButton: ({ props }) => props.closeIcon
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_divider_style', manual: true });
const { load: loadStyle } = useStyle(styles, { id: 'primevue_inplace_style', manual: true });
export default {
name: 'BaseAvatar',
name: 'BaseInplace',
extends: BaseComponent,
props: {
closable: {

View File

@ -0,0 +1,80 @@
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
const styles = `
.p-scrolltop {
position: fixed;
bottom: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.p-scrolltop-sticky {
position: sticky;
}
.p-scrolltop-sticky.p-link {
margin-left: auto;
}
.p-scrolltop-enter-from {
opacity: 0;
}
.p-scrolltop-enter-active {
transition: opacity 0.15s;
}
.p-scrolltop.p-scrolltop-leave-to {
opacity: 0;
}
.p-scrolltop-leave-active {
transition: opacity 0.15s;
}
`;
const classes = {
root: ({ props }) => ['p-scrolltop p-link p-component', { 'p-scrolltop-sticky': props.target !== 'window' }],
icon: ({ props }) => ['p-scrolltop-icon', props.icon]
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_scrolltop_style', manual: true });
export default {
name: 'BaseScrollTop',
extends: BaseComponent,
props: {
target: {
type: String,
default: 'window'
},
threshold: {
type: Number,
default: 400
},
icon: {
type: String,
default: undefined
},
behavior: {
type: String,
default: 'smooth'
}
},
css: {
classes
},
watch: {
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && loadStyle();
}
}
}
};
</script>

View File

@ -82,6 +82,11 @@ export interface ScrollTopProps {
* @type {ScrollTopPassThroughOptions}
*/
pt?: ScrollTopPassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}
/**

View File

@ -1,41 +1,23 @@
<template>
<transition name="p-scrolltop" appear @enter="onEnter" @after-leave="onAfterLeave">
<button v-if="visible" :ref="containerRef" :class="containerClass" @click="onClick" type="button" :aria-label="scrollTopAriaLabel" v-bind="ptm('root')">
<button v-if="visible" :ref="containerRef" :class="cx('root')" @click="onClick" type="button" :aria-label="scrollTopAriaLabel" v-bind="ptm('root')">
<slot name="icon">
<component :is="icon ? 'span' : 'ChevronUpIcon'" :class="['p-scrolltop-icon', icon]" v-bind="ptm('icon')" />
<component :is="icon ? 'span' : 'ChevronUpIcon'" :class="cx('icon')" v-bind="ptm('icon')" />
</slot>
</button>
</transition>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
import BaseScrollTop from './BaseScrollTop.vue';
import ChevronUpIcon from 'primevue/icons/chevronup';
import { DomHandler, ZIndexUtils } from 'primevue/utils';
export default {
name: 'ScrollTop',
extends: BaseComponent,
extends: BaseScrollTop,
scrollListener: null,
container: null,
props: {
target: {
type: String,
default: 'window'
},
threshold: {
type: Number,
default: 400
},
icon: {
type: String,
default: undefined
},
behavior: {
type: String,
default: 'smooth'
}
},
data() {
return {
visible: false
@ -104,9 +86,6 @@ export default {
}
},
computed: {
containerClass() {
return ['p-scrolltop p-link p-component', { 'p-scrolltop-sticky': this.target !== 'window' }];
},
scrollTopAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.scrollTop : undefined;
}
@ -116,38 +95,3 @@ export default {
}
};
</script>
<style>
.p-scrolltop {
position: fixed;
bottom: 20px;
right: 20px;
display: flex;
align-items: center;
justify-content: center;
}
.p-scrolltop-sticky {
position: sticky;
}
.p-scrolltop-sticky.p-link {
margin-left: auto;
}
.p-scrolltop-enter-from {
opacity: 0;
}
.p-scrolltop-enter-active {
transition: opacity 0.15s;
}
.p-scrolltop.p-scrolltop-leave-to {
opacity: 0;
}
.p-scrolltop-leave-active {
transition: opacity 0.15s;
}
</style>