-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathButtonComponent.java
More file actions
61 lines (53 loc) · 1.71 KB
/
ButtonComponent.java
File metadata and controls
61 lines (53 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package de.tschuehly.example.fragments;
import de.tschuehly.spring.viewcomponent.core.component.ViewComponent;
import de.tschuehly.spring.viewcomponent.thymeleaf.ViewContext;
/**
* Example ViewComponent demonstrating fragment rendering with multiple ViewContext types.
*
* This single component can render different button variants (primary, secondary, danger)
* based on the ViewContext type returned from the render methods.
*/
@ViewComponent
public class ButtonComponent {
/**
* ViewContext for primary action buttons.
*/
public record PrimaryButton(
String label,
String action
) implements ViewContext {}
/**
* ViewContext for secondary/alternative action buttons.
*/
public record SecondaryButton(
String label,
String action
) implements ViewContext {}
/**
* ViewContext for dangerous/destructive action buttons.
* Includes a confirmation message that will be shown before execution.
*/
public record DangerButton(
String label,
String action,
String confirmMessage
) implements ViewContext {}
/**
* Renders a primary button for main actions.
*/
public PrimaryButton primary(String label, String action) {
return new PrimaryButton(label, action);
}
/**
* Renders a secondary button for alternative actions.
*/
public SecondaryButton secondary(String label, String action) {
return new SecondaryButton(label, action);
}
/**
* Renders a danger button for destructive actions.
*/
public DangerButton danger(String label, String action, String confirmMessage) {
return new DangerButton(label, action, confirmMessage);
}
}