|
| 1 | +--- |
| 2 | +layout: docs |
| 3 | +title: Calendar |
| 4 | +description: |
| 5 | +group: Components |
| 6 | +--- |
| 7 | + |
| 8 | +import { CalendarView } from 'boot-cell/source/Extra/Calendar'; |
| 9 | +import { formatDate } from 'web-utility/source/date'; |
| 10 | + |
| 11 | +import { Example } from '../../../source/component/Example'; |
| 12 | + |
| 13 | +This component is built on the top of [`<Table />`][1] & [`<IconButton />`][2], so [FontAwesome v5][3] is required: |
| 14 | + |
| 15 | +```HTML |
| 16 | +<link |
| 17 | + rel="stylesheet" |
| 18 | + href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.13.0/css/all.min.css" |
| 19 | +/> |
| 20 | +``` |
| 21 | + |
| 22 | +## Default calendar |
| 23 | + |
| 24 | +<Example> |
| 25 | + <CalendarView date={new Date(1989, 5, 4)} /> |
| 26 | +</Example> |
| 27 | + |
| 28 | +```TSX |
| 29 | +import { render, createCell } from 'web-cell'; |
| 30 | +import { CalendarView } from 'boot-cell/source/Extra/Calendar'; |
| 31 | + |
| 32 | +render( |
| 33 | + <CalendarView date={new Date(1989, 5, 4)} /> |
| 34 | +); |
| 35 | +``` |
| 36 | + |
| 37 | +## Custom Date captions |
| 38 | + |
| 39 | +<Example> |
| 40 | + <CalendarView |
| 41 | + date={new Date(1989, 5, 4)} |
| 42 | + dateTemplate="YYYY 年 MM 月" |
| 43 | + weekDays={['一', '二', '三', '四', '五', '六', '七']} |
| 44 | + /> |
| 45 | +</Example> |
| 46 | + |
| 47 | +```TSX |
| 48 | +import { render, createCell } from 'web-cell'; |
| 49 | +import { CalendarView } from 'boot-cell/source/Extra/Calendar'; |
| 50 | + |
| 51 | +render( |
| 52 | + <CalendarView |
| 53 | + date={new Date(1989, 5, 4)} |
| 54 | + dateTemplate="YYYY 年 MM 月" |
| 55 | + weekDays={['一', '二', '三', '四', '五', '六', '七']} |
| 56 | + /> |
| 57 | +); |
| 58 | +``` |
| 59 | + |
| 60 | +## Custom Date cell |
| 61 | + |
| 62 | +<Example> |
| 63 | + <CalendarView |
| 64 | + date={new Date(1989, 5, 4)} |
| 65 | + dateTemplate="YYYY 年 MM 月" |
| 66 | + weekDays={['一', '二', '三', '四', '五', '六', '七']} |
| 67 | + renderCell={date => ( |
| 68 | + <a |
| 69 | + className="stretched-link" |
| 70 | + style={{ color: 'inherit' }} |
| 71 | + target="_blank" |
| 72 | + href={ |
| 73 | + 'https://zh.wikipedia.org/wiki/' + |
| 74 | + formatDate(date, 'M月D日') |
| 75 | + } |
| 76 | + > |
| 77 | + {date.getDate()} |
| 78 | + </a> |
| 79 | + )} |
| 80 | + /> |
| 81 | +</Example> |
| 82 | + |
| 83 | +```TSX |
| 84 | +import { render, createCell } from 'web-cell'; |
| 85 | +import { CalendarView } from 'boot-cell/source/Extra/Calendar'; |
| 86 | +import { formatDate } from 'web-utility/source/date'; |
| 87 | + |
| 88 | +render( |
| 89 | + <CalendarView |
| 90 | + date={new Date(1989, 5, 4)} |
| 91 | + dateTemplate="YYYY 年 MM 月" |
| 92 | + weekDays={['一', '二', '三', '四', '五', '六', '七']} |
| 93 | + renderCell={date => ( |
| 94 | + <a |
| 95 | + className="stretched-link" |
| 96 | + style={{ color: 'inherit' }} |
| 97 | + target="_blank" |
| 98 | + href={ |
| 99 | + 'https://zh.wikipedia.org/wiki/' + |
| 100 | + formatDate(date, 'M月D日') |
| 101 | + } |
| 102 | + > |
| 103 | + {date.getDate()} |
| 104 | + </a> |
| 105 | + )} |
| 106 | + /> |
| 107 | +); |
| 108 | +``` |
| 109 | + |
| 110 | +[1]: components/table |
| 111 | +[2]: components/icon |
| 112 | +[3]: https://fontawesome.com/ |
0 commit comments