Skip to content

Commit

Permalink
fix(sketch): remove type param from syncColorStyles and syncColorStyle
Browse files Browse the repository at this point in the history
  • Loading branch information
emyarod committed Feb 11, 2021
1 parent 625c2fb commit 68ad2d4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 31 deletions.
2 changes: 1 addition & 1 deletion packages/sketch/src/commands/colors/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sketch/src/commands/colors/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
});
}
2 changes: 1 addition & 1 deletion packages/sketch/src/commands/icons/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
Expand Down
5 changes: 2 additions & 3 deletions packages/sketch/src/commands/test/sync-shared-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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');
Expand Down
4 changes: 1 addition & 3 deletions packages/sketch/src/sharedStyles/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ function formatSharedColorStyleName({ name, grade }) {
* @param {Document} params.document
* @returns {Array<SharedStyle>}
*/
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) => {
return syncColorStyle({
document,
name: formatSharedColorStyleName({ name, grade }),
value: swatches[swatchName][grade],
type,
});
});
return result;
Expand All @@ -57,7 +56,6 @@ export function syncColorStyles({ document }, type) {
document,
name: formatSharedColorStyleName({ name }),
value,
type,
});
});

Expand Down
31 changes: 9 additions & 22 deletions packages/sketch/src/tools/sharedStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
],
});
}

0 comments on commit 68ad2d4

Please sign in to comment.