Skip to content

Commit

Permalink
provide labelProps to configure automatically injected Label element
Browse files Browse the repository at this point in the history
  • Loading branch information
haschek committed Aug 16, 2023
1 parent c61ed9d commit 771c97b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

### Added

- `<PropertyName />`
- provide `labelProps` to configure the automatically injected `Label` element when `PropertyName` is only a string

### Fixed

- `<Spacing />`
Expand Down
19 changes: 15 additions & 4 deletions src/components/PropertyValuePair/PropertyName.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
import React from "react";

import { CLASSPREFIX as eccgui } from "../../configuration/constants";
import Label from "../Label/Label";
import Label, { LabelProps } from "../Label/Label";

export interface PropertyNameProps extends React.HTMLAttributes<HTMLElement> {
/**
* Increase or decrease the width used for the property name.
*/
size?: "small" | "medium" | "large";
/**
* Additonal label properties, e.g. `tooltip`.
* It is only used if the `PropertyName` has simple text input.
*/
labelProps?: LabelProps;
}

export const PropertyName = ({ className = "", size, children, ...otherProps }: PropertyNameProps) => {
export const PropertyName = ({ className = "", size, children, labelProps, ...otherDtProps }: PropertyNameProps) => {
return (
<dt
className={
`${eccgui}-propertyvalue__property` +
(size ? ` ${eccgui}-propertyvalue__property--${size}` : "") +
(className ? " " + className : "")
}
{...otherProps}
{...otherDtProps}
>
<div>{typeof children === "string" ? <Label text={children} isLayoutForElement="span" /> : children}</div>
<div>
{typeof children === "string" ? (
<Label text={children} isLayoutForElement="span" {...labelProps} />
) : (
children
)}
</div>
</dt>
);
};
Expand Down

0 comments on commit 771c97b

Please sign in to comment.