-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adicionado componente de DatePicker (#178)
* create datepicker component * up version * remove ^ from package.json * added name and id
- Loading branch information
Showing
7 changed files
with
281 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { expect, jest } from '@storybook/jest'; | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
import { configure, userEvent, within } from '@storybook/testing-library'; | ||
import DatePicker from './index'; | ||
|
||
configure({ | ||
testIdAttribute: 'testid', | ||
}); | ||
|
||
// Mocks | ||
const onChange = jest.fn(); | ||
const calendarTestID = 'calendar-test-id'; | ||
|
||
const meta: Meta<typeof DatePicker> = { | ||
title: 'Components/DatePicker', | ||
component: DatePicker, | ||
|
||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: ['autodocs'], | ||
argTypes: { | ||
onChange: { control: { type: null } }, | ||
disableMonthPicker: { control: { type: 'boolean' } }, | ||
disableYearPicker: { control: { type: 'boolean' } }, | ||
workDays: { control: { type: 'boolean' } }, | ||
minDate: { control: { type: 'boolean' } }, | ||
maxDate: { control: { type: 'boolean' } }, | ||
}, | ||
args: { | ||
onChange: onChange, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DatePicker>; | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import React, { useRef } from 'react'; | ||
import { DateObject, DatePickerProps } from 'react-multi-date-picker'; | ||
import TextInput from '../TextInput'; | ||
import localeCalendar from './locale_calendar.json'; | ||
import { CustomCalendar } from './styles'; | ||
|
||
interface Props extends DatePickerProps { | ||
value: DateObject; | ||
onChange: (date: DateObject) => void; | ||
minDate?: Date; | ||
maxDate?: Date; | ||
name: string; | ||
id: string; | ||
disableMonthPicker?: boolean; | ||
disableYearPicker?: boolean; | ||
workDays?: boolean; | ||
holidays?: string[]; | ||
} | ||
|
||
const DatePickerComponent: React.FC<Props> = ({ | ||
value, | ||
onChange, | ||
minDate, | ||
maxDate, | ||
disableMonthPicker, | ||
disableYearPicker, | ||
workDays, | ||
holidays, | ||
name, | ||
id, | ||
}) => { | ||
const datePickerRef = useRef(); | ||
return ( | ||
<CustomCalendar | ||
locale={localeCalendar} | ||
ref={datePickerRef} | ||
render={(value, openCalendar, onChange) => { | ||
return ( | ||
<TextInput | ||
name={name} | ||
id={id} | ||
value={value} | ||
onClick={openCalendar} | ||
onChange={(e) => onChange(e)} | ||
iconRight="ChevronDownIcon" | ||
/> | ||
); | ||
}} | ||
format="DD/MM/YYYY" | ||
headerOrder={['MONTH_YEAR', 'LEFT_BUTTON', 'RIGHT_BUTTON']} | ||
value={value} | ||
arrow={false} | ||
minDate={minDate} | ||
maxDate={maxDate} | ||
onChange={onChange} | ||
disableMonthPicker={disableMonthPicker} | ||
disableYearPicker={disableYearPicker} | ||
mapDays={(days) => { | ||
const isWeekend = [0, 6].includes(days.date.weekDay.index); | ||
const isDisabled = holidays?.includes( | ||
days.date.toDate().toISOString().slice(0, 10), | ||
); | ||
|
||
if ((isWeekend && workDays) || isDisabled) { | ||
return { | ||
disabled: isWeekend, | ||
}; | ||
} | ||
return { | ||
disabled: false, | ||
}; | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default DatePickerComponent; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"name": "brl_upercase", | ||
"months": [ | ||
["Janeiro ", "JAN"], | ||
["Fevereiro", "FEV"], | ||
["Março", "MAR"], | ||
["Abril", "ABR"], | ||
["Maio", "MAI"], | ||
["Junho", "JUN"], | ||
["Julho", "JUL"], | ||
["Agosto", "AGO"], | ||
["Setembro", "SET"], | ||
["Outubro", "OUT"], | ||
["Novembro", "NOV"], | ||
["Dezembro", "DEZ"] | ||
], | ||
"weekDays": [ | ||
["Sábado", "SA"], | ||
["Domingo", "DO"], | ||
["Segunda", "SE"], | ||
["Terça", "TE"], | ||
["Quarta", "QA"], | ||
["Quinta", "QI"], | ||
["Sexta", "SE"] | ||
], | ||
"digits": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"], | ||
"meridiems": [ | ||
["AM", "am"], | ||
["PM", "pm"] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import DatePicker from 'react-multi-date-picker'; | ||
import styled from 'styled-components'; | ||
import { getTheme, pxToRem } from '@platformbuilders/theme-toolkit'; | ||
|
||
const fontSizeSm = getTheme('fontSizes.sm'); | ||
const backgroundZ0 = getTheme('background.z0'); | ||
const colorBrandPrimaryMain = getTheme('brand.primary.main'); | ||
const colorBrandPrimaryContrast = getTheme('brand.primary.contrast'); | ||
const colorTextMain = getTheme('text.main'); | ||
const spacingSm = getTheme('spacing.sm'); | ||
|
||
export const CustomCalendar = styled(DatePicker)` | ||
margin-top: ${pxToRem(-18)}; | ||
.rmdp-ym { | ||
flex-direction: row; | ||
} | ||
.rmdp-input { | ||
cursor: pointer; | ||
} | ||
.rmdp-header div { | ||
flex-direction: row; | ||
} | ||
.rmdp-header-values { | ||
margin-left: ${pxToRem(5)}; | ||
font-size: ${fontSizeSm}px; | ||
font-weight: 700; | ||
color: ${colorTextMain}; | ||
flex-direction: row; | ||
} | ||
.rmdp-arrow-container { | ||
padding-top: ${pxToRem(2)}; | ||
&:hover { | ||
background-color: ${colorBrandPrimaryMain}; | ||
box-shadow: none; | ||
> i { | ||
border: solid ${colorBrandPrimaryContrast}; | ||
border-width: 0 ${pxToRem(2)} ${pxToRem(2)} 0; | ||
} | ||
} | ||
} | ||
.rmdp-arrow { | ||
border: solid ${colorBrandPrimaryMain}; | ||
border-width: 0 ${pxToRem(2)} ${pxToRem(2)} 0; | ||
} | ||
.rmdp-left { | ||
padding-right: ${pxToRem(2)}; | ||
} | ||
.rmdp-right { | ||
padding-left: ${pxToRem(1)}; | ||
} | ||
.rmdp-arrow { | ||
color: ${colorBrandPrimaryMain}; | ||
} | ||
.rmdp-week { | ||
margin: ${spacingSm} 0; | ||
flex-direction: row; | ||
} | ||
.rmdp-week-day { | ||
color: ${colorTextMain}; | ||
font-weight: 700; | ||
} | ||
.rmdp-day { | ||
&:hover { | ||
.span { | ||
background-color: ${colorBrandPrimaryMain}10; | ||
} | ||
} | ||
} | ||
.rmdp-day span { | ||
&:hover { | ||
background-color: ${colorBrandPrimaryMain}; | ||
} | ||
} | ||
.rmdp-day.rmdp-today span { | ||
background-color: ${backgroundZ0}20; | ||
color: ${colorTextMain}; | ||
&:hover { | ||
background-color: ${colorBrandPrimaryMain}; | ||
color: ${colorBrandPrimaryContrast}; | ||
} | ||
} | ||
.rmdp-day.rmdp-selected span:not(.highlight) { | ||
background-color: ${colorBrandPrimaryMain}; | ||
color: ${colorBrandPrimaryContrast}; | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10993,6 +10993,11 @@ react-colorful@^5.1.2: | |
resolved "https://registry.yarnpkg.com/react-colorful/-/react-colorful-5.6.1.tgz#7dc2aed2d7c72fac89694e834d179e32f3da563b" | ||
integrity sha512-1exovf0uGTGyq5mXQT0zgQ80uvj2PCwvF8zY1RN9/vbJVSjSo3fsB/4L3ObbF7u70NduSiK4xu4Y6q1MHoUGEw== | ||
|
||
react-date-object@^2.1.8: | ||
version "2.1.8" | ||
resolved "https://registry.yarnpkg.com/react-date-object/-/react-date-object-2.1.8.tgz#2bc482f950d11f241bb127b08ab8152c12c2f80c" | ||
integrity sha512-94zg/9r29v/VsKsJT0E5+tPg85IyMirkU/B7qBWlhT7RDSuf9x5dczfbQOsj9TbzSVUK/Vx/ZDboOBy9hA381w== | ||
|
||
[email protected]: | ||
version "3.7.2" | ||
resolved "https://registry.yarnpkg.com/react-docgen-typescript-loader/-/react-docgen-typescript-loader-3.7.2.tgz#45cb2305652c0602767242a8700ad1ebd66bbbbd" | ||
|
@@ -11036,6 +11041,11 @@ [email protected]: | |
loose-envify "^1.1.0" | ||
scheduler "^0.23.0" | ||
|
||
react-element-popper@^2.1.6: | ||
version "2.1.6" | ||
resolved "https://registry.yarnpkg.com/react-element-popper/-/react-element-popper-2.1.6.tgz#4afb912287d57de5d442fb85e76f4d7b94fde879" | ||
integrity sha512-8va7mUmrKIkUnaM2t5Dyctd8cjgVgVcrv5vVD0FRay0sN6EPBCKa0bDi1/KmVDAjfgSIn7zQnjtc4VojcGrkgQ== | ||
|
||
react-element-to-jsx-string@^15.0.0: | ||
version "15.0.0" | ||
resolved "https://registry.yarnpkg.com/react-element-to-jsx-string/-/react-element-to-jsx-string-15.0.0.tgz#1cafd5b6ad41946ffc8755e254da3fc752a01ac6" | ||
|
@@ -11078,6 +11088,14 @@ react-is@^18.0.0: | |
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.2.0.tgz#199431eeaaa2e09f86427efbb4f1473edb47609b" | ||
integrity sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w== | ||
|
||
react-multi-date-picker@^4.4.1: | ||
version "4.4.1" | ||
resolved "https://registry.yarnpkg.com/react-multi-date-picker/-/react-multi-date-picker-4.4.1.tgz#98e137ab4829f69385d9e14f8ff6d48f31e180c8" | ||
integrity sha512-z0utCiMYijt2w3UoVJkYgsReE9l1k6DkiL13Vr2RKHnBnorKK0IYq7xpfkuMimvt7sLumFr5wTKsWumCgSkXkA== | ||
dependencies: | ||
react-date-object "^2.1.8" | ||
react-element-popper "^2.1.6" | ||
|
||
react-refresh@^0.14.0: | ||
version "0.14.0" | ||
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e" | ||
|