Skip to content

adding a props for changing the color of the months and days labels #25

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrBigoudi
Copy link

I've added a prop to let the user choose the color of the labels for the months and the days. I've done so because when I had to use this module on a really dark background image I couldn't properly read the labels which were too dark.
I've also modified the demo and the docs to handle the changes.

@razorness
Copy link
Owner

Hi @MrBigoudi. Thanks for your PR. I have a question: Is there any reason why this is more convenient than just using CSS?

@MrBigoudi
Copy link
Author

MrBigoudi commented May 9, 2023

Hi, thanks for your answer. I did these changes because I ran into an issue when I tried to use the module with tailwind while encapsulating a CalendarHeatmap inside a div. It might have been from my side but when adding a 'className="text-white"' in the div declaration, the labels weren't changing and, since I wanted to stick with tailwind only, I've tried messing with your code. This PR is pretty much a generalization of what I've done to fix my issue.

My example was the following:

<template>
    <div className="text-white">
        <CalendarHeatmap :tooltip="false" :values="heatmapData" :end-date="heatmapEndDate" :range-color="heatmapColors" :max="heatmapMaxCount"/>
  </div>
</template>

<script>
    import { CalendarHeatmap } from 'vue3-calendar-heatmap';
    import { fetchHeatmapData } from './github.js'

    export default {
        name: 'GitHubHeatmap',
        components: {
            CalendarHeatmap
        },
        data() {
            return {
                heatmapData: [],
                heatmapEndDate: "",
                heatmapColors: ['#FFFFFF', '#C4C4C4', '#9f7b7a', '#bb7672', '#d47067', '#eb6a59', '#ff6347'],
                heatmapMaxCount: 6,
                username: "mrbigoudi",
            };
        },
        methods: {
            getNow: function() {
                const today = new Date();
                this.heatmapEndDate= today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();
            }
        },

        created(){
            this.getNow();
        },

        async mounted(){
            this.heatmapData = await fetchHeatmapData(this.username);
        }

    };
</script>

@razorness
Copy link
Owner

Okay ... let's say we stick with CSS to keep Javascript execution as flat as possible. On the other hand, the use of style is always quite nasty because of its high priority. We can use the special value currentColor.

Let's change

to

fill: currentColor;

Then, we can add

color: #767676;

as default to this block

.vch__container {
.vch__legend {
display: flex;
justify-content: space-between;
align-items: center;
}
.vch__external-legend-wrapper {
margin: 0 8px;
}
}

so the rule block looks like this

	.vch__container { 
		color: #767676;		

 		.vch__legend { 
 			display: flex; 
 			justify-content: space-between; 
 			align-items: center; 
 		} 
  
 		.vch__external-legend-wrapper { 
 			margin: 0 8px; 
 		} 
 	} 

Now, it should be possible to change the color of labels with a single CSS rule at the root element of this component:

<CalendarHeatmap class="text-white" .../>

Bonus: change problably won't break anyones styling by the usage of style attribute and it's easier to customize the overall look.

You wanna try this out?

@MrBigoudi
Copy link
Author

Sure, that looks like a great compromise, I'll try it when I can !

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.

2 participants