Grafana-UI: Add invalid state to Forms.Textarea (#22775)
This commit is contained in:
@@ -16,6 +16,7 @@ import Forms from './index';
|
|||||||
import mdx from './Form.mdx';
|
import mdx from './Form.mdx';
|
||||||
import { ValidateResult } from 'react-hook-form';
|
import { ValidateResult } from 'react-hook-form';
|
||||||
import { boolean } from '@storybook/addon-knobs';
|
import { boolean } from '@storybook/addon-knobs';
|
||||||
|
import { TextArea } from './TextArea/TextArea';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
title: 'Forms/Test forms',
|
title: 'Forms/Test forms',
|
||||||
@@ -50,6 +51,7 @@ interface FormDTO {
|
|||||||
switch: boolean;
|
switch: boolean;
|
||||||
radio: string;
|
radio: string;
|
||||||
select: string;
|
select: string;
|
||||||
|
text: string;
|
||||||
nested: {
|
nested: {
|
||||||
path: string;
|
path: string;
|
||||||
};
|
};
|
||||||
@@ -88,6 +90,10 @@ const renderForm = (defaultValues?: Partial<FormDTO>) => (
|
|||||||
<Input name="nested.path" placeholder="Nested path" size="md" ref={register} />
|
<Input name="nested.path" placeholder="Nested path" size="md" ref={register} />
|
||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
|
<Field label="Textarea" invalid={!!errors.text} error="Text is required">
|
||||||
|
<TextArea name="text" placeholder="Long text" size="md" ref={register({ required: true })} />
|
||||||
|
</Field>
|
||||||
|
|
||||||
<Field label="Checkbox" invalid={!!errors.checkbox} error="We need your consent">
|
<Field label="Checkbox" invalid={!!errors.checkbox} error="We need your consent">
|
||||||
<Checkbox name="checkbox" label="Do you consent?" ref={register({ required: true })} />
|
<Checkbox name="checkbox" label="Do you consent?" ref={register({ required: true })} />
|
||||||
</Field>
|
</Field>
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ export const getInputStyles = stylesFactory(({ theme, invalid = false }: StyleDe
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// Wraps inputWraper and addons
|
// Wraps inputWrapper and addons
|
||||||
wrapper: cx(
|
wrapper: cx(
|
||||||
css`
|
css`
|
||||||
label: input-wrapper;
|
label: input-wrapper;
|
||||||
@@ -178,7 +178,6 @@ export const getInputStyles = stylesFactory(({ theme, invalid = false }: StyleDe
|
|||||||
/* we want anything that has focus and is an addon to be above input */
|
/* we want anything that has focus and is an addon to be above input */
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
`,
|
`,
|
||||||
prefix: cx(
|
prefix: cx(
|
||||||
prefixSuffix,
|
prefixSuffix,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ const getTextAreaStyle = stylesFactory((theme: GrafanaTheme, invalid = false) =>
|
|||||||
border-radius: ${theme.border.radius.sm};
|
border-radius: ${theme.border.radius.sm};
|
||||||
padding: ${theme.spacing.formSpacingBase / 4}px ${theme.spacing.formSpacingBase}px;
|
padding: ${theme.spacing.formSpacingBase / 4}px ${theme.spacing.formSpacingBase}px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
border-color: ${invalid ? theme.colors.redBase : theme.colors.formInputBorder};
|
||||||
`
|
`
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user