|
| 1 | +# Styling Element Ui |
| 2 | + |
| 3 | +## Changin All Neccessary Files |
| 4 | + |
| 5 | +File Structures [./Styles/ElementUi/*](../Styles/ElementUi) |
| 6 | + |
| 7 | + |
| 8 | +NOTE: |
| 9 | + |
| 10 | +If We Do Intend to use Element UI We Need to Move All This Files to Their Counter Part File Name in Our Main App |
| 11 | + |
| 12 | +I Have Added Here Remarks On What is Changed Based on the Original App Files |
| 13 | +``` |
| 14 | +Style/ElementUi |
| 15 | + - theme |
| 16 | + - index.css // <!-- This Holds Our Theme CSS |
| 17 | + - views |
| 18 | + - errors |
| 19 | + - 404.vue // <!-- Uses Element Ui Tags |
| 20 | + // You Can Add Other Error Pages Here |
| 21 | +
|
| 22 | + - Layouts |
| 23 | + - partials |
| 24 | + - AppFooter.vue <!-- Uses Element Ui Tags |
| 25 | + - AppHeader.vue <!-- Uses Element Ui Tags |
| 26 | +
|
| 27 | + - main.vue // <!-- Our Main Layout Uses Element Ui Tags |
| 28 | +
|
| 29 | + - pages |
| 30 | + - home.vue // <!-- Our Home Layout Uses Element Ui Tags |
| 31 | +
|
| 32 | + - app.js // <!-- Same as The Main App , No Need to replace |
| 33 | + - bootstrap.js // <!-- Holds Our Element Ui Themes |
| 34 | + - package.json // <!-- Hold All Dependencies for Element Ui |
| 35 | + - routes.js // <!-- linkActiveClass set for Element Ui |
| 36 | + - webpack.mix.js <!-- Add webpackConfig style-loader and css-loader |
| 37 | +``` |
| 38 | + |
| 39 | +Counter Part File Structure We need to Replace |
| 40 | + |
| 41 | +``` |
| 42 | +App Folder |
| 43 | + - webpack.mix.js |
| 44 | + - package.json |
| 45 | + - resources |
| 46 | + - assets |
| 47 | + - js |
| 48 | + - views |
| 49 | + - errors |
| 50 | + - 404.vue |
| 51 | + - Layouts |
| 52 | + - partials |
| 53 | + - AppFooter.vue |
| 54 | + - AppHeader.vue |
| 55 | + - main.vue |
| 56 | + - pages |
| 57 | + - home.vue |
| 58 | + - themes |
| 59 | + - index.css // element-ui default index.css Already Added in Our Main App |
| 60 | + - app.js // Same as app.js in element ui folder no Need to replace |
| 61 | + - bootstrap.js |
| 62 | + - routes.js |
| 63 | +
|
| 64 | + - sass |
| 65 | + - app.scss // <!-- This File is Empty |
| 66 | +``` |
| 67 | + |
| 68 | +Here are the List of ElementUI Files and Corresponding Counter Part in Our Main App We Need to replace |
| 69 | + |
| 70 | +- [./Styles/ElementUi/app.js](../Styles/ElementUi/app.js) --> [./resources/assets/js/app.js](.././resources/assets/js/app.js) |
| 71 | +- [./Styles/ElementUi/bootstrap.js](../Styles/ElementUi/bootstrap.js) --> [./resources/assets/js/bootstrap.js](.././resources/assets/js/bootstrap.js) |
| 72 | +- [./Styles/ElementUi/package.json](../Styles/ElementUi/package.json) --> [./package.json](../package.json) |
| 73 | +- [./Styles/ElementUi/routes.js](../Styles/ElementUi/routes.js) --> [./resources/assets/js/routes.js](.././resources/assets/js/routes.js) |
| 74 | + |
| 75 | +- [./Styles/ElementUi/webpack.mix.js](../Styles/ElementUi/webpack.mix.js) --> [./webpack.mix.js](../webpack.mix.js) |
| 76 | + |
| 77 | +- [./Styles/ElementUi/theme/index.css](../Styles/ElementUi/theme/index.css) --> [./resources/assets/js/theme/index.css](../resources/assets/js/theme/index.css) |
| 78 | + |
| 79 | +Same Structure As Our |
| 80 | +Main App Structure Located @ [resources/assets/js/views/*](../resources/assets/js/views) |
| 81 | + |
| 82 | +Lists Of Layout Files |
| 83 | + |
| 84 | +- [./Styles/ElementUi/views/errors/404.vue](../Styles/ElementUi/views/errors/404.vue) |
| 85 | + |
| 86 | +- [./Styles/ElementUi/views/Layouts/partials/AppFooter.vue](../Styles/ElementUi/views/Layouts/partials/AppFooter.vue) |
| 87 | + |
| 88 | +- [./Styles/ElementUi/views/Layouts/partials/AppHeader.vue](../Styles/ElementUi/views/Layouts/partials/AppHeader.vue) |
| 89 | + |
| 90 | +- [./Styles/ElementUi/views/Layouts/main.vue](../Styles/ElementUi/views/Layouts/main.vue) |
| 91 | + |
| 92 | +- [./Styles/ElementUi/views/pages/home.vue](../Styles/ElementUi/views/pages/home.vue) |
| 93 | + |
| 94 | +## Installing Dev Dependencies |
| 95 | + |
| 96 | +Replace [./package.json](../package.json) by [./Styles/ElementUi/package.json](../Styles/ElementUi/package.json) |
| 97 | + |
| 98 | +From Main App folder Type |
| 99 | + |
| 100 | +``` |
| 101 | +mv Styles/ElementUi/package.json package.json |
| 102 | +``` |
| 103 | + |
| 104 | +Edit and Remove all Commented Lines Using Text Editor |
| 105 | + |
| 106 | +``` |
| 107 | +vim package.json or code package.json |
| 108 | +``` |
| 109 | + |
| 110 | +Install All Dependencies Using NPM |
| 111 | +``` |
| 112 | +npm install |
| 113 | +``` |
| 114 | + |
| 115 | +or use Yarn |
| 116 | + |
| 117 | +``` |
| 118 | +rm yarn.lock |
| 119 | +yarn install |
| 120 | +``` |
| 121 | + |
| 122 | +## Compiling Assets |
| 123 | + |
| 124 | +All Commands Are Listed on [./package.json](../package.json) |
| 125 | +``` |
| 126 | +npm run dev - this will compile your app for dev |
| 127 | +
|
| 128 | +npm run hot - enable hot reloading |
| 129 | +
|
| 130 | +npm run production - compile for production all minification are added here |
| 131 | +
|
| 132 | +npm run watch - if you enable browsersync this is command to run |
| 133 | +
|
| 134 | +npm run watch poll - if you the app is a bit sluggish you may need to run this instead of watch. |
| 135 | +``` |
| 136 | + |
| 137 | + |
| 138 | +## Full Import of Element Ui Components |
| 139 | + |
| 140 | + |
| 141 | +[.bootstrap.js](../Styles/ElementUi/bootstrap.js) |
| 142 | +```js |
| 143 | +import ElementUI from 'element-ui' |
| 144 | +import 'element-ui/lib/theme-default/index.css' |
| 145 | +Vue.use(ElementUI) |
| 146 | +``` |
| 147 | + |
| 148 | +## Importing Few Components |
| 149 | + |
| 150 | + |
| 151 | +``` |
| 152 | +npm install babel-plugin-component -D |
| 153 | +``` |
| 154 | + |
| 155 | +edit .babelrc file |
| 156 | +```js |
| 157 | +{ |
| 158 | + "presets": ["es2015", "stage-2"], |
| 159 | + "plugins": [["syntax-async-functions","transform-regenerator","component", [ |
| 160 | + { |
| 161 | + "libraryName": "element-ui", |
| 162 | + "styleLibraryName": "theme-default" |
| 163 | + } |
| 164 | + ]]] |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +in your [.bootstrap.js](../Styles/ElementUi/bootstrap.js) |
| 169 | +```js |
| 170 | +import { Button, Select } from 'element-ui' |
| 171 | +Vue.use(Button) |
| 172 | +Vue.use(Select) |
| 173 | +``` |
| 174 | + |
| 175 | +[For Complete List of Component Check This Guide](./ElementUiIndividualComponentFull.md) |
| 176 | + |
| 177 | +## Internationalization |
| 178 | + |
| 179 | +For Full Import Just these line in your [.bootstrap.js](../Styles/ElementUi/bootstrap.js) |
| 180 | + |
| 181 | +```js |
| 182 | +import locale from 'element-ui/lib/locale/lang/en' |
| 183 | +Vue.use(ElementUI, { locale }) |
| 184 | +``` |
| 185 | + |
| 186 | +For Import On Demand Element Ui |
| 187 | + |
| 188 | +```js |
| 189 | +import Vue from 'vue' |
| 190 | +import { Button, Select } from 'element-ui' |
| 191 | +import lang from 'element-ui/lib/locale/lang/en' |
| 192 | +import locale from 'element-ui/lib/locale' |
| 193 | + |
| 194 | +// configure language |
| 195 | +locale.use(lang) |
| 196 | + |
| 197 | +// import components |
| 198 | +Vue.component(Button.name, Button) |
| 199 | +Vue.component(Select.name, Select) |
| 200 | + |
| 201 | +``` |
| 202 | + |
| 203 | +[For More Info About Internationalization Visit Click Here](http://element.eleme.io/#/en-US/component/i18n) |
| 204 | + |
| 205 | + |
| 206 | +## Custom Theme |
| 207 | + |
| 208 | +### Install related tool |
| 209 | + |
| 210 | +``` |
| 211 | +npm i element-theme -g |
| 212 | +``` |
| 213 | + |
| 214 | +### Then install the default theme from npm or GitHub. |
| 215 | +``` |
| 216 | +# from npm |
| 217 | +npm i element-theme-default -D |
| 218 | +
|
| 219 | +# from GitHub |
| 220 | +npm i https://github.com/ElementUI/theme-default -D |
| 221 | +``` |
| 222 | + |
| 223 | +### Initialize variable file |
| 224 | + |
| 225 | +After successfully installing the above packages, a command named et is available in CLI (if the packages are installed locally, use node_modules/.bin/et instead). Run `-i` to initialize the variable file which outputs to element-variables.css by default. |
| 226 | + |
| 227 | +``` |
| 228 | +et -i [custom output file] // We can Output it At ./resources/assets/js/theme/ |
| 229 | +
|
| 230 | +> ✔ Generator variables file |
| 231 | +``` |
| 232 | + |
| 233 | +Run this Command |
| 234 | + |
| 235 | +``` |
| 236 | +et -i ./resources/assets/js/theme/element-variables.css |
| 237 | +``` |
| 238 | + |
| 239 | +This will Out This File |
| 240 | +``` |
| 241 | +./resources/assets/js/theme/element-variables.css |
| 242 | +``` |
| 243 | + |
| 244 | +In ```element-variables.css``` you can find all the variables we used to style Element and they are defined in CSS4 style: |
| 245 | +```css |
| 246 | +:root { |
| 247 | + |
| 248 | + /* Colors |
| 249 | + -------------------------- */ |
| 250 | + --color-primary: #20a0ff; |
| 251 | + --color-success: #13ce66; |
| 252 | + --color-warning: #f7ba2a; |
| 253 | + --color-danger: #ff4949; |
| 254 | + --color-info: #50BFFF; |
| 255 | + --color-blue: #2e90fe; |
| 256 | + --color-blue-light: #5da9ff; |
| 257 | + --color-blue-lighter: rgba(var(--color-blue), 0.12); |
| 258 | + --color-white: #fff; |
| 259 | + --color-black: #000; |
| 260 | + --color-grey: #C0CCDA; |
| 261 | + |
| 262 | +``` |
| 263 | + |
| 264 | +### Modify variables |
| 265 | +Just edit element-variables.css, e.g. changing the theme color to red: |
| 266 | + |
| 267 | +```css |
| 268 | +--color-primary: red; |
| 269 | +``` |
| 270 | + |
| 271 | +### Build theme |
| 272 | + |
| 273 | +After saving the variable file, use `et` to build your theme. You can activate watch mode by adding a parameter `-w`. And if you customized the variable file's output, you need to add a parameter `-c` and variable file's name: You can specify its output directory with parameter `-o` |
| 274 | + |
| 275 | +``` |
| 276 | +et |
| 277 | + |
| 278 | +> ✔ build theme font |
| 279 | +> ✔ build element theme |
| 280 | +``` |
| 281 | + |
| 282 | + |
| 283 | + |
| 284 | +## Import custom theme |
| 285 | +By default the build theme file is placed inside ./theme. You can specify its output directory with parameter -o. Importing your own theme is just like importing the default theme, only this time you import the file you just built: |
| 286 | + |
| 287 | +Run this Command to Build element-variables.css to index.css |
| 288 | + |
| 289 | +We can Specify the output of file using `-o` flag |
| 290 | +``` |
| 291 | +et -o ./resources/assets/js/theme/index.css |
| 292 | +``` |
| 293 | + |
| 294 | +``` |
| 295 | +import './theme/index.css' |
| 296 | +import ElementUI from 'element-ui' |
| 297 | +import Vue from 'vue' |
| 298 | + |
| 299 | +Vue.use(ElementUI) |
| 300 | + |
| 301 | +``` |
| 302 | + |
| 303 | +## Import component theme on demand |
| 304 | + |
| 305 | +If you are using babel-plugin-component for on-demand import, just modify .babelrc and specify styleLibraryName to the path where your custom theme is located relative to .babelrc. Note that ~ is required: |
| 306 | + |
| 307 | +``` |
| 308 | +{ |
| 309 | + "presets": ["es2015", "stage-2"], |
| 310 | + "plugins": [["syntax-async-functions","transform-regenerator","component", [ |
| 311 | + { |
| 312 | + "libraryName": "element-ui", |
| 313 | + "styleLibraryName": "~theme" |
| 314 | + } |
| 315 | + ]]] |
| 316 | +} |
| 317 | +``` |
0 commit comments