Skip to content

Commit 119adde

Browse files
authored
Merge pull request #247 from eccenca/feature/extend-label-with-actions-CMEM-5332
Extend label by option to add other elements (CMEM-6112)
2 parents fa31e75 + d2e61e0 commit 119adde

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1818
- editor is focused on load if `autoFocus` prop is set to `true`
1919
- implemented support for `disabled` state in code editor
2020
- implemented support for `intent` states in code editor
21+
- `Label` component
22+
- added `additionalElements` property to display elements at the end of the label
2123

2224
## [24.0.1] - 2025-02-06
2325

src/components/Label/Label.stories.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { loremIpsum } from "react-lorem-ipsum";
33
import { Meta, StoryFn } from "@storybook/react";
44

5-
import { Label } from "../../index";
5+
import { Icon, Label } from "../../index";
66

77
export default {
88
title: "Forms/Label",
@@ -19,4 +19,5 @@ Default.args = {
1919
tooltip: loremIpsum({ p: 1, avgSentencesPerParagraph: 2, startWithLoremIpsum: false, random: false }).toString(),
2020
disabled: false,
2121
htmlFor: "inputid",
22+
additionalElements: <Icon name={"state-warning"} tooltipText={"message"} small />,
2223
};

src/components/Label/Label.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from "react";
22

33
import { CLASSPREFIX as eccgui } from "../../configuration/constants";
44
import Icon from "../Icon/Icon";
5+
import Spacing from "../Separation/Spacing";
56
import Tooltip, { TooltipProps } from "../Tooltip/Tooltip";
67

78
export interface LabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
@@ -34,6 +35,10 @@ export interface LabelProps extends React.LabelHTMLAttributes<HTMLLabelElement>
3435
* visual appearance of the label
3536
*/
3637
emphasis?: "strong" | "normal";
38+
/**
39+
* Add other elements to the end of the label content
40+
*/
41+
additionalElements?: React.ReactNode | React.ReactNode[];
3742
}
3843

3944
export const Label = ({
@@ -46,6 +51,7 @@ export const Label = ({
4651
tooltipProps,
4752
isLayoutForElement = "label",
4853
emphasis = "normal",
54+
additionalElements,
4955
...otherLabelProps
5056
}: LabelProps) => {
5157
let htmlElementstring = isLayoutForElement;
@@ -63,10 +69,16 @@ export const Label = ({
6369
</span>
6470
)}
6571
{children && <span className={`${eccgui}-label__other`}>{children}</span>}
72+
{additionalElements && (
73+
<>
74+
<Spacing vertical size="tiny" />
75+
{additionalElements}
76+
</>
77+
)}
6678
</>
6779
);
6880

69-
return !!text || !!info || !!tooltip || !!children ? (
81+
return !!text || !!info || !!tooltip || !!children || !!additionalElements ? (
7082
React.createElement(
7183
htmlElementstring,
7284
{

0 commit comments

Comments
 (0)