Skip to content

Commit

Permalink
FieldWithValidation
Browse files Browse the repository at this point in the history
  • Loading branch information
eszthoff committed Aug 15, 2022
1 parent ef70927 commit 4a131cb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/components/FieldWithValidation/FieldWithValidation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Tooltip } from '../Tooltip';
import { Text } from '../Text';
import styles from './FieldWithValidation.scss';

interface Props {
export interface Props {
/** a single form field, e.g. Input, TextArea, etc. It should support context=”bad” prop.
* When useTooltip is set to true, children that are ReactComponents should support forwardRef */
children: React.ReactElement;
Expand Down
2 changes: 1 addition & 1 deletion src/components/FieldWithValidation/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { FieldWithValidation } from './FieldWithValidation';
export { FieldWithValidation, Props as FieldWithValidationProps } from './FieldWithValidation';
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export { Footer } from './components/Footer';
export { Header } from './components/Header';
export { Gauge } from './components/Gauge';
export { Field } from './components/Field';
export { FieldWithValidation } from './components/FieldWithValidation';
export * from './components/FieldWithValidation';
export { FieldWrapper } from './components/FieldWrapper';
export { LoadingSpinner } from './components/LoadingSpinner';
export { LocationCard } from './components/LocationCard';
Expand Down
63 changes: 31 additions & 32 deletions stories/FieldWithValidation.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { text, boolean, withKnobs } from '@storybook/addon-knobs';
import { FieldWithValidation, Input, TextArea } from '@textkernel/oneui';
import { FieldWithValidation, Input, TextArea, FieldWithValidationProps } from '@textkernel/oneui';

const Example = () => {
export default {
title: 'Molecules/FieldWithValidation',
component: FieldWithValidation,
};

export const _FieldWithValidation = ({ errorMessage2, useTootip2, ...args }) => (
<>
<div style={{ marginBottom: '10px' }}>
<FieldWithValidation {...(args as FieldWithValidationProps)} />
</div>
<div>
<FieldWithValidation errorMessage={errorMessage2} useTooltip={useTootip2}>
<TextArea />
</FieldWithValidation>
</div>
</>
);
_FieldWithValidation.args = {
errorMessage: 'Error message',
useTooltip: false,
children: <Input />,
errorMessage2: '',
useTootip2: false,
};

export const Example = (args) => {
const [inputValue, setValue] = React.useState('');
const [errMsg, setErrMsg] = React.useState<string>();
const EMAIL_REGEX =
Expand All @@ -22,10 +45,7 @@ const Example = () => {

return (
<div style={{ marginBottom: '10px' }}>
<FieldWithValidation
errorMessage={errMsg}
useTooltip={boolean('Use tooltip for input field', false)}
>
<FieldWithValidation errorMessage={errMsg} useTooltip={args.useTooltip}>
<Input
value={inputValue}
onChange={(e) => {
Expand All @@ -37,27 +57,6 @@ const Example = () => {
</div>
);
};

storiesOf('Molecules/FieldWithValidation', module)
.addDecorator(withKnobs)
.add('FieldWithValidation', () => (
<>
<div style={{ marginBottom: '10px' }}>
<FieldWithValidation
errorMessage={text('Error message for input field', 'Something wrong')}
useTooltip={boolean('Use tooltip for input field', false)}
>
<Input />
</FieldWithValidation>
</div>
<div>
<FieldWithValidation
errorMessage={text('Error message for text field', '')}
useTooltip={boolean('Use tooltip for text field', false)}
>
<TextArea />
</FieldWithValidation>
</div>
</>
))
.add('Example implementation', () => <Example />);
Example.args = {
useTooltip: false,
};

0 comments on commit 4a131cb

Please sign in to comment.