Skip to content

Commit bcf0fcd

Browse files
authored
feat: add Menu annotation (#19147)
Menu annotation has information like title, order and icon for automatically populated menu. Matches with ViewConfig menu API in Hilla. Related-To: #19109
1 parent 672adee commit bcf0fcd

File tree

1 file changed

+78
-0
lines changed
  • flow-server/src/main/java/com/vaadin/flow/router

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Copyright 2000-2024 Vaadin Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
17+
package com.vaadin.flow.router;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Inherited;
22+
import java.lang.annotation.Retention;
23+
import java.lang.annotation.RetentionPolicy;
24+
import java.lang.annotation.Target;
25+
26+
/**
27+
* Defines menu information for a route for automatically populated menu.
28+
* <p>
29+
* {@link Menu} is used together with {@link Route} to include it automatically
30+
* in Hilla application's main menu, but only if server routes are being exposed
31+
* for client-side via 'window.Vaadin.server.views' variable in the client-side.
32+
* </p>
33+
*
34+
* @see Route
35+
*/
36+
@Retention(RetentionPolicy.RUNTIME)
37+
@Target(ElementType.TYPE)
38+
@Inherited
39+
@Documented
40+
public @interface Menu {
41+
42+
/**
43+
* Title to use in the menu. Falls back the page title if not defined.
44+
*
45+
* @return the title of the item in the menu. Empty String by default.
46+
*/
47+
String title() default "";
48+
49+
/**
50+
* Used to determine the order in the menu. Ties are resolved based on the
51+
* used title. Entries without explicitly defined ordering are put below
52+
* entries with an order. {@link Long#MIN_VALUE} is the default value and
53+
* considered as undefined.
54+
*
55+
* @return the order of the item in the menu. {@link Long#MIN_VALUE} by
56+
* default.
57+
*/
58+
long order() default Long.MIN_VALUE;
59+
60+
/**
61+
* Set to true to explicitly exclude a view from the automatically populated
62+
* menu.
63+
*
64+
* @return true to exclude the view from the menu, false otherwise
65+
*/
66+
boolean exclude() default false;
67+
68+
/**
69+
* Icon to use in the menu. Value can go inside a {@code <vaadin-icon>}
70+
* element's {@code icon} attribute which accepts icon group and name like
71+
* 'vaadin:file'. Or it can go to a {@code <vaadin-icon>} element's
72+
* {@code src} attribute which takes path to the icon. E.g.
73+
* 'line-awesome/svg/lock-open-solid.svg'.
74+
*
75+
* @return A String for an icon. Empty String by default.
76+
*/
77+
String icon() default "";
78+
}

0 commit comments

Comments
 (0)