2023-03-21 12:05:24 +00:00
|
|
|
<script>
|
|
|
|
import { ObjectUtils } from 'primevue/utils';
|
2023-05-10 11:49:54 +00:00
|
|
|
import { mergeProps } from 'vue';
|
2023-03-21 12:05:24 +00:00
|
|
|
|
2023-05-19 10:32:44 +00:00
|
|
|
const inlineStyles = {
|
|
|
|
hiddenAccessible: {
|
|
|
|
border: '0',
|
|
|
|
clip: 'rect(0 0 0 0)',
|
|
|
|
height: '1px',
|
|
|
|
margin: '-1px',
|
|
|
|
overflow: 'hidden',
|
|
|
|
padding: '0',
|
|
|
|
position: 'absolute',
|
|
|
|
width: '1px'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-03-21 12:05:24 +00:00
|
|
|
export default {
|
2023-03-31 21:51:41 +00:00
|
|
|
name: 'BaseComponent',
|
2023-03-21 12:05:24 +00:00
|
|
|
props: {
|
|
|
|
pt: {
|
|
|
|
type: Object,
|
2023-04-26 08:57:02 +00:00
|
|
|
default: undefined
|
2023-05-16 10:29:56 +00:00
|
|
|
},
|
|
|
|
unstyled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: undefined
|
2023-03-21 12:05:24 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2023-05-10 11:49:54 +00:00
|
|
|
getOption(obj = {}, key = '') {
|
2023-04-03 00:12:25 +00:00
|
|
|
const fKey = ObjectUtils.convertToFlatCase(key);
|
|
|
|
|
|
|
|
return obj[Object.keys(obj).find((k) => ObjectUtils.convertToFlatCase(k) === fKey) || ''];
|
|
|
|
},
|
2023-04-25 11:36:01 +00:00
|
|
|
getPTValue(obj = {}, key = '', params = {}) {
|
2023-05-10 11:49:54 +00:00
|
|
|
const self = ObjectUtils.getItemValue(this.getOption(obj, key), params);
|
|
|
|
const globalPT = ObjectUtils.getItemValue(this.getOption(this.defaultPT, key), params);
|
|
|
|
const merged = mergeProps(self, globalPT);
|
2023-04-25 11:36:01 +00:00
|
|
|
|
2023-05-10 11:49:54 +00:00
|
|
|
return merged;
|
|
|
|
/*
|
|
|
|
* @todo: The 'class' option in self can always be more powerful to style the component easily.
|
|
|
|
*
|
|
|
|
* return self && self['class'] ? { ...merged, ...{ class: self['class'] } } : merged;
|
|
|
|
*/
|
2023-04-25 11:36:01 +00:00
|
|
|
},
|
2023-03-21 12:05:24 +00:00
|
|
|
ptm(key = '', params = {}) {
|
2023-04-25 11:36:01 +00:00
|
|
|
return this.getPTValue(this.pt, key, { props: this.$props, state: this.$data, ...params });
|
2023-03-22 12:11:03 +00:00
|
|
|
},
|
|
|
|
ptmo(obj = {}, key = '', params = {}) {
|
2023-04-25 11:36:01 +00:00
|
|
|
return this.getPTValue(obj, key, params);
|
2023-05-19 10:32:44 +00:00
|
|
|
},
|
|
|
|
css(key = '', params = {}) {
|
|
|
|
return !this.isUnstyled ? ObjectUtils.getItemValue(this.getOption(this.$options.style && this.$options.style.classes, key), { instance: this, props: this.$props, state: this.$data, ...params }) : undefined;
|
|
|
|
},
|
|
|
|
style(key = '', when = true, params = {}) {
|
|
|
|
if (when) {
|
|
|
|
const self = ObjectUtils.getItemValue(this.getOption(this.$options.style && this.$options.style.inlineStyles, key), { instance: this, props: this.$props, state: this.$data, ...params });
|
|
|
|
const base = ObjectUtils.getItemValue(this.getOption(inlineStyles, key), { instance: this, props: this.$props, state: this.$data, ...params });
|
|
|
|
|
|
|
|
return [base, self];
|
|
|
|
}
|
|
|
|
|
|
|
|
return undefined;
|
2023-03-21 12:05:24 +00:00
|
|
|
}
|
2023-05-10 11:49:54 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
defaultPT() {
|
|
|
|
return ObjectUtils.getItemValue(this.getOption(this.$primevue.config.pt, this.$.type.name), this.defaultsParams);
|
|
|
|
},
|
|
|
|
defaultsParams() {
|
2023-05-19 10:32:44 +00:00
|
|
|
return { instance: this };
|
2023-05-16 10:29:56 +00:00
|
|
|
},
|
|
|
|
isUnstyled() {
|
|
|
|
return this.unstyled !== undefined ? this.unstyled : this.$primevue.config.unstyled;
|
2023-05-10 11:49:54 +00:00
|
|
|
}
|
2023-03-21 12:05:24 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|