Skip to content

Commit

Permalink
Refactor #5502
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Apr 2, 2024
1 parent da631a7 commit 3dcf555
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 29 deletions.
7 changes: 5 additions & 2 deletions components/lib/base/style/BaseStyle.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import Theme, { $dt } from 'primevue/themes';
import Theme from 'primevue/themes';
import { useStyle } from 'primevue/usestyle';
import { ObjectUtils } from 'primevue/utils';

/**
* @todo padding-right: ${$dt('scrollbar.width')};
*/
const css = `
.p-hidden-accessible {
border: 0;
Expand All @@ -21,7 +24,7 @@ const css = `
.p-overflow-hidden {
overflow: hidden;
padding-right: ${$dt('scrollbar.width')};
padding-right: var(--p-scrollbar-width);
}
`;

Expand Down
26 changes: 25 additions & 1 deletion components/lib/config/PrimeVue.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { FilterMatchMode } from 'primevue/api';
import { inject, reactive } from 'vue';
import Theme, { ThemeService } from 'primevue/themes';
import { inject, reactive, ref, watch } from 'vue';

export const defaultOptions = {
ripple: false,
Expand Down Expand Up @@ -165,9 +166,32 @@ export function setup(app, options) {
app.config.globalProperties.$primevue = PrimeVue;
app.provide(PrimeVueSymbol, PrimeVue);

setupTheme(app, PrimeVue);

return PrimeVue;
}

export function setupTheme(app, PrimeVue) {
const isChanged = ref(false);

watch(
PrimeVue.config.theme,
(newValue) => {
if (!isChanged.value) {
Theme.setTheme(newValue);
}

isChanged.value = false;
},
{ immediate: true, deep: true }
);

ThemeService.on('theme:change', function (newTheme) {
isChanged.value = true;
app.config.globalProperties.$primevue.config.theme = newTheme;
});
}

export default {
install: (app, options) => {
const configOptions = { ...defaultOptions, ...options };
Expand Down
26 changes: 1 addition & 25 deletions components/lib/styled/PrimeVueStyled.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as PrimeVueConfig from 'primevue/config';
import Theme, { ThemeService } from 'primevue/themes';
import PrimeOne from 'primevue/themes/primeone';
import Aura from 'primevue/themes/primeone/aura';
import { ref, watch } from 'vue';

export const defaultOptions = {
...PrimeVueConfig.defaultOptions,
Expand All @@ -19,32 +17,10 @@ export const defaultOptions = {

export const { usePrimeVue } = PrimeVueConfig;

function setupTheme(app, PrimeVue) {
const isChanged = ref(false);

watch(
PrimeVue.config.theme,
(newValue) => {
if (!isChanged.value) {
Theme.setTheme(newValue);
}

isChanged.value = false;
},
{ immediate: true, deep: true }
);

ThemeService.on('theme:change', function (newTheme) {
isChanged.value = true;
app.config.globalProperties.$primevue.config.theme = newTheme;
});
}

export default {
install: (app, options) => {
const configOptions = { ...defaultOptions, ...options, unstyled: false };
const PrimeVue = PrimeVueConfig.setup(app, configOptions);

setupTheme(app, PrimeVue);
PrimeVueConfig.setup(app, configOptions);
}
};
1 change: 0 additions & 1 deletion components/lib/themes/actions/useTheme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Theme from 'primevue/themes';

export default (theme) => {
// @todo
const [{ options: o1 }, { options: o2 }] = [Theme.getTheme(), theme];
const newTheme = {
...theme,
Expand Down

0 comments on commit 3dcf555

Please sign in to comment.