Module: Decidim::Design::ButtonsHelper

Defined in:
decidim-design/app/helpers/decidim/design/buttons_helper.rb

Instance Method Summary collapse

Instance Method Details

#background_button_row(button_args) ⇒ Object



185
186
187
188
189
190
191
# File 'decidim-design/app/helpers/decidim/design/buttons_helper.rb', line 185

def background_button_row(button_args)
  cell_args = { cell: "decidim/button", args: [button_args.slice(:icon).merge(text: t("decidim.design.helpers.send")), button_args] }
  [
    (:div, cell(cell_args[:cell], *cell_args[:args]), class: "bg-primary p-4 rounded"),
    button_args[:description] || button_args[:button_classes]
  ]
end

#button_row(button_args) ⇒ Object



177
178
179
180
181
182
183
# File 'decidim-design/app/helpers/decidim/design/buttons_helper.rb', line 177

def button_row(button_args)
  cell_args = { cell: "decidim/button", args: [button_args.slice(:icon).merge(text: t("decidim.design.helpers.send")), button_args] }
  [
    { method: :cell, args: [cell_args[:cell], *cell_args[:args]] },
    button_args[:description] || button_args[:button_classes]
  ]
end

#buttons_sectionsObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'decidim-design/app/helpers/decidim/design/buttons_helper.rb', line 6

def buttons_sections
  [
    {
      id: "sizes",
      title: t("decidim.design.helpers.sizes"),
      contents: [
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            { button_classes: "button button__primary button__xs" },
            { button_classes: "button button__primary button__sm" },
            { button_classes: "button button__primary button__lg" },
            { button_classes: "button button__primary button__xl" }
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [{ text: t("decidim.design.helpers.send") }, { button_classes: "button button__primary button__xs" }],
            call_string: [
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__primary button__xs" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__primary button__sm" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__primary button__lg" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__primary button__xl" })}
            ]
          }
        }
      ]
    },
    {
      id: "colors",
      title: t("decidim.design.helpers.colors"),
      contents: [
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            { button_classes: "button button__lg button__primary" },
            { button_classes: "button button__lg button__secondary" },
            { button_classes: "button button__lg button__tertiary" }
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [{ text: t("decidim.design.helpers.send") }, { button_classes: "button button__lg button__primary" }],
            call_string: [
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__primary" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__secondary" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__tertiary" })}
            ]
          }
        }
      ]
    },
    {
      id: "transparent",
      title: t("decidim.design.helpers.transparent"),
      contents: [
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            { button_classes: "button button__lg button__transparent-primary" },
            { button_classes: "button button__lg button__transparent-secondary" },
            { button_classes: "button button__lg button__transparent-tertiary" }
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [{ text: t("decidim.design.helpers.send") }, { button_classes: "button button__lg button__transparent-primary" }],
            call_string: [
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__transparent-primary" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__transparent-secondary" })},
              %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__transparent-tertiary" })}
            ]
          }
        },
        {
          type: :text,
          values: [t("decidim.design.helpers.transparent_description")]
        },
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            { button_classes: "button button__lg button__transparent" },
            background: true
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [{ text: t("decidim.design.helpers.send") }, { button_classes: "button button__lg button__transparent" }],
            call_string: %{cell("decidim/button", { text: "Send" }, { button_classes: "button button__lg button__transparent" })}
          }
        }
      ]
    },
    {
      id: "text",
      title: t("decidim.design.helpers.text"),
      contents: [
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            { button_classes: "button button__lg button__text" },
            { button_classes: "button button__lg button__text-primary" },
            { button_classes: "button button__lg button__text-secondary" },
            { button_classes: "button button__lg button__text-tertiary" }
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [{ text: t("decidim.design.helpers.send") }, { button_classes: "button button__lg button__text" }],
            call_string: [
              %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")} }, { button_classes: "button button__lg button__text" })},
              %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")} }, { button_classes: "button button__lg button__text-primary" })},
              %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")} }, { button_classes: "button button__lg button__text-secondary" })},
              %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")} }, { button_classes: "button button__lg button__text-tertiary" })}
            ]
          }
        }
      ]
    },
    {
      id: "icons",
      title: t("decidim.design.helpers.icons"),
      contents: [
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            { button_classes: "button button__lg button__secondary", icon: "question-line" },
            { button_classes: "button button__lg button__transparent-secondary", icon: "question-line" }
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [{ text: t("decidim.design.helpers.send"), icon: "question-line" }, { button_classes: "button button__lg button__secondary" }],
            call_string: [
              %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")}, icon: "question-line" }, { button_classes: "button button__lg button__secondary" })},
              %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")}, icon: "question-line" },
              { button_classes: "button button__lg button__transparent-secondary" })}
            ]
          }
        }
      ]
    },
    {
      id: "disabled",
      title: t("decidim.design.helpers.disabled"),
      contents: [
        {
          type: :table,
          options: buttons_table_options,
          items: buttons_table_items_from_args(
            {
              button_classes: "button button__lg button__secondary",
              html_options: { disabled: true },
              description: "<code>disabled</code> data-attribute present".html_safe
            }
          ),
          cell_snippet: {
            cell: "decidim/button",
            args: [
              { text: t("decidim.design.helpers.send") },
              { button_classes: "button button__lg button__secondary", html_options: { disabled: true } }
            ],
            call_string: %{cell("decidim/button", { text: #{t("decidim.design.helpers.send")} },
            { button_classes: "button button__lg button__secondary", html_options: { disabled: true } })}
          }
        }
      ]
    }
  ]
end

#buttons_table_items_from_args(*buttons_args, **opts) ⇒ Object



193
194
195
196
197
# File 'decidim-design/app/helpers/decidim/design/buttons_helper.rb', line 193

def buttons_table_items_from_args(*buttons_args, **opts)
  buttons_args.map do |button_args|
    opts[:background] ? background_button_row(button_args) : button_row(button_args)
  end
end

#buttons_table_optionsObject



199
200
201
# File 'decidim-design/app/helpers/decidim/design/buttons_helper.rb', line 199

def buttons_table_options
  @buttons_table_options ||= { headings: %w(Button Classes) }
end