diff --git a/src/community/advanced-data-card.tsx b/src/community/advanced-data-card.tsx index 8aba0fbed..1f945d056 100644 --- a/src/community/advanced-data-card.tsx +++ b/src/community/advanced-data-card.tsx @@ -13,13 +13,11 @@ import {vars} from '../skins/skin-contract.css'; import Box from '../box'; import Touchable from '../touchable'; import classNames from 'classnames'; -import {CardActionsGroup, useInnerText} from '../card'; +import {CardActionsGroup} from '../card'; import {useTheme} from '../hooks'; import {getPrefixedDataAttributes} from '../utils/dom'; import Inline from '../inline'; import {applyCssVars} from '../utils/css'; -import Tag from '../tag'; -import {isBiggerHeading} from '../utils/headings'; import type {PressHandler} from '../touchable'; import type {ExclusifyUnion} from '../utils/utility-types'; @@ -29,6 +27,7 @@ import type Image from '../image'; import type {ButtonPrimary, ButtonLink} from '../button'; import type {DataAttributes, HeadingType, TrackingEvent} from '../utils/types'; import type {RendersNullableElement} from '../utils/renders-element'; +import type Tag from '../tag'; import type { HighlightedValueBlock, InformationBlock, @@ -60,12 +59,11 @@ type MaybeTouchableCard = ExclusifyUnion | T>; type CardContentProps = { headline?: string | RendersNullableElement; - headlineRef?: (instance: HTMLElement | null) => void; pretitle?: string; - pretitleAs?: HeadingType; + pretitleAs?: string; pretitleLinesMax?: number; title?: string; - titleAs: HeadingType; + titleAs?: string; titleLinesMax?: number; subtitle?: string; subtitleLinesMax?: number; @@ -75,12 +73,11 @@ type CardContentProps = { const CardContent = ({ headline, - headlineRef, pretitle, - pretitleAs, + pretitleAs = 'p', pretitleLinesMax, title, - titleAs, + titleAs = 'h3', titleLinesMax, subtitle, subtitleLinesMax, @@ -90,88 +87,36 @@ const CardContent = ({ const {textPresets} = useTheme(); return ( - /** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */ -
- {isBiggerHeading(titleAs, pretitleAs) ? ( - <> - {title && ( -
- - {title} - -
- )} - {headline && ( -
- {typeof headline === 'string' ? {headline} : headline} -
- )} - {pretitle && ( -
- - {pretitle} - -
- )} - - ) : ( - <> - {pretitle && ( -
- - {pretitle} - -
- )} - {headline && ( -
- {typeof headline === 'string' ? {headline} : headline} -
- )} - {title && ( -
- - {title} - -
- )} - - )} - {subtitle && ( -
- - {subtitle} - -
+ + {headline} + {pretitle && ( + + {pretitle} + )} + + + {title} + + + {subtitle} + {description && ( )} -
+ ); }; @@ -301,7 +246,7 @@ export const AdvancedDataCard = React.forwardRef @@ -376,7 +308,6 @@ export const AdvancedDataCard = React.forwardRef
{hasExtras && ( -
+
{extra.map((item, index) => { return (
diff --git a/src/community/blocks.tsx b/src/community/blocks.tsx index 53068dd1a..0dd28a0b9 100644 --- a/src/community/blocks.tsx +++ b/src/community/blocks.tsx @@ -1,258 +1,277 @@ import * as React from 'react'; -import {Avatar, Image, Box, ResponsiveLayout, StackingGroup, Tag, Stack} from '..'; -import { - HighlightedValueBlock, - InformationBlock, - ProgressBlock, - RowBlock, - SimpleBlock, - ValueBlock, -} from './blocks'; -import imgExample from '../__stories__/images/avatar.jpg'; +import Stack from '../stack'; +import * as styles from './blocks.css'; +import * as mediaStyles from '../image.css'; +import {Text2, Text3, Text5, Text8} from '../text'; import {vars} from '../skins/skin-contract.css'; +import Inline from '../inline'; +import Box from '../box'; +import {ProgressBar} from '../progress-bar'; +import classNames from 'classnames'; +import {applyCssVars} from '../utils/css'; -import type {TagType} from '../tag'; +import type StackingGroup from '../stacking-group'; +import type Image from '../image'; +import type Tag from '../tag'; +import type {RendersNullableElement} from '../utils/renders-element'; +import type {ExclusifyUnion} from '../utils/utility-types'; -export default { - title: 'Community/Blocks', - parameters: { - fullScreen: true, - }, -}; - -type RowBlockArgs = { - title: string; - description: string; - stackingGroup: boolean; -}; +interface BlockContentProps { + title?: string; + description?: ReadonlyArray | string; +} -export const BlockRow: StoryComponent = ({title, description, stackingGroup}) => { +const BlockContent = ({title, description}: BlockContentProps) => { + const descriptionLines = typeof description === 'string' ? [description] : description; return ( - - - - - - - - - - - - ) : undefined - } - /> - - - - +
+ + {title} + + + {descriptionLines && + descriptionLines.map((paragraph, i) => ( + + {paragraph} + + ))} +
); }; -BlockRow.storyName = 'RowBlock'; -BlockRow.args = { - title: 'title', - description: 'description', - stackingGroup: true, -}; +interface RowBlockBaseProps { + title?: string; + 'aria-label'?: string; +} -type SimpleBlockArgs = { - description: string; - label: string; -}; +interface RowBlockWithDescription extends RowBlockBaseProps { + description?: string; +} + +interface RowBlockWithStackingGroup extends RowBlockBaseProps { + stackingGroup?: RendersNullableElement; +} + +type RowBlockProps = ExclusifyUnion; -export const BlockSimple: StoryComponent = ({description, label}) => { +export const RowBlock = ({ + title, + stackingGroup, + description, + 'aria-label': ariaLabel, +}: RowBlockProps): JSX.Element => { return ( - - - } - /> - - +
+ + {title && ( + + {title} + + )} + {stackingGroup ? ( + stackingGroup + ) : ( + + {description} + + )} + +
); }; -BlockSimple.storyName = 'SimpleBlock'; -BlockSimple.args = { - description: 'description', - label: 'label', -}; +interface SimpleBlockProps { + image?: RendersNullableElement; + description?: string; + 'aria-label'?: string; + label?: string; +} -type InformationBlockArgs = { - title: string; - description: string; - value: string; - secondaryValue: string; +export const SimpleBlock = ({ + image, + description, + 'aria-label': ariaLabel, + label, +}: SimpleBlockProps): JSX.Element => { + return ( +
+ + +
+ {image} +
+ + {description} + +
+
+ + {label} + +
+
+
+ ); }; -export const BlockInformation: StoryComponent = ({ +interface InformationBlockProps { + title?: string; + description?: ReadonlyArray | string; + value?: string; + secondaryValue?: string; + valueColor?: string; + 'aria-label'?: string; +} + +export const InformationBlock = ({ title, description, - value, secondaryValue, -}) => { + value, + valueColor = vars.colors.textPrimary, + 'aria-label': ariaLabel, +}: InformationBlockProps): JSX.Element => { return ( - - - - - + + +
+ + {secondaryValue} + + {value} +
+
); }; -BlockInformation.storyName = 'InformationBlock'; -BlockInformation.args = { - title: 'title', - description: 'description', - value: '20', - secondaryValue: '20', -}; - -type HighlightedValueBlockArgs = { - headline: string; - headlineType: TagType; +interface Heading { value: string; - text: string; - secondaryValue: string; - title: string; - description: string; -}; + text?: string; + valueColor?: string; +} + +interface HighlightedValueBlockProps { + headline?: RendersNullableElement; + headings?: ReadonlyArray; + title?: string; + description?: ReadonlyArray | string; + 'aria-label'?: string; +} -export const BlockHighlightedValue: StoryComponent = ({ +export const HighlightedValueBlock = ({ headline, - headlineType, - value, - text, - secondaryValue, + headings, title, description, -}) => { + 'aria-label': ariaLabel, +}: HighlightedValueBlockProps): JSX.Element => { return ( - - - {headline}} - title={title} - description={description} - headings={[ - {value, text}, - {value: secondaryValue, valueColor: vars.colors.textSecondary}, - ]} - /> - - - ); -}; +
+ {headline && {headline}} -BlockHighlightedValue.storyName = 'HighlightedValueBlock'; -BlockHighlightedValue.args = { - headline: 'Priority', - headlineType: 'promo', - text: 'text', - value: '20', - secondaryValue: '20', - title: 'title', - description: 'description', -}; -BlockHighlightedValue.argTypes = { - headlineType: { - options: ['promo', 'active', 'inactive', 'success', 'warning', 'error'], - control: {type: 'select'}, - }, + {headings && ( + + {headings.map((heading, index) => ( + + + {heading.value} + + + {heading.text} + + + ))} + + )} + {title || description ? ( + + + + ) : null} +
+ ); }; -type ValueBlockArgs = { - title: string; - value: string; - description: string; -}; +interface ValueBlockProps { + title?: string; + value?: string; + description?: ReadonlyArray | string; + valueColor?: string; + 'aria-label'?: string; +} -export const BlockValue: StoryComponent = ({title, value, description}) => { +export const ValueBlock = ({ + title, + value, + description, + valueColor = vars.colors.textPrimary, + 'aria-label': ariaLabel, +}: ValueBlockProps): JSX.Element => { return ( - - - - - +
+ + {title} + + {value} + +
); }; -BlockValue.storyName = 'ValueBlock'; -BlockValue.args = { - title: 'title', - description: 'description', - value: '20', -}; +interface ProgressBlockProps { + title?: string; + stackingGroup?: RendersNullableElement; -type ProgressBlockArgs = { - title: string; - stackingGroup: boolean; - progressPercent: number; - reverse: boolean; - value: string; - text: string; - description: string; -}; + progressPercent?: number; + reverse?: boolean; -export const BlockProgress: StoryComponent = ({ + heading: { + value: string; + valueColor?: string; + text: string; + }; + + description?: string; + 'aria-label'?: string; +} + +export const ProgressBlock = ({ title, stackingGroup, progressPercent, reverse, - value, - text, + heading, description, -}) => { + 'aria-label': ariaLabel, +}: ProgressBlockProps): JSX.Element => { return ( - - - - - - - - - - - ) : null - } - progressPercent={progressPercent} - reverse={reverse} - heading={{value, text}} - description={description} - /> - - +
+ + + + {title} + + {stackingGroup} + + {progressPercent !== undefined && ( + + )} + + {heading.value} + + {heading.text} + + + {description && ( + + {description} + + )} + +
); }; - -BlockProgress.storyName = 'ProgressBlock'; -BlockProgress.args = { - title: 'title', - stackingGroup: false, - progressPercent: 20, - reverse: false, - value: '20', - text: 'text', - description: 'description', -};