-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[@mantine/dates] TimeInput: Add format and clearable props support (#607
) * [@mantine/dates] TimeInput: Add `format` and `clearable` prop Fix for #581 and #580 * [@mantine/core] use-valid-state: Rename `rule` to `validation` * [@mantine/dates] TimeInput: Resolve conversations * [@mantine/dates] TimeInput: Fixed the problems * [@mantine/dates] TimeInput: Fixed the test * [@mantine/dates] TimeInput: Resolved issues * [@mantine/dates] TimeRangeInput: Updated usage demo
- Loading branch information
Showing
35 changed files
with
720 additions
and
120 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,49 @@ | ||
--- | ||
group: 'mantine-hooks' | ||
package: '@mantine/hooks' | ||
title: 'use-validated-state' | ||
category: 'state' | ||
order: 1 | ||
slug: /hooks/use-validated-state/ | ||
description: 'Validate state and get last valid value' | ||
import: "import { useValidatedState } from '@mantine/hooks';" | ||
docs: 'hooks/use-validated-state.mdx' | ||
source: 'mantine-hooks/src/use-validated-state/use-validated-state.ts' | ||
--- | ||
|
||
## Usage | ||
|
||
Hook validates state with a given rule each time state is set. It returns an object with current validation state, last valid value and current value: | ||
|
||
```tsx | ||
const [{ lastValidValue, value, valid }, setValue] = useValidatedState( | ||
'valid', | ||
(value) => value === 'valid' | ||
); | ||
|
||
lastValidValue; // -> valid | ||
value; // -> valid | ||
valid; // -> true | ||
|
||
setValue('invalid'); | ||
|
||
lastValidValue; // -> valid | ||
value; // -> invalid | ||
valid; // -> false | ||
``` | ||
|
||
## Definition | ||
|
||
```tsx | ||
function useValidatedState<T>( | ||
initialValue: T, | ||
validation: (value: T) => boolean | ||
): readonly [ | ||
{ | ||
value: T; | ||
lastValidValue: T; | ||
valid: boolean; | ||
}, | ||
(val: T) => void | ||
]; | ||
``` |
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
20 changes: 20 additions & 0 deletions
20
src/mantine-dates/src/components/TimeInput/demos/clearable.tsx
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,20 @@ | ||
import React from 'react'; | ||
import { TimeInput } from '../TimeInput'; | ||
|
||
const code = ` | ||
<TimeInput clearable defaultValue={new Date()} /> | ||
`; | ||
|
||
function Demo() { | ||
return ( | ||
<div style={{ maxWidth: 320, marginLeft: 'auto', marginRight: 'auto' }}> | ||
<TimeInput label="With a clear button" clearable defaultValue={new Date()} /> | ||
</div> | ||
); | ||
} | ||
|
||
export const clearable: MantineDemo = { | ||
type: 'demo', | ||
code, | ||
component: Demo, | ||
}; |
Oops, something went wrong.