How to change all react-big-calendar to French? - reactjs

I try to add culture='fr' on the BigCalendar but, I get an error.
My code is:
import moment from "moment";
BigCalendar.momentLocalizer(moment);
export default class Agenda extends Component {
constructor(props){
super(props);
this.state = {
events: [
{
title: 'Calendar 1',
start: new Date(2019, 2, 19, 15, 0, 0), //03:00 PM
end: new Date(2019, 2, 19, 16, 30, 0), //04:30 PM
},
{
title: 'Calendar 2 ',
start: new Date(2019, 2, 20, 12, 30, 0), //08:30 AM
end: new Date(2019, 2, 20, 18, 0, 0), //18:00 PM
},
{
title: 'Calendar 3 ',
start: new Date(2019, 2, 22, 10, 30, 0), //10:30 AM
end: new Date(2019, 2, 22, 19, 0, 0), //07:00 PM
},
{
title: 'Calendar 4 ',
start: new Date(2019, 2, 23, 7, 30, 0), //08:30 AM
end: new Date(2019, 2, 23, 11, 0, 0), //11:00 AM
},
],
}
render() {
return (
<div>
<BigCalendar
selectable
events={this.state.events}
defaultDate={new Date(2019, 2, 19)}
defaultView="week"
culture = 'fr'
style={{ height: "100vh" }}
/>
</div>
)
}
};
When I run it, I get :
How can I fix that ?

I resolve that by adding import 'moment/locale/fr'; on my component.

You could do it this way, I highly recommend you use the "moment" library
It makes things much easier in terms of dates apart you can translate to the language of your choice
import React, { Fragment, useState } from 'react'
import { Calendar, momentLocalizer } from 'react-big-calendar'
import "react-big-calendar/lib/css/react-big-calendar.css";
import moment from "moment";
require('moment/locale/es.js')
const localizer = momentLocalizer(moment);
function Citas() {
const [Events, setEvents] = useState([
{
start: moment().toDate(),
end: moment()
.add(1, "days")
.toDate(),
title: "Some title"
}
]);
return (
<Fragment>
<div className="font-weight-bold mb-2 px-3 shadow-sm p-2 bg-light">CITAS </div>
<div className="px-3">mas datos sobre citas
<Calendar
localizer={localizer}
defaultDate={new Date()}
defaultView="month"
events={Events}
style={{ height: "100vh" }}
messages={{
next: "sig",
previous: "ant",
today: "Hoy",
month: "Mes",
week: "Semana",
day: "Día"
}}
/>
</div>
</Fragment>
)
}
export default Citas

The error that you posted is likely because you didn't pass localizer as props to the BigCalendar. To fix that, you can try assigning a variable
const localizer = BigCalendar.momentLocalizer(moment);
and then pass it as a prop
<BigCalendar
localizer={localizer}
...
/>
Hope it helps!
reference: http://intljusticemission.github.io/react-big-calendar/examples/index.html#intro

This works for me in Spanish using react-big-calendar.
import { Calendar, momentLocalizer } from "react-big-calendar"
import moment from "moment"
import 'moment/locale/es';
//...
const localizer = momentLocalizer(moment)
//...
<DragAndDropCalendar localizer={localizer} /*otherprops*/ />

you need provide the culture props :
import { Calendar, dateFnsLocalizer } from "react-big-calendar";
import format from "date-fns/format";
import parse from "date-fns/parse";
import startOfWeek from "date-fns/startOfWeek";
import getDay from "date-fns/getDay";
import fr from "date-fns/locale/fr";
const messages = {
allDay: "Tous les jours",
previous: "Précédent",
next: "Suivant",
today: "Aujourd'hui",
month: "Mois",
week: "Semaine",
day: "Jour",
agenda: "Agenda",
date: "Date",
time: "Heure",
event: "Evenement",
};
const locales = {
fr: fr,
};
const localizer = dateFnsLocalizer({
format,
parse,
startOfWeek,
getDay,
locales,
});
..........
<Calendar
localizer={localizer}
culture="fr"

Related

How do you re-render multiple React components inside of one parent React component in one go?

I want to be able to shuffle these tickets when I click a project option in the drop down. I didn't figure it would work but I tried writing three separate useState functions for each ticket type array. I know the shuffleTickets method is being called correctly, just not doing what I want. Are you able to pass in multiple parameters for a useState function?
import React from "react";
import { useState } from "react";
import styles from "./Tickets.module.css";
import TicketTable from "./TicketTable";
import Modal from "./Modal";
const Tickets = () => {
const notStartedTickets = [
{ id: 1, assignee: "trevor strnad", time: "1h" },
{ id: 9, assignee: "trevor strnad", time: "1h" },
{ id: 10, assignee: "n8 feet under ", time: "1h" },
];
const inProgressTickets = [
{ id: 11, assignee: "n8 feet under ", time: "1h" },
{ id: 12, assignee: "ryan knight", time: "1h" },
{ id: 15, assignee: "trevor strnad", time: "1h" },
];
const completedTickets = [
{ id: 16, assignee: "n8 feet under ", time: "1h" },
{ id: 17, assignee: "ryan knight", time: "1h" },
{ id: 18, assignee: "trevor strnad", time: "1h" },
];
const [shuffledNewTickets, setShuffledNewTickets] = useState(notStartedTickets);
const [shuffledStartedTickets, setShuffledStartedTickets] = useState(inProgressTickets);
const [shuffledDoneTickets, setShuffledDoneTickets] = useState(completedTickets);
const shuffleTickets = () => {
setShuffledNewTickets(notStartedTickets.sort((a, b) => Math.random() - 0.5));
setShuffledStartedTickets(inProgressTickets.sort((a, b) => Math.random() - 0.5));
setShuffledDoneTickets(completedTickets.sort((a, b) => Math.random() - 0.5));
}
return (
<>
<div className={styles.create}>
<select className={styles.projects}>
<option value="project 1" onClick={shuffleTickets}>Project 1</option>
<option value="project 2" onClick={shuffleTickets}>Project 2</option>
<option value="project 3" onClick={shuffleTickets}>Project 3</option>
<option value="project 4" onClick={shuffleTickets}>Project 4</option>
</select>
<button onClick={toggleNewTicketModal} className={styles.button}>
create ticket
</button>
</div>
<div className={styles.tickets}>
{editTicketModal ?
<Modal onToggleModal={toggleEditTicketModal} onCreateTicket={createTicket} title={'edit ticket'}/>
: createTicketModal ?
<Modal onToggleModal={toggleNewTicketModal} onCreateTicket={createTicket} title={'new ticket'} />
: null
}
{/* {modal && (
<Modal onToggleModal={toggleModal} onCreateTicket={createTicket} title={title}/>
)} */}
<TicketTable
color={"red"}
header={"not started"}
tickets={shuffledNewTickets}
onToggleModal={toggleEditTicketModal}
/>
<TicketTable
color={"blue"}
header={"in progress"}
tickets={shuffledStartedTickets}
onToggleModal={toggleEditTicketModal}
/>
<TicketTable
color={"green"}
header={"completed"}
tickets={shuffledDoneTickets}
onToggleModal={toggleEditTicketModal}
/>
</div>
</>
);
};
export default Tickets;

I want to change the position and style of the label in the React chart

I am using react-chartjs-2. I want to display the position of the label below the graph. Also, the shape of the label is currently square, but I would like to change it to a round shape. I specified option and position: bottom, but the position of the label did not change.
import "./styles.css";
import React from "react";
import { Bar } from "react-chartjs-2";
const data = [
{
label: "a",
data: [56, 23, 55, 56, 57]
},
{
label: "b",
data: [22, 17, 32, 47, 62]
},
{
label: "c",
data: [46, 73, 25, 76, 27]
}
];
const App = () => {
const CHART_COLORS = ["#e35b2c", "#e77235", "#eb8a40"];
const list = data.map((d, index) => {
return {
label: d.label,
backgroundColor: CHART_COLORS[index],
data: d.data,
stack: 1
};
});
const options = {
legend: {
position: "bottom"
}
};
return (
<>
<div className="App">
<Bar
data={{
labels: ["block1", "block2", "block3"],
datasets: list
}}
width={100}
height={50}
options={options}
/>
</div>
</>
);
};
export default App;
Legend option is changed in latest version of chartjs to,
Namespace: options.plugins.legend
plugins: {
legend: {
position: "bottom",
labels: {
usePointStyle: true //for style circle
}
}
}
};
You can check working demo here, https://codesandbox.io/s/react-chartjs-legend-option-prbgb
Reference : https://www.chartjs.org/docs/latest/configuration/legend.html

Error in rendering a React highcharts x-range chart

I am trying to re-create the highcharts x-range demo chart (https://www.highcharts.com/demo/x-range) using the official React wrapper and I'm getting a "ReferenceError: Highcharts is not defined" error. I'm new to both react and highcharts so not sure what I'm missing here
here's the code:
import React, { useState } from 'react';
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
const AccountContractHistory = (props) => {
const [chartOptions, setChartOptions] = useState({
chart: {
type: 'xrange'
},
title: {
text: 'Highcharts X-range'
},
xAxis: {
type: 'datetime'
},
yAxis: {
title: {
text: ''
},
categories: ['Prototyping', 'Development', 'Testing'],
reversed: true
},
series: [{
name: 'Project 1',
// pointPadding: 0,
// groupPadding: 0,
borderColor: 'gray',
pointWidth: 20,
data: [{
x: Date.UTC(2014, 10, 21),
x2: Date.UTC(2014, 11, 2),
y: 0,
partialFill: 0.25
}, {
x: Date.UTC(2014, 11, 2),
x2: Date.UTC(2014, 11, 5),
y: 1
}, {
x: Date.UTC(2014, 11, 8),
x2: Date.UTC(2014, 11, 9),
y: 2
}, {
x: Date.UTC(2014, 11, 9),
x2: Date.UTC(2014, 11, 19),
y: 1
}, {
x: Date.UTC(2014, 11, 10),
x2: Date.UTC(2014, 11, 23),
y: 2
}],
dataLabels: {
enabled: true
}
}],
});
return (
<div>
<HighchartsReact
highcharts={Highcharts}
options={chartOptions}
/>
</div>
)
};
export default AccountContractHistory;
Would appreciate any help in figuring out what I'm doing wrong
Thanks
You can find a demo of this chart in React here:
https://stackblitz.com/edit/react-highcharts-xrange-demo
You have to remember to properly load highcharts modules:
https://github.com/highcharts/highcharts-react#how-to-add-a-module
Seeing same error but (using Typescript) for my fix i needed to pass in Highcharts to the xrange like so:
import Highcharts from 'highcharts';
import HighchartsReact from 'highcharts-react-official';
import xrange from 'highcharts/modules/xrange';
xrange(Highcharts);
and then the markup:
<HighchartsReact
highcharts={Highcharts}
options={options}
{...this.props}
/>

React bizchart add axis name

Im using my react project for biz-chart , i have some conflict on the adding X and Y axis to name, anyone know how to added this correctly ?
here the image description
live sample code here
Thanks
code here
import React from "react";
import {
G2,
Chart,
Geom,
Axis,
Tooltip,
Coord,
Label,
Legend,
View,
Guide,
Shape,
Facet,
Util
} from "bizcharts#3.5.8";
import DataSet from "#antv/data-set";
class Groupedcolumn extends React.Component {
render() {
const data = [
{
name: "London",
"Jan.": 18.9,
"Feb.": 28.8,
"Mar.": 39.3,
"Apr.": 81.4,
May: 47,
"Jun.": 20.3,
"Jul.": 24,
"Aug.": 35.6
},
{
name: "Berlin",
"Jan.": 12.4,
"Feb.": 23.2,
"Mar.": 34.5,
"Apr.": 99.7,
May: 52.6,
"Jun.": 35.5,
"Jul.": 37.4,
"Aug.": 42.4
}
];
const ds = new DataSet();
const dv = ds.createView().source(data);
dv.transform({
type: "fold",
fields: ["Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug."],
// 展开字段集
key: "月份",
// key字段
value: "月均降雨量" // value字段
});
return (
<div>
<Chart height={400} data={dv} forceFit>
<Axis name="月份" />
<Axis name="月均降雨量" />
<Legend />
<Tooltip
crosshairs={{
type: "y"
}}
/>
<Geom
type="interval"
position="月份*月均降雨量"
color={"name"}
adjust={[
{
type: "dodge",
marginRatio: 1 / 32
}
]}
/>
</Chart>
</div>
);
}
}
Can add a title to the Axis component
title={{
autoRotate: true, // 是否需要自动旋转,默认为 true
offset: 40, // 设置标题 title 距离坐标轴线的距离
textStyle: {
fontSize: '12',
textAlign: 'center',
fill: '#999',
fontWeight: 'bold',
},
position: 'center', // 标题的位置,**新增**
}}

How to show Modal when we click on it using reactjs?

I'm new to react and wanted to create a Calendar and wanted to add event to the respective date in the Calendar, when we click on the field it should show the modal popup but modal is not getting displayed. Here i'm using only semantic-ui-react for designing the every component. Can anyone help me to resolve this issue?
first Component:
import React, { Component } from "react";
import { render } from "react-dom";
import { Calendar, momentLocalizer } from "react-big-calendar";
import moment from "moment";
import "react-big-calendar/lib/css/react-big-calendar.css";
import CreateEvent from "./CreteEvent";
const localizer = momentLocalizer(moment);
class ShowCalendar extends Component {
constructor() {
super();
const now = new Date();
const events = [
{
id: 0,
title: "All Day Event very long title",
allDay: true,
start: new Date(2015, 3, 0),
end: new Date(2015, 3, 1)
},
{
id: 1,
title: "Long Event",
start: new Date(2015, 3, 7),
end: new Date(2015, 3, 10)
},
{
id: 2,
title: "DTS STARTS",
start: new Date(2016, 2, 13, 0, 0, 0),
end: new Date(2016, 2, 20, 0, 0, 0)
},
{
id: 3,
title: "DTS ENDS",
start: new Date(2016, 10, 6, 0, 0, 0),
end: new Date(2016, 10, 13, 0, 0, 0)
},
{
id: 4,
title: "Some Event",
start: new Date(2015, 3, 9, 0, 0, 0),
end: new Date(2015, 3, 10, 0, 0, 0)
},
{
id: 5,
title: "Conference",
start: new Date(2015, 3, 11),
end: new Date(2015, 3, 13),
desc: "Big conference for important people"
},
{
id: 6,
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"
},
{
id: 7,
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"
},
{
id: 8,
title: "Meeting",
start: new Date(2015, 3, 12, 14, 0, 0, 0),
end: new Date(2015, 3, 12, 15, 0, 0, 0)
},
{
id: 9,
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"
},
{
id: 10,
title: "Dinner",
start: new Date(2015, 3, 12, 20, 0, 0, 0),
end: new Date(2015, 3, 12, 21, 0, 0, 0)
},
{
id: 11,
title: "Birthday Party",
start: new Date(2015, 3, 13, 7, 0, 0),
end: new Date(2015, 3, 13, 10, 30, 0)
},
{
id: 12,
title: "Late Night Event",
start: new Date(2015, 3, 17, 19, 30, 0),
end: new Date(2015, 3, 18, 2, 0, 0)
},
{
id: 12.5,
title: "Late Same Night Event",
start: new Date(2015, 3, 17, 19, 30, 0),
end: new Date(2015, 3, 17, 23, 30, 0)
},
{
id: 13,
title: "Multi-day Event",
start: new Date(2015, 3, 20, 19, 30, 0),
end: new Date(2015, 3, 22, 2, 0, 0)
},
{
id: 14,
title: "Today",
start: new Date(new Date().setHours(new Date().getHours() - 3)),
end: new Date(new Date().setHours(new Date().getHours() + 3))
},
{
id: 15,
title: "Point in Time Event",
start: now,
end: now
}
];
this.state = {
name: "React",
showModal: false,
events
};
this.openModal = this.openModal.bind(this);
this.handleCloseModal = this.handleCloseModal.bind(this);
}
handleCloseModal() {
this.setState({ showModal: false });
}
openModal() {
this.setState({ showModal: true });
}
render() {
return (
<div>
<div style={{ height: "500pt" }}>
<Calendar
events={this.state.events}
startAccessor="start"
endAccessor="end"
defaultDate={moment().toDate()}
localizer={localizer}
onDrillDown={this.openModal}
/>
</div>
{this.state.showModal ? (
<CreateEvent
isOpen={this.state.showModal}
onClose={this.handleCloseModal}
/>
) : (
""
)}
</div>
);
}
}
export default ShowCalendar;
2nd Component: Modal.jsx
import React, { Component } from "react";
import { Modal, Button, Header, Icon } from "semantic-ui-react";
export default class CreteEvent extends Component {
render() {
return (
<div>
<Modal isOpen={this.props.isOpen}>
<Modal.Header>Create Event</Modal.Header>
<Modal.Content>
<Modal.Description>Hi Everyone</Modal.Description>
</Modal.Content>
<Modal.Actions>
<Button primary onClick={this.props.onClose}>
Close <Icon name="right chevron" />
</Button>
</Modal.Actions>
</Modal>
</div>
);
}
}
Here is the entire code "Code: "https://codesandbox.io/s/strange-bhaskara-1n1jc""
So I have got in to the office and could have look, you never include the semantic UI css: https://react.semantic-ui.com/usage/#theme
In index.js https://react.semantic-ui.com/usage/#theme and add semantic-ui-css as a dependency, and as #PompolutZ mentioned the modal needs open vs isOpen
There is probably some other issues, but changing the default state to true now shows the modal - might just need to fix up how the modal gets displayed, i.e. when does openModal get called. (Ah clicking the date is the driver (never used the calendar component before: had to look at the docs)
https://codesandbox.io/s/morning-darkness-hz06m?fontsize=14&hidenavigation=1&theme=dark
Add dependency to semantic-ui-css
Import css in your main index.js file:
import 'semantic-ui-css/semantic.min.css';
You need to change isOpen to just open in Modal:
import React, { Component } from "react";
import { Modal, Button, Header, Icon } from "semantic-ui-react";
export default class CreteEvent extends Component {
render() {
return (
<div>
<Modal open={this.props.isOpen}>
<Modal.Header>Create Event</Modal.Header>
<Modal.Content>
<Modal.Description>Hi Everyone</Modal.Description>
</Modal.Content>
<Modal.Actions>
<Button primary onClick={this.props.onClose}>
Close <Icon name="right chevron" />
</Button>
</Modal.Actions>
</Modal>
</div>
);
}
}
Here is fixed codesandbox: https://codesandbox.io/s/sad-lamport-y6jqg (with aforementioned import)

Resources