-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2353 from skbkontur/switcher-validation-tooltip
[Switcher] проблемы с валидацией
- Loading branch information
Showing
3 changed files
with
59 additions
and
1 deletion.
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
50 changes: 50 additions & 0 deletions
50
packages/react-ui-validations/stories/Switcher.stories.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,50 @@ | ||
import { storiesOf } from '@storybook/react'; | ||
import React from 'react'; | ||
import { Button } from '@skbkontur/react-ui/components/Button'; | ||
import { Switcher } from '@skbkontur/react-ui/components/Switcher/Switcher'; | ||
|
||
import { ValidationContainer, ValidationInfo, ValidationWrapper } from '../src'; | ||
import { Nullable } from '../typings/Types'; | ||
|
||
storiesOf('Switcher', module).add('required', () => <SwitcherStory />); | ||
|
||
interface SwitcherStoryState { | ||
value: string; | ||
} | ||
|
||
class SwitcherStory extends React.Component<{}, SwitcherStoryState> { | ||
public state: SwitcherStoryState = { | ||
value: '', | ||
}; | ||
|
||
private container: ValidationContainer | null = null; | ||
|
||
public validateValue(): Nullable<ValidationInfo> { | ||
const { value } = this.state; | ||
if (!value) { | ||
return { message: 'Поле обязательно', type: 'submit' }; | ||
} | ||
return null; | ||
} | ||
|
||
public render() { | ||
return ( | ||
<div style={{ padding: '20px 20px' }}> | ||
<ValidationContainer ref={this.refContainer}> | ||
<ValidationWrapper validationInfo={this.state.value === '' ? this.validateValue() : undefined}> | ||
<Switcher | ||
value={this.state.value} | ||
items={['string1', 'string2']} | ||
onValueChange={value => this.setState({ value })} | ||
/> | ||
</ValidationWrapper> | ||
<div style={{ padding: '20px 0' }}> | ||
<Button onClick={() => this.container && this.container.validate()}>Check</Button> | ||
</div> | ||
</ValidationContainer> | ||
</div> | ||
); | ||
} | ||
|
||
private refContainer = (el: ValidationContainer | null) => (this.container = el); | ||
} |