0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 05:33:02 -05:00

Fix style paths (#194)

* Fix style path

* add changelog
This commit is contained in:
Jordi Sala Morales 2024-06-28 08:32:56 +02:00 committed by GitHub
parent 8d185c98fd
commit 53672d8b43
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 50 additions and 5 deletions

View file

@ -0,0 +1,5 @@
---
"penpot-exporter": patch
---
Fix local styles categorization system

View file

@ -1,2 +1,4 @@
export * from './translatePaintStyle';
export * from './translateStyleName';
export * from './translateStylePath';
export * from './translateTextStyle';

View file

@ -2,6 +2,8 @@ import { translateFill } from '@plugin/translators/fills/translateFills';
import { FillStyle } from '@ui/lib/types/utils/fill';
import { translateStyleName, translateStylePath } from '.';
export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
const fillStyle: FillStyle = {
name: figmaStyle.name,
@ -10,12 +12,11 @@ export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
};
const colorName = (figmaStyle: PaintStyle, index: number): string => {
return figmaStyle.paints.length > 1 ? `Color ${index + 1}` : figmaStyle.name;
return figmaStyle.paints.length > 1 ? `Color ${index + 1}` : translateStyleName(figmaStyle);
};
let index = 0;
const path =
(figmaStyle.remote ? 'Remote / ' : '') + (figmaStyle.paints.length > 1 ? figmaStyle.name : '');
const path = translatePaintStylePath(figmaStyle);
for (const fill of figmaStyle.paints) {
const penpotFill = translateFill(fill);
@ -32,3 +33,13 @@ export const translatePaintStyle = (figmaStyle: PaintStyle): FillStyle => {
return fillStyle;
};
const translatePaintStylePath = (figmaStyle: PaintStyle) => {
const path = translateStylePath(figmaStyle);
if (figmaStyle.paints.length <= 1) {
return path;
}
return path + (path !== '' ? ' / ' : '') + translateStyleName(figmaStyle);
};

View file

@ -0,0 +1,9 @@
export const translateStyleName = (figmaStyle: BaseStyle): string => {
const splitName = figmaStyle.name.split('/');
if (splitName.length > 0) {
return splitName.pop() as string;
}
return figmaStyle.name;
};

View file

@ -0,0 +1,16 @@
export const translateStylePath = (figmaStyle: BaseStyleMixin) => {
const path = [];
if (figmaStyle.remote) {
path.push('Remote');
}
if (figmaStyle.name.includes('/')) {
const pathParts = figmaStyle.name.split('/');
pathParts.pop();
path.push(...pathParts);
}
return path.join(' / ');
};

View file

@ -9,11 +9,13 @@ import {
import { TypographyStyle } from '@ui/lib/types/shapes/textShape';
import { translateStyleName, translateStylePath } from '.';
export const translateTextStyle = (figmaStyle: TextStyle): TypographyStyle => {
const name = (figmaStyle.remote ? 'Remote / ' : '') + figmaStyle.name;
return {
name: figmaStyle.name,
name: translateStyleName(figmaStyle),
textStyle: {
...translateFontName(figmaStyle.fontName),
fontFamily: figmaStyle.fontName.family,
@ -25,7 +27,7 @@ export const translateTextStyle = (figmaStyle: TextStyle): TypographyStyle => {
lineHeight: translateLineHeight(figmaStyle)
},
typography: {
path: '',
path: translateStylePath(figmaStyle),
name
}
};