generated from gravity-ui/package-example
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c27a80
commit e28fbe0
Showing
5 changed files
with
44 additions
and
29 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import React from 'react'; | ||
|
||
import {Text} from '@gravity-ui/uikit'; | ||
|
||
export const filterTimeArray = ( | ||
times: {id: string; value: string; content: string | JSX.Element; key: string}[], | ||
cutoff: string, | ||
direction: 'greater' | 'less', | ||
) => { | ||
const isTimeFormat = (value: string) => /^\d{1,2}:\d{2}$/.test(value); | ||
|
||
const compareValues = (a: string, b: string) => { | ||
if (isTimeFormat(a) && isTimeFormat(b)) { | ||
return direction === 'less' ? a >= b : a <= b; | ||
} else { | ||
const aNum = parseInt(a, 10); | ||
const bNum = parseInt(b, 10); | ||
|
||
return direction === 'less' ? aNum >= bNum : aNum <= bNum; | ||
} | ||
}; | ||
|
||
return times.map((time) => { | ||
const disabled = compareValues(time.value, cutoff); | ||
|
||
return { | ||
...time, | ||
content: disabled ? <Text color="secondary">{time.content}</Text> : time.content, | ||
disabled, | ||
}; | ||
}); | ||
}; | ||
|
||
export const validateArray = (arr: {value: string}[]) => | ||
arr.every((obj) => /^(\d+|\d{1,2}:\d{1,2})$/.test(obj.value)); |
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