|
| 1 | +# Arbre Components |
| 2 | + |
| 3 | +Arbre allows the creation of shareable and extendable HTML components and is |
| 4 | +used throughout Active Admin to create view components. |
| 5 | + |
| 6 | +## Text Node |
| 7 | + |
| 8 | +Sometimes it makes sense to insert something into a registered resource like a |
| 9 | +non-breaking space or some text. The text_node method can be used to insert |
| 10 | +these elements into the page inside of other Arbre components or resource |
| 11 | +controller functions. |
| 12 | + |
| 13 | + ActiveAdmin.register Post do |
| 14 | + show do |
| 15 | + panel "Post Details" do |
| 16 | + row("") { post.id } |
| 17 | + row("Tags") do |
| 18 | + text_node link_to "#{tag}", |
| 19 | + admin_post_path( q: { tagged_with_contains: tag } ) |
| 20 | + text_node " ".html_safe |
| 21 | + end |
| 22 | + end |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | +## Common Components |
| 27 | + |
| 28 | +### Panel Component |
| 29 | + |
| 30 | +A panel is a component that takes up all available horizontal space and takes a |
| 31 | +title and a hash of attributes as arguments. If a sidebar is present, a panel |
| 32 | +will take up the remaining space. |
| 33 | + |
| 34 | +The following code will create two stacked panels: |
| 35 | + |
| 36 | + show do |
| 37 | + |
| 38 | + panel "Post Details" do |
| 39 | + render partial: "show_details", locals: {post: post} |
| 40 | + end |
| 41 | + |
| 42 | + panel "Post Tags" do |
| 43 | + render partial: "show_enhancements", locals: {post: post} |
| 44 | + end |
| 45 | + |
| 46 | + end |
| 47 | + |
| 48 | +### Columns Component |
| 49 | + |
| 50 | +The Columns component allows you draw content into scalable columns. All you |
| 51 | +need to do is define the number of columns and the component will take care of |
| 52 | +the rest. |
| 53 | + |
| 54 | +#### Simple Columns |
| 55 | + |
| 56 | +To create simple columnns, use the #columns method. Within the block, call the |
| 57 | +#column method to create a new column. |
| 58 | + |
| 59 | + columns do |
| 60 | + |
| 61 | + column do |
| 62 | + span "Column #1" |
| 63 | + end |
| 64 | + |
| 65 | + column do |
| 66 | + span "Column #2" |
| 67 | + end |
| 68 | + |
| 69 | + end |
| 70 | + |
| 71 | +#### Multiple Span Columns |
| 72 | + |
| 73 | +To create columns that have multiple spans, pass the :span option to the column |
| 74 | +method. |
| 75 | + |
| 76 | + columns do |
| 77 | + column :span => 2 do |
| 78 | + span "Column # 1 |
| 79 | + end |
| 80 | + column do |
| 81 | + span "Column # 2 |
| 82 | + end |
| 83 | + end |
| 84 | + |
| 85 | +By default, each column spans 1 column. The above layout would have 2 columns, |
| 86 | +the first being twice as large as the second. |
| 87 | + |
| 88 | +#### Max and Mix Column Sizes |
| 89 | + |
| 90 | +Active Admin uses a fluid width layout, causing column width to be defined |
| 91 | +using percentages. Due to using this style of layout, columns can shrink or |
| 92 | +expand past points that may not be desirable. To overcome this issue, |
| 93 | +columns provide :max_width and :min_width options. |
| 94 | + |
| 95 | + columns do |
| 96 | + column :max_width => "200px", :min_width => "100px" do |
| 97 | + span "Column # 1 |
| 98 | + end |
| 99 | + column do |
| 100 | + span "Column # 2 |
| 101 | + end |
| 102 | + end |
| 103 | + |
| 104 | +In the above example, the first column will not grow larger than 200px and will |
| 105 | +not shrink less than 100px. |
| 106 | + |
| 107 | +### Table For Component |
| 108 | + |
| 109 | +Table For provides the ability to create tables like those present in |
| 110 | +#index_as_table. table_for takes a collection and a hash of options and then |
| 111 | +uses #column to build the fields to show with the table. |
| 112 | + |
| 113 | + table_for order.payments do |
| 114 | + column "Payment Type" { |payment| payment.payment_type.titleize } |
| 115 | + column "Received On", :created_at |
| 116 | + column "Payment Details & Notes", :payment_details |
| 117 | + column "Amount" { |payment| payment.amount_in_dollars } |
| 118 | + end |
| 119 | + |
| 120 | +the #column method can take a title as its first argument and data |
| 121 | +(:your_method) as its second (or first if no title provided). Column also |
| 122 | +takes a block. |
| 123 | + |
| 124 | +### Status tag |
| 125 | + |
| 126 | +Status tags provide convenient syntactic sugar for styling items that have |
| 127 | +status. A common example of where the status tag could be useful is for orders |
| 128 | +that are complete or in progress. status_tag takes a status, like |
| 129 | +"In Progress", a type, which defaults to nil, and a hash of options. The |
| 130 | +status_tag will generate html markup that Active Admin css uses in styling. |
| 131 | + |
| 132 | + status_tag('In Progress') |
| 133 | + # => <span class='status_tag in_progress'>In Progress</span> |
| 134 | + |
| 135 | + status_tag('active', :ok) |
| 136 | + # => <span class='status_tag active ok'>Active</span> |
| 137 | + |
| 138 | + status_tag ( |
| 139 | + 'active', |
| 140 | + :ok, |
| 141 | + :class => 'important', |
| 142 | + :id => 'status_123', |
| 143 | + :label => 'on' |
| 144 | + ) |
| 145 | + # => <span class='status_tag active ok important' id='status_123'>on</span> |
0 commit comments