-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Select component that supports masks (#716)
* Refactor Select to allow masks into the component * Add autocomplete, key navigation and clear button to new select * Improve Autocomplete now it autocomplete with tab, and it doesnt open the dropdown when clearing it * Separate BaseSelect into smaller components * Add first test to Select component * Add Label to ClearInput * Return enter keypress on form to its default * Add keyboard accessibility to the select * Update displayValue when value is changed outside of select * Add automatic scroliing to select dropdown * Add specs for strings and hash options * Disable clearInput when the select is disabled * Fix label not moving on timepicker * Fix dropdown not opening with only 1 option
- Loading branch information
1 parent
26d0aaa
commit 419747c
Showing
18 changed files
with
1,255 additions
and
188 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
import '@testing-library/jest-dom' | ||
|
||
Element.prototype.scrollIntoView = () => {} | ||
|
||
Object.defineProperty(window, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation(query => ({ | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // deprecated | ||
removeListener: jest.fn(), // deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
})), | ||
}); | ||
dispatchEvent: jest.fn() | ||
})) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,60 @@ | ||
import { IMask } from 'react-imask' | ||
import { MaskedSelect, MaskedSelectProps } from '@/ui/Select/MaskedSelect' | ||
|
||
const timeOptions = () => { | ||
const hours = Array.from({ length: 24 }, (_, i) => i) | ||
const minutes = ['00', '15', '30', '45'] | ||
|
||
return hours.flatMap((h) => minutes.map((m) => `${h}:${m}`)) | ||
} | ||
|
||
const hourMinuteMask = [ | ||
{ | ||
mask: '0:@0', | ||
definitions: { | ||
'@': /[0-5]/ | ||
} | ||
}, | ||
{ | ||
mask: 'HH:MM', | ||
blocks: { | ||
HH: { | ||
mask: IMask.MaskedRange, | ||
from: 0, | ||
to: 23 | ||
}, | ||
MM: { | ||
mask: IMask.MaskedRange, | ||
from: 0, | ||
to: 59 | ||
} | ||
} | ||
} | ||
] | ||
|
||
type TimePickerProps = Omit<MaskedSelectProps, 'options' | 'mask'> | ||
|
||
export const TimePicker = ({ | ||
name, | ||
label, | ||
value, | ||
onChange, | ||
sx, | ||
disabled, | ||
required | ||
}: TimePickerProps) => { | ||
return ( | ||
<MaskedSelect | ||
options={timeOptions()} | ||
name={name} | ||
label={label} | ||
value={value} | ||
onChange={onChange} | ||
placeholder=" " | ||
sx={sx} | ||
mask={hourMinuteMask} | ||
disabled={disabled} | ||
required={required} | ||
/> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
export type Project = { | ||
id: string | ||
id: number | ||
area_id: number | ||
customer_id: number | ||
description: string | ||
|
Oops, something went wrong.