Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 6 additions & 172 deletions packages/react-core/src/components/LabelGroup/examples/LabelGroup.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,196 +13,30 @@ import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-i

### Basic

```js
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

<LabelGroup>
<Label icon={<InfoCircleIcon />}>Label 1</Label>
<Label icon={<InfoCircleIcon />} color="blue">
Label 2
</Label>
<Label icon={<InfoCircleIcon />} color="green">
Label 3
</Label>
</LabelGroup>;
```ts file="LabelGroupBasic.tsx"
```

### Overflow

```js
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

<LabelGroup>
<Label icon={<InfoCircleIcon />}>Label 1</Label>
<Label icon={<InfoCircleIcon />} color="blue">
Label 2
</Label>
<Label icon={<InfoCircleIcon />} color="green">
Label 3
</Label>
<Label icon={<InfoCircleIcon />} color="orange">
Label 4
</Label>
<Label icon={<InfoCircleIcon />} color="red">
Label 5
</Label>
<Label icon={<InfoCircleIcon />} color="purple">
Label 6
</Label>
</LabelGroup>;
```ts file="LabelGroupOverflow.tsx"
```

### Category

```js
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

<LabelGroup categoryName="Group label">
<Label icon={<InfoCircleIcon />}>Label 1</Label>
<Label icon={<InfoCircleIcon />} color="blue">
Label 2
</Label>
<Label icon={<InfoCircleIcon />} color="green">
Label 3
</Label>
</LabelGroup>;
```ts file="LabelGroupCategory.tsx"
```

### Category removable

```js
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

CategoryLabelGroupRemovable = () => {
const [labels, setLabels] = React.useState([
['Label 1', 'grey'],
['Label 2', 'blue'],
['Label 3', 'green'],
['Label 4', 'orange'],
['Label 5', 'red']
]);
const deleteCategory = () => setLabels([]);

return (
<LabelGroup categoryName="Group label" isClosable onClick={deleteCategory}>
{labels.map(([labelText, labelColor]) => (
<Label icon={<InfoCircleIcon />} color={labelColor} key={labelText}>
{labelText}
</Label>
))}
</LabelGroup>
);
};
```ts file="LabelGroupCategoryRemovable.tsx"
```

### Vertical category overflow removable

```js
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

VerticalCategoryLabelGroupOverflowRemovable = () => {
const [labels, setLabels] = React.useState([
['Label 1', 'grey'],
['Label 2', 'blue'],
['Label 3', 'green'],
['Label 4', 'orange'],
['Label 5', 'red']
]);
const deleteCategory = () => setLabels([]);

return (
<LabelGroup categoryName="Group label with a very long name" isVertical isClosable onClick={deleteCategory}>
{labels.map(([labelText, labelColor]) => (
<Label icon={<InfoCircleIcon />} color={labelColor} key={labelText}>
{labelText}
</Label>
))}
</LabelGroup>
);
};
```ts file="LabelGroupVerticalCategoryOverflowRemovable.tsx"
```

### Editable labels

```js isBeta
import React from 'react';
import { LabelGroup, Label, TextArea } from '@patternfly/react-core';

class EditableLabelGroup extends React.Component {
constructor(props) {
super(props);
this.state = {
label1: 'Editable label',
label2: 'Editable label 2',
label3: 'Editable label 3'
};
this.onEditCancel = (prevText, label) => {
this.setState({
[label]: prevText
});
};
this.onEditComplete = (newText, label) => {
this.setState({
[label]: newText
});
};
}

render() {
return (
<LabelGroup numLabels={5} isEditable>
<Label
color="blue"
onClose={Function.prototype}
onEditCancel={prevText => this.onEditCancel(prevText, 'label1')}
onEditComplete={newText => this.onEditComplete(newText, 'label1')}
isEditable
editableProps={{
'aria-label': 'Editable text',
id: 'editable-label-1'
}}
>
{this.state.label1}
</Label>
<Label color="green">Static label</Label>
<Label
color="blue"
onClose={Function.prototype}
onEditCancel={prevText => this.onEditCancel(prevText, 'label2')}
onEditComplete={newText => this.onEditComplete(newText, 'label2')}
isEditable
editableProps={{
'aria-label': 'Editable text 2',
id: 'editable-label-2'
}}
>
{this.state.label2}
</Label>
<Label
color="blue"
onClose={Function.prototype}
onEditCancel={prevText => this.onEditCancel(prevText, 'label3')}
onEditComplete={newText => this.onEditComplete(newText, 'label3')}
isEditable
editableProps={{
'aria-label': 'Editable text 3',
id: 'editable-label-3'
}}
>
{this.state.label3}
</Label>
</LabelGroup>
);
}
}
```ts file="LabelGroupEditableLabels.tsx" isBeta
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

export const LabelGroupBasic: React.FunctionComponent = () => (
<LabelGroup>
<Label icon={<InfoCircleIcon />}>Label 1</Label>
<Label icon={<InfoCircleIcon />} color="blue">
Label 2
</Label>
<Label icon={<InfoCircleIcon />} color="green">
Label 3
</Label>
</LabelGroup>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

export const LabelGroupCategory: React.FunctionComponent = () => (
<LabelGroup categoryName="Group label">
<Label icon={<InfoCircleIcon />}>Label 1</Label>
<Label icon={<InfoCircleIcon />} color="blue">
Label 2
</Label>
<Label icon={<InfoCircleIcon />} color="green">
Label 3
</Label>
</LabelGroup>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Label, LabelGroup, LabelProps } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

export const LabelGroupCategoryRemovable: React.FunctionComponent = () => {
const [labels, setLabels] = React.useState([
['Label 1', 'grey'],
['Label 2', 'blue'],
['Label 3', 'green'],
['Label 4', 'orange'],
['Label 5', 'red']
]);
const deleteCategory = () => setLabels([]);

return (
<LabelGroup categoryName="Group label" isClosable onClick={deleteCategory}>
{labels.map(([labelText, labelColor]) => (
<Label icon={<InfoCircleIcon />} color={labelColor as LabelProps['color']} key={labelText}>
{labelText}
</Label>
))}
</LabelGroup>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React from 'react';
import { LabelGroup, Label } from '@patternfly/react-core';

export const LabelGroupEditableLabels: React.FunctionComponent = () => {
const [label1, setLabel1] = React.useState('Editable label');
const [label2, setLabel2] = React.useState('Editable label 2');
const [label3, setLabel3] = React.useState('Editable label 3');

return (
<LabelGroup numLabels={5} isEditable>
<Label
color="blue"
onClose={() => Function.prototype}
onEditCancel={prevText => setLabel1(prevText)}
onEditComplete={newText => setLabel1(newText)}
isEditable
editableProps={{
'aria-label': 'Editable text',
id: 'editable-label-1'
}}
>
{label1}
</Label>
<Label color="green">Static label</Label>
<Label
color="blue"
onClose={() => Function.prototype}
onEditCancel={prevText => setLabel2(prevText)}
onEditComplete={newText => setLabel2(newText)}
isEditable
editableProps={{
'aria-label': 'Editable text 2',
id: 'editable-label-2'
}}
>
{label2}
</Label>
<Label
color="blue"
onClose={() => Function.prototype}
onEditCancel={prevText => setLabel3(prevText)}
onEditComplete={newText => setLabel3(newText)}
isEditable
editableProps={{
'aria-label': 'Editable text 3',
id: 'editable-label-3'
}}
>
{label3}
</Label>
</LabelGroup>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Label, LabelGroup } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

export const LabelGroupOverflow: React.FunctionComponent = () => (
<LabelGroup>
<Label icon={<InfoCircleIcon />}>Label 1</Label>
<Label icon={<InfoCircleIcon />} color="blue">
Label 2
</Label>
<Label icon={<InfoCircleIcon />} color="green">
Label 3
</Label>
<Label icon={<InfoCircleIcon />} color="orange">
Label 4
</Label>
<Label icon={<InfoCircleIcon />} color="red">
Label 5
</Label>
<Label icon={<InfoCircleIcon />} color="purple">
Label 6
</Label>
</LabelGroup>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import { Label, LabelGroup, LabelProps } from '@patternfly/react-core';
import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon';

export const LabelGroupVerticalCategoryOverflowRemovable: React.FunctionComponent = () => {
const [labels, setLabels] = React.useState([
['Label 1', 'grey'],
['Label 2', 'blue'],
['Label 3', 'green'],
['Label 4', 'orange'],
['Label 5', 'red']
]);
const deleteCategory = () => setLabels([]);

return (
<LabelGroup categoryName="Group label with a very long name" isVertical isClosable onClick={deleteCategory}>
{labels.map(([labelText, labelColor]) => (
<Label icon={<InfoCircleIcon />} color={labelColor as LabelProps['color']} key={labelText}>
{labelText}
</Label>
))}
</LabelGroup>
);
};