Skip to content

Commit

Permalink
#1344 Display File List always as rows variant (#1345)
Browse files Browse the repository at this point in the history
* #1344 Display File List always as rows variant

* #1344 Fix ts error
  • Loading branch information
radoslavzeman authored Sep 19, 2024
1 parent a93d063 commit 6448437
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 57 deletions.
60 changes: 13 additions & 47 deletions next/components/common/FileList/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { Typography } from '@bratislava/component-library'
import cn from 'utils/cn'

import FileCardWrapper from '@/components/cards/FileCardWrapper'
import ResponsiveCarousel from '@/components/common/Carousel/ResponsiveCarousel'
import { Enum_Componentsectionsfilelist_Variant, FileItemBlockFragment } from '@/services/graphql'
import { FileItemBlockFragment } from '@/services/graphql'

export type TFileSection = {
category?: string
Expand All @@ -16,22 +15,14 @@ export type FileListProps = {
className?: string
fileSections?: TFileSection[]
hideCategory?: boolean
variantFileList?: Enum_Componentsectionsfilelist_Variant
}

/**
* Figma: https://www.figma.com/file/17wbd0MDQcMW9NbXl6UPs8/DS-ESBS%2BBK%3A-Component-library?type=design&node-id=7940-21473&mode=dev
*/

// TODO remove grouping by category
const FileList = ({
className,
title,
text,
fileSections,
hideCategory,
variantFileList,
}: FileListProps) => {
const FileList = ({ className, title, text, fileSections, hideCategory }: FileListProps) => {
return (
<div className={cn('', className)}>
{title || text ? (
Expand All @@ -48,43 +39,18 @@ const FileList = ({
{fileSection.category && !hideCategory && (
<Typography type="h2">{fileSection.category}</Typography>
)}
{variantFileList === 'rows' && (
<ul className="mt-4 flex flex-col rounded-lg border-2 py-2 lg:mt-6">
{fileSection?.files.map((file, fileIndex) => (
// eslint-disable-next-line react/no-array-index-key
<li key={fileIndex} className="w-full">
<FileCardWrapper
fileItem={file}
variant={variantFileList}
hideBottomDivider={fileIndex === fileSection.files.length - 1}
/>
</li>
))}
</ul>
)}
{variantFileList === 'grid' && (
<div>
<div
className="mt-6 hidden grid-cols-3 gap-8 lg:grid"
data-cy="file-wrapper-desktop"
>
{fileSection?.files.map((file, fileIndex) => (
// eslint-disable-next-line react/no-array-index-key
<div key={fileIndex} className="w-full">
<FileCardWrapper fileItem={file} />
</div>
))}
</div>
<div className="lg:hidden" data-cy="file-wrapper-mobile">
<ResponsiveCarousel
items={fileSection?.files.map((file, fileIndex) => (
// eslint-disable-next-line react/no-array-index-key
<FileCardWrapper key={fileIndex} fileItem={file} />
))}
<ul className="mt-4 flex flex-col rounded-lg border-2 py-2 lg:mt-6">
{fileSection?.files.map((file, fileIndex) => (
// eslint-disable-next-line react/no-array-index-key
<li key={fileIndex} className="w-full">
<FileCardWrapper
fileItem={file}
variant="rows"
hideBottomDivider={fileIndex === fileSection.files.length - 1}
/>
</div>
</div>
)}
</li>
))}
</ul>
</div>
)
})}
Expand Down
10 changes: 2 additions & 8 deletions next/components/sections/AccordionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import FileList from '@/components/common/FileList/FileList'
import Institution from '@/components/common/Institution_Deprecated/Institution_Deprecated'
import NarrowText from '@/components/common/NarrowText/NarrowText'
import Markdown from '@/components/formatting/Markdown/Markdown'
import {
AccordionSectionFragment,
Enum_Componentsectionsfilelist_Variant,
} from '@/services/graphql'
import { AccordionSectionFragment } from '@/services/graphql'
import { isDefined } from '@/utils/isDefined'
import { groupByCategory, parsePageLink } from '@/utils/pageUtils_Deprecated'
import { isPresent } from '@/utils/utils'
Expand Down Expand Up @@ -71,10 +68,7 @@ const AccordionSection = ({ section }: AccordionSectionProps) => {
<Markdown content={item.content} variant="accordion" />
</NarrowText>
{item.fileList?.length ? (
<FileList
fileSections={[{ files: item.fileList.filter(isDefined) }]}
variantFileList={Enum_Componentsectionsfilelist_Variant.Rows}
/>
<FileList fileSections={[{ files: item.fileList.filter(isDefined) }]} />
) : null}
{link?.url && link.title && (
<Button href={link.url || '#'} variant="category-link">
Expand Down
3 changes: 1 addition & 2 deletions next/components/sections/FileListSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'

import FileList from '@/components/common/FileList/FileList'
import { Enum_Componentsectionsfilelist_Variant, FileListSectionFragment } from '@/services/graphql'
import { FileListSectionFragment } from '@/services/graphql'
import { groupByCategoryFileList } from '@/utils/pageUtils_Deprecated'
import { isPresent } from '@/utils/utils'

Expand All @@ -16,7 +16,6 @@ const FileListSection = ({ section }: FileListSectionProps) => {
title={section.title}
text={section.text}
hideCategory={!!section.title || !!section.text}
variantFileList={section.variantFileList ?? Enum_Componentsectionsfilelist_Variant.Grid}
fileSections={groupByCategoryFileList(section.fileList?.filter(isPresent) ?? [])}
/>
)
Expand Down

0 comments on commit 6448437

Please sign in to comment.