Class: CCS::Components::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ccs/components/base.rb

Overview

Component base class that all components will inherit from.

It’s main purpose is to handle the initialisation of the options which is very similar between components

Direct Known Subclasses

CCS::ContactUs, CCS::DashboardSection, CCS::DashboardSection::Panel, CCS::Footer, CCS::Footer::Link, CCS::Header, CCS::Header::Link, CCS::Logo, CCS::PasswordStrength, CCS::PasswordStrength::Test, GovUK::Accordion, GovUK::BackLink, GovUK::Breadcrumbs, GovUK::Breadcrumbs::Link, GovUK::Button, GovUK::CookieBanner, GovUK::CookieBanner::Action, GovUK::CookieBanner::Message, GovUK::Details, GovUK::ErrorMessage, GovUK::ErrorSummary, GovUK::ErrorSummary::Item, GovUK::ExitThisPage, GovUK::Field, GovUK::Field::Input::TextInput::Fix, GovUK::Field::Inputs::Item, GovUK::Fieldset, GovUK::Fieldset::Legend, GovUK::Footer, GovUK::Footer::Link, GovUK::FormGroup, GovUK::Header, GovUK::Header::Link, GovUK::Hint, GovUK::InsetText, GovUK::Label, GovUK::NotificationBanner, GovUK::Pagination, GovUK::Pagination::Increment, GovUK::Pagination::Item, GovUK::Panel, GovUK::PhaseBanner, GovUK::ServiceNavigation, GovUK::ServiceNavigation::Link, GovUK::SkipLink, GovUK::StepByStepNavigation, GovUK::StepByStepNavigation::Section, GovUK::SummaryList, GovUK::SummaryList::Action::Link, GovUK::SummaryList::Card, GovUK::SummaryList::Card::Actions, GovUK::SummaryList::Card::Title, GovUK::SummaryList::Row, GovUK::SummaryList::Row::Actions, GovUK::SummaryList::Row::Key, GovUK::SummaryList::Row::Value, GovUK::Table, GovUK::Table::Body::DataCell, GovUK::Table::Body::HeadCell, GovUK::Table::Header::HeadCell, GovUK::Tabs, GovUK::Tabs::Panel, GovUK::Tabs::Tab, GovUK::Tag, GovUK::TaskList, GovUK::TaskList::Item, GovUK::TaskList::Item::Status, GovUK::TaskList::Item::Title, GovUK::WarningText

Constant Summary collapse

DEFAULT_ATTRIBUTES =

The default attributes for the component

{}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(context:, **options) ⇒ Base

Returns a new instance of Base.

Parameters:

  • context (ActionView::Base)

    the view context where the components are being rendered

  • options (Hash)

    options for the component



32
33
34
35
36
37
38
39
# File 'lib/ccs/components/base.rb', line 32

def initialize(context:, **options)
  options[:attributes] ||= {}
  options[:attributes][:class] = "#{default_attributes[:class]} #{options[:classes]}".strip if default_attributes[:class] || options[:classes]
  (options[:attributes][:data] ||= {})[:module] = default_attributes[:data][:module] if default_attributes.dig(:data, :module)

  @context = context
  @options = options
end