-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(platform): add detail-view component
- Loading branch information
Showing
8 changed files
with
144 additions
and
27 deletions.
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
packages/platform/src/app/components/detail-view/DetailView.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { isArray, isNull, isNumber, isString, isUndefined } from 'lodash'; | ||
import React from 'react'; | ||
|
||
import { getClassName } from '@react-devui/utils'; | ||
|
||
export interface AppDetailViewProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'children'> { | ||
aList: { | ||
label: string; | ||
content: React.ReactNode; | ||
isEmpty?: boolean; | ||
}[]; | ||
aCol?: number | true | Record<'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl', number | true>; | ||
aGutter?: number | [number?, number?]; | ||
aLabelWidth?: string | number; | ||
aEmpty?: React.ReactNode; | ||
aVertical?: boolean; | ||
} | ||
|
||
export function AppDetailView(props: AppDetailViewProps): JSX.Element | null { | ||
const { | ||
aList, | ||
aCol = { xs: 12, md: 6, lg: 4, xxl: 3 }, | ||
aGutter, | ||
aLabelWidth, | ||
aEmpty = '-', | ||
aVertical = false, | ||
|
||
...restProps | ||
} = props; | ||
|
||
const [gutterX, gutterY] = isArray(aGutter) ? aGutter : [aGutter, aGutter]; | ||
const col = (() => { | ||
if (aCol === true) { | ||
return 'col'; | ||
} | ||
if (isNumber(aCol)) { | ||
return `col-${aCol}`; | ||
} | ||
|
||
const classNames: string[] = []; | ||
Object.entries(aCol).forEach(([breakpoint, col]) => { | ||
const className: (string | number)[] = ['col']; | ||
if (breakpoint !== 'xs') { | ||
className.push(breakpoint); | ||
} | ||
if (col !== true) { | ||
className.push(col); | ||
} | ||
classNames.push(className.join('-')); | ||
}); | ||
return classNames.join(' '); | ||
})(); | ||
|
||
const labelWidth = (() => { | ||
if (aVertical) { | ||
return undefined; | ||
} | ||
|
||
let maxLength = 0; | ||
if (aList) { | ||
aList.forEach((item) => { | ||
maxLength = Math.max(item.label.length, maxLength); | ||
}); | ||
} | ||
|
||
return isUndefined(aLabelWidth) ? maxLength + 1 + 'em' : aLabelWidth; | ||
})(); | ||
|
||
return ( | ||
<div | ||
{...restProps} | ||
className={getClassName(restProps.className, 'app-detail-view', 'row', { | ||
'app-detail-view--vertical': aVertical, | ||
[`gx-${gutterX}`]: gutterX, | ||
[`gy-${gutterY}`]: gutterY, | ||
})} | ||
> | ||
{aList.map(({ label, content, isEmpty: _isEmpty }) => { | ||
const isEmpty = isUndefined(_isEmpty) | ||
? (isString(content) && content.length === 0) || isUndefined(content) || isNull(content) | ||
: _isEmpty; | ||
return ( | ||
<div key={label} className={getClassName('app-detail-view__item', col)}> | ||
<div className="app-detail-view__item-label" style={{ width: labelWidth }}> | ||
{label} | ||
</div> | ||
<div className="app-detail-view__item-content">{isEmpty ? aEmpty : content}</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './DetailView'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@include b(detail-view) { | ||
@include m(vertical) { | ||
@include e(item) { | ||
flex-direction: column; | ||
} | ||
|
||
@include e(item-label) { | ||
&::after { | ||
content: none; | ||
} | ||
} | ||
} | ||
|
||
@include e(item) { | ||
display: inline-flex; | ||
gap: 8px; | ||
} | ||
|
||
@include e(item-label) { | ||
flex-shrink: 0; | ||
color: var(--#{$rd-prefix}text-color-sub); | ||
|
||
&::after { | ||
margin-left: 2px; | ||
content: ':'; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters