Skip to content

New carousel component #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
138 changes: 138 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,138 @@
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',
'An unique string to identify the caroussel component in the HTML page.',
'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',
'A name to display at the top of the carousel.',
'TEXT',
TRUE,
TRUE
),
(
'carousel',
'indicators',
'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',
'description',
'A short paragraph.',
'TEXT',
FALSE,
TRUE
),
(
'carousel',
'description_md',
'A short paragraph formatted using markdown.',
'TEXT',
FALSE,
TRUE
);

-- 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","description":"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 description_md}}<p>{{{markdown description_md}}}</p>{{else}}{{#if description}}<p>{{description}}</p>{{/if}}{{/if}}
</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>