作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
是否可以在选定的周或工具栏中显示行中的周数?
我尝试使用 ToolbarComponent,但它覆盖了所有 header 。但我想保持它相同,因为它只是添加有关选定星期的信息
class CustomElements extends PureComponent {
renderWrappedWeekDay = (date, selectedDate, dayInCurrentMonth) => {
const { classes } = this.props;
let dateClone = date.clone();
let selectedDateClone = selectedDate.clone();
const start = selectedDateClone.startOf("week").toDate();
const end = selectedDateClone.endOf("week").toDate();
const dayIsBetween = dateClone.isBetween(start, end, null, []);
const isFirstDay = dateClone.isSame(start, "day");
const isLastDay = dateClone.isSame(end, "day");
const wrapperClassName = clsx({
[classes.highlight]: dayIsBetween,
[classes.firstHighlight]: isFirstDay,
[classes.endHighlight]: isLastDay
});
const dayClassName = clsx(classes.day, {
[classes.nonCurrentMonthDay]: !dayInCurrentMonth,
[classes.highlightNonCurrentMonthDay]: !dayInCurrentMonth && dayIsBetween
});
return (
<div className={wrapperClassName}>
<IconButton className={dayClassName}>
<span>{dateClone.format("DD")} </span>
</IconButton>
</div>
);
};
render() {
const { selectedDate } = this.state;
return (
<DatePicker
label="Week picker"
value={selectedDate}
onChange={this.handleWeekChange}
renderDay={this.renderWrappedWeekDay}
labelFunc={this.formatWeekSelectLabel}
/>
);
}
}
最佳答案
这可能对你有帮助。
使用以下内容创建一个新组件“MyToolbar.js”:
import React from "react";
import { createStyles } from "@material-ui/styles";
import { withStyles, Toolbar, Button } from "@material-ui/core";
import moment from "moment";
export const styles = theme =>
createStyles({
toolbar: {
display: "flex",
flexDirection: "column",
alignItems: "flex-start",
justifyContent: "center",
height: 100,
backgroundColor:
theme.palette.type === "light"
? theme.palette.primary.main
: theme.palette.background.default
},
label: {
color:
theme.palette.type === "light"
? theme.palette.primary.contrastText
: theme.palette.background.default
}
});
const MyToolbar = ({ setOpenView, date }) => {
const today = moment(date);
var weeknumber = today.week();
var year = today.year();
var month = today.format("MMM");
const fromDate = today.startOf("week").date();
const toDate = today.endOf("week").date();
return (
<Toolbar className="MuiToolbar-root MuiToolbar-regular MuiPickersToolbar-toolbar MuiPickersDatePickerRoot-toolbar MuiToolbar-gutters">
<Button onClick={e => setOpenView("year")}>
<span className="MuiPickersToolbar-label">
<h6 className="MuiTypography-root MuiPickersToolbarText-toolbarTxt MuiTypography-subtitle1">
{year} Week {weeknumber}
</h6>
</span>
<span className="MuiTouchRipple-root" />
</Button>
<Button onClick={e => setOpenView("date")}>
<span className="MuiPickersToolbar-label">
<h4 className="MuiTypography-root MuiPickersToolbarText-toolbarTxt MuiPickersToolbarText-toolbarBtnSelected MuiTypography-h4 MuiTypography-alignCenter">
{month} {fromDate} to {toDate}
</h4>
</span>
<span className="MuiTouchRipple-root" />
</Button>
</Toolbar>
);
};
export default withStyles(styles, { name: "MuiPickersToolbar" })(MyToolbar);
在 weekPicker.js 中导入
import MyToolbar from "./MyToolbar";
并将其添加到您的 DatePicker
<DatePicker
label="Week picker"
value={selectedDate}
onChange={this.handleWeekChange}
renderDay={this.renderWrappedWeekDay}
labelFunc={this.formatWeekSelectLabel}
ToolbarComponent={MyToolbar}
/>
关于javascript - 是否可以显示所选周的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59841618/
我正在尝试用 Swift 编写这段 JavaScript 代码:k_combinations 到目前为止,我在 Swift 中有这个: import Foundation import Cocoa e
我是一名优秀的程序员,十分优秀!