gatsby-core-theme 44.0.18 → 44.0.20
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.
- package/CHANGELOG.md +22 -0
- package/package.json +1 -1
- package/src/components/molecules/carousel/default-slide/index.js +8 -9
- package/src/components/organisms/head/index.js +1 -0
- package/src/constants/responsiveBreakpoints.js +26 -0
- package/src/hooks/lazy-image/index.js +1 -0
- package/src/hooks/responsive-images/index.js +51 -0
- package/src/hooks/responsive-images/responsive-image.stories.js +111 -0
- package/src/hooks/responsive-images/responsive-image.test.js +40 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [44.0.20](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.19...v44.0.20) (2025-04-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fix test ([596cfa4](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/596cfa4980e551c8bdf73bb114647cfd70a168e4))
|
|
7
|
+
* image constant height ([e2e4821](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/e2e482171a6e3801193847ece33f8bd94bbf8251))
|
|
8
|
+
|
|
9
|
+
## [44.0.19](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.18...v44.0.19) (2025-04-17)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* add new responsive image hook ([8babdf9](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/8babdf982267920bb3a0fd7550616b4d19768c57))
|
|
15
|
+
* images dimension ([a7fd8ad](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/a7fd8adad91158e619593feece5be1361737dca3))
|
|
16
|
+
* more dynamic responsive images ([406971a](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/406971aaaec6543e74933e79a7a66851b8ea3048))
|
|
17
|
+
* small fix ([5e19d57](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/5e19d5713a9a30893c4eaf04e35c95cbc06d9d5d))
|
|
18
|
+
* small fix ([b65c9a1](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/b65c9a1dde8680ffcc3fad11359f46420027069d))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
* Merge branch 'tm-4326-images-picture' into 'master' ([d6e62ba](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/commit/d6e62ba00d60f74b2652d286950900d5d9eb8f33))
|
|
22
|
+
|
|
1
23
|
## [44.0.18](https://gitlab.com/g2m-gentoo/team-floyd/themes/gatsby-themes/compare/v44.0.17...v44.0.18) (2025-04-15)
|
|
2
24
|
|
|
3
25
|
|
package/package.json
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/* eslint-disable react/forbid-prop-types */
|
|
2
2
|
/* eslint-disable arrow-body-style */
|
|
3
|
+
/* eslint-disable react/no-danger */
|
|
3
4
|
import React from 'react';
|
|
4
5
|
import PropTypes from 'prop-types';
|
|
5
6
|
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
7
|
+
import ResponsiveImages from '~hooks/responsive-images';
|
|
8
|
+
import { getAltText } from '~helpers/getters';
|
|
8
9
|
import styles from './default-slide.module.scss';
|
|
9
10
|
|
|
10
11
|
const Slide = ({
|
|
11
12
|
item = {},
|
|
12
|
-
imageSizes = { width: 675, height: 930 },
|
|
13
13
|
slideTitle = '',
|
|
14
14
|
hideCaptions = false,
|
|
15
15
|
}) => {
|
|
16
16
|
return (
|
|
17
17
|
<>
|
|
18
18
|
{item.title && !hideCaptions && <span className={styles.title || ''}>{item.title}</span>}
|
|
19
|
-
|
|
20
|
-
<
|
|
19
|
+
{item.image && (
|
|
20
|
+
<ResponsiveImages
|
|
21
|
+
src={item?.image}
|
|
22
|
+
breakpointKey='sliders'
|
|
21
23
|
className={styles.image || ''}
|
|
22
|
-
src={imagePrettyUrl(item.image, imageSizes.width, imageSizes.height)}
|
|
23
24
|
alt={getAltText(item?.image_object, item.title || slideTitle)}
|
|
24
|
-
|
|
25
|
-
height={imageSizes.height}
|
|
25
|
+
|
|
26
26
|
/>
|
|
27
27
|
)}
|
|
28
28
|
{item.content && (
|
|
@@ -43,7 +43,6 @@ Slide.propTypes = {
|
|
|
43
43
|
label: PropTypes.string,
|
|
44
44
|
}),
|
|
45
45
|
hideCaptions: PropTypes.bool,
|
|
46
|
-
imageSizes: PropTypes.shape({ width: PropTypes.any, height: PropTypes.any }),
|
|
47
46
|
slideTitle: PropTypes.string,
|
|
48
47
|
};
|
|
49
48
|
|
|
@@ -55,6 +55,7 @@ const HeadData = ({ page = {}, siteInfo }) => {
|
|
|
55
55
|
{page.meta_robots && process.env.GATSBY_ACTIVE_ENV !== 'development' && (
|
|
56
56
|
<meta name="robots" content={page.meta_robots.join()} />
|
|
57
57
|
)}
|
|
58
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
58
59
|
|
|
59
60
|
{page.robot_options && <meta name="robots" content={getRobotOptions(page.robot_options)} />}
|
|
60
61
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable import/prefer-default-export */
|
|
2
|
+
export const responsiveBreakpoints = {
|
|
3
|
+
sliders: {
|
|
4
|
+
mobile: {
|
|
5
|
+
media: "(max-width: 767px)",
|
|
6
|
+
width: 304,
|
|
7
|
+
height: 158,
|
|
8
|
+
},
|
|
9
|
+
// tablet: {
|
|
10
|
+
// media: "(min-width: 768px) and (max-width: 1023px)",
|
|
11
|
+
// width: 675,
|
|
12
|
+
// height: 930,
|
|
13
|
+
// },
|
|
14
|
+
// laptop: {
|
|
15
|
+
// media: "(min-width: 1024px) and (max-width: 1439px)",
|
|
16
|
+
// width: 675,
|
|
17
|
+
// height: 930,
|
|
18
|
+
// },
|
|
19
|
+
desktop: {
|
|
20
|
+
media: "(min-width: 768px)",
|
|
21
|
+
width: 675,
|
|
22
|
+
height: 352,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import { imagePrettyUrl } from '~helpers/getters';
|
|
4
|
+
import { responsiveBreakpoints } from '~constants/responsiveBreakpoints';
|
|
5
|
+
|
|
6
|
+
export default function ResponsiveImages({
|
|
7
|
+
src,
|
|
8
|
+
alt = '',
|
|
9
|
+
style = {},
|
|
10
|
+
className,
|
|
11
|
+
loading = 'lazy',
|
|
12
|
+
breakpointKey = '',
|
|
13
|
+
}) {
|
|
14
|
+
|
|
15
|
+
const breakpoints = breakpointKey && responsiveBreakpoints[breakpointKey]
|
|
16
|
+
? responsiveBreakpoints[breakpointKey]
|
|
17
|
+
: {};
|
|
18
|
+
|
|
19
|
+
return (
|
|
20
|
+
<picture>
|
|
21
|
+
{Object?.entries(breakpoints)?.map(([device, config]) => (
|
|
22
|
+
<source
|
|
23
|
+
key={device}
|
|
24
|
+
media={config?.media}
|
|
25
|
+
srcSet={imagePrettyUrl(src, config?.width, config?.height)}
|
|
26
|
+
width={config?.width}
|
|
27
|
+
height={config?.height}
|
|
28
|
+
/>
|
|
29
|
+
))}
|
|
30
|
+
{/* Fallback */}
|
|
31
|
+
<img
|
|
32
|
+
loading={loading}
|
|
33
|
+
className={className}
|
|
34
|
+
alt={alt === 'null' ? '' : alt}
|
|
35
|
+
width={breakpoints?.desktop?.width}
|
|
36
|
+
height={breakpoints?.desktop?.height}
|
|
37
|
+
src={imagePrettyUrl(src, breakpoints?.desktop?.width, breakpoints?.desktop?.height)}
|
|
38
|
+
style={style}
|
|
39
|
+
/>
|
|
40
|
+
</picture>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
ResponsiveImages.propTypes = {
|
|
45
|
+
src: PropTypes.string,
|
|
46
|
+
breakpointKey: PropTypes.string,
|
|
47
|
+
alt: PropTypes.string,
|
|
48
|
+
style: PropTypes.shape({}),
|
|
49
|
+
className: PropTypes.string,
|
|
50
|
+
loading: PropTypes.string,
|
|
51
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/* eslint-disable import/no-extraneous-dependencies */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import {
|
|
4
|
+
Title,
|
|
5
|
+
Subtitle,
|
|
6
|
+
Description,
|
|
7
|
+
Primary,
|
|
8
|
+
Stories,
|
|
9
|
+
PRIMARY_STORY,
|
|
10
|
+
ArgsTable,
|
|
11
|
+
} from '@storybook/addon-docs/blocks';
|
|
12
|
+
|
|
13
|
+
import ResponsiveImages from '.';
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
title: 'Theme/Hooks/Responsive Image',
|
|
17
|
+
component: ResponsiveImages,
|
|
18
|
+
argTypes: {
|
|
19
|
+
|
|
20
|
+
style: {
|
|
21
|
+
name: 'style',
|
|
22
|
+
type: { name: 'object', required: false },
|
|
23
|
+
defaultValue: '',
|
|
24
|
+
description: 'Additional styles for the image.',
|
|
25
|
+
table: {
|
|
26
|
+
type: { summary: 'object' },
|
|
27
|
+
defaultValue: { summary: '' },
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
className: {
|
|
31
|
+
name: 'className',
|
|
32
|
+
type: { name: 'string', required: false },
|
|
33
|
+
defaultValue: '',
|
|
34
|
+
description: 'Additional class name for the image.',
|
|
35
|
+
table: {
|
|
36
|
+
type: { summary: 'string' },
|
|
37
|
+
defaultValue: { summary: '' },
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
src: {
|
|
41
|
+
name: 'src',
|
|
42
|
+
type: { name: 'string', required: false },
|
|
43
|
+
defaultValue: '',
|
|
44
|
+
description: 'The image url.',
|
|
45
|
+
table: {
|
|
46
|
+
type: { summary: 'string' },
|
|
47
|
+
defaultValue: { summary: '' },
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
alt: {
|
|
51
|
+
name: 'alt',
|
|
52
|
+
type: { name: 'string', required: false },
|
|
53
|
+
defaultValue: '',
|
|
54
|
+
description: 'The image alt attribute.',
|
|
55
|
+
table: {
|
|
56
|
+
type: { summary: 'string' },
|
|
57
|
+
defaultValue: { summary: '' },
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
parameters: {
|
|
62
|
+
docs: {
|
|
63
|
+
description: {
|
|
64
|
+
component:
|
|
65
|
+
'A component that displays a lazy-loaded `<img>`. Use this component if you have 1 image to lazyload, or if you have images for different breakpoints and want the browser to decide when to serve the images based on the device, bandwidth, etc.',
|
|
66
|
+
},
|
|
67
|
+
page: () => (
|
|
68
|
+
<>
|
|
69
|
+
<Title />
|
|
70
|
+
<Subtitle />
|
|
71
|
+
<Description />
|
|
72
|
+
<Primary />
|
|
73
|
+
<Stories />
|
|
74
|
+
<ArgsTable story={PRIMARY_STORY} />
|
|
75
|
+
</>
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const Template = (args) => <ResponsiveImages {...args} />;
|
|
82
|
+
|
|
83
|
+
export const Default = Template.bind({});
|
|
84
|
+
Default.args = {
|
|
85
|
+
src: '313df295c19d7c5f137ceda9d0cc5df7.jpeg',
|
|
86
|
+
breakpointKey: 'sliders',
|
|
87
|
+
style: { 'border-radius': '1rem' },
|
|
88
|
+
className: 'my-class',
|
|
89
|
+
srcSet: '',
|
|
90
|
+
alt: 'Image Alt',
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const ErrorImageTemplate = (args) => <ResponsiveImages {...args} />;
|
|
94
|
+
|
|
95
|
+
export const BrokenURL = ErrorImageTemplate.bind({});
|
|
96
|
+
BrokenURL.story = {
|
|
97
|
+
parameters: {
|
|
98
|
+
docs: {
|
|
99
|
+
storyDescription:
|
|
100
|
+
'The example below shows a replacement image if the original image URL is broken (returns a 404). This is useful for showing a default image if you have broken image links. Your default image can be any element, use an `<img>` or React Icon.',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
args: {
|
|
104
|
+
src: '313df295c19d7c5f137ceda9d0cc5df7.jpeg',
|
|
105
|
+
breakpointKey: 'sliders',
|
|
106
|
+
style: { 'border-radius': '1rem' },
|
|
107
|
+
className: 'my-class',
|
|
108
|
+
srcSet: '',
|
|
109
|
+
alt: 'Image Alt',
|
|
110
|
+
},
|
|
111
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/* eslint-disable no-restricted-syntax */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { render, cleanup } from '@testing-library/react';
|
|
4
|
+
import '@testing-library/jest-dom/extend-expect';
|
|
5
|
+
import ResponsiveImages from '.';
|
|
6
|
+
|
|
7
|
+
describe('ResponsiveImages function', () => {
|
|
8
|
+
test('ResponsiveImages Component', () => {
|
|
9
|
+
const { container } = render(
|
|
10
|
+
<ResponsiveImages
|
|
11
|
+
src="jackpot-village-logo-9.png"
|
|
12
|
+
alt="test"
|
|
13
|
+
/>
|
|
14
|
+
);
|
|
15
|
+
expect(container.querySelector('img')).toBeTruthy();
|
|
16
|
+
expect(container.querySelector('img')).toHaveAttribute(
|
|
17
|
+
'src',
|
|
18
|
+
'https://cdn.images.com/jackpot-village-logo-9.png'
|
|
19
|
+
);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('ResponsiveImages Component with width and heigh', () => {
|
|
23
|
+
const { container } = render(
|
|
24
|
+
<ResponsiveImages
|
|
25
|
+
src="jackpot-village-logo-9.png"
|
|
26
|
+
alt="test"
|
|
27
|
+
breakpointKey='sliders'
|
|
28
|
+
/>
|
|
29
|
+
);
|
|
30
|
+
expect(container.querySelector('img')).toBeTruthy();
|
|
31
|
+
expect(container.querySelector('img')).toHaveAttribute(
|
|
32
|
+
'src',
|
|
33
|
+
'https://cdn.images.com/fit-in/675x352/jackpot-village-logo-9.png'
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
cleanup();
|
|
40
|
+
});
|