Skip to content

Commit

Permalink
feat: add i18n support to InlineDatePicker
Browse files Browse the repository at this point in the history
Close #82
  • Loading branch information
javier-godoy authored and paodb committed Sep 3, 2024
1 parent 574f1cf commit ac0aad9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.vaadin.addons.flowingcode</groupId>
<artifactId>year-month-calendar</artifactId>
<version>4.2.2-SNAPSHOT</version>
<version>4.3.0-SNAPSHOT</version>
<name>Year Month Calendar Add-on</name>
<description>Year Month Calendar Add-on for Vaadin Flow</description>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Year Month Calendar Add-on
* %%
* Copyright (C) 2021 - 2023 Flowing Code
* Copyright (C) 2021 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,13 @@
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.HasTheme;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.Uses;
import com.vaadin.flow.function.SerializableFunction;
import com.vaadin.flow.internal.JsonSerializer;
import java.time.LocalDate;
import java.util.Objects;
import java.util.Optional;

@SuppressWarnings("serial")
Expand Down Expand Up @@ -72,4 +75,14 @@ public boolean isWeekNumbersVisible() {
return getElement().getProperty("showWeekNumbers", false);
}

/**
* Sets the i18n object.
*
* @param i18n the {@code DatepickerI18n} object used to initialize i18n
*/
public void setI18n(DatePickerI18n i18n) {
Objects.requireNonNull(i18n, "The I18N properties object should not be null");
getElement().setPropertyJson("i18n", JsonSerializer.toJson(i18n));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* #%L
* Year Month Calendar Add-on
* %%
* Copyright (C) 2021 - 2023 Flowing Code
* Copyright (C) 2021 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,8 +54,10 @@ export class InlineDatePicker extends LitElement {
this.displayDate = this.displayDate || new Date();
}
if (changedProperties.has('i18n') && this.i18n) {
this.shadowRoot.querySelector("fc-year-month-field").i18n=this.i18n;
this.shadowRoot.querySelector("fc-month-calendar").i18n=this.i18n;
[
this.shadowRoot.querySelector("fc-year-month-field"),
this.shadowRoot.querySelector("fc-month-calendar")
].forEach(e=>{if (e) e.i18n=this.i18n;});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
* #%L
* Year Month Calendar Add-on
* %%
* Copyright (C) 2021 - 2023 Flowing Code
* Copyright (C) 2021 - 2024 Flowing Code
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -34,6 +34,9 @@ public class InlineDatePickerDemo extends Div {
public InlineDatePickerDemo() {

InlineDatePicker field = new InlineDatePicker();
// #if vaadin eq 0
add(new LocaleSelector(field::setI18n));
// #endif

field.addValueChangeListener(ev->{
Notification.show(Objects.toString(ev.getValue()));
Expand Down

0 comments on commit ac0aad9

Please sign in to comment.