@ndla/ui 44.0.8 → 44.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,13 +29,12 @@ const classes = new BEMHelper({
29
29
  });
30
30
 
31
31
  type ArticleWrapperProps = {
32
- id: string;
33
32
  modifier?: string;
34
33
  children: ReactNode;
35
34
  };
36
35
 
37
- export const ArticleWrapper = forwardRef<HTMLElement, ArticleWrapperProps>(({ children, modifier, id }, ref) => (
38
- <article id={id} {...classes(undefined, modifier)} ref={ref}>
36
+ export const ArticleWrapper = forwardRef<HTMLElement, ArticleWrapperProps>(({ children, modifier }, ref) => (
37
+ <article {...classes(undefined, modifier)} ref={ref}>
39
38
  {children}
40
39
  </article>
41
40
  ));
@@ -44,9 +43,10 @@ type ArticleTitleProps = {
44
43
  icon?: ReactNode;
45
44
  label?: string;
46
45
  children: ReactNode;
46
+ id: string;
47
47
  };
48
48
 
49
- export const ArticleTitle = ({ children, icon, label }: ArticleTitleProps) => {
49
+ export const ArticleTitle = ({ children, icon, label, id }: ArticleTitleProps) => {
50
50
  const modifiers = [];
51
51
  if (icon) {
52
52
  modifiers.push('icon');
@@ -62,7 +62,7 @@ export const ArticleTitle = ({ children, icon, label }: ArticleTitleProps) => {
62
62
  <div {...classes('title', modifiers)}>
63
63
  {icon}
64
64
  {labelView}
65
- <Heading element="h1" headingStyle="h1" tabIndex={-1}>
65
+ <Heading element="h1" headingStyle="h1" id={id} tabIndex={-1}>
66
66
  {children}
67
67
  </Heading>
68
68
  </div>
@@ -197,7 +197,7 @@ export const Article = ({
197
197
 
198
198
  return (
199
199
  <div ref={wrapperRef}>
200
- <ArticleWrapper modifier={modifier} id={id} ref={articleRef}>
200
+ <ArticleWrapper modifier={modifier} ref={articleRef}>
201
201
  <LayoutItem layout="center">
202
202
  {accessMessage && <ArticleAccessMessage message={accessMessage} />}
203
203
 
@@ -209,7 +209,7 @@ export const Article = ({
209
209
  <ArticleHeaderWrapper competenceGoals={competenceGoals}>
210
210
  {heartButton ? <ArticleFavoritesButtonWrapper>{heartButton}</ArticleFavoritesButtonWrapper> : null}
211
211
 
212
- <ArticleTitle icon={icon} label={messages.label}>
212
+ <ArticleTitle id={id} icon={icon} label={messages.label}>
213
213
  {title}
214
214
  </ArticleTitle>
215
215
  <ArticleIntroduction renderMarkdown={renderMarkdown}>{introduction}</ArticleIntroduction>
@@ -95,7 +95,7 @@ const CampaignBlock = ({
95
95
  }: Props) => {
96
96
  return (
97
97
  <Container className={className} data-type="campaign-block">
98
- {imageBefore && <StyledImg src={imageBefore.src} />}
98
+ {imageBefore && <StyledImg src={imageBefore.src} alt="" />}
99
99
  <TextWrapper>
100
100
  <Heading css={headingStyle}>{title.title}</Heading>
101
101
  <StyledDescription>{description.text}</StyledDescription>
@@ -104,7 +104,7 @@ const CampaignBlock = ({
104
104
  <Forward />
105
105
  </StyledLink>
106
106
  </TextWrapper>
107
- {imageAfter && <StyledImg src={imageAfter.src} />}
107
+ {imageAfter && <StyledImg src={imageAfter.src} alt="" />}
108
108
  </Container>
109
109
  );
110
110
  };
@@ -6,13 +6,14 @@
6
6
  *
7
7
  */
8
8
 
9
- import { ReactNode } from 'react';
9
+ import { CSSProperties, ReactNode, useMemo } from 'react';
10
10
  import { breakpoints, fonts, mq, spacing, spacingUnit } from '@ndla/core';
11
11
  import styled from '@emotion/styled';
12
12
  import { Article } from '../types';
13
13
  import LayoutItem from '../Layout';
14
14
  import { Heading } from '../Typography';
15
15
  import { ArticleByline } from '../Article';
16
+ import { useMastheadHeight } from '../Masthead';
16
17
 
17
18
  interface Props {
18
19
  article: Omit<Article, 'footNotes'>;
@@ -64,11 +65,13 @@ const StyledIntroduction = styled.div`
64
65
  `;
65
66
 
66
67
  export const FrontpageArticle = ({ article, id, isWide, licenseBox }: Props) => {
68
+ const { height = 0 } = useMastheadHeight();
69
+ const cssVars = useMemo(() => ({ '--masthead-height': `${height}px` } as unknown as CSSProperties), [height]);
67
70
  const { title, introduction, content } = article;
68
71
 
69
72
  if (isWide) {
70
73
  return (
71
- <StyledArticle data-wide={isWide}>
74
+ <StyledArticle data-wide={isWide} style={cssVars}>
72
75
  <LayoutItem>{content}</LayoutItem>
73
76
  </StyledArticle>
74
77
  );
@@ -79,7 +82,7 @@ export const FrontpageArticle = ({ article, id, isWide, licenseBox }: Props) =>
79
82
  ? article.copyright.creators
80
83
  : article.copyright.processors;
81
84
  return (
82
- <StyledArticle>
85
+ <StyledArticle style={cssVars}>
83
86
  <LayoutItem>
84
87
  <Heading id={id} headingStyle="h1" element="h1" margin="normal" tabIndex={-1}>
85
88
  {title}
package/src/Grid/Grid.tsx CHANGED
@@ -90,7 +90,7 @@ const Grid = ({ columns, border, children, background, size, ...rest }: GridProp
90
90
  const StyledGridParallaxItem = styled.div`
91
91
  position: relative;
92
92
  > div {
93
- top: 0px;
93
+ top: var(--masthead-height, 0px);
94
94
  position: sticky;
95
95
  }
96
96
  `;
@@ -39,6 +39,8 @@ const StyledCardContainer = styled(SafeLink)`
39
39
  }
40
40
 
41
41
  ${mq.range({ from: breakpoints.tablet })} {
42
+ min-height: 350px;
43
+ min-width: 250px;
42
44
  max-height: 350px;
43
45
  width: 250px;
44
46
  }
@@ -46,6 +48,7 @@ const StyledCardContainer = styled(SafeLink)`
46
48
 
47
49
  const StyledImg = styled.img`
48
50
  display: none;
51
+ flex: 1;
49
52
  border-radius: ${misc.borderRadius} ${misc.borderRadius} 0 0;
50
53
  width: 100%;
51
54
 
@@ -66,6 +69,7 @@ const StyledTitle = styled.span`
66
69
  min-height: 70px;
67
70
  align-items: center;
68
71
  padding-left: ${spacing.nsmall};
72
+ margin-top: auto;
69
73
 
70
74
  border: 1px solid ${colors.brand.lighter};
71
75
  border-radius: 0 0 ${misc.borderRadius} ${misc.borderRadius};
@@ -82,8 +86,8 @@ const StyledTitle = styled.span`
82
86
  const ProgrammeCard = ({ title, narrowImage, wideImage, url }: Programme) => {
83
87
  return (
84
88
  <StyledCardContainer to={url}>
85
- {narrowImage && <StyledImg data-is-mobile="false" src={narrowImage.src} alt={narrowImage.alt} />}
86
- {wideImage && <StyledImg data-is-mobile="true" src={wideImage.src} alt={wideImage.alt} />}
89
+ {narrowImage && <StyledImg data-is-mobile="false" src={narrowImage.src} loading="lazy" alt={narrowImage.alt} />}
90
+ {wideImage && <StyledImg data-is-mobile="true" src={wideImage.src} loading="lazy" alt={wideImage.alt} />}
87
91
  <StyledTitle>{title.title}</StyledTitle>
88
92
  </StyledCardContainer>
89
93
  );