Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(sharedStyles): use param object instead of list of params #8700

Merged
merged 2 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/sketch/src/commands/icons/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ function removeDeprecatedSymbolArtboards({ icons, sizes, symbolsPage }) {
});
}

/**
* Sync Carbon icon symbols into current Sketch Document
* @param {object} params - syncIconSymbols parameters
* @param {Document} params.document - current document
* @param {Array<SymbolMaster>} params.symbols
* @param {Page} params.symbolsPage - the symbols page as identified by Sketch
* @param {Array<number>} params.sizes - array of icon sizes
*/
export function syncIconSymbols({
document,
symbols,
Expand Down
30 changes: 15 additions & 15 deletions packages/sketch/src/commands/test/sync-shared-styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ export function testSyncSharedStyles() {
*/
clear();

const textSharedStyle = syncSharedStyle(
const textSharedStyle = syncSharedStyle({
document,
'test-shared-text-style',
{
name: 'test-shared-text-style',
style: {
textColor: '#000000ff',
fontSize: 16,
textTransform: 'none',
Expand All @@ -149,19 +149,19 @@ export function testSyncSharedStyles() {
alignment: 'left',
styleType: SharedStyle.StyleType.Text,
},
SharedStyle.StyleType.Text
);
styleType: SharedStyle.StyleType.Text,
});

if (document.sharedTextStyles.length !== 1) {
throw new Error('Expected sync command to generate a shared text style');
}

syncSharedStyle(
syncSharedStyle({
document,
'test-shared-text-style',
{},
SharedStyle.StyleType.Text
);
name: 'test-shared-text-style',
style: {},
styleType: SharedStyle.StyleType.Text,
});

if (document.sharedTextStyles.length !== 1) {
throw new Error(
Expand Down Expand Up @@ -189,14 +189,14 @@ export function testSyncSharedStyles() {
throw new Error('Inserted layer is out of sync with shared text style');
}

syncSharedStyle(
syncSharedStyle({
document,
'test-shared-text-style',
{
name: 'test-shared-text-style',
style: {
textColor: '#343434ff',
},
SharedStyle.StyleType.Text
);
styleType: SharedStyle.StyleType.Text,
});

if (getTextFillColor() !== '#343434ff') {
throw new Error('Shared text style textColor was not updated');
Expand Down
6 changes: 3 additions & 3 deletions packages/sketch/src/sharedStyles/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ export function syncTextStyles(document) {
.map((token) => {
const name = formatSharedStyleName(token);
const style = convertTypeStyle(token, styles[token]);
const sharedTextStyle = syncSharedStyle(
const sharedTextStyle = syncSharedStyle({
document,
name,
style,
SharedStyle.StyleType.Text
);
styleType: SharedStyle.StyleType.Text,
});

sharedTextStyle.style.textColor = '#000000ff';
sharedTextStyle.style.borders = [];
Expand Down
33 changes: 19 additions & 14 deletions packages/sketch/src/tools/sharedStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,19 @@ import { SharedStyle, Style } from 'sketch/dom';

/**
* Sync a shared style within a document.
* @param {Document} document
* @param {string} name
* @param {object} style
* @param {StyleType?} styleType
* @param {object} params - syncSharedStyle parameters
* @param {Document} params.document
* @param {string} params.name
* @param {object} params.style
* @param {StyleType?} params.styleType
* @returns {SharedStyle}
*/
export function syncSharedStyle(
export function syncSharedStyle({
document,
name,
style,
styleType = SharedStyle.StyleType.Layer
) {
styleType = SharedStyle.StyleType.Layer,
}) {
// Figure out the type of shared style and try and find if we have already
// created a shared style with the given name
const documentSharedStyles =
Expand Down Expand Up @@ -84,12 +85,16 @@ export function syncSharedStyle(
* @returns {SharedStyle}
*/
export function syncColorStyle({ document, name, value }) {
return syncSharedStyle(document, name, {
fills: [
{
color: value,
fillType: Style.FillType.Color,
},
],
return syncSharedStyle({
document,
name,
style: {
fills: [
{
color: value,
fillType: Style.FillType.Color,
},
],
},
});
}