Skip to content

Commit

Permalink
Merge pull request #924 from geonetwork/UI-component-switch-toggle
Browse files Browse the repository at this point in the history
UI component switch toggle
  • Loading branch information
Angi-Kinas authored Jul 15, 2024
2 parents e4dc877 + e50812e commit 58b3c2e
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 39 deletions.
8 changes: 4 additions & 4 deletions libs/feature/editor/src/lib/fields.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ export const DEFAULT_FIELDS: EditorFieldsConfig = [
{
model: 'title',
formFieldConfig: {
labelKey: 'Metadata title',
labelKey: marker('editor.record.form.metadata.title'),
type: 'text',
},
},
{
model: 'abstract',
formFieldConfig: {
labelKey: 'Abstract',
labelKey: marker('editor.record.form.abstract'),
type: 'rich',
},
},
{
model: 'uniqueIdentifier',
formFieldConfig: {
labelKey: 'Unique identifier',
labelKey: marker('editor.record.form.unique.identifier'),
type: 'text',
locked: true,
},
},
{
model: 'recordUpdated',
formFieldConfig: {
labelKey: 'Record Updated',
labelKey: marker('editor.record.form.record.updated'),
type: 'text',
locked: true,
},
Expand Down
31 changes: 31 additions & 0 deletions libs/ui/inputs/src/lib/switch-toggle/switch-toggle.component.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
:host {
--mat-standard-button-toggle-height: 32px;
}

.mat-button-toggle-group-appearance-standard {
background-color: var(--color-gray-200);
padding: 4px;
display: flex;
gap: 4px;
border-radius: 8px;
}

.mat-button-toggle-appearance-standard {
color: var(--color-main);
background-color: var(--color-gray-200);
border-radius: 4px;
border-left: none;
}

.mat-button-toggle-appearance-standard.mat-button-toggle-checked {
background-color: var(--color-main);
color: var(--color-primary-white);
}

button.mat-button-toggle-button.mat-focus-indicator.mat-button-toggle-label-content {
line-height: 32px;
}

.mat-button-toggle-label-content {
line-height: 32px;
}
15 changes: 15 additions & 0 deletions libs/ui/inputs/src/lib/switch-toggle/switch-toggle.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<mat-button-toggle-group
#group="matButtonToggleGroup"
multiple="false"
class="flex w-full"
>
<mat-button-toggle
*ngFor="let option of options"
[aria-label]="option.label"
[value]="option.value"
[checked]="option.checked"
(change)="onChange(option)"
[class]="extraClasses"
>{{ option.label }}</mat-button-toggle
>
</mat-button-toggle-group>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'

import { SwitchToggleComponent } from './switch-toggle.component'
import { MatButtonToggleModule } from '@angular/material/button-toggle'
import { CommonModule } from '@angular/common'

describe('SwitchToggleComponent', () => {
let component: SwitchToggleComponent
let fixture: ComponentFixture<SwitchToggleComponent>

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [],
imports: [MatButtonToggleModule, SwitchToggleComponent, CommonModule],
})
fixture = TestBed.createComponent(SwitchToggleComponent)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
})
38 changes: 38 additions & 0 deletions libs/ui/inputs/src/lib/switch-toggle/switch-toggle.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { CommonModule } from '@angular/common'
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
Output,
} from '@angular/core'
import { MatButtonToggleModule } from '@angular/material/button-toggle'

export type SwitchToggleOption = {
label: string
value: string
checked: boolean
}

@Component({
selector: 'gn-ui-switch-toggle',
templateUrl: './switch-toggle.component.html',
styleUrls: ['./switch-toggle.component.css'],
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: true,
imports: [MatButtonToggleModule, CommonModule],
})
export class SwitchToggleComponent {
@Input() options: SwitchToggleOption[]
@Input() ariaLabel? = ''
@Input() extraClasses? = ''
@Output() selectedValue = new EventEmitter<SwitchToggleOption>()

onChange(selectedOption: SwitchToggleOption) {
this.options.find(
(option) => option.value === selectedOption.value
).checked = true

this.selectedValue.emit(selectedOption)
}
}
29 changes: 29 additions & 0 deletions libs/ui/inputs/src/lib/switch-toggle/switch-toggle.stories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Meta, moduleMetadata, StoryObj } from '@storybook/angular'
import { SwitchToggleComponent } from './switch-toggle.component'
import { MatButtonToggleModule } from '@angular/material/button-toggle'
import { CommonModule } from '@angular/common'

export default {
title: 'Inputs/SwitchToggle',
component: SwitchToggleComponent,
decorators: [
moduleMetadata({
declarations: [],
imports: [SwitchToggleComponent, MatButtonToggleModule, CommonModule],
}),
],
} as Meta<SwitchToggleComponent>

export const Primary: StoryObj<SwitchToggleComponent> = {
args: {
options: [
{ label: 'city', value: 'city', checked: true },
{ label: 'municipality', value: 'municipality', checked: false },
{ label: 'state', value: 'state', checked: false },
],
extraClasses: 'grow',
},
render: (args) => ({
props: { ...args },
}),
}
64 changes: 34 additions & 30 deletions translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,38 +165,42 @@
"downloads.format.unknown": "unbekannt",
"downloads.wfs.featuretype.not.found": "Der Layer wurde nicht gefunden",
"dropFile": "Datei ablegen",
"editor.record.form.keywords": "Schlagwörter",
"editor.record.form.abstract": "Kurzbeschreibung",
"editor.record.form.keywords": "Schlüsselwörter",
"editor.record.form.license": "Lizenz",
"editor.record.form.license.cc-by": "",
"editor.record.form.license.cc-by-sa": "",
"editor.record.form.license.cc-zero": "",
"editor.record.form.license.etalab": "",
"editor.record.form.license.etalab-v2": "",
"editor.record.form.license.odbl": "",
"editor.record.form.license.odc-by": "",
"editor.record.form.license.pddl": "",
"editor.record.form.license.cc-by": "Creative Commons CC-BY",
"editor.record.form.license.cc-by-sa": "Creative Commons CC-BY-SA",
"editor.record.form.license.cc-zero": "Creative Commons CC-0",
"editor.record.form.license.etalab": "Offene Lizenz (Etalab)",
"editor.record.form.license.etalab-v2": "Offene Lizenz v2.0 (Etalab)",
"editor.record.form.license.odbl": "Open Data Commons ODbL",
"editor.record.form.license.odc-by": "Open Data Commons ODC-By",
"editor.record.form.license.pddl": "Open Data Commons PDDL",
"editor.record.form.license.unknown": "Unbekannt oder nicht vorhanden",
"editor.record.form.resourceUpdated": "",
"editor.record.form.temporalExtents": "",
"editor.record.form.temporalExtents.addDate": "",
"editor.record.form.temporalExtents.addRange": "",
"editor.record.form.temporalExtents.date": "",
"editor.record.form.temporalExtents.range": "",
"editor.record.form.updateFrequency": "",
"editor.record.form.updateFrequency.planned": "",
"editor.record.loadError.body": "",
"editor.record.loadError.closeMessage": "",
"editor.record.loadError.title": "",
"editor.record.publish": "",
"editor.record.publishError.body": "",
"editor.record.publishError.closeMessage": "",
"editor.record.publishError.title": "",
"editor.record.publishSuccess.body": "",
"editor.record.publishSuccess.title": "",
"editor.record.saveStatus.asDraftOnly": "",
"editor.record.saveStatus.draftWithChangesPending": "",
"editor.record.saveStatus.recordUpToDate": "",
"editor.record.upToDate": "",
"editor.record.form.metadata.title": "Metadaten-Titel",
"editor.record.form.record.updated": "Datensatz zuletzt aktualisiert",
"editor.record.form.resourceUpdated": "Letztes Aktualisierungsdatum",
"editor.record.form.temporalExtents": "Zeitlicher Umfang",
"editor.record.form.temporalExtents.addDate": "Zeitpunkt",
"editor.record.form.temporalExtents.addRange": "Zeitraum",
"editor.record.form.temporalExtents.date": "Datum",
"editor.record.form.temporalExtents.range": "Datumsbereich",
"editor.record.form.unique.identifier": "Eindeutige Kennung (ID)",
"editor.record.form.updateFrequency": "Aktualisierungshäufigkeit",
"editor.record.form.updateFrequency.planned": "Die Daten sollten regelmäßig aktualisiert werden.",
"editor.record.loadError.body": "Der Datensatz konnte nicht geladen werden:",
"editor.record.loadError.closeMessage": "Verstanden",
"editor.record.loadError.title": "Fehler beim Laden des Datensatzes",
"editor.record.publish": "Diesen Datensatz veröffentlichen",
"editor.record.publishError.body": "Der Datensatz konnte nicht veröffentlicht werden:",
"editor.record.publishError.closeMessage": "Verstanden",
"editor.record.publishError.title": "Fehler beim Veröffentlichen des Datensatzes",
"editor.record.publishSuccess.body": "Der Datensatz wurde erfolgreich veröffentlicht!",
"editor.record.publishSuccess.title": "Veröffentlichung erfolgreich",
"editor.record.saveStatus.asDraftOnly": "Nur als Entwurf gespeichert - noch nicht veröffentlicht",
"editor.record.saveStatus.draftWithChangesPending": "Als Entwurf gespeichert - Änderungen stehen aus",
"editor.record.saveStatus.recordUpToDate": "Datensatz ist auf dem neuesten Stand",
"editor.record.upToDate": "Dieser Datensatz ist auf dem neuesten Stand",
"externalviewer.dataset.unnamed": "Datensatz aus dem Datahub",
"facets.block.title.OrgForResource": "Organisation",
"facets.block.title.availableInServices": "Verfügbar für",
Expand Down
8 changes: 6 additions & 2 deletions translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"downloads.format.unknown": "unknown",
"downloads.wfs.featuretype.not.found": "The layer was not found",
"dropFile": "drop file",
"editor.record.form.abstract": "Abstract",
"editor.record.form.keywords": "Keywords",
"editor.record.form.license": "License",
"editor.record.form.license.cc-by": "Creative Commons CC-BY",
Expand All @@ -176,12 +177,15 @@
"editor.record.form.license.odc-by": "Open Data Commons ODC-By",
"editor.record.form.license.pddl": "Open Data Commons PDDL",
"editor.record.form.license.unknown": "Unknown or absent",
"editor.record.form.metadata.title": "Metadata title",
"editor.record.form.record.updated": "Record updated",
"editor.record.form.resourceUpdated": "Last update date",
"editor.record.form.temporalExtents": "Temporal extent",
"editor.record.form.temporalExtents.addDate": "Time instant",
"editor.record.form.temporalExtents.addRange": "Time period",
"editor.record.form.temporalExtents.date": "Date",
"editor.record.form.temporalExtents.range": "Date range",
"editor.record.form.unique.identifier": "Unique identifier",
"editor.record.form.updateFrequency": "Update frequency",
"editor.record.form.updateFrequency.planned": "The data should be updated regularly.",
"editor.record.loadError.body": "The record could not be loaded:",
Expand Down Expand Up @@ -265,8 +269,8 @@
"organisations.sortBy.nameDesc": "Name Z → A",
"organisations.sortBy.recordCountAsc": "Publications 0 → 9",
"organisations.sortBy.recordCountDesc": "Publications 9 → 0",
"organization.details.lastPublishedDatasets": "Last published datasets",
"organization.details.lastPublishedDatasets.searchAllButton": "Search all",
"organization.details.lastPublishedDatasets": "",
"organization.details.lastPublishedDatasets.searchAllButton": "",
"organization.details.mailContact": "Contact by email",
"organization.header.recordCount": "{count, plural, =0{data} one{data} other{datas}}",
"pagination.nextPage": "Next page",
Expand Down
4 changes: 4 additions & 0 deletions translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"downloads.format.unknown": "",
"downloads.wfs.featuretype.not.found": "",
"dropFile": "",
"editor.record.form.abstract": "",
"editor.record.form.keywords": "",
"editor.record.form.license": "",
"editor.record.form.license.cc-by": "",
Expand All @@ -176,12 +177,15 @@
"editor.record.form.license.odc-by": "",
"editor.record.form.license.pddl": "",
"editor.record.form.license.unknown": "",
"editor.record.form.metadata.title": "",
"editor.record.form.record.updated": "",
"editor.record.form.resourceUpdated": "",
"editor.record.form.temporalExtents": "",
"editor.record.form.temporalExtents.addDate": "",
"editor.record.form.temporalExtents.addRange": "",
"editor.record.form.temporalExtents.date": "",
"editor.record.form.temporalExtents.range": "",
"editor.record.form.unique.identifier": "",
"editor.record.form.updateFrequency": "",
"editor.record.form.updateFrequency.planned": "",
"editor.record.loadError.body": "",
Expand Down
10 changes: 7 additions & 3 deletions translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@
"downloads.format.unknown": "inconnu",
"downloads.wfs.featuretype.not.found": "La couche n'a pas été retrouvée",
"dropFile": "Faites glisser votre fichier",
"editor.record.form.keywords": "Mots-clés",
"editor.record.form.abstract": "",
"editor.record.form.keywords": "",
"editor.record.form.license": "Licence",
"editor.record.form.license.cc-by": "",
"editor.record.form.license.cc-by-sa": "",
Expand All @@ -176,12 +177,15 @@
"editor.record.form.license.odc-by": "",
"editor.record.form.license.pddl": "",
"editor.record.form.license.unknown": "Non-reconnue ou absente",
"editor.record.form.metadata.title": "",
"editor.record.form.record.updated": "",
"editor.record.form.resourceUpdated": "Date de dernière révision",
"editor.record.form.temporalExtents": "Étendue temporelle",
"editor.record.form.temporalExtents.addDate": "Date déterminée",
"editor.record.form.temporalExtents.addRange": "Période de temps",
"editor.record.form.temporalExtents.date": "Date concernée",
"editor.record.form.temporalExtents.range": "Période concernée",
"editor.record.form.unique.identifier": "",
"editor.record.form.updateFrequency": "Fréquence de mise à jour",
"editor.record.form.updateFrequency.planned": "Ces données doivent être mise à jour régulièrement.",
"editor.record.loadError.body": "",
Expand Down Expand Up @@ -265,8 +269,8 @@
"organisations.sortBy.nameDesc": "Nom Z → A",
"organisations.sortBy.recordCountAsc": "Données 0 → 9",
"organisations.sortBy.recordCountDesc": "Données 9 → 0",
"organization.details.lastPublishedDatasets": "Dernières données publiées",
"organization.details.lastPublishedDatasets.searchAllButton": "Rechercher tous",
"organization.details.lastPublishedDatasets": "",
"organization.details.lastPublishedDatasets.searchAllButton": "",
"organization.details.mailContact": "Contacter par mail",
"organization.header.recordCount": "{count, plural, =0{donnée} one{donnée} other{données}}",
"pagination.nextPage": "Page suivante",
Expand Down
4 changes: 4 additions & 0 deletions translations/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"downloads.format.unknown": "sconosciuto",
"downloads.wfs.featuretype.not.found": "Il layer non è stato trovato",
"dropFile": "Trascina il suo file",
"editor.record.form.abstract": "",
"editor.record.form.keywords": "",
"editor.record.form.license": "Licenza",
"editor.record.form.license.cc-by": "",
Expand All @@ -176,12 +177,15 @@
"editor.record.form.license.odc-by": "",
"editor.record.form.license.pddl": "",
"editor.record.form.license.unknown": "Non riconosciuta o assente",
"editor.record.form.metadata.title": "",
"editor.record.form.record.updated": "",
"editor.record.form.resourceUpdated": "",
"editor.record.form.temporalExtents": "",
"editor.record.form.temporalExtents.addDate": "",
"editor.record.form.temporalExtents.addRange": "",
"editor.record.form.temporalExtents.date": "",
"editor.record.form.temporalExtents.range": "",
"editor.record.form.unique.identifier": "",
"editor.record.form.updateFrequency": "",
"editor.record.form.updateFrequency.planned": "",
"editor.record.loadError.body": "",
Expand Down
4 changes: 4 additions & 0 deletions translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@
"downloads.format.unknown": "",
"downloads.wfs.featuretype.not.found": "",
"dropFile": "",
"editor.record.form.abstract": "",
"editor.record.form.keywords": "",
"editor.record.form.license": "",
"editor.record.form.license.cc-by": "",
Expand All @@ -176,12 +177,15 @@
"editor.record.form.license.odc-by": "",
"editor.record.form.license.pddl": "",
"editor.record.form.license.unknown": "",
"editor.record.form.metadata.title": "",
"editor.record.form.record.updated": "",
"editor.record.form.resourceUpdated": "",
"editor.record.form.temporalExtents": "",
"editor.record.form.temporalExtents.addDate": "",
"editor.record.form.temporalExtents.addRange": "",
"editor.record.form.temporalExtents.date": "",
"editor.record.form.temporalExtents.range": "",
"editor.record.form.unique.identifier": "",
"editor.record.form.updateFrequency": "",
"editor.record.form.updateFrequency.planned": "",
"editor.record.loadError.body": "",
Expand Down
Loading

0 comments on commit 58b3c2e

Please sign in to comment.