0
Fork 0
mirror of https://github.com/penpot/penpot-plugins.git synced 2025-01-07 15:39:49 -05:00

feat(create-palette-plugin): minor visual changes

This commit is contained in:
alonso.torres 2024-05-30 09:29:25 +02:00 committed by Alonso Torres
parent a26033bb31
commit 7a22ed23ae
2 changed files with 30 additions and 15 deletions

View file

@ -6,13 +6,6 @@ function main() {
} }
function createPalette() { function createPalette() {
const frame = penpot.createFrame();
frame.name = 'Palette';
const viewport = penpot.viewport;
frame.x = viewport.center.x - 150;
frame.y = viewport.center.y - 200;
const colors = penpot.library.local.colors.sort((a, b) => const colors = penpot.library.local.colors.sort((a, b) =>
a.name.toLowerCase() > b.name.toLowerCase() a.name.toLowerCase() > b.name.toLowerCase()
? 1 ? 1
@ -21,17 +14,24 @@ function createPalette() {
: 0 : 0
); );
const cols = 4;
const rows = Math.ceil(colors.length / cols);
const width = cols * 200 + Math.max(0, cols - 1) * 10 + 20;
const height = rows * 100 + Math.max(0, rows - 1) * 10 + 20;
const frame = penpot.createFrame();
frame.name = 'Palette';
const viewport = penpot.viewport;
frame.x = viewport.center.x - width / 2;
frame.y = viewport.center.y - height / 2;
if (colors.length === 0) { if (colors.length === 0) {
// NO colors return // NO colors return
return; return;
} }
const cols = 3;
const rows = Math.ceil(colors.length / 3);
const width = cols * 150 + Math.max(0, cols - 1) * 10 + 20;
const height = rows * 100 + Math.max(0, rows - 1) * 10 + 20;
frame.resize(width, height); frame.resize(width, height);
frame.borderRadius = 8; frame.borderRadius = 8;
@ -39,11 +39,11 @@ function createPalette() {
const grid = frame.addGridLayout(); const grid = frame.addGridLayout();
for (let i = 0; i < rows; i++) { for (let i = 0; i < rows; i++) {
grid.addRow('auto'); grid.addRow('flex', 1);
} }
for (let i = 0; i < cols; i++) { for (let i = 0; i < cols; i++) {
grid.addColumn('auto'); grid.addColumn('flex', 1);
} }
grid.alignItems = 'center'; grid.alignItems = 'center';
@ -55,6 +55,8 @@ function createPalette() {
grid.verticalPadding = 10; grid.verticalPadding = 10;
grid.horizontalPadding = 10; grid.horizontalPadding = 10;
grid.horizontalSizing = 'auto';
// create text // create text
for (let row = 0; row < rows; row++) { for (let row = 0; row < rows; row++) {
for (let col = 0; col < cols; col++) { for (let col = 0; col < cols; col++) {
@ -80,9 +82,22 @@ function createPalette() {
const flex = board.addFlexLayout(); const flex = board.addFlexLayout();
flex.alignItems = 'center'; flex.alignItems = 'center';
flex.justifyContent = 'center'; flex.justifyContent = 'center';
flex.verticalPadding = 8;
flex.horizontalPadding = 8;
const text = penpot.createText(color.name); const text = penpot.createText(color.name);
text.fontWeight = 'bold';
text.fontVariantId = 'bold';
text.growType = 'auto-width'; text.growType = 'auto-width';
text.strokes = [
{
strokeColor: '#FFFFFF',
strokeWidth: 1,
strokeAlignment: 'outer',
strokeOpacity: 0.5,
strokeStyle: 'solid',
},
];
board.appendChild(text); board.appendChild(text);
} }
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 33 KiB