|
| 1 | +import { |
| 2 | + Component, |
| 3 | + DayOfWeek, |
| 4 | + QCalendarWidget, |
| 5 | + QCalendarWidgetSignals, |
| 6 | + QFont, |
| 7 | +} from "@nodegui/nodegui"; |
| 8 | +import { |
| 9 | + HorizontalHeaderFormat, |
| 10 | + SelectionMode, |
| 11 | + VerticalHeaderFormat, |
| 12 | +} from "@nodegui/nodegui/dist/lib/QtWidgets/QCalendarWidget"; |
| 13 | +import { throwUnsupported } from "../../utils/helpers"; |
| 14 | +import { RNComponent } from "../config"; |
| 15 | +import { setViewProps, ViewProps } from "../View/RNView"; |
| 16 | + |
| 17 | +export interface CalendarProps extends ViewProps<QCalendarWidgetSignals> { |
| 18 | + /** |
| 19 | + * Sets the time an inactive date edit is shown before its contents are accepted. [QCalendarWidget: setDateEditAcceptDelay](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setdateeditacceptdelay) |
| 20 | + */ |
| 21 | + dateEditAcceptDelay?: number; |
| 22 | + /** |
| 23 | + * Sets whether the date edit popup is enabled. [QCalendarWidget: setDateEditEnabled](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setdateeditenabled) |
| 24 | + */ |
| 25 | + dateEditEnabled?: boolean; |
| 26 | + /** |
| 27 | + * Sets a value identifying the day displayed in the first column. [QCalendarWidget: setFirstDayOfWeek](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setfirstdayofweek) |
| 28 | + */ |
| 29 | + firstDayOfWeek?: DayOfWeek; |
| 30 | + /** |
| 31 | + * Sets a font for the action. [QCalendarWidget: setFont](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setfont) |
| 32 | + */ |
| 33 | + font?: QFont; |
| 34 | + /** |
| 35 | + * Sets whether the table grid is displayed. [QCalendarWidget: setGridVisible](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setgridvisible) |
| 36 | + */ |
| 37 | + gridVisible?: boolean; |
| 38 | + /** |
| 39 | + * Sets the format of the horizontal header. [QCalendarWidget: setHorizontalHeaderFormat](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#sethorizontalheaderformat) |
| 40 | + */ |
| 41 | + horizontalHeaderFormat?: HorizontalHeaderFormat; |
| 42 | + /** |
| 43 | + * Sets whether the navigation bar is shown or not. [QCalendarWidget: setNavigationBarVisible](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setnavigationbarvisible) |
| 44 | + */ |
| 45 | + navigationBarVisible?: boolean; |
| 46 | + /** |
| 47 | + * Sets the type of selection the user can make in the calendar. [QCalendarWidget: setSelectionMode](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setselectionmode) |
| 48 | + */ |
| 49 | + selectionMode?: SelectionMode; |
| 50 | + /** |
| 51 | + * Sets the format of the vertical header. [QCalendarWidget: setVerticalHeaderFormat](https://docs.nodegui.org/docs/api/generated/classes/qcalendarwidget#setverticalheaderformat) |
| 52 | + */ |
| 53 | + verticalHeaderFormat?: VerticalHeaderFormat; |
| 54 | +} |
| 55 | + |
| 56 | +const setCalendarProps = ( |
| 57 | + widget: RNCalendar, |
| 58 | + newProps: CalendarProps, |
| 59 | + oldProps: CalendarProps |
| 60 | +) => { |
| 61 | + const setter: CalendarProps = { |
| 62 | + set dateEditAcceptDelay(delay: number) { |
| 63 | + widget.setDateEditAcceptDelay(delay); |
| 64 | + }, |
| 65 | + set dateEditEnabled(enable: boolean) { |
| 66 | + widget.setDateEditEnabled(enable); |
| 67 | + }, |
| 68 | + set firstDayOfWeek(dayOfWeek: DayOfWeek) { |
| 69 | + widget.setFirstDayOfWeek(dayOfWeek); |
| 70 | + }, |
| 71 | + set font(font: QFont) { |
| 72 | + widget.setFont(font); |
| 73 | + }, |
| 74 | + set gridVisible(show: boolean) { |
| 75 | + widget.setGridVisible(show); |
| 76 | + }, |
| 77 | + set horizontalHeaderFormat(format: HorizontalHeaderFormat) { |
| 78 | + widget.setHorizontalHeaderFormat(format); |
| 79 | + }, |
| 80 | + set navigationBarVisible(visible: boolean) { |
| 81 | + widget.setNavigationBarVisible(visible); |
| 82 | + }, |
| 83 | + set selectionMode(mode: SelectionMode) { |
| 84 | + widget.setSelectionMode(mode); |
| 85 | + }, |
| 86 | + set verticalHeaderFormat(format: VerticalHeaderFormat) { |
| 87 | + widget.setVerticalHeaderFormat(format); |
| 88 | + }, |
| 89 | + }; |
| 90 | + Object.assign(setter, newProps); |
| 91 | + setViewProps(widget, newProps, oldProps); |
| 92 | +}; |
| 93 | + |
| 94 | +/** |
| 95 | + * @ignore |
| 96 | + */ |
| 97 | +export class RNCalendar extends QCalendarWidget implements RNComponent { |
| 98 | + setProps(newProps: CalendarProps, oldProps: CalendarProps): void { |
| 99 | + setCalendarProps(this, newProps, oldProps); |
| 100 | + } |
| 101 | + appendInitialChild(child: Component): void { |
| 102 | + throwUnsupported(this); |
| 103 | + } |
| 104 | + appendChild(child: Component): void { |
| 105 | + throwUnsupported(this); |
| 106 | + } |
| 107 | + insertBefore(child: Component, beforeChild: Component): void { |
| 108 | + throwUnsupported(this); |
| 109 | + } |
| 110 | + removeChild(child: Component): void { |
| 111 | + throwUnsupported(this); |
| 112 | + } |
| 113 | + static tagName = "calendar"; |
| 114 | +} |
0 commit comments