Skip to content

Commit 59c9cf4

Browse files
committed
better tabs example
1 parent 5712eb5 commit 59c9cf4

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
create table if not exists tab_example_cards as
2+
select 'Leaf' as title, 'Leaf_1_web' as img, 'f4' as prefix, 'green' as color union all
3+
select 'Caterpillar', 'Caterpillar_of_box_tree_moth%2C_Germany_2019', 'a9', 'green' union all
4+
select 'Butterfly', 'Common_brimstone_butterfly_(Gonepteryx_rhamni)_male', '6a', 'green' union all
5+
select 'Flower', 'Red-poppy-flower_-_West_Virginia_-_ForestWander', 'fd', 'red' union all
6+
select 'Bird', 'Summer_tanager_(Piranga_rubra)_male_Copan_3', 'dd', 'red' union all
7+
select 'Medusa', 'Aurelia_aurita_2', '5c', 'blue';
8+
9+
select 'tab' as component, true as center;
10+
select 'Show all cards' as title, 'All things are beautiful' as description, '?' as link, $tab is null as active;
11+
select format('Show %s cards', color) as title,
12+
format('%s things are beautiful', color) as description,
13+
format('?tab=%s', color) as link,
14+
$tab=color as active,
15+
case $tab when color then color end as color -- only show the color when the tab is active
16+
from tab_example_cards
17+
group by color;
18+
19+
20+
select 'card' as component;
21+
select title,
22+
format('https://upload.wikimedia.org/wikipedia/commons/thumb/%s/%s/%s.jpg/640px-%s.jpg', substr(prefix,1,1), prefix, img, img) as top_image,
23+
color
24+
from tab_example_cards
25+
where $tab is null or $tab = color;
26+
27+
select 'text' as component, 'See [source code on GitHub](https://github.com/lovasoa/SQLpage/blob/main/examples/official-site/examples/tabs.sql)' as contents_md;

examples/official-site/sqlpage/migrations/13_tab.sql

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ For example, if the page is `/my-page.sql`, then the first tab will have a link
8181
8282
You could then for instance display contents coming from the database based on the value of the `tab` parameter.
8383
For instance: `SELECT ''text'' AS component, contents_md FROM my_page_contents WHERE tab = $tab`
84-
',
84+
85+
Note that the example below is completely static, and does not use the `tab` parameter to actually switch between tabs.
86+
View the [dynamic tabs example](examples/tabs.sql).
87+
',
8588
JSON(
8689
'[
8790
{ "component": "tab" },

0 commit comments

Comments
 (0)