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

Add internal theming support #536

Closed

Conversation

nick2432
Copy link

@nick2432 nick2432 commented Jan 26, 2024

Description

This pull request enhances the UiToolbar component by integrating theme tokens for background and text colors. Previously, the component used hardcoded colors, and now it dynamically fetches the appropriate color values from the theme tokens based on the component's properties, textColor. This modification ensures that the component adheres to theming conventions and allows for easier customization through theme tokens.

Related Issues

Closes #296

Addresses #PR# HERE

Screenshot

Screenshot from 2024-01-26 19-05-54
Screenshot from 2024-01-26 19-05-40

@MisRob MisRob self-requested a review January 26, 2024 18:53
@MisRob MisRob added the TODO: needs review Waiting for review label Jan 26, 2024
@MisRob MisRob self-assigned this Jan 30, 2024
@MisRob
Copy link
Member

MisRob commented Feb 2, 2024

Thanks @nick2432, this is heading in a good direction. I left some first pointers.

@@ -23,16 +21,16 @@
</div>
</slot>
</div>
</div>

<div class="ui-toolbar__body" :class="{ 'has-brand-divider': hasBrandDivider }">
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand how this change relates to the theming issue being resolved in this pull request, could you explain what's its motivation?

<slot>
<div v-if="title" class="ui-toolbar__title">
{{ title }}
</div>
</slot>
<slot name="navigation" class="ui-toolbar__nav"></slot>
Copy link
Member

Choose a reason for hiding this comment

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

Why is this slot removed?

@@ -66,7 +64,7 @@
},
textColor: {
type: String,
default: 'black', // 'black' or 'white'
default: 'default', // 'black' or 'white'
Copy link
Member

@MisRob MisRob Feb 2, 2024

Choose a reason for hiding this comment

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

There are still places in this component that expect textColor be either 'black' or 'white', for example progressColor function or it seems that even some Ui sub-components.

The most straightforward way to deal with it I can think of, while preserving the approach you've used, would be to keep

textColor: {
  type: String,
  default: 'black', // 'black' or 'white'
}

and then internally map 'black' to tokens.text and 'white' to tokens.textInverted when setting the text color (similarly to your getColor). This won't break other places that still expect these two strings.

return this.$themeTokens.surface;
} else {
const tokens = this.textColor.split('.');
return this.$themeTokens[tokens[1]] || '';
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what you intended to do here, can you explain?

Copy link
Author

Choose a reason for hiding this comment

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

This is for passing any of the theme tokens listed in the KDS documentation. For example, in the above-given screenshot, I used the themetoken.document token, and it worked.
Screenshot from 2024-01-26 19-05-54

Copy link
Member

@MisRob MisRob Feb 7, 2024

Choose a reason for hiding this comment

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

textColor="$themeTokens.document" means that you're passing string "$themeTokens.document" rather than variable $themeTokens.document that will evaluate into a color code.

If we were going to pass theme tokens via the textColor prop, then we'd want to accept them like :textColor="$themeTokens.document" which is a shortcut for v-bind that passes variables https://v2.vuejs.org/v2/guide/components-props#Passing-Static-or-Dynamic-Props. Then you wouldn't need

const tokens = this.textColor.
return this.$themeTokens[tokens[1]] || '';

However, looking at the approach you took overall, I'd recommend you accept only 'black' and 'white' strings as textColor (same as previously) but translated them into theme colors as explained here #536 (comment).

height: $ui-toolbar-height;
padding-left: rem(16px);
max-width: 100%;
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need changes of styles other than those related to theming

Copy link
Member

Choose a reason for hiding this comment

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

This is just one example. I'd recommend cleaning up other places as well. If you saw a bug that you wanted to implement an extra fix for, please always explain the motivation for changes.

@MisRob MisRob marked this pull request as draft February 2, 2024 13:28
@nick2432
Copy link
Author

nick2432 commented Feb 3, 2024

@MisRob , I accidentally made a lot of changes. I apologize for that.

@MisRob
Copy link
Member

MisRob commented Feb 7, 2024

No problem, @nick2432. Please (1) look at look at guidance here #536 (comment) and (2) clean up all changes that are not related to theming.

@MisRob
Copy link
Member

MisRob commented Feb 7, 2024

I marked this as draft since there's lots of work in progress and it seems we're figuring out a suitable approach. For your work, that doesn't change anything. Please mention me when you finished your updates and I will have a look again. Thank you!

@MisRob
Copy link
Member

MisRob commented Feb 14, 2024

Hi @nick2432, please note that the main branch is now renamed to `develop. You may need to update your local environment.

@MisRob
Copy link
Member

MisRob commented Feb 21, 2024

Hi @nick2432 I'm sorry but I will close this since meanwhile we needed to do some work around theming and will need to rethink our approach to this issue.

@MisRob MisRob closed this Feb 21, 2024
@MisRob
Copy link
Member

MisRob commented Feb 21, 2024

Thank you!

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

Successfully merging this pull request may close these issues.

Full theming support for toolbars
2 participants