Skip to content

Commit 1568777

Browse files
committed
Allow minimum contrast to be controlled by storybook
1 parent f66c45b commit 1568777

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

src/app/components/FrostedGlassPromo/FrostedGlassPanel.jsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import styled from '@emotion/styled';
3-
import { node, string } from 'prop-types';
3+
import { node, number, string } from 'prop-types';
44

55
import { GEL_SPACING_DBL } from '@bbc/gel-foundations/spacings';
66
import useImageColour from '../../hooks/useImageColour';
@@ -51,10 +51,10 @@ const Children = styled.div`
5151
`}
5252
`;
5353

54-
const FrostedGlassPanel = ({ image, children }) => {
54+
const FrostedGlassPanel = ({ image, children, minimumContrast }) => {
5555
const { isLoading, colour } = useImageColour(image, {
5656
fallbackColour: FALLBACK_COLOUR,
57-
minimumContrast: 8,
57+
minimumContrast,
5858
contrastColour: '#ffffff',
5959
});
6060

@@ -71,6 +71,11 @@ const FrostedGlassPanel = ({ image, children }) => {
7171
FrostedGlassPanel.propTypes = {
7272
image: string.isRequired,
7373
children: node.isRequired,
74+
minimumContrast: number,
75+
};
76+
77+
FrostedGlassPanel.defaultProps = {
78+
minimumContrast: 8,
7479
};
7580

7681
export default FrostedGlassPanel;

src/app/components/FrostedGlassPromo/index.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const FrostedGlassPromo = ({
7474
url,
7575
eventTrackingData,
7676
index,
77+
minimumContrast,
7778
}) => {
7879
const { script, service } = useContext(ServiceContext);
7980

@@ -113,7 +114,10 @@ const FrostedGlassPromo = ({
113114
image,
114115
)}
115116
/>
116-
<FrostedGlassPanel image={image.smallSrc || image.src}>
117+
<FrostedGlassPanel
118+
image={image.smallSrc || image.src}
119+
minimumContrast={minimumContrast}
120+
>
117121
<H3>
118122
<A script={script} service={service} href={url} onClick={onClick}>
119123
{children}
@@ -131,6 +135,7 @@ FrostedGlassPromo.propTypes = {
131135
footer: node,
132136
eventTrackingData: shape({}),
133137
index: number,
138+
minimumContrast: number,
134139
image: shape({
135140
src: string.isRequired,
136141
alt: string.isRequired,
@@ -147,6 +152,7 @@ FrostedGlassPromo.defaultProps = {
147152
footer: null,
148153
eventTrackingData: null,
149154
index: 0,
155+
minimumContrast: 8,
150156
};
151157

152158
export default withData(FrostedGlassPromo);

src/app/components/FrostedGlassPromo/index.stories.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { withServicesKnob } from '@bbc/psammead-storybook-helpers';
3-
import { withKnobs, text } from '@storybook/addon-knobs';
3+
import { withKnobs, text, number } from '@storybook/addon-knobs';
44

55
import { RequestContextProvider } from '#contexts/RequestContext';
66
import { ServiceContextProvider } from '#contexts/ServiceContext';
@@ -35,11 +35,13 @@ const Component = props => {
3535
'Main Body',
3636
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean quam magna, lacinia ut arcu in, vulputate ultricies lectus. Vestibulum purus ligula, finibus vel ultrices in, pretium non neque. Sed mauris ante, mollis ac metus fermentum, vestibulum malesuada felis. Nullam a congue mauris. Nulla venenatis felis ac eleifend rutrum.',
3737
);
38+
const minimumContrast = number('Minimum Contrast', 8);
3839
return (
3940
<Wrappers {...props}>
4041
<Promo
4142
image={{ src: imageUrl, alt: '', width: 500, height: 250, ratio: 52 }}
4243
url="#"
44+
minimumContrast={minimumContrast}
4345
>
4446
{mainBody}
4547
</Promo>

0 commit comments

Comments
 (0)