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

feat(sketch): create shared styles for icon stroke #5744

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(sketch): create shared styles for icon stroke
  • Loading branch information
emyarod committed Apr 8, 2020
commit a1954b9c409142f5b278cd537dfcae3d1ab7663c
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);
const sharedStyles = syncColorStyles(document, 'fill');
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.getSelectedDocument());
syncColorStyles(Document.getSelectedDocument(), 'fill');
});
}
4 changes: 2 additions & 2 deletions packages/sketch/src/commands/icons/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export function syncIconSymbols(
sharedLayerStyles,
sizes = [32, 24, 20, 16]
) {
const sharedStyles = syncColorStyles(document);
const sharedStyles = syncColorStyles(document, 'fill');
const [sharedStyle] = sharedStyles.filter(
({ name }) => name === 'color / black'
({ name }) => name === 'color / fill / black'
);

if (!sharedStyle) {
Expand Down
2 changes: 1 addition & 1 deletion packages/sketch/src/commands/themes/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function generate() {
command('commands/themes/generate', () => {
const document = Document.getSelectedDocument();
const page = selectPage(findOrCreatePage(document, 'themes'));
const sharedStyles = syncThemeColorStyles(document);
const sharedStyles = syncThemeColorStyles(document, 'fill');

const tokens = groupByKey(sharedStyles, sharedStyle => {
const [_namespace, _category, _group, token] = sharedStyle.name.split(
Expand Down
2 changes: 1 addition & 1 deletion packages/sketch/src/commands/themes/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ import { syncThemeColorStyles } from '../../sharedStyles/themes';
export function sync() {
command('commands/themes/sync', () => {
const document = Document.getSelectedDocument();
syncThemeColorStyles(document);
syncThemeColorStyles(document, 'fill');
});
}
21 changes: 14 additions & 7 deletions packages/sketch/src/sharedStyles/colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ const { black, white, orange, yellow, ...swatches } = colors;
* @param {Document} document
* @returns {Array<SharedStyle>}
*/
export function syncColorStyles(document) {
export function syncColorStyles(document, type) {
const sharedStyles = Object.keys(swatches).flatMap(swatchName => {
const name = formatTokenName(swatchName);
const result = Object.keys(swatches[swatchName]).map(grade => {
return syncColorStyle(
document,
formatSharedStyleName(name, grade),
swatches[swatchName][grade]
formatSharedStyleName(name, type, grade),
swatches[swatchName][grade],
type
);
});
return result;
Expand All @@ -37,21 +38,27 @@ export function syncColorStyles(document) {
['orange', orange['40']],
['yellow', yellow['30']],
].map(([name, value]) => {
return syncColorStyle(document, formatSharedStyleName(name), value);
return syncColorStyle(
document,
formatSharedStyleName(name, type),
value,
type
);
});

return sharedStyles.concat(singleColors);
}

/**
* Our shared style name will need to have the `color` namespace alongside a
* name for the swatch and an optional grade.
* name for the swatch, the style type, and an optional grade.
* @param {string} name
* @param {string} type
* @param {string?} grade
* @returns {string}
*/
function formatSharedStyleName(name, grade) {
return ['color', name.split('-').join(' '), grade]
function formatSharedStyleName(name, type, grade) {
return ['color', type, name.split('-').join(' '), grade]
.filter(Boolean)
.join(' / ');
}
5 changes: 3 additions & 2 deletions packages/sketch/src/sharedStyles/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ const { colors } = tokens;
/**
* Sync theme color shared styles to the given document and return the result
* @param {Document} document
* @param {string} styleType
* @returns {Array<SharedStyle>}
*/
export function syncThemeColorStyles(document) {
export function syncThemeColorStyles(document, styleType) {
const themes = {
'White theme': white,
'Gray 10 theme': g10,
Expand All @@ -43,7 +44,7 @@ export function syncThemeColorStyles(document) {
const name = `theme / ${theme.toLowerCase()} / ${type} tokens / ${formatTokenName(
token
)}`;
return syncColorStyle(document, name, themes[theme][token]);
return syncColorStyle(document, name, themes[theme][token], styleType);
});
});

Expand Down
21 changes: 12 additions & 9 deletions packages/sketch/src/tools/sharedStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,18 @@ export function syncSharedStyle(
* @param {Document} document
* @param {string} name
* @param {string} value
* @param {string} type
* @returns {SharedStyle}
*/
export function syncColorStyle(document, name, value) {
return syncSharedStyle(document, name, {
fills: [
{
color: value,
fillType: Style.FillType.Color,
},
],
});
export function syncColorStyle(document, name, value, type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding a type to the end of this and updating all the call signatures that exist already, would it make sense to add a syncFillStyle and syncBorderStyle helper and then we can call them separately?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so would those two additional helpers be called by the sharedStyles helpers?

if (type === 'fill') {
return syncSharedStyle(document, name, {
fills: [
{
color: value,
fillType: Style.FillType.Color,
},
],
});
}
}