If you use Sass with webpack
and vue-loader
in your project, you can customize the components by overriding Sass variables and then importing the .vue
source files.
-
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 are not using Vue CLI:
-
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') } }
-
-
If you are using Vue CLI, add the following to
vue.config.js
(details):module.exports = { css: { loaderOptions: { sass: { data: `@import "@/styles/variables.scss";` } } } }
-
Now you can customize the component styles by overriding Keen UI variables in the
variables.scss
file you created.
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 'keen-ui/src/bootstrap'; // Required to setup Keen UI, should be imported only once in your project import UiButton from 'keen-ui/src/UiButton.vue'; 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 Vue from 'vue';
import KeenUI from 'keen-ui';
Vue.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