diff --git a/source/_posts/2018-12-27-rebuilding-bartik-with-vuejs-tailwind-css-part-2.md b/source/_posts/2018-12-27-rebuilding-bartik-with-vuejs-tailwind-css-part-2.md index dba3c243..53104112 100644 --- a/source/_posts/2018-12-27-rebuilding-bartik-with-vuejs-tailwind-css-part-2.md +++ b/source/_posts/2018-12-27-rebuilding-bartik-with-vuejs-tailwind-css-part-2.md @@ -6,16 +6,21 @@ tags: - tweet - vuejs has_tweets: true -draft: true --- {% block excerpt %} -In the [original post](/blog/rebuilding-bartik-with-vuejs-tailwind-css) I detailed how I built a clone of Drupal’s Bartik theme with [Vue.js][1] and [Tailwind CSS][2]. This post details some updates that I’ve made to it since then. +In [the original post](/blog/rebuilding-bartik-with-vuejs-tailwind-css) I detailed how I built a clone of Drupal’s Bartik theme with [Vue.js][vuejs] and [Tailwind CSS][tailwind]. This follow-up post details some updates that I’ve made to it since then. {% endblock %} {% block content %} -## Customising Tailwind +## Customising Tailwind’s colours -### Colours +During the first version of the page, my thoughts were to not edit the Tailwind configuration, however I changed my mind on this whilst working on the subsequent updates and did make some changes and customisations to the `tailwind.js` file. + +By default, Tailwind includes a full colour palette including colours such as yellows, oranges, reds that weren’t being used in this page so they were removed. This makes the file more readable as well as reduces the number of classes that Tailwind generates. + +Whist I was changing the colours, I also took the opportunity to tweak the values of the remaining colours to more closely match Bartik’s original colours. + +I also added a `black-60` class which uses [RGBA](https://css-tricks.com/the-power-of-rgba) to provide a semi-transparent background. I used this when adding the [skip to main content link](#adding-the-skip-to-main-content-link). ```js let colors = { @@ -35,24 +40,19 @@ let colors = { 'blue-dark': '#2779bd', 'blue': '#3490dc', 'blue-light': '#bcdefa', + + 'green-dark': '#325E1C', + 'green': '#77B159', + 'green-light': '#CDE2C2', + 'green-lighter': '#F3FAEE', } ``` -### Plugins +## Adding default styling for links -```js -plugins: [ - require('tailwindcss/plugins/container')({ - // center: true, - // padding: '1rem', - }), - require('tailwindcss-skip-link')(), -], -``` +In the first version, every link was individually styled which resulted in a lot of duplicate classes and a potential maintenance issue. -## Extracting Tailwind components for link styling - -`src/components/Welcome.vue`: +I added a `style` section within `Welcome.vue`, and added some default styling for links based on their location on the page - [extracting some Tailwind components](https://tailwindcss.com/docs/extracting-components).
{% raw %} ```vuejs @@ -80,6 +80,8 @@ plugins: [ ``` +Within the `style` section, I’m able to use Tailwind’s custom `@apply` directive to inject it’s rules into more traditional CSS, rather than needing to add them onto every link. + ```vuejs ``` -`src/components/Welcome.vue`: +The component provides the wrapping div and the appropriate classes in a single easy-to-maintain location, and [uses a slot](https://vuejs.org/v2/guide/components-slots.html) as a placeholder for the main content. -```vuejs - -

Search

+That means that within `Welcome.vue`, the markup within the `sidebar-block` tags will be used as the block contents. -
-
- - - -
-
-
+```html + +

My block contents.

+
``` ## Adding the Skip to Main Content Link +One thing [that was missing](https://github.com/opdavies/rebuilding-bartik/issues/1) was the 'Skip to main content link'. This an accessibility feature that allows for users who are navigating the page using only a keyboard to bypass the navigation links and skip straight to the main content if they wish by clicking a link that is hidden and only visible whilst it’s focussed on. + +Here is the markup that I used, which is placed directly after the opening `` tag. + ```html - + ``` +I initially tried to implement the same feature on this website using [Tailwind’s visually hidden plugin](https://www.npmjs.com/package/tailwindcss-visuallyhidden) which also contains a `focussable` class, though I wasn’t able to style it the way that I needed. I created my own [Tailwind skip link plugin](https://www.npmjs.com/package/tailwindcss-skip-link) and moved the re-usable styling there. + +To enable the plugin, I needed to add it within the `plugins` section of my `tailwind.js` file: + +```js +plugins: [ + require('tailwindcss/plugins/container')(), + require('tailwindcss-skip-link')(), +], +``` + +I added only the page-specific styling classes to the link (as well as the `skip-link` class that the plugin requires) as well as my own focus state to the skip link that I did within the `style` section of `App.vue`. + ```vuejs ``` + +![The Bartik clone with the skip to main content link visible](/images/blog/rebuilding-bartik-vue-tailwind-part-2/skip-link.png){.border} + +## Adding the DrupalMessage component + +I also added a version of Drupal’s status message. For readability, this is contained within it’s own component, `DrupalMessage.vue`, though it contains only a static template and has no `script` or any of it’s own data. + +```html + +``` + +I did need to make one change to the `tailwind.js` file - within `modules` I needed to enable the `borderStyle` module for hover and focus states in order for Tailwind to generate the additional classes. + +```js +modules: { + // ... + borderStyle: ['responsive', 'hover', 'focus'], + // ... +} +``` + +The message is included within the Welcome component by including the `` element, though rather than importing it there, it’s registed as a global component so it would be available to any other components that could be added in the future. + +This is done within `main.js`: + +```js +// ... + +import DrupalMessage from '@/components/DrupalMessage.vue' + +Vue.component('DrupalMessage', DrupalMessage) + +new Vue({ + render: h => h(App), +}).$mount('#app') +``` + +![The Bartik clone with the Drupal Message component visible](/images/blog/rebuilding-bartik-vue-tailwind-part-2/drupal-message.png){.border} + +__The updated version is [live on Netlify][netlify], and the [latest source code is available on GitHub][github].__ {% endblock %} -[0]: https://www.drupal.org -[1]: https://vuejs.org -[2]: https://tailwindcss.com -[3]: https://github.com/opdavies/rebuilding-bartik -[4]: https://rebuilding-bartik.netlify.com -[5]: https://www.drupal.org/project/tailwindcss +[github]: https://github.com/opdavies/rebuilding-bartik +[netlify]: https://rebuilding-bartik.netlify.com +[tailwind]: https://tailwindcss.com +[vuejs]: https://vuejs.org diff --git a/source/images/blog/rebuilding-bartik-vue-tailwind-part-2/drupal-message.png b/source/images/blog/rebuilding-bartik-vue-tailwind-part-2/drupal-message.png new file mode 100644 index 00000000..9244d92a Binary files /dev/null and b/source/images/blog/rebuilding-bartik-vue-tailwind-part-2/drupal-message.png differ diff --git a/source/images/blog/rebuilding-bartik-vue-tailwind-part-2/skip-link.png b/source/images/blog/rebuilding-bartik-vue-tailwind-part-2/skip-link.png new file mode 100644 index 00000000..693cda51 Binary files /dev/null and b/source/images/blog/rebuilding-bartik-vue-tailwind-part-2/skip-link.png differ