Skip to content

Commit

Permalink
correctly translate font style
Browse files Browse the repository at this point in the history
  • Loading branch information
jordisala1991 committed Apr 29, 2024
1 parent fff31d7 commit 09f4ff5
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions plugin-src/transformers/partials/transformTextStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import slugify from 'slugify';

import {
translateFontStyle,
translateFontVariantId,
translateHorizontalAlign,
translateLetterSpacing,
translateLineHeight,
Expand Down Expand Up @@ -32,9 +33,9 @@ export const transformTextStyle = (
fontFamily: segment.fontName.family,
fontId: `gfont-${slugify(segment.fontName.family.toLowerCase())}`,
fontSize: segment.fontSize.toString(),
fontStyle: segment.fontName.style,
fontStyle: translateFontStyle(segment.fontName.style),
fontWeight: segment.fontWeight.toString(),
fontVariantId: translateFontStyle(segment.fontName.style),
fontVariantId: translateFontVariantId(segment.fontName.style),
textAlign: translateHorizontalAlign(node.textAlignHorizontal),
textDecoration: translateTextDecoration(segment),
textTransform: translateTextTransform(segment),
Expand Down
1 change: 1 addition & 0 deletions plugin-src/translators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './translateBlendMode';
export * from './translateShadowEffects';
export * from './translateFills';
export * from './translateFontStyle';
export * from './translateFontVariantId';
export * from './translateGrowType';
export * from './translateHorizontalAlign';
export * from './translateLetterSpacing';
Expand Down
10 changes: 8 additions & 2 deletions plugin-src/translators/translateFontStyle.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export const translateFontStyle = (style: string) => {
return style.toLowerCase().replace(/\s/g, '');
import { TextFontStyle } from '@ui/lib/types/text/textContent';

export const translateFontStyle = (style: string): TextFontStyle => {
if (style.toLowerCase().includes('italic')) {
return 'italic';
}

return 'normal';
};
3 changes: 3 additions & 0 deletions plugin-src/translators/translateFontVariantId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const translateFontVariantId = (style: string) => {
return style.toLowerCase().replace(/\s/g, '');
};
3 changes: 2 additions & 1 deletion ui-src/lib/types/text/textContent.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export type TextContent = {

export type TextVerticalAlign = 'top' | 'bottom' | 'center';
export type TextHorizontalAlign = 'left' | 'right' | 'center' | 'justify';
export type TextFontStyle = 'normal' | 'italic';

type ParagraphSet = {
type: 'paragraph-set';
Expand All @@ -32,7 +33,7 @@ type TextStyle = {
fontFamily?: string;
fontVariantId?: string;
fontSize?: string;
fontStyle?: string;
fontStyle?: TextFontStyle;
fontWeight?: string;
textDecoration?: string;
textTransform?: string;
Expand Down

0 comments on commit 09f4ff5

Please sign in to comment.