Note: By the end of Q1 2024, PrimeVue v4 will be introduced with a modern theming architecture based on design tokens and css variables.
-- PrimeVue is a design agnostic library so unlike other UI libraries it does not enforce a certain styling such as material or bootstrap. In order to achieve this, styling has been separated into two parts, core and theme. The core resides - inside PrimeVue to implement the structure of the components such as positioning whereas theme brings the colors and spacing. -
- -- PrimeVue ships with various free themes to choose from. The list below states all the available themes in the npm distribution with import paths. For a live preview, use the configurator - at the topbar to switch themes. -
-Each PrimeVue theme exports numerous CSS variables, refer to
- Themes are created with SASS using the primevue-sass-theme project available at github. This repository contains all the scss files for the components and the variables - of the built-in themes so that you may customize an existing theme or create your own. The scss variables used in a theme are available at the SASS API documentation. -
-- There are 2 alternatives to create your own theme. First option is compiling a theme with command line sass whereas second option is embedding scss files within your project to let your build environment do the compilation. In all cases, - the generated theme file should be imported to your project. -
- -- The theme scss is available as open source at primevue-sass-theme repository. The theme-base folder contains the theming structure of the components, themes under - themes folder import the base and define the SCSS variables. The themes folder also contains all the built-in themes so you can customize their code as well. -
-- To create your own theme, download the release matching your PrimeVue version and access the themes/mytheme folder. The sass variables to customize are - available under the variables folder. The _fonts file can be used to define a custom font for your project whereas the optional _extensions file is provided to add overrides to the components designs. The - theme.scss file imports the theme files along with the theme-base folder at the root to combine everything together. Next step would be compilation of the scss that can either be command line or within your project. -
- -Once your theme is ready run the following command to compile it. Note that sass command should be available in your terminal.
-- Then copy and import the theme.css file in your application. For example, in a Vite based template like create-vue, you may place theme.css under assets folder and then import it an - main.js. -
-- This approach eliminates the manual compilation by delegating it to your build environment that has the ability to compile SCSS. Copy the theme-base folder along with themes/mytheme folder to your application where assets - reside. At a suitable location like main.js or App.vue, import the theme.scss from assets/themes/mytheme. That would be it, during build time, your project will compile the sass and import the theme. Any - changes to your theme will be reflected instantly. -
-- PrimeFlex is a lightweight responsive CSS utility library to accompany Prime UI libraries and static webpages as well. PrimeVue can be used with any CSS utility library like bootstrap and tailwind - however PrimeFlex has benefits like integration with PrimeVue themes using CSS variables so that colors classes e.g. bg-blue-500 receive the color code from the PrimeVue theme being used. PrimeVue follows the CSS utility approach - of PrimeFlex and currently does not provide an extended style property like sx. Same approach is also utilized in PrimeBlocks for PrimeVue project as well. -
- -Here is an example to demonstrate how to align 3 buttons horizontally on bigger screens and display them as stacked on smaller ones.
-- Solution below works however there is room for improvement. The upcoming styling api will greatly improve dynamic theme switching ability, eliminates the prerequisites with the introduction of CSS variables and dynamic imports. -
-- Themes can be dynamically changed using the PrimeVue.changeTheme function. For this feature to work, there are two prerequisites. To begin with, the themes should be publicly available under the public folder in your project - by copying them from PrimeVue resources/themes folder. Second part is making the theme.css accessible via a link element so that the id of the link can be provided as the 3rd parameter to the changeTheme function. -
-In a Vite based project like create-vue, the link can be placed at index.html.
-Nuxt applications can configure the link element using nuxt.config.js.
-In addition to PrimeFlex, PrimeVue has a couple of css utility classes on its own as well.
-Name | -Description | -
---|---|
p-component | -Applies component theming such as font-family and font-size to an element. | -
p-fluid | -Applies 100% width to all descendant components. | -
p-disabled | -Applies an opacity to display as disabled. | -
p-sr-only | -Element becomes visually hidden however accessibility is still available. | -
p-reset | -Resets the browsers defaults. | -
p-link | -Renders a button as a link. | -
p-error | -Indicates an error text. | -
p-invalid | -Applies the invalid style to a text or a form field. | -
+ PrimeVue is a design agnostic library so unlike some other UI libraries it does not enforce a certain styling such as material design. Styling is decoupled from the components using the themes instead. A theme consists of two parts; + base and preset. The base is the style rules with CSS variables as placeholders whereas the preset is a set of design tokens to feed a base by mapping the tokens to CSS variables. A base may be configured with different + presets, currently Aura is the only preset and in upcoming version more presets will be available. Similarly, PrimeOne is the default base and a new base inspired by Material Design is coming up with a near future update. +
+ +The core of the styled mode architecture is based on a concept named design token, a preset defines the token configuration in 3 tiers; primitive, semantic and component.
++ Primitive tokens have no context, a color palette is a good example for a primitive token such as blue-50 to blue-900. A token named blue-500 may be used as the primary color, the background of a message however on + its own, the name of the token does not indicate context. Usually they are utilized by the semantic tokens. +
+ ++ Semantic tokens define content and their names indicate where they are utilized, a well known example of a semantic token is the primary.color. Semantic tokens map to primitive tokens or other semantic tokens. The + colorScheme token group is a special variable to define tokens based on the color scheme active in the application, this allows defining different tokens based on the color scheme like implementing dark mode. +
+ ++ Component tokens are isolated tokens per component such as inputtext.background or button.color that map to the semantic tokens. As an example, button.background component token maps to the + primary.color semantic token which maps to the green.500 primitive token. +
+ ++ Use primitive tokens when defining the core color palette and semantic tokens to specify the common design elements such as focus ring, primary colors and surfaces. Components tokens should only be used when customizing a specific + component. By defining your own design tokens as a custom preset, you'll be able to define your own style without touching CSS. Overriding the PrimeVue components using style classes is not a best practice and should be the last resort, + design tokens are the suggested approach. +
+CSS Layer.
+CSS Layer.
+The options property defines the how the CSS would be generated from the design tokens of the preset.
+The prefix of the CSS variables, defaults to p. For instance, the primary.color design token would be var(--p-primary-color).
++ The CSS rule to encapsulate the CSS variables of the dark mode, the default is the system to generate @media (prefers-color-scheme: dark). If you need to make the dark mode toggleable based on the user selection define a + class selector such as .app-dark and toggle this class at the document root. See the dark mode toggle section below for example. +
++ Defines whether the styles should be defined inside a CSS layer named primevue or not. A CSS layer would be handy to + declare a custom cascade layer for easier customization. The default is false. View the CSS layer section for an example usage. +
+The theme property is used to customize the initial theme that is preconfigured to be PrimeOne base with the Aura preset by default. The following is the default configuration and only needs to be defined for customization.
+ +Choose from a variety of themes or develop your own theme easily.
-Choose from a variety of pre-styled themes or develop your own..
+