Class: Playbook::KitBase

Direct Known Subclasses

PbAdvancedTable::AdvancedTable, PbAdvancedTable::TableActionBar, PbAdvancedTable::TableBody, PbAdvancedTable::TableHeader, PbAdvancedTable::TableRow, PbAdvancedTable::TableSubrowHeader, PbAvatar::Avatar, PbBackground::Background, PbBadge::Badge, PbBody::Body, PbBreadCrumbs::BreadCrumbItem, PbBreadCrumbs::BreadCrumbs, PbButton::Button, PbButtonToolbar::ButtonToolbar, PbCaption::Caption, PbCard::Card, PbCard::CardBody, PbCard::CardHeader, PbCheckbox::Checkbox, PbCircleIconButton::CircleIconButton, PbCollapsible::Collapsible, PbCollapsible::CollapsibleContent, PbCollapsible::CollapsibleIcon, PbCollapsible::CollapsibleMain, PbContact::Contact, PbCopyButton::CopyButton, PbCurrency::Currency, PbDashboardValue::DashboardValue, PbDate::Date, PbDatePicker::DatePicker, PbDateRangeInline::DateRangeInline, PbDateRangeStacked::DateRangeStacked, PbDateStacked::DateStacked, PbDateTime::DateTime, PbDateTimeStacked::DateTimeStacked, PbDateYearStacked::DateYearStacked, PbDetail::Detail, PbDialog::Dialog, PbDialog::DialogBody, PbDialog::DialogFooter, PbDialog::DialogHeader, PbDistributionBar::DistributionBar, PbDocs::KitExample, PbDraggable::Draggable, PbDraggable::DraggableContainer, PbDraggable::DraggableItem, PbDropdown::Dropdown, PbDropdown::DropdownContainer, PbDropdown::DropdownOption, PbDropdown::DropdownTrigger, PbEmptyState::EmptyState, PbFileUpload::FileUpload, PbFilter::Filter, PbFixedConfirmationToast::FixedConfirmationToast, PbFlex::Flex, PbFlex::FlexItem, PbForm::Form, PbFormGroup::FormGroup, PbFormPill::FormPill, PbFullScreen::FullScreen, PbHashtag::Hashtag, PbHighlight::Highlight, PbHomeAddressStreet::CityEmphasis, PbHomeAddressStreet::HomeAddressStreet, PbHomeAddressStreet::NoneEmphasis, PbHomeAddressStreet::StreetEmphasis, PbIcon::Icon, PbIconButton::IconButton, PbIconCircle::IconCircle, PbIconStatValue::IconStatValue, PbIconValue::IconValue, PbImage::Image, PbLabelPill::LabelPill, PbLabelValue::LabelValue, PbLayout::Body, PbLayout::Footer, PbLayout::Header, PbLayout::Item, PbLayout::Layout, PbLayout::Sidebar, PbLegend::Legend, PbLink::Link, PbList::Item, PbList::List, PbLoadingInline::LoadingInline, PbMessage::Message, PbMessage::MessageMention, PbMultiLevelSelect::MultiLevelSelect, PbMultipleUsers::MultipleUsers, PbMultipleUsersStacked::MultipleUsersStacked, PbNav::Item, PbNav::Nav, PbOnlineStatus::OnlineStatus, PbOverlay::Overlay, PbPagination::Pagination, PbPassphrase::Passphrase, PbPbBarGraph::PbBarGraph, PbPbCircleChart::PbCircleChart, PbPbGaugeChart::PbGaugeChart, PbPbLineGraph::PbLineGraph, PbPerson::Person, PbPersonContact::PersonContact, PbPhoneNumberInput::PhoneNumberInput, PbPill::Pill, PbPopover::Popover, PbProgressPills::ProgressPills, PbProgressSimple::ProgressSimple, PbProgressStep::ProgressStep, PbProgressStep::ProgressStepItem, PbRadio::Radio, PbRichTextEditor::RichTextEditor, PbSectionSeparator::SectionSeparator, PbSelect::Select, PbSelectableCard::SelectableCard, PbSelectableCardIcon::SelectableCardIcon, PbSelectableIcon::SelectableIcon, PbSelectableList::SelectableList, PbSelectableList::SelectableListItem, PbSkeletonLoading::SkeletonLoading, PbSource::Source, PbStarRating::StarRating, PbStatChange::StatChange, PbStatValue::StatValue, PbTable::Table, PbTable::TableBody, PbTable::TableCell, PbTable::TableHead, PbTable::TableHeader, PbTable::TableRow, PbTextInput::AddOn, PbTextInput::TextInput, PbTextarea::Textarea, PbTime::Time, PbTimePicker::TimePicker, PbTimeRangeInline::TimeRangeInline, PbTimeStacked::TimeStacked, PbTimeline::Detail, PbTimeline::Item, PbTimeline::Label, PbTimeline::Step, PbTimeline::Timeline, PbTimestamp::Timestamp, PbTitle::Title, PbTitleCount::TitleCount, PbTitleDetail::TitleDetail, PbToggle::Toggle, PbTooltip::Tooltip, PbTypeahead::Typeahead, PbUser::User, PbUserBadge::UserBadge, PbWeekdayStacked::WeekdayStacked

Constant Summary collapse

EMPTY_HASH =
{}.freeze

Constants included from Border

Border::BORDER_PROP_MAP, Border::BORDER_VALUES

Constants included from MaxHeight

MaxHeight::MAX_HEIGHT_VALUES

Constants included from MinHeight

MinHeight::MIN_HEIGHT_VALUES

Constants included from Height

Height::HEIGHT_VALUES

Constants included from VerticalAlign

VerticalAlign::SCREEN_SIZES, VerticalAlign::VERTICAL_ALIGN_VALUES

Constants included from Bottom

Bottom::BOTTOM_VALUES

Constants included from PositionPropsCss

PositionPropsCss::POSITION_VALUES

Constants included from Right

Right::RIGHT_VALUES

Constants included from Top

Top::TOP_VALUES

Constants included from Left

Left::LEFT_VALUES

Constants included from Truncate

Truncate::TRUNCATE_VALUES

Constants included from Overflow

Overflow::OVERFLOW_VALUES

Constants included from TextAlign

TextAlign::SCREEN_SIZES, TextAlign::TEXT_ALIGN_VALUES

Constants included from BorderRadius

BorderRadius::BORDER_RADIUS_VALUES

Constants included from Hover

Hover::HOVER_ATTRIBUTES, Hover::HOVER_BACKGROUND_VALUES, Hover::HOVER_COLOR_VALUES, Hover::HOVER_SCALE_VALUES, Hover::HOVER_SHADOW_VALUES, Hover::HOVER_UNDERLINE_VALUES, Hover::HOVER_VISIBLE_VALUES

Constants included from Position

Position::POSITION_VALUES

Constants included from GridAutoFlow

GridAutoFlow::GRID_AUTO_FLOW_VALUES, GridAutoFlow::SCREEN_SIZES

Constants included from Order

Order::ORDER_VALUES, Order::SCREEN_SIZES

Constants included from FlexShrink

FlexShrink::FLEX_SHRINK_VALUES, FlexShrink::SCREEN_SIZES

Constants included from FlexGrow

FlexGrow::FLEX_GROW_VALUES, FlexGrow::SCREEN_SIZES

Constants included from Flex

Flex::FLEX_VALUES, Flex::SCREEN_SIZES

Constants included from AlignSelf

AlignSelf::ALIGN_SELF_VALUES, AlignSelf::SCREEN_SIZES

Constants included from AlignContent

AlignContent::ALIGN_CONTENT_VALUES, AlignContent::SCREEN_SIZES

Constants included from AlignItems

AlignItems::ALIGN_ITEMS_VALUES, AlignItems::SCREEN_SIZES

Constants included from JustifyItems

JustifyItems::JUSTIFY_ITEMS_VALUES, JustifyItems::SCREEN_SIZES

Constants included from JustifySelf

JustifySelf::JUSTIFY_SELF_VALUES, JustifySelf::SCREEN_SIZES

Constants included from JustifyContent

JustifyContent::JUSTIFY_CONTENT_VALUES, JustifyContent::SCREEN_SIZES

Constants included from FlexWrap

FlexWrap::FLEX_WRAP_VALUES, FlexWrap::SCREEN_SIZES

Constants included from FlexDirection

FlexDirection::FLEX_DIRECTION_VALUES, FlexDirection::SCREEN_SIZES

Constants included from Cursor

Cursor::CURSOR_VALUES

Constants included from Display

Display::DISPLAY_SIZE_VALUES, Display::DISPLAY_VALUES

Constants included from LineHeight

LineHeight::LINE_HEIGHT_VALUES

Constants included from Shadow

Shadow::SHADOW_VALUES

Constants included from NumberSpacing

NumberSpacing::NUMBER_SPACING_VALUES

Constants included from ZIndex

ZIndex::SCREEN_SIZES, ZIndex::Z_INDEX_VALUES

Constants included from Spacing

Spacing::BREAK_METHOD_VALUES, Spacing::GAP_VALUES, Spacing::MAX_WIDTH_VALUES, Spacing::MIN_WIDTH_VALUES, Spacing::SCREEN_SIZES, Spacing::SCREEN_SIZE_VALUES, Spacing::SPACING_HASH_SKIP_KEYS, Spacing::SPACING_PROP_MAP, Spacing::SPACING_VALUES, Spacing::WIDTH_VALUES

Instance Attribute Summary

Attributes included from Props

#values

Instance Method Summary collapse

Methods included from Border

border_class_for, border_class_for_prop, #border_options, #border_props, #border_values, included

Methods included from MaxHeight

included, #max_height_options, #max_height_props, #max_height_values

Methods included from MinHeight

included, #min_height_options, #min_height_props, #min_height_values

Methods included from Height

#height_options, #height_props, #height_values, included

Methods included from VerticalAlign

included, #vertical_align_options, #vertical_align_props, #vertical_align_values

Methods included from Bottom

#bottom_options, #bottom_values, included

Methods included from PositionPropsCss

#positioning_css

Methods included from Right

included, #right_options, #right_values

Methods included from Top

included, #top_options, #top_values

Methods included from Left

included, #left_options, #left_values

Methods included from Truncate

included, #truncate_options, #truncate_props, #truncate_values

Methods included from Overflow

included, #overflow_options, #overflow_props, #overflow_values

Methods included from TextAlign

included, #text_align_options, #text_align_props, #text_align_values

Methods included from BorderRadius

#border_radius_options, #border_radius_props, #border_radius_values, included

Methods included from Hover

#hover_attributes, #hover_background_values, #hover_color_values, #hover_options, #hover_props, #hover_scale_values, #hover_shadow_values, #hover_underline_values, #hover_values, #hover_visible_values, included

Methods included from Position

included, #position_options, #position_values

Methods included from GridAutoFlow

#grid_auto_flow_options, #grid_auto_flow_props, #grid_auto_flow_values, included

Methods included from Grid

#grid_options, included

Methods included from Order

included, #order_options, #order_props, #order_values

Methods included from FlexShrink

#flex_shrink_options, #flex_shrink_props, #flex_shrink_values, included

Methods included from FlexGrow

#flex_grow_options, #flex_grow_props, #flex_grow_values, included

Methods included from Flex

#flex_options, #flex_props, #flex_values, included

Methods included from AlignSelf

#align_self_options, #align_self_props, #align_self_values, included

Methods included from AlignContent

#align_content_options, #align_content_props, #align_content_values, included

Methods included from AlignItems

#align_items_options, #align_items_props, #align_items_values, included

Methods included from JustifyItems

included, #justify_items_options, #justify_items_props, #justify_items_values

Methods included from JustifySelf

included, #justify_self_options, #justify_self_props, #justify_self_values

Methods included from JustifyContent

included, #justify_content_options, #justify_content_props, #justify_content_values

Methods included from FlexWrap

#flex_wrap_options, #flex_wrap_props, #flex_wrap_values, included

Methods included from FlexDirection

#flex_direction_options, #flex_direction_props, #flex_direction_values, included

Methods included from Cursor

#cursor_options, #cursor_props, #cursor_values, included

Methods included from Display

#display_options, #display_props, #display_size_values, #display_values, included

Methods included from LineHeight

included, #line_height_options, #line_height_props, #line_height_values

Methods included from Shadow

included, #shadow_options, #shadow_props, #shadow_values

Methods included from NumberSpacing

included, #number_spacing_options, #number_spacing_values

Methods included from ZIndex

included, #screen_size_values, #z_index_options, #z_index_props, #z_index_values

Methods included from Spacing

#break_method_values, #column_gap_options, #column_gap_props, #filter_classname, #gap_options, #gap_props, #gap_values, included, #max_width_options, #max_width_props, #max_width_values, #min_width_options, #min_width_props, #min_width_values, #row_gap_options, #row_gap_props, #screen_size_values, #spacing_options, #spacing_props, #spacing_values, #width_options, #width_props, #width_values

Methods included from Classnames

#dark_props, #generate_classname, #generate_classname_without_spacing, included

Methods included from Props

#initialize, #prop

Methods included from PbKitHelper

#deprecated_kit_warning, #pb_rails

Methods included from PbFormsHelper

#pb_form_with

Instance Method Details

#combined_html_optionsObject

rubocop:enable Style/OptionalBooleanParameter



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/playbook/kit_base.rb', line 127

def combined_html_options
  ho = html_options
  inline = dynamic_inline_props

  # Fast path: no custom html_options and no inline styles (the common case)
  return data_attributes if ho.empty? && inline.nil?

  merged = default_html_options.dup

  ho.each do |key, value|
    if key == :style && value.is_a?(Hash)
      merged[:style] = value.map { |k, v| "#{k.to_s.tr('_', '-')}: #{v}" }.join("; ")
    else
      merged[key] = value
    end
  end

  if inline
    merged[:style] = merged[:style] ? "#{merged[:style]}; #{inline}" : inline
  end

  merged.deep_merge(data_attributes)
end

#global_inline_propsObject



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/playbook/kit_base.rb', line 174

def global_inline_props
  h = height
  mh = min_height
  xh = max_height
  gtc = grid_template_columns
  gtr = grid_template_rows
  gta = grid_template_areas
  gc = grid_column
  gr = grid_row
  ga = grid_area
  gac = grid_auto_columns
  gar = grid_auto_rows
  return EMPTY_HASH if h.nil? && mh.nil? && xh.nil? &&
                       gtc.nil? && gtr.nil? && gta.nil? &&
                       gc.nil? && gr.nil? && ga.nil? &&
                       gac.nil? && gar.nil?

  r = {}
  r[:height] = h if h
  r[:min_height] = mh if mh
  r[:max_height] = xh if xh
  r[:grid_template_columns] = gtc if gtc
  r[:grid_template_rows] = gtr if gtr
  r[:grid_template_areas] = gta if gta
  r[:grid_column] = gc if gc
  r[:grid_row] = gr if gr
  r[:grid_area] = ga if ga
  r[:grid_auto_columns] = gac if gac
  r[:grid_auto_rows] = gar if gar
  r
end

#objectObject



95
96
97
# File 'lib/playbook/kit_base.rb', line 95

def object
  self
end

#pb_content_tag(name = :div, content_or_options_with_block = {}, options = {}, escape = true, &block) ⇒ Object

rubocop:disable Style/OptionalBooleanParameter



119
120
121
122
123
124
# File 'lib/playbook/kit_base.rb', line 119

def (name = :div, content_or_options_with_block = {}, options = {}, escape = true, &block)
  combined_options = options
                     .merge(combined_html_options)
                     .merge(kit_base_default_options.merge(content_or_options_with_block))
  (name, combined_options, options, escape, &block)
end

#react_component(component_name, props = {}, html_options = {}) ⇒ Object

Custom react_component helper to replace Webpacker React This will render a div with data attributes for the component name and props The mounting script will look for these divs and mount the appropriate React components Sister def in app/helpers/react_helper in playbook-website. Any changes here should be reflected there.



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/playbook/kit_base.rb', line 155

def react_component(component_name, props = {}, html_options = {})
  # Convert props to JSON for the data attribute
  props_json = props.to_json

  # Build the HTML attributes
  html_attrs = {
    "data-pb-react-component" => component_name,
    "data-pb-react-props" => props_json,
  }

  # Merge with any additional HTML options
  html_attrs.merge!(html_options)

  # Return the div element
  (:div, "", html_attrs)
end