Skip to content

Commit

Permalink
Adds vertical padding to input fields, adds vaadin-side-nav examples,…
Browse files Browse the repository at this point in the history
… organize styles.
  • Loading branch information
juuso-vaadin committed Oct 10, 2024
1 parent 34c80b0 commit a795706
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 122 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package com.example.application.views.applayoutsample;

import com.example.application.views.componentssample.ComponentsSampleView;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.applayout.AppLayout;
import com.vaadin.flow.component.applayout.DrawerToggle;
import com.vaadin.flow.component.html.H1;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.Scroller;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.sidenav.SideNav;
import com.vaadin.flow.component.sidenav.SideNavItem;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.theme.lumo.LumoUtility;

@PageTitle("App Layout Sample")
@Route("app-layout-sample")
public class AppLayoutSample extends AppLayout {

public AppLayoutSample() {
DrawerToggle toggle = new DrawerToggle();

H1 title = new H1("MyApp");
title.getStyle().set("font-size", "var(--lumo-font-size-l)")
.set("margin", "0");

SideNav nav = getSideNav();

Scroller scroller = new Scroller(nav);
scroller.setClassName(LumoUtility.Padding.SMALL);

addToDrawer(scroller);
addToNavbar(toggle, title);

HorizontalLayout navExamples = new HorizontalLayout(createSideNavLabelled(), createSideNavHierarchy());
navExamples.setPadding(true);
navExamples.setSpacing(true);
setContent(navExamples);
}


private Component createSideNavLabelled() {
SideNav baseNav = new SideNav();
baseNav.addItem(new SideNavItem("Dashboard", AppLayoutSample.class,
VaadinIcon.DASHBOARD.create()));
SideNavItem calendarLink = new SideNavItem("Calendar", "",
VaadinIcon.CALENDAR.create());
baseNav.addItem(calendarLink);

Icon calendarNotification = VaadinIcon.BELL.create();
calendarNotification.getElement().getThemeList()
.add("badge error pill");
calendarNotification.getStyle().set("padding", "var(--lumo-space-xs");
calendarNotification.getElement().setAttribute("aria-label",
"Upcoming appointment");
calendarLink.setSuffixComponent(calendarNotification);

SideNav messagesNav = new SideNav();
messagesNav.setLabel("Messages");
SideNavItem inboxLink = new SideNavItem("Inbox", "",
VaadinIcon.INBOX.create());
Span inboxCounter = new Span("12");
inboxCounter.getElement().getThemeList().add("badge contrast pill");
inboxCounter.getElement().setAttribute("aria-label",
"12 unread messages");
inboxLink.setSuffixComponent(inboxCounter);
messagesNav.addItem(inboxLink);
messagesNav.addItem(new SideNavItem("Sent", "",
VaadinIcon.PAPERPLANE.create()));
messagesNav.addItem(new SideNavItem("Trash", "",
VaadinIcon.TRASH.create()));

SideNav adminNav = new SideNav();
adminNav.setLabel("Admin");
adminNav.setCollapsible(true);
adminNav.addItem(new SideNavItem("Users", "",
VaadinIcon.GROUP.create()));
adminNav.addItem(new SideNavItem("Permissions", "",
VaadinIcon.KEY.create()));

VerticalLayout navWrapper = new VerticalLayout(baseNav, messagesNav, adminNav);
navWrapper.setSpacing(true);
navWrapper.setWidth("320px");
navWrapper.setHeightFull();
navWrapper.getStyle().set("background", "var(--lumo-base-color-60pct)");
baseNav.setWidthFull();
messagesNav.setWidthFull();
adminNav.setWidthFull();

return navWrapper;
}

private Component createSideNavHierarchy() {
SideNav sideNav = new SideNav();
sideNav.addItem(new SideNavItem("Dashboard", AppLayoutSample.class,
VaadinIcon.DASHBOARD.create()));
SideNavItem calendarLink = new SideNavItem("Calendar", "",
VaadinIcon.CALENDAR.create());
sideNav.addItem(calendarLink);

Icon calendarNotification = VaadinIcon.BELL.create();
calendarNotification.getElement().getThemeList()
.add("badge error pill");
calendarNotification.getStyle().set("padding", "var(--lumo-space-xs");
calendarNotification.getElement().setAttribute("aria-label",
"Upcoming appointment");
calendarLink.setSuffixComponent(calendarNotification);

SideNavItem messagesLink = new SideNavItem("Messages", "", VaadinIcon.ENVELOPE.create());
messagesLink.setExpanded(true);
SideNavItem inboxLink = new SideNavItem("Inbox", "",
VaadinIcon.INBOX.create());
Span inboxCounter = new Span("12");
inboxCounter.getElement().getThemeList().add("badge contrast pill");
inboxCounter.getElement().setAttribute("aria-label",
"12 unread messages");
inboxLink.setSuffixComponent(inboxCounter);
messagesLink.addItem(inboxLink);
messagesLink.addItem(new SideNavItem("Sent", "",
VaadinIcon.PAPERPLANE.create()));
messagesLink.addItem(new SideNavItem("Trash", "",
VaadinIcon.TRASH.create()));
sideNav.addItem(messagesLink);

SideNavItem adminSection = new SideNavItem("Admin");
adminSection.setExpanded(true);
adminSection.setPrefixComponent(VaadinIcon.COG.create());
adminSection.addItem(new SideNavItem("Users", "",
VaadinIcon.GROUP.create()));
adminSection.addItem(new SideNavItem("Permissions", "",
VaadinIcon.KEY.create()));
sideNav.addItem(adminSection);

VerticalLayout navWrapper = new VerticalLayout(sideNav);
navWrapper.setSpacing(true);
navWrapper.setWidth("320px");
navWrapper.setHeightFull();
navWrapper.getStyle().set("background", "var(--lumo-base-color-60pct)");
sideNav.setWidthFull();

return navWrapper;
}

private SideNav getSideNav() {
SideNav sideNav = new SideNav();
sideNav.addItem(
new SideNavItem("Dashboard", "/dashboard",
VaadinIcon.DASHBOARD.create()),
new SideNavItem("Orders", "/orders", VaadinIcon.CART.create()),
new SideNavItem("Customers", "/customers",
VaadinIcon.USER_HEART.create()),
new SideNavItem("Products", "/products",
VaadinIcon.PACKAGE.create()),
new SideNavItem("Documents", "/documents",
VaadinIcon.RECORDS.create()),
new SideNavItem("Tasks", "/tasks", VaadinIcon.LIST.create()),
new SideNavItem("Analytics", "/analytics",
VaadinIcon.CHART.create()));
return sideNav;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.vaadin.flow.component.html.*;
import com.vaadin.flow.component.icon.Icon;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.listbox.ListBox;
import com.vaadin.flow.component.listbox.MultiSelectListBox;
import com.vaadin.flow.component.menubar.MenuBar;
import com.vaadin.flow.component.messages.MessageList;
Expand All @@ -52,7 +51,6 @@
import com.vaadin.flow.component.textfield.TextFieldVariant;
import com.vaadin.flow.component.upload.Upload;
import com.vaadin.flow.component.upload.receivers.MultiFileMemoryBuffer;
import com.vaadin.flow.data.renderer.ComponentRenderer;
import com.vaadin.flow.data.renderer.LitRenderer;
import com.vaadin.flow.data.renderer.Renderer;
import com.vaadin.flow.data.value.ValueChangeMode;
Expand All @@ -68,8 +66,6 @@
import java.time.ZoneOffset;
import java.util.*;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@PageTitle("Components Sample")
@Route(value = "components-sample")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
vaadin-app-layout:not([overlay])::part(drawer) {
background-color: transparent;
border-inline-end: transparent;
}

vaadin-app-layout:not([overlay])::part(navbar) {
background-color: var(--lumo-base-color-60pct);
background-image: none;
border-bottom-style: solid;
border-bottom-width: min(var(--view-inset), var(--view-border-width));
border-color: var(--view-border-color);
background: var(--view-background);
background-clip: var(--view-background-clip);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ vaadin-month-calendar::part(month-header) {
font-weight: 600;
}

/* TODO would need a dedicated custom property to control the hover background color */
/* vaadin-month-calendar::part(date)::before {
--lumo-primary-color-10pct: var(--lumo-contrast-10pct);
} */
vaadin-date-time-picker vaadin-date-picker {
margin-inline-end: calc(var(--vaadin-input-field-border-width) * -1);
position: relative;
}

vaadin-date-time-picker vaadin-date-picker::after {
content: "";
position: absolute;
height: 100%;
width: var(--vaadin-input-field-border-width);
background: var(--lumo-base-color);
inset-inline-end: 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
::part(overlay) {
background: var(--view-glow), hsl(var(--base-h) var(--base-s) max(calc(var(--base-l) + 7%), 8%));
box-shadow: inset 0 0.5px 0 0 var(--lumo-tint-5pct), inset 0 0 0 0.5px var(--lumo-tint-10pct), 0 0 0 1px var(--lumo-shade-5pct), var(--lumo-box-shadow-l);
-webkit-backdrop-filter: blur(var(--blur-radius));
backdrop-filter: blur(var(--blur-radius));
font-weight: inherit;
}


vaadin-dialog-overlay::part(header),
vaadin-dialog-overlay::part(footer) {
background: transparent;
}

vaadin-dialog-overlay::part(footer) {
padding: var(--lumo-space-m);
}

/* :is(vaadin-select-overlay, vaadin-context-menu-overlay, vaadin-menu-bar-overlay, vaadin-combo-box-overlay, vaadin-multi-select-combo-box-overlay, vaadin-time-picker-overlay) :is([role=menuitem], [role=option]):is(:hover, [expanded]),
vaadin-item:hover {
background-color: var(--lumo-contrast-10pct);
} */

@media (prefers-reduced-motion) {

:is([opening], [closing]),
:is([opening], [closing])::part(overlay) {
animation: none;
}

vaadin-dialog-overlay:is([opening], [closing]),
vaadin-dialog-overlay:is([opening], [closing])::part(overlay) {
animation: none;
}
}

vaadin-tooltip-overlay {
/* TODO should probably be the default style. Without this, tooltips close to the viewport edge can get scrollbars. */
inset: 0;
}

vaadin-tooltip-overlay::part(overlay) {
font-weight: 500;
}

@media (max-width: 420px), (max-height: 420px) {
:is(vaadin-context-menu-overlay, vaadin-menu-bar-overlay, vaadin-select-overlay)::part(overlay) {
max-height: 80vh;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ vaadin-menu-bar-item.uncheckable::part(checkmark) {
display: none;
}

vaadin-menu-bar.icon-only vaadin-menu-bar-item> :not(vaadin-icon) {
display: none;
}


@media (pointer: fine) {
vaadin-menu-bar-item {
Expand Down
Loading

0 comments on commit a795706

Please sign in to comment.