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

Work on code generation for C# / .NET (MAUI) #1162

Open
wants to merge 3 commits into
base: v4
Choose a base branch
from

Conversation

hansmbakker
Copy link

@hansmbakker hansmbakker commented Apr 16, 2024

Issue #, if available: #977

Description of changes:

Export tokens to C# class format, so that they are also usable in C#, and so that you can generate compilable code. This is intended to be usable in .NET MAUI.

  • Support for Color
  • Support for numbers / dimensions
  • Support for string
  • Support for token references
  • Support for grouping tokens in classes, and cross-referencing them
  • Support for effects like shadow

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@hansmbakker
Copy link
Author

@jorenbroekema

What I am struggling with, is

  • style dictionary flattens everything
  • how can I have groups of (color) tokens that are exported to different classes, that cross-reference each other?

The use case is this:
I want to have 3 classes of color tokens:

  • ColorTokens: color tokens.static.text-on-bg.standard.moderate references color aliases.neutral.800
  • ColorAliases: color aliases.neutral.800 references primitives.grey.800
  • ColorPrimitives: primitives.grey.800 resolves to #525252ff

* @typedef {import('../../../../types/File.d.ts').File} File
* @typedef {import('../../../../types/Config.d.ts').LocalOptions} LocalOptions
*/

Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks great!

@@ -157,5 +157,13 @@
"unist-util-visit": "^5.0.0",
"uuid": "^9.0.1",
"yaml": "^2.3.4"
},
"mocha": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah cool, then we can also remove these params in the scripts['test:node'] for brevity right?

@jorenbroekema
Copy link
Collaborator

It sounds like what you're looking for is something that is similar to outputReferences, this feature is theoretically implementable in any format but it's not super trivial to do it. I see that you're reusing createPropertyFormatter which has an implementation for outputReferences which is great, that definitely helps a lot, is there something that you feel is missing from that?

const file = setCSharpFileProperties({
accessModifier: 'public',
});
expect(file.accessModifier).to.equal('public ');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
expect(file.accessModifier).to.equal('public ');
expect(file.accessModifier).to.equal('public');

I think it's better to add the needed whitespace later in the format itself rather than doing it here. A few days ago I refactored all of the existing templates and also this file: https://github.com/amzn/style-dictionary/blob/v4/lib/common/formatHelpers/setSwiftFileProperties.js#L50 and then add the whitespacing here: https://github.com/amzn/style-dictionary/blob/v4/lib/common/templates/ios-swift/any.swift.template.js#L24

*/
export default function setCSharpFileProperties(options) {
if (typeof options.accessModifier === 'undefined') {
options.accessModifier = 'public ';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
options.accessModifier = 'public ';
options.accessModifier = 'public';

options.accessModifier = 'public ';
} else {
if (options.accessModifier !== '') {
options.accessModifier = `${options.accessModifier} `;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
options.accessModifier = `${options.accessModifier} `;
options.accessModifier = `${options.accessModifier}`;

@jorenbroekema
Copy link
Collaborator

I reviewed your PR thusfar and it looks great! let me know if there's anything I can help with, you can also reach me on Slack if you wanna have a call at some point to flesh out some of the details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants