Skip to content

Commit c55a073

Browse files
committed
feat(calendar-web): custom button tooltip and styling per toolbar item
1 parent 31b8295 commit c55a073

File tree

5 files changed

+53
-16
lines changed

5 files changed

+53
-16
lines changed

packages/pluggableWidgets/calendar-web/src/Calendar.editorConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export function getProperties(values: CalendarPreviewProps, defaultProperties: P
4848
}
4949

5050
values.toolbarItems?.forEach((item, index) => {
51+
if (item.itemType === "title") {
52+
hideNestedPropertiesIn(defaultProperties, values, "toolbarItems", index, ["buttonTooltip", "buttonStyle"]);
53+
}
5154
// Hide all format properties for non-view items (navigation buttons, title)
5255
if (!["day", "month", "agenda", "week", "work_week"].includes(item.itemType)) {
5356
hideNestedPropertiesIn(defaultProperties, values, "toolbarItems", index, [

packages/pluggableWidgets/calendar-web/src/Calendar.xml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,6 @@
170170
<category>Appearance</category>
171171
<description>Optional text for the button or title. If empty, a default localized label is used.</description>
172172
</property>
173-
<property key="tooltip" type="textTemplate" required="false">
174-
<caption>Tooltip</caption>
175-
<category>Appearance</category>
176-
<description>Optional hover text for the button.</description>
177-
</property>
178173
<property key="renderMode" type="enumeration" defaultValue="button">
179174
<caption>Render mode</caption>
180175
<category>Appearance</category>
@@ -184,6 +179,24 @@
184179
<enumerationValue key="link">Link</enumerationValue>
185180
</enumerationValues>
186181
</property>
182+
<property key="buttonTooltip" type="textTemplate" required="false">
183+
<caption>Button tooltip</caption>
184+
<category>Appearance</category>
185+
<description>Tooltip for the button.</description>
186+
</property>
187+
<property key="buttonStyle" type="enumeration" defaultValue="default">
188+
<caption>Button style</caption>
189+
<category>Appearance</category>
190+
<description>Style of the button.</description>
191+
<enumerationValues>
192+
<enumerationValue key="default">Default</enumerationValue>
193+
<enumerationValue key="primary">Primary</enumerationValue>
194+
<enumerationValue key="success">Success</enumerationValue>
195+
<enumerationValue key="info">Info</enumerationValue>
196+
<enumerationValue key="warning">Warning</enumerationValue>
197+
<enumerationValue key="danger">Danger</enumerationValue>
198+
</enumerationValues>
199+
</property>
187200
<property key="customViewHeaderDayFormat" type="textTemplate" required="false">
188201
<caption>Header day format</caption>
189202
<category>Custom formats</category>

packages/pluggableWidgets/calendar-web/src/components/Toolbar.tsx

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export type ResolvedToolbarItem = {
5151
itemType: "previous" | "today" | "next" | "title" | "month" | "week" | "work_week" | "day" | "agenda";
5252
position: "left" | "center" | "right";
5353
caption?: string;
54-
tooltip?: string;
5554
renderMode: "button" | "link";
5655
// Custom formatting/text options for Custom view
5756
customViewHeaderDayFormat?: string;
@@ -62,6 +61,9 @@ export type ResolvedToolbarItem = {
6261
customViewTextHeaderDate?: string;
6362
customViewTextHeaderTime?: string;
6463
customViewTextHeaderEvent?: string;
64+
// Custom button presentation
65+
customButtonTooltip?: string;
66+
customButtonStyle?: "default" | "primary" | "success" | "info" | "warning" | "danger";
6567
};
6668

6769
export function createConfigurableToolbar(items: ResolvedToolbarItem[]): (props: ToolbarProps) => ReactElement {
@@ -72,18 +74,28 @@ export function createConfigurableToolbar(items: ResolvedToolbarItem[]): (props:
7274
onClick: () => void,
7375
active = false,
7476
renderMode: "button" | "link" = "button",
75-
tooltip?: string
77+
tooltip?: string,
78+
styleClass?: string
7679
): ReactElement => (
7780
<Button
7881
key={key}
79-
className={classNames("btn", renderMode === "link" ? "btn-link" : "btn-default", { active })}
82+
className={classNames("btn", styleClass ?? (renderMode === "link" ? "btn-link" : "btn-default"), {
83+
active
84+
})}
8085
onClick={onClick}
8186
title={tooltip}
8287
>
8388
{content}
8489
</Button>
8590
);
8691

92+
const resolveStyleClass = (item: ResolvedToolbarItem): string => {
93+
if (item.renderMode === "link") {
94+
return "btn-link";
95+
}
96+
return `btn-${item.customButtonStyle ?? "default"}`;
97+
};
98+
8799
const groups: Record<"left" | "center" | "right", ResolvedToolbarItem[]> = {
88100
left: [],
89101
center: [],
@@ -102,7 +114,8 @@ export function createConfigurableToolbar(items: ResolvedToolbarItem[]): (props:
102114
() => onNavigate(Navigate.PREVIOUS),
103115
false,
104116
item.renderMode,
105-
item.tooltip
117+
item.customButtonTooltip,
118+
resolveStyleClass(item)
106119
);
107120
case "today":
108121
// Always provide a default caption for 'today' button
@@ -112,7 +125,8 @@ export function createConfigurableToolbar(items: ResolvedToolbarItem[]): (props:
112125
() => onNavigate(Navigate.TODAY),
113126
false,
114127
item.renderMode,
115-
item.tooltip
128+
item.customButtonTooltip,
129+
resolveStyleClass(item)
116130
);
117131
case "next":
118132
return renderButton(
@@ -121,12 +135,13 @@ export function createConfigurableToolbar(items: ResolvedToolbarItem[]): (props:
121135
() => onNavigate(Navigate.NEXT),
122136
false,
123137
item.renderMode,
124-
item.tooltip
138+
item.customButtonTooltip,
139+
resolveStyleClass(item)
125140
);
126141
case "title":
127142
// Title always shows the formatted label, regardless of caption
128143
return (
129-
<span key="title" className="calendar-label" title={item.tooltip}>
144+
<span key="title" className="calendar-label" title={item.customButtonTooltip}>
130145
{label}
131146
</span>
132147
);
@@ -144,7 +159,8 @@ export function createConfigurableToolbar(items: ResolvedToolbarItem[]): (props:
144159
() => onView(name),
145160
view === name,
146161
item.renderMode,
147-
item.tooltip
162+
item.customButtonTooltip,
163+
resolveStyleClass(item)
148164
);
149165
}
150166
default:

packages/pluggableWidgets/calendar-web/src/helpers/CalendarPropsBuilder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,9 @@ export class CalendarPropsBuilder {
313313
itemType: i.itemType,
314314
position: i.position,
315315
caption: i.caption?.value,
316-
tooltip: i.tooltip?.value,
317316
renderMode: i.renderMode,
317+
customButtonTooltip: i.buttonTooltip?.value,
318+
customButtonStyle: i.buttonStyle,
318319
customViewHeaderDayFormat: i.customViewHeaderDayFormat?.value,
319320
customViewCellDateFormat: i.customViewCellDateFormat?.value,
320321
customViewGutterTimeFormat: i.customViewGutterTimeFormat?.value,

packages/pluggableWidgets/calendar-web/typings/CalendarProps.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ export type PositionEnum = "left" | "center" | "right";
2020

2121
export type RenderModeEnum = "button" | "link";
2222

23+
export type ButtonStyleEnum = "default" | "primary" | "success" | "info" | "warning" | "danger";
24+
2325
export interface ToolbarItemsType {
2426
itemType: ItemTypeEnum;
2527
position: PositionEnum;
2628
caption?: DynamicValue<string>;
27-
tooltip?: DynamicValue<string>;
2829
renderMode: RenderModeEnum;
30+
buttonTooltip?: DynamicValue<string>;
31+
buttonStyle: ButtonStyleEnum;
2932
customViewHeaderDayFormat?: DynamicValue<string>;
3033
customViewCellDateFormat?: DynamicValue<string>;
3134
customViewGutterTimeFormat?: DynamicValue<string>;
@@ -50,8 +53,9 @@ export interface ToolbarItemsPreviewType {
5053
itemType: ItemTypeEnum;
5154
position: PositionEnum;
5255
caption: string;
53-
tooltip: string;
5456
renderMode: RenderModeEnum;
57+
buttonTooltip: string;
58+
buttonStyle: ButtonStyleEnum;
5559
customViewHeaderDayFormat: string;
5660
customViewCellDateFormat: string;
5761
customViewGutterTimeFormat: string;

0 commit comments

Comments
 (0)