Skip to content

Commit 58b2b4d

Browse files
committed
Custom layouts! Finally ! Adds a width parameter in the card component
fixes #476
1 parent 7d1f642 commit 58b2b4d

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
- fix [datagrid](https://sql.ophir.dev/documentation.sql?component=datagrid#component) color pills display when they contain long text.
1818
- fix the "started successfully" message being displayed before the error message when the server failed to start.
1919
- add support for using the system's native SSL Certificate Authority (CA) store in `sqlpage.fetch`. See the new `system_root_ca_certificates` configuration option.
20+
- New `width` attribute in the [card](https://sql.ophir.dev/documentation.sql?component=card#component) component to set the width of the card. This finally allows you to create custom layouts, by combining the `embed` and `width` attributes of the card component.
21+
- This also updates the default layout of the card component: when `columns` is not set, there is now a default of 4 columns instead of 5.
2022

2123
## 0.25.0 (2024-07-13)
2224

examples/official-site/sqlpage/migrations/31_card_docs_update.sql

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
77
('title', 'Text header at the top of the list of cards.', 'TEXT', TRUE, TRUE),
88
('description', 'A short paragraph displayed below the title.', 'TEXT', TRUE, TRUE),
99
('description_md', 'A short paragraph displayed below the title - formatted using markdown.', 'TEXT', TRUE, TRUE),
10-
('columns', 'The number of columns in the grid of cards. This is just a hint, the grid will adjust dynamically to the user''s screen size, rendering fewer columns if needed to fit the contents.', 'INTEGER', TRUE, TRUE),
10+
('columns', 'The number of columns in the grid of cards. This is just a hint, the grid will adjust dynamically to the user''s screen size, rendering fewer columns if needed to fit the contents. To control the size of cards individually, use the `width` row-level property instead.', 'INTEGER', TRUE, TRUE),
1111
-- item level
1212
('title', 'Name of the card, displayed at the top.', 'TEXT', FALSE, FALSE),
1313
('description', 'The body of the card, where you put the main text contents of the card.
@@ -26,7 +26,8 @@ INSERT INTO parameter(component, name, description, type, top_level, optional) S
2626
('icon', 'Name of an icon to display on the left side of the card.', 'ICON', FALSE, TRUE),
2727
('color', 'The name of a color, to be displayed on the left of the card to highlight it.', 'COLOR', FALSE, TRUE),
2828
('background_color', 'The background color of the card.', 'COLOR', FALSE, TRUE),
29-
('active', 'Whether this item in the grid is considered "active". Active items are displayed more prominently.', 'BOOLEAN', FALSE, TRUE)
29+
('active', 'Whether this item in the grid is considered "active". Active items are displayed more prominently.', 'BOOLEAN', FALSE, TRUE),
30+
('width', 'The width of the card, between 1 (smallest) and 12 (full-width). The default width is 3, resulting in 4 cards per line.', 'INTEGER', FALSE, TRUE)
3031
) x;
3132
INSERT INTO parameter(component, name, description_md, type, top_level, optional) SELECT 'card', * FROM (VALUES
3233
('embed', 'A url whose contents will be fetched and injected into the body of this card.
@@ -61,12 +62,12 @@ INSERT INTO example(component, description, properties) VALUES
6162
{"title": "Squirrel", "description_md": "The **chipmunk** is a small, striped rodent of the family Sciuridae. Chipmunks are found in North America, with the exception of the Siberian chipmunk which is found primarily in Asia.", "top_image": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Tamias-rufus-001.jpg/640px-Tamias-rufus-001.jpg" },
6263
{"title": "Spider", "description_md": "The **jumping spider family** (_Salticidae_) contains more than 600 described genera and about *6000 described species*, making it the largest family of spiders with about 13% of all species.", "top_image": "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ab/Jumping_spiders_%28Salticidae%29.jpg/640px-Jumping_spiders_%28Salticidae%29.jpg" }
6364
]')),
64-
('card', 'Beautifully colored cards',
65+
('card', 'Beautifully colored cards with variable width. The blue card (width 6) takes half the screen, whereas of the red and green cards have the default width of 3',
6566
json('[
66-
{"component":"card", "title":"Beautifully colored cards", "columns": 3},
67+
{"component":"card", "title":"Beautifully colored cards" },
6768
{"title": "Red card", "color": "red", "background_color": "red-lt", "description": "Penalty! You are out!", "icon":"play-football" },
68-
{"title": "Green card", "color": "green", "background_color": "green-lt", "description": "Welcome to the United States of America !", "icon":"user-dollar" },
69-
{"title": "Blue card", "color": "blue", "background_color": "blue-lt", "description": "The Blue Card facilitates migration of foreigners to Europe.", "icon":"currency-euro" }
69+
{"title": "Blue card", "color": "blue", "width": 6, "background_color": "blue-lt", "description": "The Blue Card facilitates migration of foreigners to Europe.", "icon":"currency-euro" },
70+
{"title": "Green card", "color": "green", "background_color": "green-lt", "description": "Welcome to the United States of America !", "icon":"user-dollar" }
7071
]')),
7172
('card', 'Cards with remote content',
7273
json('[

sqlpage/templates/card.handlebars

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
{{#if description_md}}
88
{{{markdown description_md}}}
99
{{/if}}
10-
<div class="
11-
row
12-
row-cols-1
13-
{{#if columns}}
14-
{{#if (gt columns 2)}}row-cols-sm-2{{/if}}
10+
<div class="row gx-2 gy-2 mt-1 mb-3 {{class}}
11+
{{~#if columns~}}
12+
{{#if (gt columns 2)}} row-cols-sm-2 {{/if}}
1513
row-cols-lg-{{columns}}
16-
{{else}}
17-
row-cols-sm-2
18-
row-cols-md-3
19-
row-cols-lg-4
20-
row-cols-xl-5
21-
{{/if}}
22-
gx-2 gy-2
23-
mt-1 mb-3 {{class}}">
14+
{{/if}}">
2415
{{#each_row}}
25-
<div class="col {{class}}" {{#if id}}id="{{id}}"{{/if}}>
16+
<div class="
17+
{{#unless ../columns}}
18+
{{~#if width~}}
19+
{{~#if (lt width 6)}} col-12 col-md-6 {{/if~}}
20+
col-md-{{width~}}
21+
{{~else~}}
22+
col-12 col-md-6 col-lg-3
23+
{{~/if~}}
24+
{{/unless}} {{class}}"
25+
{{~#if id}} id="{{id}}"{{/if}}>
2626
<div class="card h-100
2727
{{~#if active}} card-active{{/if~}}
2828
{{~#if background_color}} bg-{{background_color}} text-{{background_color}}-fg{{/if~}}

0 commit comments

Comments
 (0)