Skip to content

Commit 7d525c7

Browse files
authored
fix: multiline centered text (#125)
1 parent 74196a6 commit 7d525c7

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

apps/dashboard/src/lib/__tests__/__snapshots__/export.test.ts.snap

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`elementsToReactElements > should ignore dynamic texts by default 1`] =
2020
"marginBottom": 0,
2121
"marginTop": 0,
2222
"position": "absolute",
23+
"textAlign": "left",
2324
"top": "0px",
2425
"width": "100px",
2526
},
@@ -74,6 +75,7 @@ exports[`elementsToReactElements > should render text chidrens 1`] = `
7475
"marginBottom": 0,
7576
"marginTop": 0,
7677
"position": "absolute",
78+
"textAlign": "left",
7779
"top": "0px",
7880
"width": "100px",
7981
},
@@ -143,6 +145,7 @@ exports[`elementsToReactElements > should replace dynamic texts if present 1`] =
143145
"marginBottom": 0,
144146
"marginTop": 0,
145147
"position": "absolute",
148+
"textAlign": "left",
146149
"top": "0px",
147150
"width": "100px",
148151
},

apps/dashboard/src/lib/__tests__/elements.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ describe("createElementStyle", () => {
319319
"marginBottom": 0,
320320
"marginTop": 0,
321321
"position": "absolute",
322+
"textAlign": "left",
322323
"top": "20px",
323324
"width": "100px",
324325
}
@@ -369,6 +370,7 @@ describe("createElementStyle", () => {
369370
"marginBottom": 0,
370371
"marginTop": 0,
371372
"position": "absolute",
373+
"textAlign": "left",
372374
"textShadow": "2px 2px 4px blue",
373375
"top": "20px",
374376
"width": "100px",
@@ -413,6 +415,7 @@ describe("createElementStyle", () => {
413415
"marginBottom": 0,
414416
"marginTop": 0,
415417
"position": "absolute",
418+
"textAlign": "center",
416419
"top": "20px",
417420
"width": "100px",
418421
}
@@ -456,6 +459,7 @@ describe("createElementStyle", () => {
456459
"marginBottom": 0,
457460
"marginTop": 0,
458461
"position": "absolute",
462+
"textAlign": "right",
459463
"top": "20px",
460464
"width": "100px",
461465
}

apps/dashboard/src/lib/elements.ts

+3
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ export function createElementStyle(element: OGElement): CSSProperties {
189189
fontSize: `${element.fontSize}px`,
190190
lineHeight: element.lineHeight,
191191
letterSpacing: `${element.letterSpacing}px`,
192+
// We need both textAlign and justifyContent to center the text
193+
// so that it works with both single and multi-line text
194+
textAlign: element.align,
192195
justifyContent:
193196
element.align === "center"
194197
? "center"

0 commit comments

Comments
 (0)