Skip to content

Commit 3969f35

Browse files
Refactor: Pull out boolean out of CSS
Co-authored-by: Daniel Clifton <[email protected]>
1 parent 70fc405 commit 3969f35

File tree

2 files changed

+21
-39
lines changed

2 files changed

+21
-39
lines changed

dotcom-rendering/src/components/ShareButton.importable.tsx

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,10 @@ type Context = 'ArticleMeta' | 'LiveBlock' | 'SubMeta' | 'ImageCaption';
4141

4242
const sharedButtonStyles = (
4343
sizeXSmall: boolean,
44-
context: Context,
45-
format: ArticleFormat,
44+
isNonLabsGalleryMeta: boolean,
4645
) => css`
4746
transition: none;
48-
border-color: ${format.design === ArticleDesign.Gallery &&
49-
format.theme !== ArticleSpecial.Labs &&
50-
context == 'ArticleMeta'
47+
border-color: ${isNonLabsGalleryMeta
5148
? themePalette('--share-button-border-meta')
5249
: sizeXSmall
5350
? themePalette('--share-button-xsmall-border')
@@ -135,17 +132,16 @@ export const CopyNativeShareButton = ({
135132
size,
136133
isLiveBlogMeta,
137134
isCopied,
138-
context,
139-
format,
135+
isNonLabsGalleryMeta,
140136
}: {
141137
onShare: () => void;
142138
size?: Size;
143139
isLiveBlogMeta: boolean;
144140
isCopied: boolean;
145-
context: Context;
146-
format: ArticleFormat;
141+
isNonLabsGalleryMeta: boolean;
147142
}) => {
148143
const sizeXSmall = size === 'xsmall';
144+
149145
return (
150146
<Button
151147
onClick={onShare}
@@ -158,7 +154,7 @@ export const CopyNativeShareButton = ({
158154
...(isCopied
159155
? [copiedButtonStyles(sizeXSmall)]
160156
: [buttonStyles(sizeXSmall)]),
161-
sharedButtonStyles(sizeXSmall, context, format),
157+
sharedButtonStyles(sizeXSmall, isNonLabsGalleryMeta),
162158
isLiveBlogMeta && liveBlogMobileMeta(isCopied),
163159
])}
164160
data-gu-name="share-button"
@@ -172,16 +168,15 @@ export const EmailLink = ({
172168
href,
173169
size,
174170
isLiveBlogMeta,
175-
format,
176-
context,
171+
isNonLabsGalleryMeta,
177172
}: {
178173
href: string;
179174
size?: Size;
180175
isLiveBlogMeta: boolean;
181-
format: ArticleFormat;
182-
context: Context;
176+
isNonLabsGalleryMeta: boolean;
183177
}) => {
184178
const sizeXSmall = size === 'xsmall';
179+
185180
return (
186181
<LinkButton
187182
href={href}
@@ -192,7 +187,7 @@ export const EmailLink = ({
192187
icon={<SvgShareWeb />}
193188
cssOverrides={css([
194189
buttonStyles(sizeXSmall),
195-
sharedButtonStyles(sizeXSmall, context, format),
190+
sharedButtonStyles(sizeXSmall, isNonLabsGalleryMeta),
196191
isLiveBlogMeta && liveBlogMobileMeta(false),
197192
])}
198193
>
@@ -231,6 +226,11 @@ export const ShareButton = ({
231226
const isLiveBlogMeta =
232227
format.design === ArticleDesign.LiveBlog && context === 'ArticleMeta';
233228

229+
const isNonLabsGalleryMeta =
230+
format.design === ArticleDesign.Gallery &&
231+
format.theme !== ArticleSpecial.Labs &&
232+
context === 'ArticleMeta';
233+
234234
const isDesktop = useMatchMedia(`(min-width: ${breakpoints.desktop}px)`);
235235

236236
const isLiveBlogBlockDesktop = isDesktop && context === 'LiveBlock';
@@ -281,8 +281,7 @@ export const ShareButton = ({
281281
size={size}
282282
isLiveBlogMeta={isLiveBlogMeta}
283283
isCopied={isCopied}
284-
context={context}
285-
format={format}
284+
isNonLabsGalleryMeta={isNonLabsGalleryMeta}
286285
/>
287286
);
288287
case 'copy':
@@ -299,8 +298,7 @@ export const ShareButton = ({
299298
size={size}
300299
isLiveBlogMeta={isLiveBlogMeta}
301300
isCopied={isCopied}
302-
context={context}
303-
format={format}
301+
isNonLabsGalleryMeta={isNonLabsGalleryMeta}
304302
/>
305303
);
306304
case 'email':
@@ -309,8 +307,7 @@ export const ShareButton = ({
309307
href={`mailto:?subject=${webTitle}&body=${shareData.url}`}
310308
size={size}
311309
isLiveBlogMeta={isLiveBlogMeta}
312-
context={context}
313-
format={format}
310+
isNonLabsGalleryMeta={isNonLabsGalleryMeta}
314311
/>
315312
);
316313
}

dotcom-rendering/src/components/ShareButton.stories.tsx

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,7 @@ export const LinkCopied = () => {
5959
isCopied={true}
6060
isLiveBlogMeta={false}
6161
size="small"
62-
format={{
63-
display: ArticleDisplay.Standard,
64-
theme: Pillar.News,
65-
design: ArticleDesign.Standard,
66-
}}
67-
context="ArticleMeta"
62+
isNonLabsGalleryMeta={false}
6863
/>
6964
);
7065
};
@@ -78,12 +73,7 @@ export const LiveBlogMobileMeta = () => {
7873
isCopied={false}
7974
isLiveBlogMeta={true}
8075
size="small"
81-
format={{
82-
display: ArticleDisplay.Standard,
83-
theme: Pillar.News,
84-
design: ArticleDesign.Standard,
85-
}}
86-
context="ArticleMeta"
76+
isNonLabsGalleryMeta={false}
8777
/>
8878
);
8979
};
@@ -111,12 +101,7 @@ export const EmailLinkStory = () => {
111101
`}
112102
isLiveBlogMeta={true}
113103
size="small"
114-
format={{
115-
display: ArticleDisplay.Standard,
116-
theme: Pillar.News,
117-
design: ArticleDesign.Standard,
118-
}}
119-
context="ArticleMeta"
104+
isNonLabsGalleryMeta={false}
120105
/>
121106
);
122107
};

0 commit comments

Comments
 (0)