|
1 | 1 | # Theme |
2 | 2 |
|
3 | | -## Storefront UI |
| 3 | +A project without any theme would just show a blank page, but if you have seen any of Vue Storefront demos or created a project using our CLI, you know that's not the case. So what makes it look like it does? |
4 | 4 |
|
5 | | -<center> |
6 | | -<img src="../images/theme/storefront-ui.jpg" /> |
7 | | -</center> |
| 5 | +This page will describe what makes the default theme, how to customize it, and what tricks we use to improve the performance. |
8 | 6 |
|
9 | | -Almost every component in our default theme uses components whose names start with `Sf`. These come from [Storefront UI](http://storefrontui.io/) - a design system and library of Vue.js components dedicated to e-commerce, maintained by the Vue Storefront core team. It comes with [Storybook](https://storybook.storefrontui.io/) to help you customize and test the components. |
| 7 | +## What's makes a default theme |
10 | 8 |
|
11 | | -The library is fully customizable. It can be used in different contexts and with different designs. |
12 | | -It's excellent for the multi-tenancy model as a shared UI library that can be customized differently for each tenant. |
| 9 | +Although, at first glance, it might look like all of our e-commerce integrations use the same exact theme, it's not the case. All of them are built upon the same base theme and modify it to work well and cover features of a given platform. This means that some integrations might have more pages, different UI elements, or additional Nuxt.js modules or plugins. |
13 | 10 |
|
14 | | -To learn more about Storefront UI, please check its [Documentation](https://docs.storefrontui.io/). |
| 11 | +For this reason, in this section, we will focus only on the common parts of all themes. |
15 | 12 |
|
16 | | -::: tip Want to use another UI library? No problem! |
17 | | -If you don't want to use Storefront UI, feel free to remove it from your project. It's just a UI layer, and the project can work with any other UI library or a custom code. |
18 | | -::: |
| 13 | +### Preinstalled modules and libraries |
19 | 14 |
|
20 | | -## Customizing the theme |
| 15 | +Every new Vue Storefront project comes with a set of preinstalled Nuxt.js modules and plugins, as well as Vue.js libraries. These packages offer a variety of features from cookie handling to form validation and are used by the base theme. You can remove some of them, but only if you decide to create a custom theme from scratch. |
21 | 16 |
|
22 | | -### Changing existing pages, components, and layouts |
| 17 | +#### Nuxt.js modules and plugins |
23 | 18 |
|
24 | | -To update the existing components, you need to identify them first. Vue.js Devtools helps us in that. Open the tool and click on the `Select` button above the component tree, then click on the DOM element you want to update. One of the components in the tree should get highlighted. You can look for the component with the same name in the `layout`, `pages`, or `components` directories and update it to your needs. However, there are few exceptions to this rule. |
| 19 | +- [`@nuxt/typescript-build`](https://typescript.nuxtjs.org/) - for TypeScript support, |
| 20 | +- [`@nuxtjs/pwa`](https://pwa.nuxtjs.org/) - for PWA functionalities, |
| 21 | +- [`@nuxtjs/composition-api`](https://composition-api.nuxtjs.org/) - for Composition API support, |
| 22 | +- [`@nuxtjs/style-resources`](https://www.npmjs.com/package/@nuxtjs/style-resources) - for importing SASS variables globally, |
| 23 | +- [`nuxt-i18n`](https://i18n-legacy.nuxtjs.org/) - for internationalization (translations and price formatting), |
| 24 | +- [`nuxt-purgecss`](https://purgecss.com/guides/nuxt.html) - for removing unused CSS from the final build, |
| 25 | +- [`cookie-universal-nuxt`](https://www.npmjs.com/package/cookie-universal-nuxt) - for handling cookies on the server (SSR) and client (browser). |
25 | 26 |
|
26 | | -#### `Sf` components |
| 27 | +#### Vue.js libraries |
27 | 28 |
|
28 | | -If the name of the component starts with `Sf` (indicating that it comes from Storefront UI), you should refer to the direct **parent** component. The behavior and look of such components can be changed by passing different properties and using slots. Refer to the StorefrontUI documentation linked above for more information. |
| 29 | +- [`vee-validate`](https://vee-validate.logaretm.com/v3) - for frontend form validation, |
| 30 | +- [`vue-scrollto/nuxt`](https://www.npmjs.com/package/vue-scrollto) - for smooth scrolling to HTML elements, |
| 31 | +- [`vue-lazy-hydration`](https://www.npmjs.com/package/vue-lazy-hydration) - for delaying hydration and improving performance. |
29 | 32 |
|
30 | | -#### `LazyHydrate` and `Anonymous Component` components |
| 33 | +### Storefront UI |
31 | 34 |
|
32 | | -These two components come from the `vue-lazy-hydration` library and are wrappers around other components. In Vue Storefront, they are used to improve the performance by deferring the hydration process (when components become interactive) and don't affect the look of other components. |
| 35 | +<figure style="text-align: center"> |
| 36 | + <img |
| 37 | + src="../images/storefront-ui.webp" |
| 38 | + alt="StorefrontUI logo and default theme" |
| 39 | + /> |
| 40 | + <figcaption style="font-size: 0.9rem">(Click to zoom)</figcaption> |
| 41 | +</figure> |
33 | 42 |
|
34 | | -If you encounter one of these components, you should refer to the direct **child** component. |
| 43 | +Almost every page in our default theme uses components whose names start with `Sf`. These come from the [Storefront UI](http://storefrontui.io/) — a design system and library of Vue.js components dedicated to e-commerce, maintained by the Vue Storefront team. Every component can be heavily customized using [props](https://vuejs.org/v2/guide/components-props.html) and [slots](https://vuejs.org/v2/guide/components-slots.html). |
35 | 44 |
|
36 | | -### Router base property |
| 45 | +Please check [Storefront UI documentation](https://docs.storefrontui.io/) to learn more and interactively customize and test the components. |
37 | 46 |
|
38 | | -There is an option to set base URL for your store. |
| 47 | +::: tip Want to use another UI library? No problem! |
| 48 | +If you don't want to use Storefront UI, feel free to remove it from your project. It's just a UI layer, and the project can work with any other UI library or a custom code. |
| 49 | +::: |
39 | 50 |
|
40 | | -This can be useful if you need to serve your store as a different context root, from within a bigger Web site. |
| 51 | +## How to customize the theme |
41 | 52 |
|
42 | | -Add following configuration to `nuxt.config.js` |
43 | | -```javascript |
44 | | -// nuxt.config.js |
| 53 | +Every default theme will need customization at some point. Regardless of how complex the changes are, we recommend reusing as much from the default theme as possible. This will not only save you time but will likely reduce the number of bugs, thanks to the time we spend on stabilization and testing. |
45 | 54 |
|
46 | | -export default { |
47 | | - router: { |
48 | | - base: "/myShop/" |
49 | | - } |
50 | | -}; |
51 | | -``` |
| 55 | +### Updating layouts, pages, and components |
52 | 56 |
|
53 | | -:::warning Be careful |
54 | | -When using base router property you need to wrap all assets relative links in addBasePath(), this will automatically add base path to them and prevent redirects. (example below) |
55 | | -::: |
| 57 | +To update the existing component, you need to identify it first, and Vue.js Devtools is invaluable in this. Open the Vue.js Devtools, right-click the DOM element you want to update, and select `Inspect Vue component`. One of the components in the tree in Vue.js Devtools should get highlighted. You can look for the component with the same name in the `layout`, `pages`, or `components` directories and update it to your needs. However, there are a few exceptions to this rule described below. |
56 | 58 |
|
| 59 | +#### `Sf` components |
57 | 60 |
|
| 61 | +If the component's name starts with `Sf`, it means that it comes from [StorefrontUI](https://storefrontui.io/) library. The look and behavior of such components are controlled using props and slots passed from the direct **parent** component. |
58 | 62 |
|
59 | | -```javascript |
60 | | -//use addBasePath on relative url |
61 | | -<SfImage :src="addBasePath(`/homepage/imageA.webp`)" /> |
62 | | -<SfBanner :image="addBasePath('/homepage/bannerA.png')" /> |
63 | | - |
64 | | -//In theme file import addBasePath from vue-storefront core |
65 | | -import { addBasePath } from '@vue-storefront/core'; |
66 | | - |
67 | | -setup() { |
68 | | - return { |
69 | | - // if you want to use it in template you need to exprt it |
70 | | - addBasePath |
71 | | - } |
72 | | -} |
73 | | -``` |
| 63 | +#### `LazyHydrate` and `Anonymous Component` components |
74 | 64 |
|
75 | | -## Updating styles |
| 65 | +These two components come from the [vue-lazy-hydration](https://github.com/maoberlehner/vue-lazy-hydration) library and are wrappers around other components. They are used to improve the performance by deferring the hydration process (making components interactive) and don't affect the look of other components. The behavior of such components is controlled using props passed from the direct **parent** component. |
76 | 66 |
|
77 | | -There are few ways of updating the default styles. Below we describe the most optimal ways for the most common cases. |
| 67 | +### Updating styles |
78 | 68 |
|
79 | | -### Adding global styleheet |
| 69 | +There are a few ways of updating the default styles. Below we describe the most optimal methods for the most common cases. |
| 70 | + |
| 71 | +#### Adding global styleheet |
80 | 72 |
|
81 | 73 | To add global styles applied to all pages, use the [css property](https://nuxtjs.org/docs/2.x/configuration-glossary/configuration-css/) in `nuxt.config.js`. |
82 | 74 |
|
83 | | -### Adding stylesheet to specific layout, page, or component |
| 75 | +#### Adding stylesheet to specific layout, page, or component |
84 | 76 |
|
85 | | -To add a stylesheet to a specific component, use `@import` regardless if you are using CSS, SCSS, or LESS. |
| 77 | +To add a stylesheet to a specific component, use `@import` regardless of whether you are using CSS, SCSS, or LESS. |
86 | 78 |
|
87 | 79 | ```vue |
88 | 80 | <style> |
89 | 81 | @import "@/assets/stylesheet.css"; |
90 | 82 | </style> |
91 | 83 | ``` |
92 | 84 |
|
93 | | -### Using variables, mixins, and function in components |
| 85 | +#### Using variables, mixins, and function in components |
94 | 86 |
|
95 | | -Usually, to access style variables, mixins, and functions, we have to import them in every component separately. Thanks to [@nuxtjs/style-resources](https://github.com/nuxt-community/style-resources-module#readme) module, we can register them in `nuxt.config.js` and access them without extra `@import` statements. |
| 87 | +Usually, to access style variables, mixins, and functions, we import them in every component separately. Thanks to the [@nuxtjs/style-resources](https://github.com/nuxt-community/style-resources-module#readme) module, we can register them in `nuxt.config.js` and access them without extra `@import` statements. |
96 | 88 |
|
97 | 89 | :::danger Be careful |
98 | | -Stylesheets in `styleResources` should **only** contain variables, mixins, and functions. During the build process, the components import these stylesheets. Any styles declared in them are added to every component, which can significantly hurt the performance and application size. |
| 90 | +Stylesheets in `styleResources` should **only** contain variables, mixins, and functions. During the build process, the components import these stylesheets. Any **styles** declared in them are added to every component, significantly impacting the performance and application size. |
99 | 91 | ::: |
100 | 92 |
|
101 | 93 | We use this approach to have access to StorefrontUI helpers in all components: |
102 | 94 |
|
103 | | -```js |
| 95 | +```javascript |
104 | 96 | // nuxt.config.js |
| 97 | + |
105 | 98 | export default { |
106 | 99 | styleResources: { |
107 | | - scss: [require.resolve('@storefront-ui/shared/styles/_helpers.scss', { paths: [process.cwd()] })] |
| 100 | + scss: [ |
| 101 | + require.resolve('@storefront-ui/shared/styles/_helpers.scss', { paths: [process.cwd()] }) |
| 102 | + ] |
108 | 103 | }, |
109 | 104 | }; |
110 | 105 | ``` |
111 | | - |
112 | | -## Preinstalled modules and libraries |
113 | | - |
114 | | -Below you can find a list of the most important Nuxt Modules and libraries that come preinstalled with the default theme: |
115 | | - |
116 | | -### Nuxt.js modules |
117 | | - |
118 | | -- `@nuxtjs/pwa`; |
119 | | -- `nuxt-i18n`; |
120 | | -- `@vue-storefront/nuxt`; |
121 | | - - `@nuxtjs/composition-api`; |
122 | | - - `@nuxt/typescript-build`; |
123 | | - - `@nuxtjs/style-resources`; |
124 | | - - `nuxt-purgecss`; |
125 | | -- `@vue-storefront/nuxt-theme`; |
126 | | - - `vue-lazy-hydration`; |
127 | | - |
128 | | -### Libraries |
129 | | - |
130 | | -- [`@storefront-ui/vue`](https://storefrontui.io); |
131 | | -- [`vee-validate`](https://vee-validate.logaretm.com/v3); |
132 | | -- [`lodash`](https://lodash.com/); |
0 commit comments