Skip to content
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

feat(sbb-train-formation): introduce new types and refactoring #3199

Merged
merged 17 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 2 additions & 2 deletions src/elements/card/card-badge/readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The `sbb-card-badge` can contain some information like prices or discounts,
and can be used in [sbb-card](/docs/components-sbb-card-sbb-card--docs) or
[sbb-selection-expansion-panel](/docs/components-sbb-selection-expansion-panel--docs).
and can be used in [sbb-card](/docs/elements-sbb-card-sbb-card--docs) or
[sbb-selection-expansion-panel](/docs/elements-sbb-selection-expansion-panel--docs).

To achieve the correct spacing between elements inside the card badge, we recommend to use `span`-elements.
All content parts are presented with a predefined gap in between.
Expand Down
21 changes: 21 additions & 0 deletions src/elements/core/i18n/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ export const i18nLocomotiveLabel: Record<string, string> = {
it: 'Locomotiva',
};

export const i18nSleepingWagonLabel: Record<string, string> = {
de: 'Schlafwagen',
en: 'Sleeping car',
fr: 'Voiture-lits',
it: 'Carrozza letti',
};

export const i18nCouchetteWagonLabel: Record<string, string> = {
de: 'Liegewagen',
en: 'Couchette car',
fr: 'Voiture-couchettes',
it: 'Carrozza cuccette',
};

export const i18nRestaurantWagonLabel: Record<string, string> = {
de: 'Speisewagen',
en: 'Dining car',
fr: 'Voiture-restaurant',
it: 'Carrozza ristorante',
};

export const i18nBlockedPassage: Record<string, Record<string, string>> = {
previous: {
de: 'Kein Durchgang zum vorherigen Wagen',
Expand Down
15 changes: 15 additions & 0 deletions src/elements/core/styles/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,18 @@ input[data-sbb-time-input] {
max-width: var(--sbb-time-input-s-max-width);
}
}

// TODO: move to train formation after css refactoring
sbb-train-formation:has(sbb-train[direction-label]) {
--sbb-train-formation-reserve-spacing-display: block;
}

// TODO: move to train formation after css refactoring
sbb-train-formation:has(sbb-train-wagon[sector]) {
--sbb-train-formation-show-sectors-gap: 1;
}

// TODO: move to train formation after css refactoring
sbb-train-formation:not(:has(sbb-train-wagon[label])) {
--sbb-train-formation-wagon-label-display: none;
}
2 changes: 1 addition & 1 deletion src/elements/radio-button/radio-button-panel/readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
The `sbb-radio-button-panel` component provides the same functionality as a native `<input type="radio"/>` enhanced with the selection panel design and functionalities. Use multiple `sbb-radio-button-panel` components inside a [sbb-radio-button-group](/docs/components-sbb-radio-button-sbb-radio-button-group--docs) component in order to display a radio input within a group.
The `sbb-radio-button-panel` component provides the same functionality as a native `<input type="radio"/>` enhanced with the selection panel design and functionalities. Use multiple `sbb-radio-button-panel` components inside a [sbb-radio-button-group](/docs/elements-sbb-radio-button-sbb-radio-button-group--docs) component in order to display a radio input within a group.

```html
<sbb-radio-button-group value="Value one" aria-label="Radio group label">
Expand Down
4 changes: 2 additions & 2 deletions src/elements/train/train-blocked-passage/readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
A `sbb-train-blocked-passage` is a visual representation of a blocked passage between
[sbb-train-wagon](/docs/timetable-sbb-train-wagon--docs)s.
[sbb-train-wagon](/docs/elements-timetable-sbb-train-wagon--docs)s.

It is used inside the [sbb-train](/docs/timetable-sbb-train--docs) element.
It is used inside the [sbb-train](/docs/elements-timetable-sbb-train--docs) element.

```html
<sbb-train-blocked-passage></sbb-train-blocked-passage>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
display: block;

--sbb-train-blocked-passage-height: var(--sbb-train-formation-wagon-height);
--sbb-train-blocked-passage-background-color: var(--sbb-color-red);
--sbb-train-blocked-passage-background-color: var(--sbb-color-red125);
--sbb-train-blocked-passage-bar-color: var(--sbb-color-white);
--sbb-train-blocked-passage-icon-dimension: #{sbb.px-to-rem-build(16)};
--sbb-train-blocked-passage-icon-bar-width: #{sbb.px-to-rem-build(10)};
Expand All @@ -24,7 +24,7 @@
&::before {
content: '';
display: var(--sbb-train-formation-wagon-label-display, block);
height: calc(var(--sbb-font-size-text-s) * var(--sbb-typo-line-height-body-text));
height: calc(var(--sbb-font-size-text-xxs) * var(--sbb-typo-line-height-body-text));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
export const snapshots = {};

snapshots["sbb-train-formation should render with one train DOM"] =
`<sbb-train-formation>
`<sbb-train-formation view="side">
<sbb-train
direction="left"
slot="li-0"
>
<sbb-train-wagon
data-has-visible-wagon-content=""
sector="A"
slot="li-0"
type="wagon"
Expand All @@ -20,10 +19,7 @@ snapshots["sbb-train-formation should render with one train DOM"] =
/* end snapshot sbb-train-formation should render with one train DOM */

snapshots["sbb-train-formation should render with one train Shadow DOM"] =
`<div
class="sbb-train-formation"
style="--sbb-train-direction-width: 800px;"
>
`<div class="sbb-train-formation">
<div
aria-hidden="true"
class="sbb-train-formation__sectors"
Expand Down Expand Up @@ -59,13 +55,12 @@ snapshots["sbb-train-formation should render with one train Shadow DOM"] =
/* end snapshot sbb-train-formation should render with one train Shadow DOM */

snapshots["sbb-train-formation should render with multiple trains DOM"] =
`<sbb-train-formation>
`<sbb-train-formation view="side">
<sbb-train
direction="left"
slot="li-0"
>
<sbb-train-wagon
data-has-visible-wagon-content=""
sector="A"
slot="li-0"
type="wagon"
Expand All @@ -77,7 +72,6 @@ snapshots["sbb-train-formation should render with multiple trains DOM"] =
slot="li-1"
>
<sbb-train-wagon
data-has-visible-wagon-content=""
sector="B"
slot="li-0"
type="wagon"
Expand All @@ -89,10 +83,7 @@ snapshots["sbb-train-formation should render with multiple trains DOM"] =
/* end snapshot sbb-train-formation should render with multiple trains DOM */

snapshots["sbb-train-formation should render with multiple trains Shadow DOM"] =
`<div
class="sbb-train-formation"
style="--sbb-train-direction-width: 800px;"
>
`<div class="sbb-train-formation">
<div
aria-hidden="true"
class="sbb-train-formation__sectors"
Expand Down Expand Up @@ -158,7 +149,7 @@ snapshots["sbb-train-formation should render with multiple trains A11y tree Chro
},
{
"role": "text",
"name": "Sector, A"
"name": "Train coach, Sector, A"
},
{
"role": "heading",
Expand All @@ -171,7 +162,7 @@ snapshots["sbb-train-formation should render with multiple trains A11y tree Chro
},
{
"role": "text",
"name": "Sector, B"
"name": "Train coach, Sector, B"
}
]
}
Expand All @@ -196,7 +187,7 @@ snapshots["sbb-train-formation should render with multiple trains A11y tree Fire
},
{
"role": "text leaf",
"name": "Sector, A"
"name": "Train coach, Sector, A"
},
{
"role": "heading",
Expand All @@ -209,7 +200,7 @@ snapshots["sbb-train-formation should render with multiple trains A11y tree Fire
},
{
"role": "text leaf",
"name": "Sector, B"
"name": "Train coach, Sector, B"
}
]
}
Expand Down
29 changes: 20 additions & 9 deletions src/elements/train/train-formation/readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
The `sbb-train-formation` is a component used as a top container element
for wrapping [sbb-train](/docs/timetable-sbb-train--docs)s.

## Style

It has no properties, and it applies the possible scrollable-width to every given `sbb-train`
as CSS variable (`--sbb-train-direction-width`) initially and on resize.
for wrapping [sbb-train](/docs/elements-timetable-sbb-train--docs)s.

```html
<sbb-train-formation>
Expand Down Expand Up @@ -50,13 +45,29 @@ as CSS variable (`--sbb-train-direction-width`) initially and on resize.
</sbb-train-formation>
```

### View

The perspective of the train can be switched with the `view` property between `side` (default) and `top`.

### Inline padding

In certain circumstances there should be a left and right padding applied, but including the scrollbar.
To achieve the inline padding, set a value to the
CSS variable `--sbb-train-formation-padding-inline` like `var(--sbb-spacing-fixed-4x)`.

<!-- Auto Generated Below -->

## Properties

| Name | Attribute | Privacy | Type | Default | Description |
| ---------------- | ------------------ | ------- | --------- | ------- | -------------------------------- |
| `hideWagonLabel` | `hide-wagon-label` | public | `boolean` | `false` | Option to hide all wagon labels. |
| Name | Attribute | Privacy | Type | Default | Description |
| ------ | --------- | ------- | ----------------- | -------- | --------------------------------------------------------------- |
| `view` | `view` | public | `'side' \| 'top'` | `'side'` | Whether the view of the wagons is from side or top perspective. |

## CSS Properties

| Name | Default | Description |
| -------------------------------------- | ------- | ---------------------------------------------------------------- |
| `--sbb-train-formation-padding-inline` | `0px` | Defines the inline padding inside the horizontal scrolling area. |

## Slots

Expand Down
40 changes: 27 additions & 13 deletions src/elements/train/train-formation/train-formation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
:host {
display: block;

--sbb-train-formation-inline-padding: var(--sbb-spacing-fixed-4x);
--sbb-train-formation-background-color: var(--sbb-color-white);
--sbb-train-formation-sector-label-color: var(--sbb-color-metal);
--sbb-train-formation-sector-line-color: var(--sbb-color-smoke);
--sbb-train-formation-sector-line-color: var(--sbb-color-cement);
--sbb-train-formation-blocked-passage-width: #{sbb.px-to-rem-build(16)};
--sbb-train-formation-text-color: var(--sbb-color-charcoal);
--sbb-train-formation-vertical-gap: var(--sbb-spacing-fixed-2x);

@include sbb.if-forced-colors {
--sbb-train-formation-sector-line-color: CanvasText;
}
}

:host([hide-wagon-label]) {
--sbb-train-formation-wagon-label-display: none;
}

.sbb-train-formation {
@include sbb.scrollbar;

Expand All @@ -31,16 +27,19 @@
'start trains end' auto / auto 1fr auto;
position: relative;
overflow-x: auto;
background-color: var(--sbb-train-formation-background-color);
row-gap: calc(
var(--sbb-train-formation-show-sectors-gap, 0) * var(--sbb-train-formation-vertical-gap)
);
padding-block-end: var(--sbb-train-formation-vertical-gap);
color: var(--sbb-train-formation-text-color);
}

// Enable inline padding
&::before,
&::after {
content: '';
display: block;
width: var(--sbb-train-formation-inline-padding);
background-color: var(--sbb-train-formation-background-color);
width: var(--sbb-train-formation-padding-inline);
}

&::before {
Expand Down Expand Up @@ -68,14 +67,12 @@
--_gap-sum: calc((var(--_total-count) - 1) * var(--sbb-train-formation-wagon-gap));
--_sector-width: calc(var(--_wagon-sum) + var(--_blocked-passage-sum) + var(--_gap-sum));

@include sbb.text-s--regular;
@include sbb.text-xs--regular;

flex: 0 0 var(--_sector-width);
color: var(--sbb-train-formation-sector-label-color);
text-align: center;
position: relative;
display: inline-block;
margin-block-end: var(--sbb-spacing-fixed-4x);
max-width: var(--_sector-width);

// Line behind the sector-label
Expand Down Expand Up @@ -114,3 +111,20 @@
.sbb-train-formation__train-list > :is(li, span) {
display: inline-flex;
}

// TODO: Move to sbb-train-wagon after CSS refactoring
:host([view='side']) {
--sbb-train-formation-wagon-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M12.5,0.5 h55 a12,12 0 0 1 12,12 v15 a12,12 0 0 1 -12,12 h-55 a12,12 0 0 1 -12,-12 v-15 a12,12 0 0 1 12,-12 z' stroke='%23000000' stroke-width='1'/%3E%3C/svg%3E");
--sbb-train-formation-wagon-closed-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Crect x='0.5' y='0.5' width='79' height='39' rx='11.5' stroke='%23000000'/%3E%3Cpath d='M76 4L4 36' stroke='%23000000'/%3E%3Cpath d='M76 36L4 4' stroke='%23000000'/%3E%3C/svg%3E");
--sbb-train-formation-wagon-end-left-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M10.745 7.90416C13.5624 3.30431 18.5686 0.5 23.9627 0.5H68C74.3513 0.5 79.5 5.64873 79.5 12V28C79.5 34.3513 74.3513 39.5 68 39.5H11.922C2.93614 39.5 -2.57807 29.6562 2.11537 21.9934L10.745 7.90416Z' stroke='%23000000'/%3E%3C/svg%3E");
--sbb-train-formation-locomotive-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M10.745 7.90416C13.5624 3.30431 18.5686 0.5 23.9627 0.5H56.0373C61.4314 0.5 66.4376 3.30432 69.255 7.90416L77.8846 21.9934C82.5781 29.6562 77.0639 39.5 68.078 39.5H11.922C2.93615 39.5 -2.57807 29.6562 2.11537 21.9934L10.745 7.90416Z' stroke='%23000000'/%3E%3C/svg%3E");
--sbb-train-formation-wagon-end-right-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M0.5 12C0.5 5.64873 5.64873 0.5 12 0.5H56.0373C61.4314 0.5 66.4376 3.30432 69.255 7.90416L77.8846 21.9934C82.5781 29.6562 77.0638 39.5 68.0779 39.5H12C5.64873 39.5 0.5 34.3513 0.5 28V12Z' stroke='%23000000'/%3E%3C/svg%3E");
}

:host([view='top']) {
--sbb-train-formation-wagon-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M8.5,0.5 h63 a8,8 0 0 1 8,8 v23 a8,8 0 0 1 -8,8 h-63 a8,8 0 0 1 -8,-8 v-23 a8,8 0 0 1 8,-8 z' stroke='%23000000' stroke-width='1'/%3E%3C/svg%3E%0A");
--sbb-train-formation-wagon-closed-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Crect x='0.5' y='0.5' width='79' height='39' rx='7.5' stroke='%23000000'/%3E%3Cpath d='M77.5 2.5L2.5 37.5' stroke='%23000000'/%3E%3Cpath d='M77.5 37.5L2.5 2.5' stroke='%23000000'/%3E%3C/svg%3E");
--sbb-train-formation-wagon-end-left-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath transform='translate(80,40) rotate(180)' d='M8.5,0.5 h51.5 a19.5,19.5 0 0 1 19.5,19.5 v0 a19.5,19.5 0 0 1 -19.5,19.5 h-51.5 a8,8 0 0 1 -8,-8 v-23 a8,8 0 0 1 8,-8 z' stroke='%23000000' stroke-width='1'/%3E%3C/svg%3E");
--sbb-train-formation-locomotive-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M20,0.5 h40 a19.5,19.5 0 0 1 19.5,19.5 v0 a19.5,19.5 0 0 1 -19.5,19.5 h-40 a19.5,19.5 0 0 1 -19.5,-19.5 v0 a19.5,19.5 0 0 1 19.5,-19.5 z' stroke='%23000000' stroke-width='1'/%3E%3C/svg%3E%0A");
--sbb-train-formation-wagon-end-right-shape: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='80' height='40' viewBox='0 0 80 40' fill='none'%3E%3Cpath d='M8.5,0.5 h51.5 a19.5,19.5 0 0 1 19.5,19.5 v0 a19.5,19.5 0 0 1 -19.5,19.5 h-51.5 a8,8 0 0 1 -8,-8 v-23 a8,8 0 0 1 8,-8 z' stroke='%23000000' stroke-width='1'/%3E%3C/svg%3E");
}
Loading
Loading