Skip to main content

Cards

Presents options as cards for the user. Cards may be selectable.

Examples

Basic Example

The following example demonstrate some of the available functionality for read_cards

from abstra.forms import read_cards

card = read_cards(
"Choose your favorite dessert",
[
{
"title": "Crepe",
"subtitle": "French",
"image": "https://cdn.pixabay.com/photo/2017/01/30/13/56/pancakes-2020870_1280.jpg",
"description": "A crêpe or crepe is a type of very thin pancake.",
},
{
"title": "Pancake",
"subtitle": "American",
"image": "https://cdn.pixabay.com/photo/2018/07/10/21/23/pancake-3529653_1280.jpg",
"description": "A pancake is a flat cake, often thin and round.",
},
{
"title": "Waffle",
"subtitle": "Belgian",
"image": "https://cdn.pixabay.com/photo/2020/05/19/20/54/waffles-5192625_1280.jpg",
"description": "A waffle is a patterned dish made from leavened batter or dough.",
},
],
)
# card = { 'title': ..., 'subtitle': ..., 'image': ..., 'description': ..., 'topLeftExtra': ..., 'topRightExtra': ... }

A multiple selection question with search enabled.

from abstra.forms import read_cards

card = read_cards(
"Which desserts do you like?",
[
{
"title": "Crepe",
"subtitle": "French",
"image": "https://cdn.pixabay.com/photo/2017/01/30/13/56/pancakes-2020870_1280.jpg",
"description": "A crêpe or crepe is a type of very thin pancake.",
},
{
"title": "Pancake",
"subtitle": "American",
"image": "https://cdn.pixabay.com/photo/2018/07/10/21/23/pancake-3529653_1280.jpg",
"description": "A pancake is a flat cake, often thin and round.",
},
{
"title": "Waffle",
"subtitle": "Belgian",
"image": "https://cdn.pixabay.com/photo/2020/05/19/20/54/waffles-5192625_1280.jpg",
"description": "A waffle is a patterned dish made from leavened batter or dough.",
},
],
multiple=True,
searchable=True,
)

Parameters

NameDescriptionType
labelThe text related to this inputstr
optionsList of dicts representing the cards, each dict can have the following keys: title, subtitle, image, description, topLeftExtra, topRightExtralist
multipleWhether the user can select multiple options. Defaults to False.bool
initial_valueThe initial value to display to the user. Defaults to None.list
searchableWhether to show a search bar. Defaults to False.bool
layoutWhether the cards layout should be 'list' or 'grid'. Defaults to 'list'. The 'grid' only applies to desktop resolutions.str
columnsWhen layout is 'grid', how many columns to displayint
disabledwhether the input is disabled. Defaults to False.bool
requiredWhether the input is required or not eg. "this field is required". Defaults to True.Union[bool, str]
hintA tooltip displayed to the user. Defaults to None.str
end_programWhether the program should end after the widget is shown. Defaults to False.bool
full_widthWhether the input should use full screen width. Defaults to False.bool
button_textWhat text to display on the button when the widget is not part of a Page. Defaults to 'Next'.str

Return Values

TypeDescription
Union[list, any]The options/option selected by the user