Skip to content

Commit

Permalink
fix(DefinitionList): layout fixes (#1910)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug authored Oct 22, 2024
1 parent bdfed60 commit e5cde3a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/components/DefinitionList/DefinitionList.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $block: '.#{variables.$ns}definition-list';
&_responsive {
#{$block}__term-container {
--_--term-width: auto;
flex: 1 0 50%;
flex: 1 0 min-content;
}
}
&_vertical {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import type {DefinitionListItemProps} from '../types';

interface DefinitionProps extends Pick<DefinitionListItemProps, 'copyText' | 'children'> {}

export function Definition({copyText, children}: DefinitionProps) {
export function DefinitionContent({copyText, children}: DefinitionProps) {
const definitionContent = children ?? '—';

return copyText ? (
<div className={b('copy-container')}>
<span>{definitionContent}</span>
{definitionContent}
<ClipboardButton
size="s"
text={copyText}
Expand Down
11 changes: 5 additions & 6 deletions src/components/DefinitionList/components/DefinitionListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ import React from 'react';

import {b} from '../constants';
import type {DefinitionListItemProps} from '../types';
import {getTitle, isUnbreakableOver} from '../utils';
import {isUnbreakableOver} from '../utils';

import {Definition} from './Definition';
import {DefinitionContent} from './DefinitionContent';
import {useDefinitionListAttributes} from './DefinitionListContext';
import {Term} from './Term';
import {TermContent} from './TermContent';

export function DefinitionListItem({name, children, copyText, note}: DefinitionListItemProps) {
const {direction, keyStyle, valueStyle} = useDefinitionListAttributes();
return (
<div className={b('item')}>
<dt className={b('term-container')} style={keyStyle}>
<Term direction={direction} name={name} note={note} />
<TermContent direction={direction} name={name} note={note} />
</dt>
<dd
className={b('definition')}
title={getTitle(children)}
style={{
...valueStyle,
lineBreak:
Expand All @@ -26,7 +25,7 @@ export function DefinitionListItem({name, children, copyText, note}: DefinitionL
: undefined,
}}
>
<Definition copyText={copyText}>{children}</Definition>
<DefinitionContent copyText={copyText}>{children}</DefinitionContent>
</dd>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {
DefinitionListItemNote,
DefinitionListItemProps,
} from '../types';
import {getTitle} from '../utils';

interface NoteElementsProps {
note?: DefinitionListItemNote;
Expand Down Expand Up @@ -55,7 +54,7 @@ interface TermProps extends Pick<DefinitionListItemProps, 'note' | 'name'> {
direction?: DefinitionListDirection;
}

export function Term({note, name, direction}: TermProps) {
export function TermContent({note, name, direction}: TermProps) {
const noteElement = note ? (
<React.Fragment>
&nbsp;
Expand All @@ -65,7 +64,7 @@ export function Term({note, name, direction}: TermProps) {
return (
<React.Fragment>
<div className={b('term-wrapper')}>
<span title={getTitle(name)}>{name}</span>
{name}
{noteElement}
</div>
{direction === 'horizontal' && <div className={b('dots')} />}
Expand Down
10 changes: 0 additions & 10 deletions src/components/DefinitionList/utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import type React from 'react';

export function isUnbreakableOver(limit: number) {
return function (value: string): boolean {
const posibleLines = value.split(/\s+/);

return posibleLines.some((line) => line.length > limit);
};
}

export function getTitle(content?: React.ReactNode) {
if (typeof content === 'string' || typeof content === 'number') {
return String(content);
}

return undefined;
}

0 comments on commit e5cde3a

Please sign in to comment.