Calendar
Data única
| D | S | T | Q | Q | S | S |
|---|---|---|---|---|---|---|
Intervalo
| D | S | T | Q | Q | S | S |
|---|---|---|---|---|---|---|
import { Calendar } from '@rivocode/ui'Quando usar
O mes cru, para quem quer o calendário na própria tela.
E a única peça do catalogo com fundacao de fora, a react-day-picker, e ela
entra só como motor: nenhuma folha de estilo dela e importada, todo o desenho vem
dos nossos tokens. O locale padrão e pt-BR.
Em largura de celular mostra um mes só, mesmo quando pedem mais, e o dia ganha 44px de alvo.
A troca de mês anima: o mês novo entra pelo lado para onde a pessoa andou, em
200ms, e com "reduzir movimento" ligado a troca é instantânea. animate={false}
desliga.
No React Native
Traduz: o @rivocode/ui-native exporta Calendar - mês desenhado à mão; valor ISO aaaa-mm-dd, exibição dd/mm/aaaa; o mês novo entra por fade. A API não é a mesma do web (no nativo tudo é controlado), e a tabela de paridade diz o que muda peça a peça.
API
| Prop | Tipo |
|---|---|
animate0.4.0Animate navigating between months. | boolean |
aria-label0.4.0The aria-label attribute to add to the container element. | string |
aria-labelledby0.4.0The aria-labelledby attribute to add to the container element. | string |
autoFocus0.4.0When a selection mode is set, DayPicker will focus the first selected day (if set) or today's date (if not disabled). | boolean |
broadcastCalendar0.4.0Display the weeks in the month following the broadcast calendar. | boolean |
captionLayout0.4.0Show dropdowns to navigate between months or years. | "dropdown""dropdown-months""dropdown-years""label" |
classNames0.4.0Change the class names used by DayPicker. | Partial<ClassNames> |
components0.4.0Change the components used for rendering the calendar elements. | Partial<CustomComponents> |
dateLib0.4.0Replace the default date library with a custom one. | Partial<DateLib> |
defaultMonth0.4.0The initial month to show in the calendar. | Date |
dir0.4.0The text direction of the calendar. | string |
disabled0.4.0Apply the `disabled` modifier to the matching days. | Matcher[] | Matcher |
disableNavigation0.4.0Disable the navigation between months. | boolean |
endMonth0.4.0The latest month to end the month navigation. | Date |
firstWeekContainsDate0.4.0The day of January that is always in the first week of the year. | 1 | 4 |
fixedWeeks0.4.0Display always 6 weeks per each month, regardless of the month’s number of weeks. | boolean |
footer0.4.0Add a footer to the calendar, acting as a live region. | ReactNode |
formatters0.4.0Formatters used to format dates to strings. | Partial<Formatters> |
hidden0.4.0Apply the `hidden` modifier to the matching days. | Matcher[] | Matcher |
hideNavigation0.4.0Hide the navigation buttons. | boolean |
hideWeekdays0.4.0Hide the row displaying the weekday row header. | boolean |
ISOWeek0.4.0Use ISO week dates instead of the locale setting. | boolean |
labels0.4.0Labels creators to override the defaults. | Partial<Labels> |
lang0.4.0Add the language tag to the container element. | string |
locale0.4.0The locale object used to localize dates. | Partial<DayPickerLocale> |
mode0.4.0Enable the selection of a single day, multiple days, or a range of days. | "multiple""range""single" |
modifiers0.4.0Add modifiers to the matching days. | Record<string, Matcher[]Matcherundefined> |
modifiersClassNames0.4.0Change the class name for the day matching the `modifiers`. | ModifiersClassNames |
modifiersStyles0.4.0Change the class name for the day matching the modifiers. | ModifiersStyles |
month0.4.0The month displayed in the calendar. | Date |
navLayout0.4.0Adjust the positioning of the navigation buttons. | "after" | "around" |
nonce0.4.0A cryptographic nonce ("number used once") which can be used by Content Security Policy for the inline `style` attributes. | string |
noonSafe0.4.0Keep calendar math at noon in the configured timeZone to avoid historical second-level offsets drifting dates across midnight. | boolean |
numberOfMonths0.4.0The number of displayed months. | number |
numerals0.4.0The numeral system to use when formatting dates. | Numerals |
onDayBlur0.4.0Event handler when a day is blurred. | DayEventHandler<FocusEvent<Element, Element>> |
onDayClick0.4.0Event handler when a day is clicked. | DayEventHandler<MouseEvent<Element, MouseEvent>> |
onDayFocus0.4.0Event handler when a day is focused. | DayEventHandler<FocusEvent<Element, Element>> |
onDayKeyDown0.4.0Event handler when a key is pressed on a day. | DayEventHandler<KeyboardEvent<Element>> |
onDayMouseEnter0.4.0Event handler when the mouse enters a day. | DayEventHandler<MouseEvent<Element, MouseEvent>> |
onDayMouseLeave0.4.0Event handler when the mouse leaves a day. | DayEventHandler<MouseEvent<Element, MouseEvent>> |
onMonthChange0.4.0Event fired when the user navigates between months. | MonthChangeEventHandler |
onNextClick0.4.0Event handler when the next month button is clicked. | MonthChangeEventHandler |
onPrevClick0.4.0Event handler when the previous month button is clicked. | MonthChangeEventHandler |
pagedNavigation0.4.0Paginate the month navigation displaying the `numberOfMonths` at a time. | boolean |
required0.4.0Whether the selection is required. | boolean |
reverseMonths0.4.0Render the months in reversed order (when numberOfMonths is set) to display the most recent month first. | boolean |
reverseYears0.4.0Reverse the order of years in the dropdown when using `captionLayout="dropdown"` or `captionLayout="dropdown-years"`. | boolean |
role0.4.0The role attribute to add to the container element. | "application" | "dialog" |
showOutsideDays0.4.0Show the outside days (days falling in the next or the previous month). | boolean |
showWeekNumber0.4.0Show the week numbers column. | boolean |
startMonth0.4.0The earliest month to start the month navigation. | Date |
styles0.4.0Change the inline styles of the HTML elements. | Partial<Styles> |
timeZone0.4.0The time zone (IANA or UTC offset) to use in the calendar (experimental). | string |
title0.4.0Add a `title` attribute to the container element. | string |
today0.4.0The today’s date. | Date |
useAdditionalDayOfYearTokens0.4.0Enable `YY` and `YYYY` for day of year tokens when formatting or parsing dates. | boolean |
useAdditionalWeekYearTokens0.4.0Enable `DD` and `DDDD` for week year tokens when formatting or parsing dates. | boolean |
weekStartsOn0.4.0The index of the first day of the week (0 - Sunday). | 0123456 |
Além destas, a peça aceita className, style, id e children, repassados ao elemento de baixo.
Partes
Calendar se monta com estas peças. Todas vivem nesta página, porque separar cada uma num endereço obrigaria a abrir seis abas para montar uma tela.
CalendarPanel
/calendar-panel.mdA casca do calendário: painel ancorado na mesa, folha de baixo no celular.
O DatePicker e o DateRangePicker já a usam por dentro. Ela sai exportada
para o seletor de data que a sua tela inventa (o filtro de período de um
relatório, o calendário de agendamento) continuar trocando de formato do mesmo
jeito que os da casa.
A troca é de formato e não de conteúdo. Calendário ancorado num campo perto do rodapé do celular abre para fora da tela ou por cima do teclado, e a pessoa precisa rolar a página com o painel aberto. A folha resolve isso sem mexer em nada do que vai dentro.
const [aberto, setAberto] = useState(false)
<CalendarPanel
open={aberto}
onOpenChange={setAberto}
title="Período do relatório"
trigger={<Button variant="secondary">Escolher período</Button>}
footer={<Button onClick={aplicar}>Aplicar</Button>}
>
<Calendar mode="range" selected={faixa} onSelect={setFaixa} />
</CalendarPanel>
open, onOpenChange e title são obrigatórios, e os três pelo mesmo motivo.
A abertura é controlada porque quem confirma com um rodapé precisa fechar o
painel no momento certo, e não no clique. O title é o nome que o leitor de
tela anuncia no celular, onde o painel vira folha e perde o campo ao lado que
dava o contexto.
| Prop | Tipo |
|---|---|
onOpenChangeobrigatória0.4.0 | (isOpen: boolean) => void |
openobrigatória0.4.0 | boolean |
titleobrigatória0.4.0Titulo lido no celular, onde o painel vira folha e perde o contexto. | string |
triggerobrigatória0.4.0O elemento que abre. | ReactElement<unknown, string | JSXElementConstructor<any>> |
align0.4.0 | "end" | "start" |
footer0.4.0 | ReactNode |
Além destas, a peça aceita className, style, id e children, repassados ao elemento de baixo.