Skip to content

Commit

Permalink
Merge pull request #174 from kausaltech/feat/support-custom-cat-icon-…
Browse files Browse the repository at this point in the history
…sizes

Support custom category icon sizes
  • Loading branch information
woodwoerk authored Sep 28, 2023
2 parents f21fc6d + 713644a commit 51dd26d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
4 changes: 2 additions & 2 deletions common/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 29 additions & 7 deletions components/contentblocks/CategoryPageHeaderBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import React, { useContext } from 'react';
import { gql, useQuery } from '@apollo/client';
import { Container, Row, Col } from 'reactstrap';
import styled from 'styled-components';
import { Theme } from '@kausal/themes/types';
import PlanContext, { usePlan } from 'context/plan';
import { Link } from 'common/links';
import { useTranslation } from 'common/i18n';
import CategoryMetaBar from 'components/actions/CategoryMetaBar';
import AttributesBlock, {
Attributes,
attributeHasValue,
} from 'components/common/AttributesBlock';
import AttributesBlock, { Attributes } from 'components/common/AttributesBlock';
import { useTheme } from 'common/theme';
import {
CategoryPageMainTopBlock,
Expand Down Expand Up @@ -40,6 +38,12 @@ export const GET_CATEGORY_ATTRIBUTE_TYPES = gql`
}
`;

enum IconSize {
S = 'S',
M = 'M',
L = 'L',
}

const CategoryHeader = styled.div`
width: 100%;
position: relative;
Expand Down Expand Up @@ -157,8 +161,20 @@ const Breadcrumb = styled.div`
margin-bottom: ${(props) => props.theme.spaces.s100};
`;

const CategoryIconImage = styled.img`
max-height: ${(props) => props.theme.spaces.s600};
const getIconHeight = (size: IconSize = IconSize.M, theme: Theme) => {
switch (size) {
case IconSize.L:
return '180px';
case IconSize.S:
return theme.spaces.s400;
case IconSize.M:
default:
return theme.spaces.s600;
}
};

const CategoryIconImage = styled.img<{ size?: IconSize }>`
max-height: ${({ theme, size }) => getIconHeight(size, theme)};
margin-bottom: ${(props) => props.theme.spaces.s100};
`;

Expand Down Expand Up @@ -313,7 +329,13 @@ function CategoryPageHeaderBlock({
/
</Breadcrumb>
)}
{iconImage && <CategoryIconImage src={iconImage} alt />}
{iconImage && (
<CategoryIconImage
size={(page?.layout?.iconSize as IconSize) ?? undefined}
src={iconImage}
alt=""
/>
)}
<h1>
{identifier && <Identifier>{identifier}.</Identifier>} {title}
</h1>
Expand Down
1 change: 1 addition & 0 deletions pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const templatedCategoryPageFragment = gql`
fragment TemplatedCategoryPageFragment on CategoryPage {
layout {
__typename
iconSize
layoutMainTop {
__typename
... on CategoryPageAttributeTypeBlock {
Expand Down

0 comments on commit 51dd26d

Please sign in to comment.