Skip to content

Commit 3a80a0f

Browse files
Merge pull request #49 from Azure-Samples/mirza/fe/cta-colors
Add button style utility and apply styles in ShowcaseCard and ShowcaseListTile components
2 parents 5f822f2 + 8dfc575 commit 3a80a0f

3 files changed

Lines changed: 83 additions & 9 deletions

File tree

src/components/gallery/ShowcaseCard/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import ShowcaseDialog from "../ShowcaseDialog/index";
1313

1414
import type { User } from "../../../data/tags";
1515
import { getButtonText } from "../../../utils/buttonTextUtils";
16+
import { getButtonStyles } from "../../../utils/buttonStyleUtils";
1617
import OptimizedImage from "../../OptimizedImage";
1718

1819
const LEARNING_PATH_TAGS = [
@@ -59,6 +60,9 @@ function ShowcaseCard({
5960
const [isOpen, { setTrue: openDialog, setFalse: dismissDialog }] =
6061
useBoolean(false);
6162

63+
const buttonText = getButtonText(user.website, user.tags);
64+
const ctaStyles = getButtonStyles(buttonText);
65+
6266
const [githubData, setGithubData] = useState<GitHubRepoInfo>(null);
6367

6468
const fetchGitHubData = async (owner: string, repo: string) => {
@@ -141,7 +145,7 @@ function ShowcaseCard({
141145
key={displayTitle}
142146
tags={tags}
143147
cardPanel={false}
144-
buttonText={getButtonText(user.website, user.tags)}
148+
buttonText={buttonText}
145149
/>
146150
</div>
147151
<div style={{ padding: 16 }}>
@@ -166,24 +170,25 @@ function ShowcaseCard({
166170
{/* <CardFooter> */}
167171
{user.website && (
168172
<Button
169-
appearance="primary"
173+
appearance="outline"
170174
as="a"
171175
href={user.website}
172176
target="_blank"
173177
rel="noopener noreferrer"
174178
onClick={(e) => e.stopPropagation()}
175179
style={{
176180
width: "100%",
177-
fontSize: "16px",
178-
backgroundColor: "#0078d4",
181+
fontSize: "14px",
182+
fontWeight: 600,
179183
display: "flex",
180184
alignItems: "center",
181185
justifyContent: "center",
182186
paddingLeft: "16px",
183187
paddingRight: "16px",
188+
...ctaStyles,
184189
}}
185190
>
186-
<span>{getButtonText(user.website, user.tags)}</span>
191+
<span>{buttonText}</span>
187192
</Button>
188193
)}
189194
{/* </CardFooter> */}

src/components/gallery/ShowcaseListTile/index.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import styleCSS from "../ShowcaseCard/styles.module.css";
1111
import ShowcaseDialog from "../ShowcaseDialog/index";
1212
import ShowcaseCardTag from "../ShowcaseTag/index";
1313
import { getButtonText } from "../../../utils/buttonTextUtils";
14+
import { getButtonStyles } from "../../../utils/buttonStyleUtils";
1415
import OptimizedImage from "../../OptimizedImage";
1516

1617
export default function ShowcaseListTile({
@@ -22,6 +23,8 @@ export default function ShowcaseListTile({
2223
}) {
2324
const [isOpen, { setTrue: openDialog, setFalse: dismissDialog }] =
2425
useBoolean(false);
26+
const buttonText = getButtonText(user.website, user.tags);
27+
const ctaStyles = getButtonStyles(buttonText);
2528
const shouldUseLearningPathContent =
2629
!!user.learningPathTitle && !!user.learningPathDescription;
2730
const displayTitle = shouldUseLearningPathContent
@@ -87,7 +90,7 @@ export default function ShowcaseListTile({
8790
<ShowcaseCardTag
8891
tags={user.tags}
8992
cardPanel={false}
90-
buttonText={getButtonText(user.website, user.tags)}
93+
buttonText={buttonText}
9194
/>
9295
</div>
9396
<div className={styleCSS.listTitle}>{displayTitle}</div>
@@ -96,23 +99,25 @@ export default function ShowcaseListTile({
9699
</div>
97100
{user.website && (
98101
<Button
99-
appearance="primary"
102+
appearance="outline"
100103
as="a"
101104
href={user.website}
102105
target="_blank"
103106
rel="noopener noreferrer"
104107
onClick={(e) => e.stopPropagation()}
105108
style={{
106109
marginTop: 12,
107-
backgroundColor: "#0078d4",
110+
fontSize: "14px",
111+
fontWeight: 600,
108112
display: "flex",
109113
alignItems: "center",
110114
justifyContent: "center",
111115
paddingLeft: "16px",
112116
paddingRight: "16px",
117+
...ctaStyles,
113118
}}
114119
>
115-
<span>{getButtonText(user.website, user.tags)}</span>
120+
<span>{buttonText}</span>
116121
</Button>
117122
)}
118123
</div>

src/utils/buttonStyleUtils.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
export interface ButtonStyles {
7+
backgroundColor: string;
8+
border: string;
9+
color: string;
10+
borderRadius: string;
11+
}
12+
13+
const BUTTON_STYLE_MAP: Record<string, ButtonStyles> = {
14+
Documentation: {
15+
backgroundColor: "#ECF9FF",
16+
border: "1px solid #AED4F2",
17+
color: "#0078D4",
18+
borderRadius: "3px 3px 14px 14px",
19+
},
20+
"Solution Accelerator": {
21+
backgroundColor: "#F1FBF1",
22+
border: "1px solid #B7D8B7",
23+
color: "#107C10",
24+
borderRadius: "3px 3px 14px 14px",
25+
},
26+
Video: {
27+
backgroundColor: "#FEF7EE",
28+
border: "1px solid #DDC4A2",
29+
color: "#CE811D",
30+
borderRadius: "3px 3px 14px 14px",
31+
},
32+
Training: {
33+
backgroundColor: "#FAF4FF",
34+
border: "1px solid #CDBFDE",
35+
color: "#5C2D91",
36+
borderRadius: "3px 3px 14px 14px",
37+
},
38+
Workshop: {
39+
backgroundColor: "#FAF4FF",
40+
border: "1px solid #CDBFDE",
41+
color: "#5C2D91",
42+
borderRadius: "3px 3px 14px 14px",
43+
},
44+
Blog: {
45+
backgroundColor: "#FFEFFD",
46+
border: "1px solid #E6B9E1",
47+
color: "#B140A3",
48+
borderRadius: "3px 3px 14px 14px",
49+
},
50+
};
51+
52+
const DEFAULT_BUTTON_STYLES: ButtonStyles = {
53+
backgroundColor: "#ECF9FF",
54+
border: "1px solid #AED4F2",
55+
color: "#0078D4",
56+
borderRadius: "3px 3px 14px 14px",
57+
};
58+
59+
/**
60+
* Returns CTA button styles (background, border, text color, border-radius) based on button text.
61+
*/
62+
export function getButtonStyles(buttonText: string): ButtonStyles {
63+
return BUTTON_STYLE_MAP[buttonText] ?? DEFAULT_BUTTON_STYLES;
64+
}

0 commit comments

Comments
 (0)