Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
150 changes: 150 additions & 0 deletions examples/official-site/sqlpage/migrations/33_carousel_component.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
INSERT INTO component (name, description, icon, introduced_in_version)
VALUES (
'carousel',
'A carousel is used to display multiple pieces of visual content without taking up too much space.',
'carousel-horizontal',
'0.18.0'
);

INSERT INTO parameter (
component,
name,
description,
type,
top_level,
optional
)
VALUES (
'carousel',
'name',
'Name of the carousel.',
'TEXT',
TRUE,
FALSE
Copy link
Collaborator

@lovasoa lovasoa Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid having such requirements in sqlpage. We can do with it if there is no other choice, but it looks like this is an internal implementation technicality. Wouldn't it be better if the user didn't have to specify an id and make sure it is unique ? It is very easy to end up with duplicate identifiers and errors that are completely impossible to debug if you don't already understand html, javascript and the DOM. And the entire idea of sqlpage is to get rid of such prerequisites.

Couldn't we auto-generate an id like carousel_{{query_number}} where query_number comes from https://github.com/lovasoa/SQLpage/blob/main/src/render.rs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's possible to use an id like carousel_{{query_number}} but it seems to me not accessible in the template. If I understand the Rust code, the value of query_number is only initialized where an error is occured and only in development mode.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes render.rs needs to be updated to add query_number to the handlebars context.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can look at how row_index is added to the context.
query_number needs to be passed all the way down to the SplitTemplateRenderer

),
(
'carousel',
'title',
'Title of the carousel.',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs does not make it clear what the difference between name and title is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed with 'An unique string to identify the caroussel component in the HTML page.' and 'A name to display at the top of the carousel.'

'TEXT',
TRUE,
TRUE
),
(
'carousel',
'indicators',
'Style of image indicators (e.g. square, dot).',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should list possible values exhaustively here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the moment, the carousel supports only dots and square indicators. I changed with 'Style of image indicators (square or dot).'

'TEXT',
TRUE,
TRUE
),
(
'carousel',
'vertical',
'Whether to use the vertical image indicators.',
'BOOLEAN',
TRUE,
TRUE
),
(
'carousel',
'controls',
'Whether to show the control links to go previous or next item.',
'BOOLEAN',
TRUE,
TRUE
),
(
'carousel',
'width',
'Width of the component, between 1 and 12.',
'NUMBER',
TRUE,
FALSE
),
(
'carousel',
'center',
'Whether to center the carousel.',
'BOOLEAN',
TRUE,
TRUE
),
(
'carousel',
'fade',
'Whether to apply the fading effect.',
'BOOLEAN',
TRUE,
TRUE
),
(
'carousel',
'image',
'The URL (absolute or relative) of an image to display in the carousel.',
'URL',
FALSE,
FALSE
),
(
'carousel',
'title',
'Add caption to the slide.',
'TEXT',
FALSE,
TRUE
),
(
'carousel',
'contents',
'Add paragraph to the slide.',
'TEXT',
FALSE,
TRUE
);


select
'carousel' as component,
'somecats' as name,
'Some cats' as title,
'square' as indicators, --square or dot
FALSE as vertical,
TRUE as controls,
6 as width,
TRUE as center,
FALSE as fade;

select
"https://placekitten.com/408/285" as image,
'Second cat' as title,
'Some representative placeholder content for the second slide.' as contents;
select
"https://placekitten.com/408/286" as image,
'Third cat' as title;

-- Insert example(s) for the component
INSERT INTO example(component, description, properties)
VALUES
(
'carousel',
'A basic example of carousel',
JSON(
'[
{"component":"carousel","name":"cats1","title":"Cats","width":6},
{"image":"https://placekitten.com/408/285"},
{"image":"https://placekitten.com/408/286"}
]'
)
),
(
'carousel',
'An advanced example of carousel with controls',
JSON(
'[
{"component":"carousel","name":"cats2","title":"Cats","width":6,"center":"TRUE","controls":"TRUE"},
{"image":"https://placekitten.com/408/285","title":"A first cat","contents":"The cat (Felis catus), commonly referred to as the domestic cat or house cat, is the only domesticated species in the family Felidae."},
{"image":"https://placekitten.com/408/286","title":"Another cat"}
]'
)
);
40 changes: 40 additions & 0 deletions sqlpage/templates/carousel.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<div class="card my-2 col-md-{{default width 12}}{{#if center}} mx-auto{{/if}}">
<div class="card-body">
{{#if title}}
<div class="d-flex align-items-center">
<div class="subheader">{{title}}</div>
</div>
{{/if}}
<div id="{{name}}" class="carousel slide{{#if fade}} carousel-fade{{/if}}" data-bs-ride="carousel">
<div class="carousel-indicators{{#if indicators}} carousel-indicators-{{indicators}}{{/if}}{{#if vertical}} carousel-indicators-vertical{{/if}}">
{{#each_row}}
<button type="button" data-bs-target="#{{../name}}" data-bs-slide-to="{{@row_index}}" {{#if (eq @row_index 0)}}class="active"{{/if}}></button>
{{#delay}}
{{flush_delayed}}
<div class="carousel-item {{#if (eq @row_index 0)}}active{{/if}}">
<img class="d-block w-100" alt="{{image}}" src="{{image}}" />
{{#if title}}
<div class="carousel-caption d-none d-md-block">
<h5>{{title}}</h5>
{{#if contents}}<p>{{contents}}</p>{{/if}}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the possibility to render markdown descriptions ?

Like other components, with description and description_md

</div>
{{/if}}
</div>
{{/delay}}
{{/each_row}}
</div>
<div class="carousel-inner">{{flush_delayed}}</div>
</div>
</div>
{{#if controls}}
<a class="carousel-control-prev" data-bs-target="#{{name}}" role="button" data-bs-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="visually-hidden">Previous</span>
</a>
<a class="carousel-control-next" data-bs-target="#{{name}}" role="button" data-bs-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="visually-hidden">Next</span>
</a>
{{/if}}
</div>