question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

change background-color event by events array

See original GitHub issue

Hello Guys

I have in my array the prop color of user, where I would like to change the background color of the event to rgb defined, how to do this by sending the array?

I have not yet created the events api, but the color stays in this.getUsers ()

import React, { Component } from 'react';
import { connect } from 'react-redux';
import {
  RctCollapsibleCard, Title, IntlMessages, AppConfig,
  Row, Col, CheckboxList
} from './../../components/custom';
import {
  getUsersAPI
} from './../../actions';
import BigCalendar from 'react-big-calendar';
import moment from 'moment';
import { array } from 'prop-types';

BigCalendar.setLocalizer(BigCalendar.momentLocalizer(moment))

let MyOtherNestedComponent = () => <div>NESTED COMPONENT</div>

let MyCustomHeader = ({ label }) => (
  <div>
    CUSTOM HEADER:
    <div>{label}</div>
    <MyOtherNestedComponent />
  </div>
)

class ScheduleComponent extends Component {
  constructor(props, context) {
    super(props, context);
    //I have not yet created the events api, but the color stays in this.getUsers ()
    this.events = [
      {
        'title': 'All Day Event very long title',
        'allDay': true,
        'start': new Date(2015, 3, 0),
        'end': new Date(2015, 3, 1)
      },
      {
        'title': 'Long Event',
        'start': new Date(2015, 3, 7),
        'end': new Date(2015, 3, 10)
      },

      {
        'title': 'DTS STARTS',
        'start': new Date(2016, 2, 13, 0, 0, 0),
        'end': new Date(2016, 2, 20, 0, 0, 0)
      },

      {
        'title': 'DTS ENDS',
        'start': new Date(2016, 10, 6, 0, 0, 0),
        'end': new Date(2016, 10, 13, 0, 0, 0)
      },

      {
        'title': 'Some Event',
        'start': new Date(2015, 3, 9, 0, 0, 0),
        'end': new Date(2015, 3, 9, 0, 0, 0)
      },
      {
        'title': 'Conference',
        'start': new Date(2015, 3, 11),
        'end': new Date(2015, 3, 13),
        desc: 'Big conference for important people'
      },
      {
        'title': 'Meeting',
        'start': new Date(2015, 3, 12, 10, 30, 0, 0),
        'end': new Date(2015, 3, 12, 12, 30, 0, 0),
        desc: 'Pre-meeting meeting, to prepare for the meeting'
      },
      {
        'title': 'Lunch',
        'start': new Date(2015, 3, 12, 12, 0, 0, 0),
        'end': new Date(2015, 3, 12, 13, 0, 0, 0),
        desc: 'Power lunch'
      },
      {
        'title': 'Meeting',
        'start': new Date(2015, 3, 12, 14, 0, 0, 0),
        'end': new Date(2015, 3, 12, 15, 0, 0, 0)
      },
      {
        'title': 'Happy Hour',
        'start': new Date(2015, 3, 12, 17, 0, 0, 0),
        'end': new Date(2015, 3, 12, 17, 30, 0, 0),
        desc: 'Most important meal of the day'
      },
      {
        'title': 'Dinner',
        'start': new Date(2015, 3, 12, 20, 0, 0, 0),
        'end': new Date(2015, 3, 12, 21, 0, 0, 0)
      },
      {
        'title': 'Birthday Party',
        'start': new Date(2015, 3, 13, 7, 0, 0),
        'end': new Date(2015, 3, 13, 10, 30, 0)
      },
      {
        'title': 'Birthday Party 2',
        'start': new Date(2015, 3, 13, 7, 0, 0),
        'end': new Date(2015, 3, 13, 10, 30, 0)
      },
      {
        'title': 'Birthday Party 3',
        'start': new Date(2015, 3, 13, 7, 0, 0),
        'end': new Date(2015, 3, 13, 10, 30, 0)
      },
      {
        'title': 'Late Night Event',
        'start': new Date(2015, 3, 17, 19, 30, 0),
        'end': new Date(2015, 3, 18, 2, 0, 0)
      },
      {
        'title': 'Multi-day Event',
        'start': new Date(2015, 3, 20, 19, 30, 0),
        'end': new Date(2015, 3, 22, 2, 0, 0)
      }
    ];

    this.state = {
      listUsers: []
    };
  }

  componentWillMount() {

    this.props.getUsersAPI()

  }

  componentWillReceiveProps(nextProps) {
    let newArr = [];

    nextProps.users.map((array, i) => {

      let status = nextProps.user.id == array.id ? true : false;

      newArr.push({
        id: array.id,
        description: array.name,
        status: status,
        color: array.color
      });
    });

    this.setState({
      listUsers: newArr
    });
  }

  updateListStatus(users){
    this.setState({
      listUsers: users
    });
  }

  render() {
    return (
        <div>
          <Title title={<IntlMessages id="sidebar.schedule" />} match={this.props.match} />
            <RctCollapsibleCard>
            <Col sm={12}>
              <Row>
                <Col sm={9}>
                  <BigCalendar
                    selectable
                  
                    events={this.events}
                    defaultView="week"
                    culture={AppConfig.locale.languageId}
                    scrollToTime={new Date(1970, 1, 1, 6)}
                    defaultDate={new Date(2015, 3, 12)}
                    onSelectEvent={event => alert(event.title)}
                    onSelectSlot={slotInfo =>
                      alert(
                        `selected slot: \n\nstart ${slotInfo.start.toLocaleString()} ` +
                        `\nend: ${slotInfo.end.toLocaleString()}` +
                        `\naction: ${slotInfo.action}`
                      )
                    }
                    
                  />
                </Col>
                <Col sm={3}>
                  <CheckboxList 
                    items={this.state.listUsers}
                    onUpdateList={this.updateListStatus.bind(this)}
                  />
                </Col>
              </Row>
            </Col>
                    
          </RctCollapsibleCard>
        </div>
      );
   
  }
}

// map state to props
const mapStateToProps = ({ userAPI, authUser }) => {

  const { user } = authUser;
  const { users } = userAPI;

  return { users, user };
}

export default connect(mapStateToProps, {
  getUsersAPI
})(ScheduleComponent);

image

Does anyone know how I can do this?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
Deboracgscommented, Aug 18, 2018

eventPropGetter={event => { const user = this.state.listUsers.find(user => user.id === event.user_id); const backgroundColor = user ? user.color : "#fff"; return { style: { backgroundColor } }; }

this is a solution

0reactions
cutterblcommented, Mar 31, 2022

@Vetrivel-VP Take a look at the dayPropGetter documentation

Read more comments on GitHub >

github_iconTop Results From Across the Web

swift3 - How to change background color of events array in ...
I'm having an 2arrays of dates and want to set different colors for particular event please help how to do ...
Read more >
How to change the background color after clicking the button ...
Approach 1: This approach uses JavaScript to change the background color after clicking the button. Use HTML DOM Style backgroundColor Property ...
Read more >
JavaScript For Loop Click Event ← Issues & Solutions Explained
hello. Can you explain how to code for a single button that changes the background color value with every click using an array?...
Read more >
HTML DOM Style backgroundColor Property - W3Schools
The backgroundColor property sets or returns the background color of an element. See Also: HTML Styles: The background Property. CSS Tutorial: CSS Backgrounds....
Read more >
Change Background Color Automatically JavaScript - YouTube
Change Background Color Automatically JavaScriptTo change website color automatically in javascript, all you need is to make an array of ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found