Skip to content
Open
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
9 changes: 1 addition & 8 deletions src/app-components/Text/DisplayText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,8 @@ interface TextProps {
labelId?: string;
}

export const DisplayText = ({ value, iconUrl, iconAltText, labelId }: TextProps) => (
export const DisplayText = ({ value, labelId }: Pick<TextProps, 'value' | 'labelId'>) => (
<>
{iconUrl && (
<img
src={iconUrl}
className={classes.icon}
alt={iconAltText}
/>
)}
{labelId && <span aria-labelledby={labelId}>{value}</span>}
{!labelId && <span>{value}</span>}
</>
Expand Down
9 changes: 8 additions & 1 deletion src/components/label/Label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type LabelProps = PropsWithChildren<{
className?: string;
overrideId?: string;
textResourceBindings?: ExprResolved<TRBLabel>;
labelPrefix?: React.ReactNode;
}> &
DesignsystemetLabelProps;

Expand All @@ -47,6 +48,7 @@ export function LabelInner(props: LabelInnerProps) {
renderLabelAs,
className,
textResourceBindings: overriddenTrb,
labelPrefix,
...designsystemetLabelProps
} = props;

Expand All @@ -67,7 +69,12 @@ export function LabelInner(props: LabelInnerProps) {
const labelId = getLabelId(id);
const labelContentProps: LabelContentProps = {
id,
label: textResourceBindings.title,
label: (
<>
{labelPrefix}
{textResourceBindings.title}
</>
),
description: textResourceBindings.description,
help: textResourceBindings.help,
required,
Expand Down
23 changes: 20 additions & 3 deletions src/layout/Text/TextComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,26 @@ export const TextComponent = ({ baseComponentId }: PropsFromGenericComponent<'Te
const direction = _direction ?? 'horizontal';
const { langAsString } = useLanguage();

const iconElement = icon && (
<img
src={icon}
className={classes.icon}
alt={textResourceBindings?.title ? langAsString(textResourceBindings.title) : ''}
/>
);

if (!textResourceBindings?.title) {
return <DisplayText value={value} />;
return (
<div
className={cn(
classes.textComponent,
direction === 'vertical' ? classes.vertical : classes.horizontal,
)}
>
{iconElement}
<DisplayText value={value} />
</div>
);
}

return (
Expand All @@ -25,6 +43,7 @@ export const TextComponent = ({ baseComponentId }: PropsFromGenericComponent<'Te
label={{
baseComponentId,
renderLabelAs: 'span',
labelPrefix: iconElement,
className: cn(
classes.label,
classes.textComponent,
Expand All @@ -34,8 +53,6 @@ export const TextComponent = ({ baseComponentId }: PropsFromGenericComponent<'Te
>
<DisplayText
value={value}
iconUrl={icon}
iconAltText={langAsString(textResourceBindings.title)}
labelId={getLabelId(id)}
/>
</ComponentStructureWrapper>
Expand Down
Loading