Skip to content

Add method to set tooltip for days of week #13

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

Merged
merged 2 commits into from
Apr 10, 2025
Merged
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
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>com.flowingcode.vaadin.addons</groupId>
<artifactId>day-of-week-selector-addon</artifactId>
<version>1.0.2-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>Day of Week Selector Add-on</name>
<description>Day of Week Selector Add-on for Vaadin Flow</description>
<url>https://www.flowingcode.com/en/open-source/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ public void setValue(DayOfWeek first, DayOfWeek... rest) {
* @param i18n the internationalized properties, not <code>null</code>
*/
public void setI18N(DatePickerI18n i18n) {
setWeekDaysShort(i18n.getWeekdaysShort());
if (i18n.getWeekdaysShort() != null) {
setWeekDaysShort(i18n.getWeekdaysShort());
}
if (i18n.getWeekdays() != null) {
setWeekDaysTooltip(i18n.getWeekdays());
}
if (i18n.getFirstDayOfWeek() == 0) {
setFirstDayOfWeek(DayOfWeek.SUNDAY);
} else {
Expand All @@ -202,6 +207,22 @@ public void setWeekDaysShort(List<String> weekdaysShort) {
}
}

/**
* Sets the tooltips of the week days, starting from {@code sun} and ending on {@code sat}.
*
* @param weekdaysTooltip the tooltips of the week days
*/
public void setWeekDaysTooltip(List<String> weekdaysTooltip) {
Objects.requireNonNull(weekdaysTooltip);

for (DayOfWeek day : DayOfWeek.values()) {
int index = day.getValue() % 7;
String text = weekdaysTooltip.get(index);
getButtons().filter(button -> button.getDayOfWeek() == day)
.forEach(button -> button.setTooltipText(text));
}
}

/**
* Sets the first day of the week.
* <p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@
package com.flowingcode.vaadin.addons.dayofweekselector;

import com.flowingcode.vaadin.addons.demo.DemoSource;
import com.vaadin.flow.component.datepicker.DatePicker.DatePickerI18n;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import java.time.DayOfWeek;
import java.time.format.TextStyle;
import java.util.List;
import java.util.stream.Stream;

@DemoSource
@PageTitle("I18N")
Expand All @@ -34,6 +37,21 @@ public class DayOfWeekSelectorI18NDemo extends Div {

public DayOfWeekSelectorI18NDemo() {
DayOfWeekSelector selector = new DayOfWeekSelector();
selector.setLabel("I18N with DatePickerI18n");

DatePickerI18n i18n = new DatePickerI18n();
i18n.setWeekdaysShort(Stream.of(DayOfWeek.values())
.map(d -> d.getDisplayName(TextStyle.NARROW_STANDALONE, getLocale())).toList());
i18n.setWeekdays(Stream.of(DayOfWeek.values())
.map(d -> d.getDisplayName(TextStyle.FULL_STANDALONE, getLocale())).toList());
i18n.setFirstDayOfWeek(DayOfWeek.MONDAY.getValue() - 1);
selector.setI18N(i18n);
add(selector);

selector = new DayOfWeekSelector();
selector.setLabel("I18N without DatePickerI18n");
selector.setWeekDaysTooltip(
List.of("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"));
selector.setWeekDaysShort(List.of("D", "L", "M", "X", "J", "V", "S"));
selector.setFirstDayOfWeek(DayOfWeek.MONDAY);
add(selector);
Expand Down