Refactor #3965 - For InlineMessage

pull/3997/head
Bahadır Sofuoğlu 2023-05-25 17:15:19 +03:00
parent 34d2b65236
commit 0d3816522a
3 changed files with 66 additions and 36 deletions

View File

@ -0,0 +1,56 @@
<script>
import BaseComponent from 'primevue/basecomponent';
import { useStyle } from 'primevue/usestyle';
const styles = `
.p-inline-message {
display: inline-flex;
align-items: center;
justify-content: center;
vertical-align: top;
}
.p-inline-message-icon-only .p-inline-message-text {
visibility: hidden;
width: 0;
}
.p-fluid .p-inline-message {
display: flex;
}
`;
const classes = {
root: ({ props, instance }) => ['p-inline-message p-component p-inline-message-' + props.severity, { 'p-inline-message-icon-only': !instance.$slots.default }],
icon: ({ props }) => ['p-inline-message-icon', props.icon],
text: 'p-inline-message-text'
};
const { load: loadStyle } = useStyle(styles, { id: 'primevue_inlinemessage_style', manual: true });
export default {
name: 'BaseInlineMessage',
extends: BaseComponent,
props: {
severity: {
type: String,
default: 'error'
},
icon: {
type: String,
default: undefined
}
},
css: {
classes
},
watch: {
isUnstyled: {
immediate: true,
handler(newValue) {
!newValue && loadStyle();
}
}
}
};
</script>

View File

@ -76,6 +76,11 @@ export interface InlineMessageProps {
* @type {InlineMessagePassThroughOptions}
*/
pt?: InlineMessagePassThroughOptions;
/**
* When enabled, it removes component related styles in the core.
* @defaultValue false
*/
unstyled?: boolean;
}
/**
* Defines valid slots in InlineMessage slots.

View File

@ -1,16 +1,16 @@
<template>
<div aria-live="polite" :class="containerClass" v-bind="ptm('root')">
<div aria-live="polite" :class="cx('root')" v-bind="ptm('root')">
<slot name="icon">
<component :is="icon ? 'span' : iconComponent" :class="['p-inline-message-icon', icon]" v-bind="ptm('icon')"></component>
<component :is="icon ? 'span' : iconComponent" :class="cx('icon')" v-bind="ptm('icon')"></component>
</slot>
<span class="p-inline-message-text" v-bind="ptm('text')">
<span :class="cx('text')" v-bind="ptm('text')">
<slot>&nbsp;</slot>
</span>
</div>
</template>
<script>
import BaseComponent from 'primevue/basecomponent';
import BaseInlineMessage from './BaseInlineMessage.vue';
import CheckIcon from 'primevue/icons/check';
import ExclamationTriangleIcon from 'primevue/icons/exclamationtriangle';
import InfoCircleIcon from 'primevue/icons/infocircle';
@ -18,17 +18,7 @@ import TimesCircleIcon from 'primevue/icons/timescircle';
export default {
name: 'InlineMessage',
extends: BaseComponent,
props: {
severity: {
type: String,
default: 'error'
},
icon: {
type: String,
default: undefined
}
},
extends: BaseInlineMessage,
timeout: null,
data() {
return {
@ -43,9 +33,6 @@ export default {
}
},
computed: {
containerClass() {
return ['p-inline-message p-component p-inline-message-' + this.severity, { 'p-inline-message-icon-only': !this.$slots.default }];
},
iconComponent() {
return {
info: InfoCircleIcon,
@ -57,21 +44,3 @@ export default {
}
};
</script>
<style>
.p-inline-message {
display: inline-flex;
align-items: center;
justify-content: center;
vertical-align: top;
}
.p-inline-message-icon-only .p-inline-message-text {
visibility: hidden;
width: 0;
}
.p-fluid .p-inline-message {
display: flex;
}
</style>