Skip to content

Commit

Permalink
Fixed #5502 - Add PrimeVueStyled and PrimeVueUnstyled plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Apr 1, 2024
1 parent 0e70f79 commit 71715f5
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 41 deletions.
51 changes: 10 additions & 41 deletions components/lib/config/PrimeVue.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { FilterMatchMode } from 'primevue/api';
import Theme, { ThemeService } from 'primevue/themes';
import PrimeOne from 'primevue/themes/primeone';
import Aura from 'primevue/themes/primeone/aura';
import { inject, reactive, ref, watch } from 'vue';
import { inject, reactive } from 'vue';

export const defaultOptions = {
ripple: false,
Expand Down Expand Up @@ -136,21 +133,11 @@ export const defaultOptions = {
menu: 1000,
tooltip: 1100
},
theme: {
base: PrimeOne,
preset: Aura,
options: {
prefix: 'p',
darkModeSelector: 'system',
cssLayer: false
}
},
pt: undefined,
ptOptions: {
mergeSections: true,
mergeProps: false
},
unstyled: false,
csp: {
nonce: undefined
}
Expand All @@ -168,37 +155,19 @@ export function usePrimeVue() {
return PrimeVue;
}

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

watch(
PrimeVue.config.theme,
(newValue) => {
if (!isChanged.value) {
Theme.setTheme(newValue);
}
export function setup(app, options) {
const PrimeVue = {
config: reactive(options)
};

isChanged.value = false;
},
{ immediate: true, deep: true }
);
app.config.globalProperties.$primevue = PrimeVue;
app.provide(PrimeVueSymbol, PrimeVue);

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

export default {
install: (app, options) => {
const configOptions = options ? { ...defaultOptions, ...options } : { ...defaultOptions };
const PrimeVue = {
config: reactive(configOptions)
};

app.config.globalProperties.$primevue = PrimeVue;
app.provide(PrimeVueSymbol, PrimeVue);

setupTheme(app, PrimeVue);
install: () => {
console.error("This plugin has been removed in v4 version. Use 'PrimeVueStyled' plugin for styled mode, and 'PrimeVueUnstyled' plugin for unstyled mode.");
}
};
1 change: 1 addition & 0 deletions components/lib/styled/PrimeVueStyled.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../config';
50 changes: 50 additions & 0 deletions components/lib/styled/PrimeVueStyled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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,
theme: {
base: PrimeOne,
preset: Aura,
options: {
prefix: 'p',
darkModeSelector: 'system',
cssLayer: false
}
}
};

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);
}
};
6 changes: 6 additions & 0 deletions components/lib/styled/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"main": "./primevuestyled.cjs.js",
"module": "./primevuestyled.esm.js",
"unpkg": "./primevuestyled.min.js",
"types": "./PrimeVueStyled.d.ts"
}
1 change: 1 addition & 0 deletions components/lib/unstyled/PrimeVueUnstyled.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../config';
11 changes: 11 additions & 0 deletions components/lib/unstyled/PrimeVueUnstyled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import * as PrimeVueConfig from 'primevue/config';

export const { defaultOptions, usePrimeVue } = PrimeVueConfig;

export default {
install: (app, options) => {
const configOptions = { ...defaultOptions, ...options, unstyled: true };

PrimeVueConfig.setup(app, configOptions);
}
};
6 changes: 6 additions & 0 deletions components/lib/unstyled/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"main": "./primevueunstyled.cjs.js",
"module": "./primevueunstyled.esm.js",
"unpkg": "./primevueunstyled.min.js",
"types": "./PrimeVueUnstyled.d.ts"
}

0 comments on commit 71715f5

Please sign in to comment.