Cards as List Items

Use the cards as list items pattern to create visually rich lists as an alternative to grids or feeds. This pattern uses a combination of cards and billboards to show lists of like items; you can easily modify it to change the number of cards per row. This page explains how you can use the cards as list items pattern in your interface, and walks you through the design structure of the pattern in detail.

cards_as_list_items_pattern_orig.png

Design Structure

The purpose of this section is to break down this expression so you can better understand how to adapt this pattern to your own data.

The main components in this pattern are card layouts, side by side layouts, and billboard layouts. The image below displays how the pattern looks on a blank interface with callouts of the main components. You can examine the entire expression or jump down to the subsections below with referenced line numbers to see a detailed breakdown of the main components.

cards_as_list_pattern.png

Pattern Expression

When you drag and drop the cards as list items pattern onto your interface, 139 lines of expressions will be added to the section where you dragged it.

1
2
3
4
5
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
{
  load(
    local!houses: {
      {street: "2310 Groveland Ter",   city: "Reston", state: "VA", price: 879000,  beds: 3, baths: 2.5, sqft: 1934, img: "https://images.unsplash.com/photo-1492889971304-ac16ab4a4a5a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=058c56771e5c8d1f9adf38dc794f6e0e&auto=format&fit=crop&w=3306&q=80"},
      {street: "4147 Woodlane Dr",     city: "Reston", state: "VA", price: 719400,  beds: 2, baths: 1.5, sqft: 1415, img: "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=193a24d3505792ef2c9ace43b00fe4f5&auto=format&fit=crop&w=1400&q=60"},
      {street: "1924 Victoria Dr",     city: "Reston", state: "VA", price: 925000,  beds: 3, baths: 2,   sqft: 2451, img: "https://images.unsplash.com/photo-1485996463739-9cb09adbe6c5?ixlib=rb-0.3.5&s=95f7a5e9e6c1c6637b6d686ee5946e53&auto=format&fit=crop&w=800&q=60"},
      {street: "5850 Paddock Way",     city: "Reston", state: "VA", price: 925000,  beds: 4, baths: 3.5, sqft: 3290, img: "https://images.unsplash.com/photo-1437751695201-298be97a82a8?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=1a6e6c222ee269587d9d336902f370e5&auto=format&fit=crop&w=800&q=60"},
      {street: "2900 Carver Rd, #301", city: "Reston", state: "VA", price: 529200,  beds: 1, baths: 1.5, sqft: 1160, img: "https://images.unsplash.com/photo-1460317442991-0ec209397118?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b95599cb95166892018645cd2a22923a&auto=format&fit=crop&w=800&q=60"},
      {street: "7714 Andreas Ave",     city: "Reston", state: "VA", price: 742900,  beds: 2, baths: 2,   sqft: 1930, img: "https://images.unsplash.com/photo-1501183638710-841dd1904471?ixlib=rb-0.3.5&s=d9e9fe8649144a11972a8cbb10ad6cd3&auto=format&fit=crop&w=800&q=60"}
    },
    local!numCols: 3, /* Change this to set a different number of columns. */
    local!selection,
    {
      a!columnsLayout(
        columns: a!forEach(
          items: enumerate(local!numCols) + 1,
          expression: with(
            local!colIndex: fv!index,
            a!columnLayout(
              contents: {
                a!forEach(
                  items: local!houses,
                  expression: a!cardLayout(
                    contents: {
                      a!billboardLayout(
                        backgroundMedia: a!webImage(
                          source: fv!item.img
                        ),
                        overlayContents: {
                          a!sideBySideLayout(
                            items: {
                              a!sideBySideItem(
                                item: a!richTextDisplayField(
                                  label: "Street",
                                  labelPosition: "COLLAPSED",
                                  value: a!richTextItem(
                                    text: fv!item.street,
                                    size: "MEDIUM",
                                    style: "STRONG"
                                  )
                                )
                              ),
                              a!sideBySideItem(
                                item: a!richTextDisplayField(
                                  label: "City & State",
                                  labelPosition: "COLLAPSED",
                                  value: fv!item.city & ", " & fv!item.state
                                ),
                                width: "MINIMIZE"
                              )
                            },
                            alignVertical: "MIDDLE"
                          )
                        },
                        height: "SHORT",
                        marginBelow: "STANDARD"
                      ),
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Price",
                              labelPosition: "COLLAPSED",
                              value: a!richTextItem(
                                text: dollar(fv!item.price, 0),
                                size: "LARGE",
                                style: "STRONG"
                              )
                            )
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Beds",
                              value: fv!item.beds
                            ),
                            width: "MINIMIZE"
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Baths",
                              value: fv!item.baths
                            ),
                            width: "MINIMIZE"
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Sq. Ft.",
                              value: fixed(fv!item.sqft, 0, false)
                            ),
                            width: "MINIMIZE"
                          )
                        }
                      )
                    },
                    link: a!dynamicLink(saveInto: a!save(local!selection, fv!item.street)),
                    /* This logic assigns each card to the right column */
                    showWhen: or(mod(fv!index, local!numCols) = local!colIndex, and(mod(fv!index, local!numCols) = 0, local!colIndex = local!numCols)),
                    marginBelow: "STANDARD"
                  )
                )
              }
            )
          )
        ),
        alignvertical: "TOP",
        showWhen: isNull(local!selection)
      ),
      a!richTextDisplayField(
        value: "Details for " & local!selection & " would appear here",
        showWhen: not(isNull(local!selection)),
        align: "CENTER"
      ),
      a!richTextDisplayField(
        labelPosition: "COLLAPSED",
        value: {
          char(10),
          char(10),
          a!richTextIcon(
            icon: "arrow-left",
            link: a!dynamicLink(
              saveInto: a!save(local!selection, null)
            ),
            linkStyle: "STANDALONE",
            color: "ACCENT"
          ),
          a!richTextItem(
            text: " Go back",
            link: a!dynamicLink(
              saveInto: a!save(local!selection, null)
            ),
            linkStyle: "STANDALONE"
          )
        },
        showWhen: not(isNull(local!selection)),
        align: "CENTER"
      )
    }
  )
}

[Line 1-12] Define Columns and User Selection

At the top of the pattern, local variables are set up to index the house data, define the number of columns, and the user selection.

1
2
3
4
5
6
7
8
9
10
11
12
{
  load(
    local!houses: {
      {street: "2310 Groveland Ter",   city: "Reston", state: "VA", price: 879000,  beds: 3, baths: 2.5, sqft: 1934, img: "https://images.unsplash.com/photo-1492889971304-ac16ab4a4a5a?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=058c56771e5c8d1f9adf38dc794f6e0e&auto=format&fit=crop&w=3306&q=80"},
      {street: "4147 Woodlane Dr",     city: "Reston", state: "VA", price: 719400,  beds: 2, baths: 1.5, sqft: 1415, img: "https://images.unsplash.com/photo-1480074568708-e7b720bb3f09?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=193a24d3505792ef2c9ace43b00fe4f5&auto=format&fit=crop&w=1400&q=60"},
      {street: "1924 Victoria Dr",     city: "Reston", state: "VA", price: 925000,  beds: 3, baths: 2,   sqft: 2451, img: "https://images.unsplash.com/photo-1485996463739-9cb09adbe6c5?ixlib=rb-0.3.5&s=95f7a5e9e6c1c6637b6d686ee5946e53&auto=format&fit=crop&w=800&q=60"},
      {street: "5850 Paddock Way",     city: "Reston", state: "VA", price: 925000,  beds: 4, baths: 3.5, sqft: 3290, img: "https://images.unsplash.com/photo-1437751695201-298be97a82a8?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=1a6e6c222ee269587d9d336902f370e5&auto=format&fit=crop&w=800&q=60"},
      {street: "2900 Carver Rd, #301", city: "Reston", state: "VA", price: 529200,  beds: 1, baths: 1.5, sqft: 1160, img: "https://images.unsplash.com/photo-1460317442991-0ec209397118?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=b95599cb95166892018645cd2a22923a&auto=format&fit=crop&w=800&q=60"},
      {street: "7714 Andreas Ave",     city: "Reston", state: "VA", price: 742900,  beds: 2, baths: 2,   sqft: 1930, img: "https://images.unsplash.com/photo-1501183638710-841dd1904471?ixlib=rb-0.3.5&s=d9e9fe8649144a11972a8cbb10ad6cd3&auto=format&fit=crop&w=800&q=60"}
    },
    local!numCols: 3, /* Change this to set a different number of columns. */
    local!selection,

[Line 13-107] Using a Loop Function for Card Layouts with Nested Components

We use a!forEach() to loop through each column that contains a card layout. Each card layout contains a billboard layout to display the overlay of the street and city/state on the card layout image, as well as a side by side layout to display the price, beds, baths, and Sq. Ft. The card layout link parameter uses a!dynamicLink() to save the user's selection.

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
     {
      a!columnsLayout(
        columns: a!forEach(
          items: enumerate(local!numCols) + 1,
          expression: with(
            local!colIndex: fv!index,
            a!columnLayout(
              contents: {
                a!forEach(
                  items: local!houses,
                  expression: a!cardLayout(
                    contents: {
                      a!billboardLayout(
                        backgroundMedia: a!webImage(
                          source: fv!item.img
                        ),
                        overlayContents: {
                          a!sideBySideLayout(
                            items: {
                              a!sideBySideItem(
                                item: a!richTextDisplayField(
                                  label: "Street",
                                  labelPosition: "COLLAPSED",
                                  value: a!richTextItem(
                                    text: fv!item.street,
                                    size: "MEDIUM",
                                    style: "STRONG"
                                  )
                                )
                              ),
                              a!sideBySideItem(
                                item: a!richTextDisplayField(
                                  label: "City & State",
                                  labelPosition: "COLLAPSED",
                                  value: fv!item.city & ", " & fv!item.state
                                ),
                                width: "MINIMIZE"
                              )
                            },
                            alignVertical: "MIDDLE"
                          )
                        },
                        height: "SHORT",
                        marginBelow: "STANDARD"
                      ),
                      a!sideBySideLayout(
                        items: {
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Price",
                              labelPosition: "COLLAPSED",
                              value: a!richTextItem(
                                text: dollar(fv!item.price, 0),
                                size: "LARGE",
                                style: "STRONG"
                              )
                            )
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Beds",
                              value: fv!item.beds
                            ),
                            width: "MINIMIZE"
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Baths",
                              value: fv!item.baths
                            ),
                            width: "MINIMIZE"
                          ),
                          a!sideBySideItem(
                            item: a!richTextDisplayField(
                              label: "Sq. Ft.",
                              value: fixed(fv!item.sqft, 0, false)
                            ),
                            width: "MINIMIZE"
                          )
                        }
                      )
                    },
                    link: a!dynamicLink(saveInto: a!save(local!selection, fv!item.street)),
                    /* This logic assigns each card to the right column */
                    showWhen: or(mod(fv!index, local!numCols) = local!colIndex, and(mod(fv!index, local!numCols) = 0, local!colIndex = local!numCols)),
                    marginBelow: "STANDARD"
                  )
                )
              }
            )
          )
        ),
        alignvertical: "TOP",
        showWhen: isNull(local!selection)
      ),

[Line 108-139] Display Selection Content with Rich Text Display Fields

We then use rich text display fields to display the content of each house if the user selected one. These display fields would be where you could replace content to fit your own use case.

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
      a!richTextDisplayField(
        value: "Details for " & local!selection & " would appear here",
        showWhen: not(isNull(local!selection)),
        align: "CENTER"
      ),
      a!richTextDisplayField(
        labelPosition: "COLLAPSED",
        value: {
          char(10),
          char(10),
          a!richTextIcon(
            icon: "arrow-left",
            link: a!dynamicLink(
              saveInto: a!save(local!selection, null)
            ),
            linkStyle: "STANDALONE",
            color: "ACCENT"
          ),
          a!richTextItem(
            text: " Go back",
            link: a!dynamicLink(
              saveInto: a!save(local!selection, null)
            ),
            linkStyle: "STANDALONE"
          )
        },
        showWhen: not(isNull(local!selection)),
        align: "CENTER"
      )
    }
  )
}
FEEDBACK