From 68ad2d4273c7cb555dfef21868f0581fe09f900c Mon Sep 17 00:00:00 2001 From: emyarod Date: Mon, 8 Feb 2021 13:30:26 -0600 Subject: [PATCH] fix(sketch): remove type param from syncColorStyles and syncColorStyle --- .../sketch/src/commands/colors/generate.js | 2 +- packages/sketch/src/commands/colors/sync.js | 2 +- packages/sketch/src/commands/icons/shared.js | 2 +- .../src/commands/test/sync-shared-styles.js | 5 ++- packages/sketch/src/sharedStyles/colors.js | 4 +-- packages/sketch/src/tools/sharedStyles.js | 31 ++++++------------- 6 files changed, 15 insertions(+), 31 deletions(-) diff --git a/packages/sketch/src/commands/colors/generate.js b/packages/sketch/src/commands/colors/generate.js index 5e78207d37b5..8fdb78149675 100644 --- a/packages/sketch/src/commands/colors/generate.js +++ b/packages/sketch/src/commands/colors/generate.js @@ -19,7 +19,7 @@ export function generate() { command('commands/colors/generate', () => { const document = Document.getSelectedDocument(); const page = selectPage(findOrCreatePage(document, 'color')); - const sharedStyles = syncColorStyles({ document }, 'fill'); + const sharedStyles = syncColorStyles({ document }); const { black, white, colors, support } = groupByKey( sharedStyles, (sharedStyle) => { diff --git a/packages/sketch/src/commands/colors/sync.js b/packages/sketch/src/commands/colors/sync.js index 026c727f16ec..7703e8c59b35 100644 --- a/packages/sketch/src/commands/colors/sync.js +++ b/packages/sketch/src/commands/colors/sync.js @@ -11,6 +11,6 @@ import { syncColorStyles } from '../../sharedStyles/colors'; export function sync() { command('commands/colors/sync', () => { - syncColorStyles({ document: Document.getSelectedDocument() }, 'fill'); + syncColorStyles({ document: Document.getSelectedDocument() }); }); } diff --git a/packages/sketch/src/commands/icons/shared.js b/packages/sketch/src/commands/icons/shared.js index b04b6f463f64..a87bbc4c73ae 100644 --- a/packages/sketch/src/commands/icons/shared.js +++ b/packages/sketch/src/commands/icons/shared.js @@ -20,7 +20,7 @@ export function syncIconSymbols({ symbolsPage, sizes = [32, 24, 20, 16], }) { - const sharedStyles = syncColorStyles({ document }, 'fill'); + const sharedStyles = syncColorStyles({ document }); const [sharedStyle] = sharedStyles.filter( ({ name }) => name === 'color / fill / black' ); diff --git a/packages/sketch/src/commands/test/sync-shared-styles.js b/packages/sketch/src/commands/test/sync-shared-styles.js index db4cd71705a5..65c35fdfc411 100644 --- a/packages/sketch/src/commands/test/sync-shared-styles.js +++ b/packages/sketch/src/commands/test/sync-shared-styles.js @@ -46,14 +46,13 @@ export function testSyncSharedStyles() { document, name: 'black', value: '#000000', - type: 'fill', }); if (document.sharedLayerStyles.length !== 1) { throw new Error('Expected sync command to generate a shared layer style'); } - syncColorStyle({ document, name: 'black', value: '#000000', type: 'fill' }); + syncColorStyle({ document, name: 'black', value: '#000000' }); if (document.sharedLayerStyles.length !== 1) { throw new Error( @@ -123,7 +122,7 @@ export function testSyncSharedStyles() { throw new Error('The layer is not in sync with the shared style'); } - syncColorStyle({ document, name: 'black', value: '#dedede', type: 'fill' }); + syncColorStyle({ document, name: 'black', value: '#dedede' }); if (getLayerFillColor() !== '#dededeff') { throw new Error('The layer did not update to the new shared style'); diff --git a/packages/sketch/src/sharedStyles/colors.js b/packages/sketch/src/sharedStyles/colors.js index 31b425bc5087..5ea0afae2771 100644 --- a/packages/sketch/src/sharedStyles/colors.js +++ b/packages/sketch/src/sharedStyles/colors.js @@ -33,7 +33,7 @@ function formatSharedColorStyleName({ name, grade }) { * @param {Document} params.document * @returns {Array} */ -export function syncColorStyles({ document }, type) { +export function syncColorStyles({ document }) { const sharedStyles = Object.keys(swatches).flatMap((swatchName) => { const name = formatTokenName(swatchName); const result = Object.keys(swatches[swatchName]).map((grade) => { @@ -41,7 +41,6 @@ export function syncColorStyles({ document }, type) { document, name: formatSharedColorStyleName({ name, grade }), value: swatches[swatchName][grade], - type, }); }); return result; @@ -57,7 +56,6 @@ export function syncColorStyles({ document }, type) { document, name: formatSharedColorStyleName({ name }), value, - type, }); }); diff --git a/packages/sketch/src/tools/sharedStyles.js b/packages/sketch/src/tools/sharedStyles.js index 8c2f3898a7da..ad9da6b48100 100644 --- a/packages/sketch/src/tools/sharedStyles.js +++ b/packages/sketch/src/tools/sharedStyles.js @@ -66,28 +66,15 @@ export function syncSharedStyle( * @param {Document} params.document * @param {string} params.name * @param {string} params.value - * @param {string} params.type * @returns {SharedStyle} */ -export function syncColorStyle({ document, name, value, type }) { - if (type === 'fill') { - return syncSharedStyle(document, name, { - fills: [ - { - color: value, - fillType: Style.FillType.Color, - }, - ], - }); - } - if (type === 'border') { - return syncSharedStyle(document, name, { - borders: [ - { - color: value, - fillType: Style.FillType.Color, - }, - ], - }); - } +export function syncColorStyle({ document, name, value }) { + return syncSharedStyle(document, name, { + fills: [ + { + color: value, + fillType: Style.FillType.Color, + }, + ], + }); }