mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 18:30:41 -06:00
grafana/ui: Add invalid prop to the TagsInput (#34409)
* Add invalid prop to the tag input * Enable controls
This commit is contained in:
parent
a9c0b08ac3
commit
ca416df9d1
@ -1,11 +1,11 @@
|
||||
import { Meta, Story, Preview, Props } from '@storybook/addon-docs/blocks';
|
||||
import { Meta, Props } from '@storybook/addon-docs/blocks';
|
||||
import { TagsInput } from './TagsInput';
|
||||
|
||||
<Meta title="MDX|TagsInput" component={TagsInput} />
|
||||
|
||||
# TagsInput
|
||||
|
||||
A set of an input field and a button next to it that allows the user to add new tags. The added tags are previewed under the input and can be removed there by clicking the "X" icon. You can customize the width of the input.
|
||||
A set of an input field and a button next to it that allows the user to add new tags. The added tags are previewed next to the input and can be removed by clicking the "X" icon. You can customize the width of the input.
|
||||
|
||||
### Props
|
||||
<Props of={TagsInput} />
|
||||
|
@ -1,9 +1,10 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Meta, Story } from '@storybook/react';
|
||||
import { TagsInput, Props } from './TagsInput';
|
||||
import { withCenteredStory } from '../../utils/storybook/withCenteredStory';
|
||||
import { TagsInput } from '@grafana/ui';
|
||||
import mdx from './TagsInput.mdx';
|
||||
import { StoryExample } from '../../utils/storybook/StoryExample';
|
||||
import { VerticalGroup } from '../Layout/Layout';
|
||||
import mdx from './TagsInput.mdx';
|
||||
|
||||
export default {
|
||||
title: 'Forms/TagsInput',
|
||||
@ -13,12 +14,20 @@ export default {
|
||||
docs: {
|
||||
page: mdx,
|
||||
},
|
||||
knobs: {
|
||||
disable: true,
|
||||
},
|
||||
controls: {
|
||||
exclude: ['onChange', 'className', 'tags'],
|
||||
},
|
||||
},
|
||||
};
|
||||
} as Meta;
|
||||
|
||||
export const Basic = () => {
|
||||
type StoryProps = Omit<Props, 'onChange' | 'className' | 'tags'>;
|
||||
|
||||
export const Basic: Story<StoryProps> = (props) => {
|
||||
const [tags, setTags] = useState<string[]>([]);
|
||||
return <TagsInput tags={tags} onChange={setTags} />;
|
||||
return <TagsInput {...props} tags={tags} onChange={setTags} />;
|
||||
};
|
||||
|
||||
export const WithManyTags = () => {
|
||||
|
@ -8,12 +8,17 @@ import { Input } from '../Input/Input';
|
||||
|
||||
export interface Props {
|
||||
placeholder?: string;
|
||||
/** Array of selected tags */
|
||||
tags?: string[];
|
||||
onChange: (tags: string[]) => void;
|
||||
width?: number;
|
||||
className?: string;
|
||||
/** Toggle disabled state */
|
||||
disabled?: boolean;
|
||||
/** Enable adding new tags when input loses focus */
|
||||
addOnBlur?: boolean;
|
||||
/** Toggle invalid state */
|
||||
invalid?: boolean;
|
||||
}
|
||||
|
||||
export const TagsInput: FC<Props> = ({
|
||||
@ -24,6 +29,7 @@ export const TagsInput: FC<Props> = ({
|
||||
className,
|
||||
disabled,
|
||||
addOnBlur,
|
||||
invalid,
|
||||
}) => {
|
||||
const [newTagName, setNewName] = useState('');
|
||||
const styles = useStyles(getStyles);
|
||||
@ -77,6 +83,7 @@ export const TagsInput: FC<Props> = ({
|
||||
value={newTagName}
|
||||
onKeyUp={onKeyboardAdd}
|
||||
onBlur={onBlur}
|
||||
invalid={invalid}
|
||||
suffix={
|
||||
newTagName.length > 0 && (
|
||||
<Button fill="text" className={styles.addButtonStyle} onClick={onAdd} size="md">
|
||||
|
Loading…
Reference in New Issue
Block a user