You can customize the components by overriding Sass variables and importing the components from keen-ui/src
if you use Sass in your project with one the following setups:
- Vite
- Vue CLI
- Webpack and
vue-loader
-
Create a
variables.scss
file somewhere in your project, for example, atsrc/styles/variables.scss
.Note Since this file will be imported into every Sass file, make sure it doesn't contain any CSS rules. It should contain only Sass variables, functions or mixins.
-
If you're using Vite, add the following to
vite.config.js
(more details here):const scssVariablesFile = path .resolve(__dirname, "./src/styles/variables.scss") .replace(/\\/g, "/"); export default defineConfig({ css: { preprocessorOptions: { scss: { additionalData: `@use "${scssVariablesFile}" as *;`, }, }, }, });
See
usage-examples/vite-sass-customization
for a complete example. -
If you are using Vue CLI, add the following to
vue.config.js
(more details here):module.exports = { css: { loaderOptions: { sass: { data: `@use "@/styles/variables.scss" as *;`, }, }, }, };
-
If you are using Webpack +
vue-loader
without Vue CLI, do the following:-
Install
sass-resources-loader
.npm install sass-resources-loader --save-dev
-
Add the following rule to your webpack config file:
{ loader: 'sass-resources-loader', options: { resources: path.resolve(__dirname, './src/styles/variables.scss') } }
-
-
Now you can customize the component styles by overriding Keen UI variables in the
variables.scss
file you created, and importing the component from source. Read on for more details.
The primary
and accent
theme colors can be customized using the $brand-primary-color
and $brand-accent-color
variables.
-
Add the following to your
variables.scss
file:$brand-primary-color: #673ab7; $brand-accent-color: #ff4081;
-
Import and use the components from
keen-ui/src
. Example:<!-- App.vue --> <template> <div> <ui-button color="primary">Primary button</ui-button> <ui-button color="accent">Accent button</ui-button> </div> </template> <script> import { UiButton } from "keen-ui/src/index"; export default { components: { UiButton, }, }; </script>
All other variables in keen-ui/src/styles/variables.scss
can be overridden to customize other aspects of the components in the same manner as the example above.
Some components also have component-specific variables that can be found in their source files. Those can be overridden as well.
You can also override the rem()
Sass function by defining a rem-custom()
function to be used instead for calculating the size of components, as described below. Please refer to the original function in src/styles/util.scss
.
All components use the rem
CSS unit for properties with length values (e.g. font-size
, margin
, padding
, width
, height
, etc). This allows you to customize the size of all components by setting font-size
on the root (<html>
) element.
The default root font size is 100%
, which uses the browser's font size setting, typically 16px
.
To scale the size of components up, set a font size higher than 100%
on the root element, for example:
html {
font-size: 110%;
}
To scale the size of components down, set a font size lower than 100%
on the root element, for example:
html {
font-size: 90%;
}
Component props which have default values can be changed globally when installing Keen UI as a Vue plugin, or when using individual components.
import { createApp } from "vue";
import KeenUI from "keen-ui";
const app = createApp();
app.use(KeenUI, {
UiButton: {
disableRipple: true,
},
UiTooltip: {
position: "top",
},
});
import { UiButton } from "keen-ui";
import configure from "keen-ui/src/configure";
configure(UiButton, {
disableRipple: true,
});
// UiButton's disableRipple prop is now true by default
// Now you can register and use UiButton