Module: Playbook::Props

Extended by:
ActiveSupport::Concern
Included in:
Playbook::PbAvatar::Avatar, Playbook::PbAvatarActionButton::AvatarActionButton, Playbook::PbBackground::Background, Playbook::PbBadge::Badge, Playbook::PbBarGraph::BarGraph, Playbook::PbBody::Body, Playbook::PbButton::Button, Playbook::PbButtonToolbar::ButtonToolbar, Playbook::PbCaption::Caption, Playbook::PbCard::Card, Playbook::PbCard::CardBody, Playbook::PbCard::CardHeader, Playbook::PbCheckbox::Checkbox, Playbook::PbCircleChart::CircleChart, Playbook::PbCircleIconButton::CircleIconButton, Playbook::PbContact::Contact, Playbook::PbCurrency::Currency, Playbook::PbDashboardValue::DashboardValue, Playbook::PbDate::Date, Playbook::PbDatePicker::DatePicker, Playbook::PbDateRangeInline::DateRangeInline, Playbook::PbDateRangeStacked::DateRangeStacked, Playbook::PbDateStacked::DateStacked, Playbook::PbDateTime::DateTime, Playbook::PbDateTimeStacked::DateTimeStacked, Playbook::PbDateYearStacked::DateYearStacked, Playbook::PbDistributionBar::DistributionBar, Playbook::PbFileUpload::FileUpload, Playbook::PbFilter::Filter, Playbook::PbFixedConfirmationToast::FixedConfirmationToast, Playbook::PbFlex::Flex, Playbook::PbFlex::FlexItem, Playbook::PbForm::Form, Playbook::PbFormGroup::FormGroup, Playbook::PbFormPill::FormPill, Playbook::PbGauge::Gauge, Playbook::PbHashtag::Hashtag, Playbook::PbHighlight::Highlight, Playbook::PbHomeAddressStreet::HomeAddressStreet, Playbook::PbIcon::Icon, Playbook::PbIconCircle::IconCircle, Playbook::PbIconStatValue::IconStatValue, Playbook::PbIconValue::IconValue, Playbook::PbImage::Image, Playbook::PbLabelPill::LabelPill, Playbook::PbLabelValue::LabelValue, Playbook::PbLayout::Body, Playbook::PbLayout::Footer, Playbook::PbLayout::Header, Playbook::PbLayout::Layout, Playbook::PbLayout::Sidebar, Playbook::PbLegend::Legend, Playbook::PbLineGraph::LineGraph, Playbook::PbList::Item, Playbook::PbList::List, Playbook::PbLoadingInline::LoadingInline, Playbook::PbMessage::Message, Playbook::PbMultipleUsers::MultipleUsers, Playbook::PbMultipleUsersStacked::MultipleUsersStacked, Playbook::PbNav::Item, Playbook::PbNav::Nav, Playbook::PbOnlineStatus::OnlineStatus, Playbook::PbPerson::Person, Playbook::PbPersonContact::PersonContact, Playbook::PbPill::Pill, Playbook::PbPopover::Popover, Playbook::PbProgressPills::ProgressPills, Playbook::PbProgressSimple::ProgressSimple, Playbook::PbProgressStep::ProgressStep, Playbook::PbProgressStep::ProgressStepItem, Playbook::PbRadio::Radio, Playbook::PbRichTextEditor::RichTextEditor, Playbook::PbSectionSeparator::SectionSeparator, Playbook::PbSelect::Select, Playbook::PbSelectableCard::SelectableCard, Playbook::PbSelectableCardIcon::SelectableCardIcon, Playbook::PbSelectableIcon::SelectableIcon, Playbook::PbSelectableList::SelectableList, Playbook::PbSelectableList::SelectableListItem, Playbook::PbSource::Source, Playbook::PbStarRating::StarRating, Playbook::PbStatChange::StatChange, Playbook::PbStatValue::StatValue, Playbook::PbTable::Table, Playbook::PbTable::TableRow, Playbook::PbTextInput::TextInput, Playbook::PbTextarea::Textarea, Playbook::PbTime::Time, Playbook::PbTimeRangeInline::TimeRangeInline, Playbook::PbTimeStacked::TimeStacked, Playbook::PbTimeline::Item, Playbook::PbTimeline::Timeline, Playbook::PbTimestamp::Timestamp, Playbook::PbTitle::Title, Playbook::PbTitleCount::TitleCount, Playbook::PbTitleDetail::TitleDetail, Playbook::PbToggle::Toggle, Playbook::PbTooltip::Tooltip, Playbook::PbTypeahead::Typeahead, Playbook::PbUser::User, Playbook::PbUserBadge::UserBadge, Playbook::PbWeekdayStacked::WeekdayStacked
Defined in:
app/pb_kits/playbook/props.rb,
app/pb_kits/playbook/props/base.rb,
app/pb_kits/playbook/props/date.rb,
app/pb_kits/playbook/props/enum.rb,
app/pb_kits/playbook/props/hash.rb,
app/pb_kits/playbook/props/proc.rb,
app/pb_kits/playbook/props/array.rb,
app/pb_kits/playbook/props/number.rb,
app/pb_kits/playbook/props/string.rb,
app/pb_kits/playbook/props/boolean.rb,
app/pb_kits/playbook/props/numeric.rb,
app/pb_kits/playbook/props/hash_array.rb,
app/pb_kits/playbook/props/percentage.rb,
app/pb_kits/playbook/props/number_array.rb

Defined Under Namespace

Classes: Array, Base, Boolean, Date, Enum, Error, Hash, HashArray, Number, NumberArray, Numeric, Percentage, Proc, String

Instance Method Summary collapse

Instance Method Details

#dark_propsObject



46
47
48
# File 'app/pb_kits/playbook/props.rb', line 46

def dark_props
  dark ? "dark" : nil
end

#generate_classname(*name_parts, separator: "_") ⇒ Object



50
51
52
53
54
55
56
57
# File 'app/pb_kits/playbook/props.rb', line 50

def generate_classname(*name_parts, separator: "_")
  [
    name_parts.compact.join(separator),
    prop(:classname),
    spacing_props,
    dark_props
  ].compact.join(" ")
end

#generate_classname_without_spacing(*name_parts, separator: "_") ⇒ Object



59
60
61
62
63
64
# File 'app/pb_kits/playbook/props.rb', line 59

def generate_classname_without_spacing(*name_parts, separator: "_")
  [
    name_parts.compact.join(separator),
    prop(:classname),
  ].compact.join(" ")
end

#initialize(prop_values = {}, &block) ⇒ Object



25
26
27
28
29
30
# File 'app/pb_kits/playbook/props.rb', line 25

def initialize(prop_values = {}, &block)
  self.values = { children: block }.merge(Hash(prop_values))
  self.class.props.each do |key, definition|
    definition.validate! values[key]
  end
end

#prop(name) ⇒ Object



32
33
34
# File 'app/pb_kits/playbook/props.rb', line 32

def prop(name)
  self.class.props[name].value values[name]
end

#spacing_optionsObject



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/pb_kits/playbook/props.rb', line 92

def spacing_options
  {
    margin: "m",
    margin_bottom: "mb",
    margin_left: "ml",
    margin_right: "mr",
    margin_top: "mt",
    margin_x: "mx",
    margin_y: "my",
    padding: "p",
    padding_bottom: "pb",
    padding_left: "pl",
    padding_right: "pr",
    padding_top: "pt",
    padding_x: "px",
    padding_y: "py",
  }
end

#spacing_propsObject



36
37
38
39
40
41
42
43
44
# File 'app/pb_kits/playbook/props.rb', line 36

def spacing_props
  selected_props = spacing_options.keys.select { |sk| try(sk) }
  return nil unless selected_props.present?

  selected_props.map do |k|
    spacing_value = send(k)
    "#{spacing_options[k]}_#{spacing_value}" if spacing_values.include? spacing_value
  end.compact.join(" ")
end

#spacing_valuesObject



111
112
113
# File 'app/pb_kits/playbook/props.rb', line 111

def spacing_values
  %w[none xs sm md lg xl]
end