Skip to content

Commit

Permalink
Merge branch 'feature/input' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillermo Angeles committed Sep 27, 2023
2 parents f70d9c1 + 204a17a commit 0e9b789
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 22 deletions.
21 changes: 21 additions & 0 deletions src/components/Input/Input.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,27 @@ export const InputDate = {
}
};

export const InputDateWithCalendar = {
args: {
design: 'secondary',
type:'date',
showCalendar: true,
defaultValue: undefined
},
play: async ({canvasElement, step}: any) =>{
const canvas = within(canvasElement);
const input = canvas.getByRole('input');
const placeholder = canvas.getByRole('placeholder');
await step('render', async () =>{
expect(input).toBeInTheDocument();
expect(placeholder).toBeInTheDocument();
});
await step('typing', async () =>{
userEvent.type(input, '23052023', { delay: 100 });
});
}
};

export const InputPassword = {
args: {
design: 'secondary',
Expand Down
36 changes: 21 additions & 15 deletions src/components/Input/InputDate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ const InputDate = (props: InputDatePrimaryProps | InputDateSecondaryProps) =>{

const onChange = (e: any) =>{
const value = e.target.value;
if(value.length === 2 || value.length === 5){
if(text && value.length < text.length){
//Remove
setText(value.slice(0, -1));
}
else setText(value+'/');
}
else if(value.length === 10){
setText(value);
const date:any = moment(value, 'DD/MM/YYYY').toDate();
if(props.showCalendar){
const date:any = moment(value, 'YYYY-MM-DD').toDate();
props.onChange && props.onChange(date);
}
else setText(value);
else{
if(value.length === 2 || value.length === 5){
if(text && value.length < text.length){
//Remove
setText(value.slice(0, -1));
}
else setText(value+'/');
}
else if(value.length === 10){
setText(value);
const date:any = moment(value, 'DD/MM/YYYY').toDate();
props.onChange && props.onChange(date);
}
else setText(value);
}
}


Expand All @@ -31,7 +37,7 @@ const InputDate = (props: InputDatePrimaryProps | InputDateSecondaryProps) =>{
value={text}
containerStyle={{flex: 1, ...props.containerStyle}}
{...props}
type='text'
type={props.showCalendar ? 'date' : 'text'}
maxLength={10}
onChange={onChange}
/>
Expand All @@ -40,7 +46,7 @@ const InputDate = (props: InputDatePrimaryProps | InputDateSecondaryProps) =>{
value={text}
containerStyle={{flex: 1, ...props.containerStyle}}
{...props}
type='text'
type={props.showCalendar ? 'date' : 'text'}
maxLength={10}
onChange={onChange}
/>
Expand All @@ -49,9 +55,9 @@ const InputDate = (props: InputDatePrimaryProps | InputDateSecondaryProps) =>{
export default InputDate;
export interface InputDatePrimaryProps extends InputPrimaryProps {
design?: 'primary',

showCalendar?: boolean
}
export interface InputDateSecondaryProps extends InputSecondaryProps {
design?: 'secondary',

showCalendar?: boolean
}
7 changes: 0 additions & 7 deletions src/components/Input/InputStyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ const Input = styled.input<{hideCalendar?: boolean}>`
&::placeholder{
color: ${Color.text.neutralMedium}
}
&::-webkit-calendar-picker-indicator {
display: ${props => props.hideCalendar && 'none'};
-webkit-appearance: ${props => props.hideCalendar && 'none'};
}
&::-webkit-calendar-picker-indicator {
background: none;
}
`
const InputStyled = forwardRef((props: InputStyledProps, ref: any) =>{

Expand Down

0 comments on commit 0e9b789

Please sign in to comment.