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
13 changes: 1 addition & 12 deletions src/app-components/Text/DisplayText.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import React from 'react';

import classes from 'src/app-components/Text/Text.module.css';

interface TextProps {
value: string;
iconUrl?: string;
iconAltText?: string;
labelId?: string;
}

export const DisplayText = ({ value, iconUrl, iconAltText, labelId }: TextProps) => (
export const DisplayText = ({ value, labelId }: TextProps) => (
<>
{iconUrl && (
<img
src={iconUrl}
className={classes.icon}
alt={iconAltText}
/>
)}
{labelId && <span aria-labelledby={labelId}>{value}</span>}
{!labelId && <span>{value}</span>}
</>
Expand Down
5 changes: 5 additions & 0 deletions src/components/label/Label.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
gap: var(--ds-size-2);
}

.iconWithTitle {
display: flex;
align-items: center;
}

.fullWidth {
width: 100%;
}
Expand Down
35 changes: 26 additions & 9 deletions 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>;
icon?: React.ReactNode;
}> &
DesignsystemetLabelProps;

Expand All @@ -46,6 +47,7 @@ export function LabelInner(props: LabelInnerProps) {
overrideId,
renderLabelAs,
className,
icon,
textResourceBindings: overriddenTrb,
...designsystemetLabelProps
} = props;
Expand Down Expand Up @@ -101,15 +103,30 @@ export function LabelInner(props: LabelInnerProps) {
{/* we want this "label" not to be rendered as a <label>,
because it does not belong to an input element */}
<LabelGridItemWrapper labelGrid={grid?.labelGrid}>
<DesignsystemetLabel
asChild
{...designsystemetLabelProps}
>
<LabelContent
{...labelContentProps}
id={id}
/>
</DesignsystemetLabel>
{icon ? (
<span className={classes.iconWithTitle}>
{icon}
<DesignsystemetLabel
asChild
{...designsystemetLabelProps}
>
<LabelContent
{...labelContentProps}
id={id}
/>
</DesignsystemetLabel>
</span>
) : (
<DesignsystemetLabel
asChild
{...designsystemetLabelProps}
>
<LabelContent
{...labelContentProps}
id={id}
/>
</DesignsystemetLabel>
)}
</LabelGridItemWrapper>
{children}
</span>
Expand Down
9 changes: 7 additions & 2 deletions src/layout/Text/TextComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ export const TextComponent = ({ baseComponentId }: PropsFromGenericComponent<'Te
classes.textComponent,
direction === 'vertical' ? classes.vertical : classes.horizontal,
),
icon: icon && (
<img
src={icon}
className={classes.icon}
alt={langAsString(textResourceBindings.title)}
/>
),
}}
>
<DisplayText
value={value}
iconUrl={icon}
iconAltText={langAsString(textResourceBindings.title)}
labelId={getLabelId(id)}
/>
</ComponentStructureWrapper>
Expand Down