diff options
Diffstat (limited to 'src/components/atoms/lists')
| -rw-r--r-- | src/components/atoms/lists/description-list.module.scss | 42 | ||||
| -rw-r--r-- | src/components/atoms/lists/description-list.stories.tsx | 18 | ||||
| -rw-r--r-- | src/components/atoms/lists/description-list.tsx | 45 |
3 files changed, 86 insertions, 19 deletions
diff --git a/src/components/atoms/lists/description-list.module.scss b/src/components/atoms/lists/description-list.module.scss index 4758816..caa2711 100644 --- a/src/components/atoms/lists/description-list.module.scss +++ b/src/components/atoms/lists/description-list.module.scss @@ -6,18 +6,6 @@ gap: var(--spacing-2xs); margin: 0; - &__item { - display: flex; - flex-flow: column wrap; - gap: var(--spacing-2xs); - - @include mix.media("screen") { - @include mix.dimensions("sm") { - flex-flow: row wrap; - } - } - } - &__term { flex: 0 0 max-content; color: var(--color-fg-light); @@ -27,16 +15,40 @@ &__description { flex: 0 0 auto; margin: 0; + } + + &__item { + display: flex; + } + + &--inline &__item { + flex-flow: column wrap; @include mix.media("screen") { - @include mix.dimensions("sm") { - &:not(:first-of-type) { + @include mix.dimensions("xs") { + flex-flow: row wrap; + gap: var(--spacing-2xs); + + .list__description:not(:first-of-type) { &::before { content: "/"; - margin: 0 var(--spacing-2xs); + margin-right: var(--spacing-2xs); } } } } } + + &--column#{&}--responsive { + @include mix.media("screen") { + @include mix.dimensions("xs") { + flex-flow: row wrap; + gap: var(--spacing-lg); + } + } + } + + &--column &__item { + flex-flow: column wrap; + } } diff --git a/src/components/atoms/lists/description-list.stories.tsx b/src/components/atoms/lists/description-list.stories.tsx index c65241d..66d94af 100644 --- a/src/components/atoms/lists/description-list.stories.tsx +++ b/src/components/atoms/lists/description-list.stories.tsx @@ -6,6 +6,9 @@ import DescriptionListComponent, { export default { title: 'Atoms/Lists', component: DescriptionListComponent, + args: { + layout: 'column', + }, argTypes: { className: { control: { @@ -31,6 +34,21 @@ export default { value: {}, }, }, + layout: { + control: { + type: 'select', + }, + description: 'The list layout.', + options: ['column', 'inline'], + table: { + category: 'Options', + defaultValue: { summary: 'column' }, + }, + type: { + name: 'string', + required: false, + }, + }, }, } as ComponentMeta<typeof DescriptionListComponent>; diff --git a/src/components/atoms/lists/description-list.tsx b/src/components/atoms/lists/description-list.tsx index a5ab1d5..0a92465 100644 --- a/src/components/atoms/lists/description-list.tsx +++ b/src/components/atoms/lists/description-list.tsx @@ -22,9 +22,29 @@ export type DescriptionListProps = { */ className?: string; /** + * Set additional classnames to the `dd` element. + */ + descriptionClassName?: string; + /** + * Set additional classnames to the `dt`/`dd` couple wrapper. + */ + groupClassName?: string; + /** * The list items. */ items: DescriptionListItem[]; + /** + * The list items layout. Default: column. + */ + layout?: 'inline' | 'column'; + /** + * Define if the layout should automatically create rows/columns. + */ + responsiveLayout?: boolean; + /** + * Set additional classnames to the `dt` element. + */ + termClassName?: string; }; /** @@ -34,8 +54,16 @@ export type DescriptionListProps = { */ const DescriptionList: VFC<DescriptionListProps> = ({ className = '', + descriptionClassName = '', + groupClassName = '', items, + layout = 'column', + responsiveLayout = false, + termClassName = '', }) => { + const layoutModifier = `list--${layout}`; + const responsiveModifier = responsiveLayout ? 'list--responsive' : ''; + /** * Retrieve the description list items wrapped in a div element. * @@ -45,10 +73,13 @@ const DescriptionList: VFC<DescriptionListProps> = ({ const getItems = (listItems: DescriptionListItem[]): JSX.Element[] => { return listItems.map(({ id, term, value }) => { return ( - <div key={id} className={styles.list__item}> - <dt className={styles.list__term}>{term}</dt> + <div key={id} className={`${styles.list__item} ${groupClassName}`}> + <dt className={`${styles.list__term} ${termClassName}`}>{term}</dt> {value.map((currentValue, index) => ( - <dd key={`${id}-${index}`} className={styles.list__description}> + <dd + key={`${id}-${index}`} + className={`${styles.list__description} ${descriptionClassName}`} + > {currentValue} </dd> ))} @@ -57,7 +88,13 @@ const DescriptionList: VFC<DescriptionListProps> = ({ }); }; - return <dl className={`${styles.list} ${className}`}>{getItems(items)}</dl>; + return ( + <dl + className={`${styles.list} ${styles[layoutModifier]} ${styles[responsiveModifier]} ${className}`} + > + {getItems(items)} + </dl> + ); }; export default DescriptionList; |
