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;
|
||||||
@@ -149,37 +149,36 @@ export const getInputStyles = stylesFactory(({ theme, invalid = false }: StyleDe
|
|||||||
color: ${colors.formInputDisabledText};
|
color: ${colors.formInputDisabledText};
|
||||||
`,
|
`,
|
||||||
addon: css`
|
addon: css`
|
||||||
label: input-addon;
|
label: input-addon;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-grow: 0;
|
flex-grow: 0;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
position: relative;
|
position: relative;
|
||||||
|
|
||||||
&:first-child {
|
&:first-child {
|
||||||
|
border-top-right-radius: 0;
|
||||||
|
border-bottom-right-radius: 0;
|
||||||
|
> :last-child {
|
||||||
border-top-right-radius: 0;
|
border-top-right-radius: 0;
|
||||||
border-bottom-right-radius: 0;
|
border-bottom-right-radius: 0;
|
||||||
> :last-child {
|
|
||||||
border-top-right-radius: 0;
|
|
||||||
border-bottom-right-radius: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
|
border-top-left-radius: 0;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
> :first-child {
|
||||||
border-top-left-radius: 0;
|
border-top-left-radius: 0;
|
||||||
border-bottom-left-radius: 0;
|
border-bottom-left-radius: 0;
|
||||||
> :first-child {
|
|
||||||
border-top-left-radius: 0;
|
|
||||||
border-bottom-left-radius: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
> *:focus {
|
}
|
||||||
/* we want anything that has focus and is an addon to be above input */
|
> *:focus {
|
||||||
z-index: 2;
|
/* we want anything that has focus and is an addon to be above input */
|
||||||
}
|
z-index: 2;
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
prefix: cx(
|
prefix: cx(
|
||||||
prefixSuffix,
|
prefixSuffix,
|
||||||
css`
|
css`
|
||||||
|
|||||||
@@ -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