• Stars
    star
    150
  • Rank 247,323 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created over 4 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Lightweight Ruby on Rails components for developing with the GOV.UK Design System.

GOV.UK Components for Ruby on Rails

Tests Maintainability Gem version Gem Test coverage Licence GOV.UK Design System version ViewComponent Rails Ruby

This gem provides a suite of reusable components for the GOV.UK Design System. It is intended to provide a lightweight alternative to the GOV.UK Publishing Components library and is built with GitHub’s ViewComponent framework.

It aims to implement the functionality from the original Nunjucks macros in a way that will feel more familiar to Rails developers. Blocks are preferred over strings of HTML, beneath the surface each component is just a Ruby object, everything is inheritable and overrideable.

Documentation

The gem comes with a full guide that covers most aspects of day-to-day use, along with code and output examples. The examples in the guide (and the guide itself) are built using the components, so it will always be up to date.

Netlify Status

What’s included?

All of the non-form components from the GOV.UK Design System are implemented by this library as ViewComponents. Form components are implemented by the GOV.UK Form Builder.

The provided components are:

This library also provides helpers for creating links, buttons, skip links and back to top links.

Alternative syntax

All of the components can be rendered in two ways:

  • directly using Rails’ #render method:

      <%= render GovukComponent::WarningTextComponent.new do %>
        A serious warning
      <% end %>
  • via the helper wrapper:

      <%= govuk_warning_text do %>
        A serious warning
      <% end %>

    The naming convention for helpers is govuk_ followed by the component’s name in snake case. You can see the full list in GovukComponentsHelper.

Example use

This library allows components to be rendered with Rails’ render method or via the provided helpers. Here we’ll use the govuk_tabs to render three tabbed sections:

<%= govuk_tabs(title: 'Days of the week') do |component| %>
  <% component.with_tab(label: 'Monday') do %>
    <p>Monday’s child is fair of face</p>
  <% end %>

  <% component.with_tab(label: 'Tuesday') do %>
    <p>Tuesday’s child is full of grace</p>
  <% end %>

  <% component.with_tab(label: 'Wednesday') do %>
    <p>Wednesday’s child is full of woe</p>
  <% end %>
<% end %>

Here are the rendered tabs:

Tabs preview

For examples on usage see the guide page.

Setup

Add this line to your config/application.rb:

require "govuk/components"

Services using this library

Forks

Installation

Add this line to your application’s Gemfile:

gem 'govuk-components'

And then execute:

bundle

Or install it yourself as:

gem install govuk-components

Contributing

Bug reports and feature requests are most welcome, please raise an issue or submit a pull request.

Currently we're using GOVUK Lint to ensure code meets the GOV.UK guidelines. Please ensure that any PRs also adhere to this standard.

To help keep the logs clean and tidy, please configure git to use your full name:

git config --global user.name "Julius Hibbert"

Licence

The gem is available as open source under the terms of the MIT License.

More Repositories

1

govuk-form-builder

A form builder for Ruby on Rails that’s compatible with the GOV.UK Design System.
Ruby
75
star
2

govuk-eleventy-plugin

Write documentation using Markdown and publish it using GOV.UK styles.
JavaScript
54
star
3

govuk-design-history-template

Document and share design decisions. Create a permanent record of how your service has developed over time.
Nunjucks
24
star
4

govuk-services-list

A catalogue of digital services from the UK government and its agencies.
HTML
23
star
5

x-govuk.github.io

A community-maintained collection of resources which are useful for working on GOV.UK services.
JavaScript
19
star
6

govuk-prototype-rig

A re-imagined version of the GOV.UK Prototype Kit.
JavaScript
8
star
7

govuk-markdown

Convert Markdown into GOV.UK Frontend-compliant HTML.
JavaScript
7
star
8

govuk-prototype-wizard

Build and iterate ‘one thing per page’ user journeys when prototyping GOV.UK services.
JavaScript
6
star
9

govuk-prototype-filters

Prototype with data using helpful template filters.
JavaScript
6
star
10

html-attributes-utils

A small collection of utilities to ease working with hashes of HTML attributes
Ruby
4
star
11

govuk-services-frontend-stats

Ruby
4
star
12

marked-govspeak

Govspeak Markdown extensions for Marked.
JavaScript
3
star
13

govuk-prototype-components

Use common components that are not yet part of the GOV.UK Design System.
Nunjucks
3
star
14

markdown-it-govuk

Plugin for markdown-it to convert Markdown into GOV.UK Frontend-compliant HTML
JavaScript
2
star
15

nhsuk-prototype-rig

An NHS.UK version of the GOV.UK Prototype Rig
JavaScript
2
star
16

prototype-navigation-radios

A radio navigation solution for the GOVUK Prototype Kit
JavaScript
2
star
17

govuk-accessibility-mistakes-forms

Porting accessibility-examples to eleventy
Nunjucks
1
star
18

govuk-rspec-helpers

RSpec test helpers for GOV.UK services
Ruby
1
star