-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor timetable base components (#2060)
Co-authored-by: Tommmaso Menga <[email protected]>
- Loading branch information
1 parent
5a3424d
commit 871bd8e
Showing
42 changed files
with
540 additions
and
438 deletions.
There are no files selected for viewing
14 changes: 7 additions & 7 deletions
14
src/components/sbb-timetable-barrier-free/sbb-timetable-barrier-free.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
import sampleData from './sbb-timetable-barrier-free.sample-data'; | ||
import { assert, fixture } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
import { SbbTimetableBarrierFree } from './sbb-timetable-barrier-free'; | ||
|
||
const config = JSON.stringify(sampleData[0]); | ||
|
||
describe('sbb-timetable-barrier-free', () => { | ||
let element, page; | ||
let element: SbbTimetableBarrierFree; | ||
|
||
it('renders', async () => { | ||
page = await newE2EPage(); | ||
await page.setContent( | ||
`<sbb-timetable-barrier-free config='${config}'></sbb-timetable-barrier-free>`, | ||
element = await fixture( | ||
html`<sbb-timetable-barrier-free config="${config}"></sbb-timetable-barrier-free>`, | ||
); | ||
|
||
element = await page.find('sbb-timetable-barrier-free'); | ||
expect(element).toHaveClass('hydrated'); | ||
assert.instanceOf(element, SbbTimetableBarrierFree); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 28 additions & 22 deletions
50
src/components/sbb-timetable-barrier-free/sbb-timetable-barrier-free.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,64 @@ | ||
import { Component, Element, h, JSX, Prop, State } from '@stencil/core'; | ||
|
||
import icons from '../../global/timetable/icons.json'; | ||
import { i18nBarrierFreeTravel } from '../../global/i18n'; | ||
import { | ||
documentLanguage, | ||
HandlerRepository, | ||
languageChangeHandlerAspect, | ||
} from '../../global/eventing'; | ||
import { CSSResult, html, LitElement, TemplateResult } from 'lit'; | ||
import { customElement, property, state } from 'lit/decorators.js'; | ||
import Style from './sbb-timetable-barrier-free.scss?lit&inline'; | ||
|
||
@customElement('sbb-timetable-barrier-free') | ||
export class SbbTimetableBarrierFree extends LitElement { | ||
public static override styles: CSSResult = Style; | ||
|
||
@Component({ | ||
shadow: true, | ||
styleUrl: 'sbb-timetable-barrier-free.scss', | ||
tag: 'sbb-timetable-barrier-free', | ||
}) | ||
export class SbbTimetableBarrierFree { | ||
/** | ||
* Stringified JSON which defines most of the | ||
* content of the component. Please check the | ||
* individual stories to get an idea of the | ||
* structure. | ||
*/ | ||
@Prop() public config!: string; | ||
|
||
@State() private _currentLanguage = documentLanguage(); | ||
@property() public config!: string; | ||
|
||
@Element() private _element!: HTMLElement; | ||
@state() private _currentLanguage = documentLanguage(); | ||
|
||
private _handlerRepository = new HandlerRepository( | ||
this._element, | ||
this, | ||
languageChangeHandlerAspect((l) => (this._currentLanguage = l)), | ||
); | ||
|
||
public connectedCallback(): void { | ||
public override connectedCallback(): void { | ||
super.connectedCallback(); | ||
this._handlerRepository.connect(); | ||
} | ||
|
||
public disconnectedCallback(): void { | ||
public override disconnectedCallback(): void { | ||
super.disconnectedCallback(); | ||
this._handlerRepository.disconnect(); | ||
} | ||
|
||
public render(): JSX.Element { | ||
protected override render(): TemplateResult { | ||
const config = JSON.parse(this.config); | ||
|
||
const a11yLabel = `${i18nBarrierFreeTravel[this._currentLanguage]} ${config.text}`; | ||
const appearanceClass = ' barrier-free--second-level'; | ||
|
||
return ( | ||
<p aria-label={a11yLabel} class={`barrier-free${appearanceClass}`} role="text"> | ||
<span class="barrier-free__text--visually-hidden">{a11yLabel}</span> | ||
return html` | ||
<p aria-label=${a11yLabel} class=${`barrier-free${appearanceClass}`} role="text"> | ||
<span class="barrier-free__text--visually-hidden">${a11yLabel}</span> | ||
<span aria-hidden="true" class="barrier-free__text" role="presentation"> | ||
<span class="barrier-free__icon" innerHTML={icons[config.icon]}></span> | ||
{config.text} | ||
<span class="barrier-free__icon" .innerHTML=${icons[config.icon]}></span> | ||
${config.text} | ||
</span> | ||
</p> | ||
); | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
'sbb-timetable-barrier-free': SbbTimetableBarrierFree; | ||
} | ||
} |
15 changes: 8 additions & 7 deletions
15
src/components/sbb-timetable-duration/sbb-timetable-duration.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
import sampleData from './sbb-timetable-duration.sample-data'; | ||
import { assert, fixture } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
import { SbbTimetableDuration } from './sbb-timetable-duration'; | ||
|
||
const config = JSON.stringify(sampleData[0]); | ||
|
||
describe('sbb-timetable-duration', () => { | ||
let element, page; | ||
let element: SbbTimetableDuration; | ||
|
||
it('renders', async () => { | ||
page = await newE2EPage(); | ||
await page.setContent(`<sbb-timetable-duration config='${config}'></sbb-timetable-duration>`); | ||
|
||
element = await page.find('sbb-timetable-duration'); | ||
expect(element).toHaveClass('hydrated'); | ||
element = await fixture( | ||
html`<sbb-timetable-duration config="${config}"></sbb-timetable-duration>`, | ||
); | ||
assert.instanceOf(element, SbbTimetableDuration); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 8 additions & 7 deletions
15
src/components/sbb-timetable-occupancy/sbb-timetable-occupancy.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { newE2EPage } from '@stencil/core/testing'; | ||
import sampleData from './sbb-timetable-occupancy.sample-data'; | ||
import { assert, fixture } from '@open-wc/testing'; | ||
import { html } from 'lit/static-html.js'; | ||
import { SbbTimetableOccupancy } from './sbb-timetable-occupancy'; | ||
|
||
const config = JSON.stringify(sampleData[3]); | ||
|
||
describe('sbb-timetable-occupancy', () => { | ||
let element, page; | ||
let element: SbbTimetableOccupancy; | ||
|
||
it('renders', async () => { | ||
page = await newE2EPage(); | ||
await page.setContent(`<sbb-timetable-occupancy config='${config}'></sbb-timetable-occupancy>`); | ||
|
||
element = await page.find('sbb-timetable-occupancy'); | ||
expect(element).toHaveClass('hydrated'); | ||
element = await fixture( | ||
html`<sbb-timetable-occupancy config="${config}"></sbb-timetable-occupancy>`, | ||
); | ||
assert.instanceOf(element, SbbTimetableOccupancy); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.