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

Please allow styling of event colors with css variables by switching to ngStyle #845

Closed
RobertProvencal opened this issue Jan 7, 2019 · 8 comments
Labels

Comments

@RobertProvencal
Copy link

RobertProvencal commented Jan 7, 2019

Hi Matthew

Would it be possible to switch the css attribute used for styling an event color and border to use the angular notation? Doing this would allow an end-user to leverage css variables and make our css less hard coded.

For example within the calendar-week-view-event-component.ts, you will find
<div class="cal-event" [style.backgroundColor]="weekEvent.event.color?.secondary" [style.borderColor]="weekEvent.event.color?.primary" ....

Ideally, we would like to see:
<div class="cal-event" [ngStyle.backgroundColor]="weekEvent.event.color?.secondary" [ngStyle.borderColor]="weekEvent.event.color?.primary" ...

This would allow us to change our css file from say:

Blue: { primary: '#89CFF0', // --nw-color-spectrum-blue-light secondary: '#B3F0FE' // --nw-color-brand-1 }
to:

Blue: { primary: 'var(--nw-color-spectrum-blue-light)', secondary: 'var(--nw-color-brand-1)' }
Does that make sense? Please let me know if you need additional info.

Thanks,
Robert.

Minimal reproduction of the problem with instructions

Versions

  • angular-calendar:
  • Browser name and version: Chrome v71
@mattlewis92 mattlewis92 added the bug label Feb 3, 2019
@mattlewis92
Copy link
Owner

Hey, apologies for the late reply, I tried to do [ngStyle.backgroundColor]="weekEvent.event.color?.secondary" but it doesn't seem to work. I checked and it doesn't seem like angular has any support for CSS variables: angular/angular#9343 I'd love to support them though, if you know of a way that we could support them easily?

@no-response
Copy link

no-response bot commented Mar 24, 2019

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

@no-response no-response bot closed this as completed Mar 24, 2019
@gtoroptsev
Copy link

Hey, apologies for the late reply, I tried to do [ngStyle.backgroundColor]="weekEvent.event.color?.secondary" but it doesn't seem to work. I checked and it doesn't seem like angular has any support for CSS variables: angular/angular#9343 I'd love to support them though, if you know of a way that we could support them easily?

Hi Matthew,
Please try this code, it allows to set background color without angular sanitize console error

[ngStyle]="{'background': weekEvent.event.color?.secondary}"

@mattlewis92
Copy link
Owner

It doesn't work for me: https://stackblitz.com/edit/angular-fzjdae?file=demo/template.html Can you show me an example of it working?

@gtoroptsev
Copy link

gtoroptsev commented Mar 30, 2019

It doesn't work for me: https://stackblitz.com/edit/angular-fzjdae?file=demo/template.html Can you show me an example of it working?

https://stackblitz.com/edit/angular-fzjdae-xrmgys?file=demo%2Ftemplate.html

at first we define css variables in styles.css

:host { --blue-primary: #1e90ff; --blue-secondary: #D1E8FF; }

then assign them to colors object (wrapped in var())

const colors: any = { blue: { primary: 'var(--blue-primary)', secondary: 'var(--blue-secondary)' } };

and last step is to assign colors obj properties to our dom element

[ngStyle]="{ 'color': colors.blue.primary, 'background-color': colors.blue.secondary }">

I think it will be useful in projects with multiple themes - just save css variables of calendar event objects
or in case if designer apply color palette updates we don't need to apply db migrations etc.

@mattlewis92
Copy link
Owner

Ahhh, I see what I was doing wrong now, I missed off the var() surrounding the variable name, ok this should be doable!

@mattlewis92
Copy link
Owner

Fixed in 0.27.2 🎉

@gtoroptsev
Copy link

Fixed in 0.27.2 🎉

thank you, it works now!

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

No branches or pull requests

3 participants