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

WIP: added option for gradient class selection #8

Closed
Closed
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
10 changes: 8 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,16 @@ export function generateFontExtension(textStyles) {
export function options(context) {
return {
useColorNames: context.getOption('use_color_names'),
linearGradientClassName: context.getOption('linear_gradient_class_name'),
};
}

export function linearGradientLayer(gradient, project, useColorNames) {
export function linearGradientLayer(
gradient,
project,
useColorNames,
gradientClassName
) {
let colorStopsString = '';
let colorStopsPositionString = '';
const { colorStops } = gradient;
Expand All @@ -81,7 +87,7 @@ export function linearGradientLayer(gradient, project, useColorNames) {
colorStopsPositionString += `${colorStop.position}${divideString}`;
});

let string = 'let gradientLayer = CAGradientLayer()\n';
let string = `let gradientLayer = ${gradientClassName}()\n`;
string += 'gradientLayer.frame = view.bounds\n';
if (gradient.angle === 90) {
string += 'gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5)\n';
Expand Down
9 changes: 7 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ export function styleguideTextStyles(context, textStyles) {

export function layer(context, layerParams) {
let string = '';
const { useColorNames } = options(context);
const { useColorNames, linearGradientClassName } = options(context);
const { gradient } = layerParams.fills[0];
if (gradient !== undefined) {
switch (gradient.type) {
case 'linear':
string += linearGradientLayer(gradient, context.project, useColorNames);
string += linearGradientLayer(
gradient,
context.project,
useColorNames,
linearGradientClassName
);
break;
case 'radial':
string += radialGradientLayer(gradient, context.project, useColorNames);
Expand Down
6 changes: 6 additions & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
"type": "switch",
"id": "use_color_names",
"default": true
},
{
"name": "Linear gradient class name",
"type": "text",
"id": "linear_gradient_class_name",
"default": "CAGradientLayer"
}
]
}