diff --git a/src/Inputs/Datepicker/Datebox.tsx b/src/Inputs/Datepicker/Datebox.tsx index d1e6fbef..5a21a9f1 100644 --- a/src/Inputs/Datepicker/Datebox.tsx +++ b/src/Inputs/Datepicker/Datebox.tsx @@ -14,6 +14,12 @@ import { Button } from '../Button/Button'; const SIZE = 40; +export enum PriceStatus { + Good, + Okay, + Surge, +} + const displayDate = (date: Date = new Date()): string => `${MONTHS[date.getMonth()]}, ${date.getFullYear()}`; @@ -26,6 +32,7 @@ const buildCalendar = ( date: Date, value: Date, selectDate: React.MouseEventHandler, + selectedDays: IDataObject[], ): React.ReactElement[] => { const start = new Date(date); start.setDate(1); @@ -36,15 +43,33 @@ const buildCalendar = ( let exit = false; while (!exit) { row.push( - - {start.getDate()} - , + + {start.getDate()} +
+ {selectedDays[0] != null + ? selectedDays.map((day) => { + if (sameDate(start, day.date)) { + return ( + day.date !== new Date(0, 0, 0) && ( + + {day.price} + + ) + ); + } + return null; + }) + : null} +
+ , ); start.setDate(start.getDate() + 1); if (start.getDay() === 0) { @@ -63,6 +88,12 @@ const buildCalendar = ( return items; }; +export interface IDataObject { + date: Date; + price: string; + priceStatus: number; +} + export interface DateboxProps extends React.HTMLAttributes { changePage: (change?: number) => React.MouseEventHandler; selectedDate?: Date; @@ -70,6 +101,7 @@ export interface DateboxProps extends React.HTMLAttributes { animate: boolean; value: Date | undefined; clearDate?: Function; + adjustedPriceDays: IDataObject[]; } export const Datebox: React.FC = ({ @@ -79,6 +111,7 @@ export const Datebox: React.FC = ({ selectDate, animate, value, + adjustedPriceDays, }): React.ReactElement => ( @@ -99,6 +132,7 @@ export const Datebox: React.FC = ({ selectedDate || new Date(), value || new Date(), selectDate, + adjustedPriceDays, )} @@ -171,26 +205,40 @@ const CalendarWeek = styled.li` `; const CalendarDay = styled.span<{ + data: string; +}>``; + +const DayWrapper = styled.div<{ faded: boolean; selected: boolean; - data: string; }>` ${transition(['background-color', 'color'])} - ${flex('center')} - width: ${SIZE - 4}px; - height: ${SIZE - 4}px; + width: ${SIZE - 3}px; + height: ${SIZE - 3}px; margin: 2px; - border-radius: 50%; - + border-radius: 35%; + /* + ${flex('center')} + */ ${({ faded }): string => (faded ? 'opacity: 0.3;' : '')} ${({ selected, theme }): string => styledCondition( selected, ` - background-color: ${theme.colors.primary}; + background-color: ${theme.colors.occupancyStatusColors.Occupied}; cursor: pointer; color: white; `, clickable('#ffffff', 0.05), )} `; + +const Price = styled.div<{ + priceColor: PriceStatus; +}>` + font-size: 12px; + ${({ priceColor }): string => + (priceColor === PriceStatus.Good ? 'color: #026c45;' : '') || + (priceColor === PriceStatus.Okay ? 'color: #FFD700;' : '') || + (priceColor === PriceStatus.Surge ? 'color: #ff0000;' : '')} +`; diff --git a/src/Inputs/Datepicker/Datepicker.stories.tsx b/src/Inputs/Datepicker/Datepicker.stories.tsx index 490c598d..8d974abe 100644 --- a/src/Inputs/Datepicker/Datepicker.stories.tsx +++ b/src/Inputs/Datepicker/Datepicker.stories.tsx @@ -2,7 +2,6 @@ import React from 'react'; import { Meta, Story } from '@storybook/react'; import { Datepicker, DatepickerProps } from '../../index'; - export default { title: 'Components/Atoms/Datepicker', component: Datepicker, @@ -12,6 +11,23 @@ export default { label: 'label', placeholder: 'Placeholder', description: 'Description', + adjustedPriceDays: [ + { + date: new Date(2022, 0, 19), + price: '$25', + priceStatus: 1, + }, + { + date: new Date(2022, 0, 18), + price: '$45', + priceStatus: 0, + }, + { + date: new Date(2022, 0, 17), + price: '$70', + priceStatus: 2, + }, + ], }, } as Meta; diff --git a/src/Inputs/Datepicker/index.tsx b/src/Inputs/Datepicker/index.tsx index 5870af8c..18868b62 100644 --- a/src/Inputs/Datepicker/index.tsx +++ b/src/Inputs/Datepicker/index.tsx @@ -14,7 +14,7 @@ import { LabelLayout as LL, LabelLayoutProps, } from '../../Fragments'; -import { Datebox } from './Datebox'; +import { Datebox, IDataObject } from './Datebox'; const printDate = (date?: Date): string => { if (date) { @@ -33,6 +33,7 @@ export interface DatepickerProps extends LabelLayoutProps { onClear?: Function; value?: Date; initialShow?: boolean; + adjustedPriceDays?: IDataObject[]; } export const Datepicker: React.FC = ({ @@ -41,6 +42,9 @@ export const Datepicker: React.FC = ({ onClear = (): void => undefined, placeholder = 'MM-DD-YYYY', initialShow, + adjustedPriceDays = [ + { date: new Date(0, 0, 0), price: '0', priceStatus: 0 }, + ], ...props }): React.ReactElement => { const theme = useTheme(); @@ -161,6 +165,7 @@ export const Datepicker: React.FC = ({ animate={animate} value={value} clearDate={clearDate} + adjustedPriceDays={adjustedPriceDays} /> )}