Skip to content

Commit 79c3efb

Browse files
authored
ensure navigateModalScreen supports custom widget title (#1112)
1 parent b080230 commit 79c3efb

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

.changeset/tame-onions-lick.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@ensembleui/react-kitchen-sink": patch
3+
"@ensembleui/react-runtime": patch
4+
---
5+
6+
ensure navigateModalScreen supports custom widget title

apps/kitchen-sink/src/ensemble/screens/forms.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ View:
4242
inputs:
4343
storVar: ${ensemble.storage.get('inputVal')}
4444
userVar: ${ensemble.user}
45+
title:
46+
Column:
47+
children:
48+
- Text:
49+
text: Modal title
50+
- Text:
51+
text: Modal subtitle
52+
styles:
53+
fontSize: ${typography.fontSize['14']}
54+
fontWeight: ${typography.fontWeight.light}
4555
- Button:
4656
label: show dialog
4757
onTap:

packages/runtime/src/runtime/modal/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const ModalWrapper: React.FC<PropsWithChildren> = ({ children }) => {
8383
isDialog: boolean;
8484
key: string;
8585
context?: { [key: string]: unknown };
86+
title?: React.ReactNode;
8687
}>();
8788
const evaluatedOptions = useEvaluate(
8889
nextModal
@@ -125,7 +126,10 @@ export const ModalWrapper: React.FC<PropsWithChildren> = ({ children }) => {
125126
const nextModalState = {
126127
visible: true,
127128
content: nextModal.content,
128-
options: evaluatedOptions.options,
129+
options: {
130+
...evaluatedOptions.options,
131+
...(nextModal.title ? { title: nextModal.title } : {}),
132+
},
129133
key: nextModal.key,
130134
isDialog: Boolean(nextModal.isDialog),
131135
};
@@ -154,12 +158,14 @@ export const ModalWrapper: React.FC<PropsWithChildren> = ({ children }) => {
154158
isDialog = false,
155159
modalContext?: { [key: string]: unknown },
156160
): void => {
161+
const hasStringTitle = isString(options.title);
157162
setNextModal({
158163
content,
159-
options: omit(options, [!isString(options.title) ? "title" : ""]),
164+
options: hasStringTitle ? options : omit(options, "title"),
160165
isDialog,
161166
context: modalContext,
162167
key: generateRandomString(10),
168+
title: hasStringTitle ? undefined : options.title,
163169
});
164170
},
165171
[],

0 commit comments

Comments
 (0)