Skip to content

Conversation

@jschuler
Copy link
Collaborator

This adds the global var that is referenced to get the final value.

Example:

export default {
  name: '--pf-c-alert--BackgroundColor',
  value: '#fff',
  var: 'var(--pf-c-alert--BackgroundColor)',
  global: 'var(--pf-global--BackgroundColor--light-100)' // this field is new
};

What: Towards #3521

Additional issues:

@patternfly-build
Copy link
Collaborator

patternfly-build commented Feb 26, 2020

@codecov-io
Copy link

Codecov Report

Merging #3832 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3832      +/-   ##
==========================================
+ Coverage      71%   71.01%   +0.01%     
==========================================
  Files         785      785              
  Lines       10638    10642       +4     
  Branches     2314     2314              
==========================================
+ Hits         7553     7557       +4     
  Misses       2655     2655              
  Partials      430      430
Flag Coverage Δ
#misc 95.45% <ø> (ø) ⬆️
#patternfly3 85.89% <ø> (ø) ⬆️
#patternfly4 60.03% <100%> (+0.02%) ⬆️
Impacted Files Coverage Δ
...es/patternfly-4/react-tokens/src/generateTokens.js 94.59% <100%> (+0.65%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f7ee95...d2b0355. Read the comment docs.

Copy link
Contributor

@redallen redallen left a comment

Choose a reason for hiding this comment

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

Step 1 is close! I've written something to help you get started on step 2 when you're ready:

const fs = require('fs');
const sassString = fs.readFileSync(require.resolve('@patternfly/patternfly/_variables.scss'), 'utf8');

const chartNum = decl.property.startsWith('--pf-chart-') && !isNaN(populatedValue);
const calculatedValue = chartNum ? Number(populatedValue).valueOf() : populatedValue;
tokens[key] = {
...tokens[key],
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we assigning to tokens[key] more than once for each key? That isn't good.

return computedValue ? computedValue.value : `var(${match})`;
});
// Avoid stringifying numeric chart values
const chartNum = decl.property.startsWith('--pf-chart-') && !isNaN(populatedValue);
Copy link
Contributor

@redallen redallen Feb 26, 2020

Choose a reason for hiding this comment

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

Can't we *just numerify all numbers that pass isNaN and remove the .startsWith('--pf-chart-') logic?

});
// Avoid stringifying numeric chart values
const chartNum = decl.property.startsWith('--pf-chart-') && !isNaN(populatedValue);
const calculatedValue = chartNum ? Number(populatedValue).valueOf() : populatedValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this logic to be on line 36?

value: calculatedValue,
var: `var(${property})`
};
const isGlobal = populatedValue.indexOf('--pf-global') > -1;
Copy link
Contributor

@redallen redallen Feb 26, 2020

Choose a reason for hiding this comment

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

Nit: You can use .startsWith() and spread into tokens[key] = to reduce these 4 lines down to 1. Like

tokens[key ] = {
  ...(populatedValue.startsWith('--pf-global') && { global: populatedValue })
}

@jschuler
Copy link
Collaborator Author

CLosed in favor of #3896

@jschuler jschuler closed this Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants