-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) O3-3773 Support Summary Tiles component in esm-styleguide commons-lib #1113
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './summary-card-component'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useMemo } from 'react'; | ||
import { Tile, Column } from '@carbon/react'; | ||
import styles from './tile.scss'; | ||
|
||
export interface SummaryCardProps { | ||
columns: Array<SummaryCardColumn>; | ||
headerTitle: string; | ||
maxRowItems?: number; | ||
} | ||
|
||
export interface SummaryCardColumn { | ||
header: string; | ||
value: string; | ||
summary?: string; | ||
} | ||
|
||
export const SummaryCard: React.FC<SummaryCardProps> = ({ columns, headerTitle, maxRowItems }: SummaryCardProps) => { | ||
const groupedColumns = useMemo(() => { | ||
if (maxRowItems && columns.length > maxRowItems) { | ||
let groups: SummaryCardColumn[][] = []; | ||
for (let i = 0; i < columns.length; i += maxRowItems) { | ||
groups.push(columns.slice(i, i + maxRowItems)); | ||
} | ||
return groups; | ||
} | ||
return [columns]; | ||
}, [columns, maxRowItems]); | ||
|
||
return ( | ||
<Tile className={styles.tile}> | ||
<div className={styles.cardTitle}> | ||
<h4 className={styles.title}> {headerTitle} </h4> | ||
</div> | ||
{maxRowItems ? ( | ||
groupedColumns.map((group) => ( | ||
<Column className={styles.columnContainer}> | ||
{group.map((column) => ( | ||
<SummaryItem column={column} /> | ||
))} | ||
</Column> | ||
)) | ||
) : ( | ||
<Column className={styles.columnContainer}> | ||
{columns.map((column) => ( | ||
<SummaryItem column={column} /> | ||
))} | ||
</Column> | ||
)} | ||
</Tile> | ||
); | ||
}; | ||
|
||
function SummaryItem({ column }: { column: SummaryCardColumn }) { | ||
return ( | ||
<div className={styles.tileBox}> | ||
<div className={styles.tileBoxColumn}> | ||
<span className={styles.tileTitle}> {column.header} </span> | ||
<span className={styles.tileValue}>{column.value}</span> | ||
{column.summary && <span className={styles.tileSummary}>{column.summary}</span>} | ||
</div> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
@use '@carbon/styles/scss/colors'; | ||
@use '@carbon/styles/scss/spacing'; | ||
@use '@carbon/styles/scss/type'; | ||
@import '../root.scss'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't do this. Follow the guidelines Dennis suggested yesterday on the call (or look through the developer docs) |
||
|
||
.title { | ||
@extend .productiveHeading03; | ||
} | ||
|
||
.cardTitle { | ||
display: flex; | ||
justify-content: space-between; | ||
padding: spacing.$spacing-04 0 spacing.$spacing-04 spacing.$spacing-05; | ||
} | ||
|
||
.cardTitle > h4:after { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
content: ''; | ||
display: block; | ||
width: 2rem; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use the Carbon tokens for defining spacing wherever possible. This helps ensure that the UI remains consistent with Carbon guidelines. |
||
padding-top: 0.188rem; | ||
border-bottom: 0.375rem solid $brand-teal-01; | ||
} | ||
|
||
.tile { | ||
height: 100%; | ||
padding: 1px 0 16px 16px; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nothing over 1px should be specified in px. |
||
margin: 0.5rem; | ||
border: solid 1px #e0e0e0; | ||
display: flex; | ||
flex-direction: column; | ||
flex: 1; | ||
background-color: #ffffff; | ||
} | ||
|
||
.tileTitle { | ||
@include type.type-style('label-01'); | ||
display: block; | ||
} | ||
|
||
.columnContainer { | ||
margin: 0px 0px 20px 20px; | ||
font-size: 14px; | ||
font-weight: 500; | ||
font-stretch: normal; | ||
font-style: normal; | ||
line-height: 1.29; | ||
letter-spacing: 0.16px; | ||
color: #525252; | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.tileBoxColumn { | ||
width: 100%; | ||
display: 'flex'; | ||
flex-direction: 'row'; | ||
} | ||
|
||
.widgetContainer { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A number of these rules seem to not be used by this component, so they probably don't belong here. |
||
background-color: $ui-background; | ||
} | ||
|
||
.newServiceEnrolmentBtn { | ||
margin-bottom: 0.5em; | ||
text-align: right; | ||
} | ||
|
||
.newServiceEnrolmentBtn > button { | ||
background-color: $ui-background; | ||
} | ||
|
||
.widgetContainer :global(.cds--data-table) thead th button span { | ||
height: unset !important; | ||
} | ||
|
||
.tileSubTitle { | ||
height: 16px; | ||
font-size: 16px; | ||
line-height: 1.33; | ||
letter-spacing: 0.32px; | ||
color: #525252; | ||
display: block; | ||
} | ||
|
||
.tileValue { | ||
display: block; | ||
font-size: 20px; | ||
line-height: 1.29; | ||
color: #161616; | ||
display: block; | ||
margin: 15px 65px 24px 0; | ||
} | ||
|
||
.tabletTileTitle { | ||
margin: 0px 0px 10px 20px; | ||
font-size: 14px; | ||
font-weight: 500; | ||
font-stretch: normal; | ||
font-style: normal; | ||
line-height: 1.29; | ||
letter-spacing: 0.16px; | ||
color: #525252; | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
.tileBox { | ||
width: 25%; | ||
display: flex; | ||
flex-direction: row; | ||
flex: 1; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any time you're using a
map
you should supply akey
to the component, either derived from the data or at least using the index of the item.