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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- editor is focused on load if `autoFocus` prop is set to `true`
- implemented support for `disabled` state in code editor
- implemented support for `intent` states in code editor
- `Label` component
- added `additionalElements` property to display elements at the end of the label

## [24.0.1] - 2025-02-06

Expand Down
3 changes: 2 additions & 1 deletion src/components/Label/Label.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";
import { loremIpsum } from "react-lorem-ipsum";
import { Meta, StoryFn } from "@storybook/react";

import { Label } from "../../index";
import { Icon, Label } from "../../index";

export default {
title: "Forms/Label",
Expand All @@ -19,4 +19,5 @@ Default.args = {
tooltip: loremIpsum({ p: 1, avgSentencesPerParagraph: 2, startWithLoremIpsum: false, random: false }).toString(),
disabled: false,
htmlFor: "inputid",
additionalElements: <Icon name={"state-warning"} tooltipText={"message"} small />,
};
14 changes: 13 additions & 1 deletion src/components/Label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from "react";

import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import Icon from "../Icon/Icon";
import Spacing from "../Separation/Spacing";
import Tooltip, { TooltipProps } from "../Tooltip/Tooltip";

export interface LabelProps extends React.LabelHTMLAttributes<HTMLLabelElement> {
Expand Down Expand Up @@ -34,6 +35,10 @@ export interface LabelProps extends React.LabelHTMLAttributes<HTMLLabelElement>
* visual appearance of the label
*/
emphasis?: "strong" | "normal";
/**
* Add other elements to the end of the label content
*/
additionalElements?: React.ReactNode | React.ReactNode[];
}

export const Label = ({
Expand All @@ -46,6 +51,7 @@ export const Label = ({
tooltipProps,
isLayoutForElement = "label",
emphasis = "normal",
additionalElements,
...otherLabelProps
}: LabelProps) => {
let htmlElementstring = isLayoutForElement;
Expand All @@ -63,10 +69,16 @@ export const Label = ({
</span>
)}
{children && <span className={`${eccgui}-label__other`}>{children}</span>}
{additionalElements && (
<>
<Spacing vertical size="tiny" />
{additionalElements}
</>
)}
</>
);

return !!text || !!info || !!tooltip || !!children ? (
return !!text || !!info || !!tooltip || !!children || !!additionalElements ? (
React.createElement(
htmlElementstring,
{
Expand Down