React Fullcalendar v4 工具提示
React Fullcalendar v4 tooltip
Fullcalendar React 组件:
import FullCalendar from "@fullcalendar/react";
import timeGrid from "@fullcalendar/resource-timegrid";
import resourceDayGridPlugin from '@fullcalendar/resource-daygrid';
class FC extends React.Component {
calendarComponentRef = React.createRef();
constructor(props) {
super(props);
this.state = {
events:[{ "id": 1, "title": "event 1", "description":"some description"},......]
}
}
eventRender(info){
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
}
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
}
Tooltip.js 包含在 header
<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<script rc="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js">/script>
正是在 React 中尝试这个 demo,但它在 React 版本中不起作用。
但工具提示不起作用
Fullcalendar React 示例项目sample project react fullcalendar
工具提示使用 Tooltip.js
eventRender(info){
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
}
在组件中:
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
或
import ReactTooltip from 'react-tooltip'
和处理方法eventPosition
handleEventPositioned(info) {
info.el.setAttribute("data-tip","some text tip");
ReactTooltip.rebuild();
}
和
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventPositioned={this.handleEventPositioned}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
全日历 v5
与content injection hook e.g. for Material-ui tooltip:
eventContent: ( arg ) => {
return (
<Tooltip title={ <Typography color="inherit">Tooltip with HTML</Typography> } arrow>
{ renderInnerContent( arg ) }
</Tooltip>
);
}
如果您想要与默认内容完全相同的内容,请从 fullcalendar 源复制函数:
/**
* https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/common/src/common/StandardEvent.tsx#L79
*/
function renderInnerContent( innerProps ) {
return (
<div className='fc-event-main-frame'>
{ innerProps.timeText &&
<div className='fc-event-time'>{ innerProps.timeText }</div>
}
<div className='fc-event-title-container'>
<div className='fc-event-title fc-sticky'>
{ innerProps.event.title || <Fragment> </Fragment> }
</div>
</div>
</div>
);
}
要将 ListView
内容与默认内容区分开来,您可以使用此代码(给定 Calendar reference calendarRef):
eventContent: ( arg ) => {
const data = calendarRef.current.getApi().getCurrentData();
const viewSpec = data.viewSpecs[arg.view.type];
let innerContent;
if (viewSpec.component === ListView) {
/**
* https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/list/src/ListViewEventRow.tsx#L55
*/
innerContent = renderListInnerContent( arg );
} else {
innerContent = renderInnerContent( arg );
}
return ( <Tooltip ... >{ innerContent }</Tooltip>);
};
工具提示使用 tippy 和 eventMouseEnter
handleMouseEnter = (arg) =>{
tippy(arg.el, {
content: "my tooltip!"
});
}
在组件中
render() {
return (
<FullCalendar ref={this.calendarRef}
plugins={[dayGridPlugin, interactionPlugin]}
initialView="dayGridMonth"
weekends={true}
eventMouseEnter={this.handleMouseEnter}
/>
)
}
到目前为止我做得最好。这至少会给一个事件一个标题。
<FullCalendar eventDidMount={renderEventContent} .....
function renderEventContent(info) {
info.el.setAttribute('title', info.event.title)
}
Fullcalendar React 组件:
import FullCalendar from "@fullcalendar/react";
import timeGrid from "@fullcalendar/resource-timegrid";
import resourceDayGridPlugin from '@fullcalendar/resource-daygrid';
class FC extends React.Component {
calendarComponentRef = React.createRef();
constructor(props) {
super(props);
this.state = {
events:[{ "id": 1, "title": "event 1", "description":"some description"},......]
}
}
eventRender(info){
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
}
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
}
Tooltip.js 包含在 header
<script src="https://unpkg.com/popper.js/dist/umd/popper.min.js"></script>
<script rc="https://unpkg.com/tooltip.js/dist/umd/tooltip.min.js">/script>
正是在 React 中尝试这个 demo,但它在 React 版本中不起作用。
但工具提示不起作用
Fullcalendar React 示例项目sample project react fullcalendar
工具提示使用 Tooltip.js
eventRender(info){
var tooltip = new Tooltip(info.el, {
title: info.event.extendedProps.description,
placement: 'top',
trigger: 'hover',
container: 'body'
});
}
在组件中:
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventRender={this.eventRender}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
或
import ReactTooltip from 'react-tooltip'
和处理方法eventPosition
handleEventPositioned(info) {
info.el.setAttribute("data-tip","some text tip");
ReactTooltip.rebuild();
}
和
render() {
return <FullCalendar
events={this.state.getEvents}
defaultView="resourceTimeGridDay"
plugins={[timeGrid, interactionPlugin, resourceDayGridPlugin]}
eventPositioned={this.handleEventPositioned}
schedulerLicenseKey="GPL-My-Project-Is-Open-Source"
/>
}
全日历 v5
与content injection hook e.g. for Material-ui tooltip:
eventContent: ( arg ) => {
return (
<Tooltip title={ <Typography color="inherit">Tooltip with HTML</Typography> } arrow>
{ renderInnerContent( arg ) }
</Tooltip>
);
}
如果您想要与默认内容完全相同的内容,请从 fullcalendar 源复制函数:
/**
* https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/common/src/common/StandardEvent.tsx#L79
*/
function renderInnerContent( innerProps ) {
return (
<div className='fc-event-main-frame'>
{ innerProps.timeText &&
<div className='fc-event-time'>{ innerProps.timeText }</div>
}
<div className='fc-event-title-container'>
<div className='fc-event-title fc-sticky'>
{ innerProps.event.title || <Fragment> </Fragment> }
</div>
</div>
</div>
);
}
要将 ListView
内容与默认内容区分开来,您可以使用此代码(给定 Calendar reference calendarRef):
eventContent: ( arg ) => {
const data = calendarRef.current.getApi().getCurrentData();
const viewSpec = data.viewSpecs[arg.view.type];
let innerContent;
if (viewSpec.component === ListView) {
/**
* https://github.com/fullcalendar/fullcalendar/blob/495d925436e533db2fd591e09a0c887adca77053/packages/list/src/ListViewEventRow.tsx#L55
*/
innerContent = renderListInnerContent( arg );
} else {
innerContent = renderInnerContent( arg );
}
return ( <Tooltip ... >{ innerContent }</Tooltip>);
};
工具提示使用 tippy 和 eventMouseEnter
handleMouseEnter = (arg) =>{
tippy(arg.el, {
content: "my tooltip!"
});
}
在组件中
render() {
return (
<FullCalendar ref={this.calendarRef}
plugins={[dayGridPlugin, interactionPlugin]}
initialView="dayGridMonth"
weekends={true}
eventMouseEnter={this.handleMouseEnter}
/>
)
}
到目前为止我做得最好。这至少会给一个事件一个标题。
<FullCalendar eventDidMount={renderEventContent} .....
function renderEventContent(info) {
info.el.setAttribute('title', info.event.title)
}