Skip to content

Commit 28060e9

Browse files
author
dphuang2
committed
add cta button
1 parent 4d39cba commit 28060e9

File tree

11 files changed

+68
-2
lines changed

11 files changed

+68
-2
lines changed

generator/konfig-next-app/src/components/DemoHeader.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { TABS } from './HeaderButton'
77
import { HeaderTabs } from './HeaderTabs'
88
import type { GenerateLogoLinkResponse } from '@/utils/generate-logo-link'
99
import { MarkdownPageProps } from '@/utils/generate-props-for-markdown-page'
10+
import { KonfigYamlCommonType } from 'konfig-lib'
1011

1112
export const DemoHeader = observer(
1213
({
@@ -21,6 +22,7 @@ export const DemoHeader = observer(
2122
repo,
2223
logo,
2324
allMarkdown,
25+
cta,
2426
}: {
2527
opened: boolean
2628
setOpened: Dispatch<SetStateAction<boolean>>
@@ -33,6 +35,7 @@ export const DemoHeader = observer(
3335
owner: string
3436
repo: string
3537
logo: GenerateLogoLinkResponse
38+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
3639
}) => {
3740
return (
3841
<HeaderWrapper
@@ -46,6 +49,7 @@ export const DemoHeader = observer(
4649
opened={opened}
4750
setOpened={setOpened}
4851
title={state.portalTitle ? state.portalTitle : state.portalName}
52+
cta={cta}
4953
/>
5054
<HeaderTabs
5155
hasLightAndDarkLogo={typeof logo !== 'string'}

generator/konfig-next-app/src/components/DemoPortal.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import { DemoTableOfContents } from './DemoTableOfContents'
3131
import { DemoEditThisPage } from './DemoEditThisPage'
3232
import { DemoLastRan } from './DemoLastRan'
3333
import { DemoHeader } from './DemoHeader'
34-
import type { SocialObject } from 'konfig-lib/dist/KonfigYamlCommon'
34+
import type {
35+
KonfigYamlCommonType,
36+
SocialObject,
37+
} from 'konfig-lib/dist/KonfigYamlCommon'
3538
import Head from 'next/head'
3639
import { NAVBAR_WIDTH } from './ReferenceNavbar'
3740
import { proseContainerWidthStyles } from '@/utils/prose-container-width-styles'
@@ -176,6 +179,7 @@ export const DemoPortal = observer(
176179
repo,
177180
logo,
178181
allMarkdown,
182+
cta,
179183
}: {
180184
state: PortalState
181185
sandbox?: boolean
@@ -186,6 +190,7 @@ export const DemoPortal = observer(
186190
allMarkdown: MarkdownPageProps['allMarkdown']
187191
repo: string
188192
logo: GenerateLogoLinkResponse
193+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
189194
}) => {
190195
const theme = useMantineTheme()
191196
const { colorScheme, toggleColorScheme } = useMantineColorScheme()
@@ -330,6 +335,7 @@ export const DemoPortal = observer(
330335
state={state}
331336
sandbox={sandbox}
332337
logo={logo}
338+
cta={cta}
333339
/>
334340
}
335341
>

generator/konfig-next-app/src/components/DocumentationHeader.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { HeaderTabs } from './HeaderTabs'
66
import { TABS } from './HeaderButton'
77
import type { GenerateLogoLinkResponse } from '@/utils/generate-logo-link'
88
import { MarkdownPageProps } from '@/utils/generate-props-for-markdown-page'
9+
import { KonfigYamlCommonType } from 'konfig-lib'
910

1011
export function DocumentationHeader({
1112
opened,
@@ -17,6 +18,7 @@ export function DocumentationHeader({
1718
repo,
1819
logo,
1920
allMarkdown,
21+
cta,
2022
}: {
2123
opened: boolean
2224
setOpened: Dispatch<SetStateAction<boolean>>
@@ -27,6 +29,7 @@ export function DocumentationHeader({
2729
repo: string
2830
logo: GenerateLogoLinkResponse
2931
allMarkdown: MarkdownPageProps['allMarkdown']
32+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
3033
}) {
3134
return (
3235
<HeaderWrapper
@@ -40,6 +43,7 @@ export function DocumentationHeader({
4043
setOpened={setOpened}
4144
title={title}
4245
logo={logo}
46+
cta={cta}
4347
/>
4448
<HeaderTabs
4549
hasLightAndDarkLogo={typeof logo !== 'string'}

generator/konfig-next-app/src/components/LayoutHeader.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
Box,
33
Burger,
4+
Button,
45
Group,
56
MantineNumberSize,
67
MediaQuery,
@@ -19,6 +20,7 @@ import type { GenerateLogoLinkResponse } from '@/utils/generate-logo-link'
1920
import { useHeaderColor } from '@/utils/use-header-color'
2021
import { MarkdownPageProps } from '@/utils/generate-props-for-markdown-page'
2122
import { Search } from './Search'
23+
import { KonfigYamlCommonType } from 'konfig-lib'
2224

2325
const useLogoStyles = createStyles(() => ({
2426
logo: {
@@ -34,13 +36,15 @@ export const LayoutHeader = observer(
3436
breakpoint,
3537
allMarkdown,
3638
logo,
39+
cta,
3740
}: {
3841
title: string
3942
opened: boolean
4043
setOpened: Dispatch<SetStateAction<boolean>>
4144
breakpoint: MantineNumberSize
4245
logo: GenerateLogoLinkResponse
4346
allMarkdown: MarkdownPageProps['allMarkdown']
47+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
4448
}) => {
4549
const theme = useMantineTheme()
4650
const baseUrl = useBaseUrl()
@@ -109,6 +113,30 @@ export const LayoutHeader = observer(
109113
<div className="sm:hidden">
110114
<Search />
111115
</div>
116+
{cta ? (
117+
<Button
118+
variant={
119+
!hasLightAndDarkLogo
120+
? 'filled'
121+
: theme.colorScheme === 'dark'
122+
? 'light'
123+
: 'filled'
124+
}
125+
component="a"
126+
target="_blank"
127+
className="hidden sm:block"
128+
color={
129+
!hasLightAndDarkLogo
130+
? 'dark'
131+
: theme.colorScheme === 'dark'
132+
? 'brand'
133+
: 'dark'
134+
}
135+
href={cta.url}
136+
>
137+
{cta.label}
138+
</Button>
139+
) : null}
112140
<ColorSchemeToggle hasLightAndDarkLogo={typeof logo !== 'string'} />
113141
</Group>
114142
</Box>

generator/konfig-next-app/src/components/ReferenceHeader.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { TABS } from './HeaderButton'
55
import { HeaderTabs } from './HeaderTabs'
66
import type { GenerateLogoLinkResponse } from '@/utils/generate-logo-link'
77
import { MarkdownPageProps } from '@/utils/generate-props-for-markdown-page'
8+
import { KonfigYamlCommonType } from 'konfig-lib'
89

910
export function ReferenceHeader({
1011
opened,
@@ -17,6 +18,7 @@ export function ReferenceHeader({
1718
repo,
1819
logo,
1920
allMarkdown,
21+
cta,
2022
}: {
2123
opened: boolean
2224
hasDocumentation: boolean
@@ -28,6 +30,7 @@ export function ReferenceHeader({
2830
allMarkdown: MarkdownPageProps['allMarkdown']
2931
repo: string
3032
logo: GenerateLogoLinkResponse
33+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
3134
}) {
3235
return (
3336
<HeaderWrapper
@@ -41,6 +44,7 @@ export function ReferenceHeader({
4144
setOpened={setOpened}
4245
title={title}
4346
logo={logo}
47+
cta={cta}
4448
/>
4549
<HeaderTabs
4650
hasLightAndDarkLogo={typeof logo !== 'string'}

generator/konfig-next-app/src/pages/[org]/[portal]/[demo].tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const DemoPage = observer(
6363
repo,
6464
faviconLink,
6565
logo,
66+
cta,
6667
}: InferGetStaticPropsType<typeof getStaticProps>) => {
6768
const state = useMemo(
6869
() =>
@@ -119,6 +120,7 @@ const DemoPage = observer(
119120
owner={owner}
120121
repo={repo}
121122
logo={logo}
123+
cta={cta}
122124
/>
123125
</MantineProvider>
124126
)

generator/konfig-next-app/src/pages/[org]/[portal]/docs/[[...doc]].tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ const DocumentationPage = observer(
104104
faviconLink,
105105
logo,
106106
metaDescription,
107+
cta,
107108
}: InferGetServerSidePropsType<typeof getStaticProps>) => {
108109
const theme = useMantineTheme()
109110
const { colorScheme } = useMantineColorScheme()
@@ -245,6 +246,7 @@ const DocumentationPage = observer(
245246
title={title}
246247
demos={demos}
247248
logo={logo}
249+
cta={cta}
248250
/>
249251
}
250252
>

generator/konfig-next-app/src/pages/[org]/[portal]/reference/[tag]/[operationId].tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const Operation = ({
9292
allMarkdown,
9393
logo,
9494
metaDescription,
95+
cta,
9596
}: InferGetStaticPropsType<typeof getStaticProps>) => {
9697
const { colors } = useMantineTheme()
9798
const { colorScheme } = useMantineColorScheme()
@@ -180,6 +181,7 @@ const Operation = ({
180181
<ReferenceHeader
181182
owner={owner}
182183
repo={repo}
184+
cta={cta}
183185
hasDocumentation={hasDocumentation}
184186
allMarkdown={allMarkdown}
185187
opened={opened}

generator/konfig-next-app/src/utils/generate-demos-from-github.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { generateDemosFromFilenameAndContent } from './generate-demos-from-file-
33
import { createOctokitInstance } from './octokit'
44
import { githubGetFileContent } from './github-get-file-content'
55
import { githubGetRepository } from './github-get-repository'
6-
import type { KonfigYamlType, SocialObject } from 'konfig-lib'
6+
import type {
7+
KonfigYamlCommonType,
8+
KonfigYamlType,
9+
SocialObject,
10+
} from 'konfig-lib'
711
import { Octokit } from '@octokit/rest'
812
import { generateFaviconLink } from './generate-favicon-link'
913
import {
@@ -46,6 +50,7 @@ export type FetchResult = {
4650
hasDocumentation: boolean
4751
faviconLink: string | null
4852
logo: GenerateLogoLinkResponse
53+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
4954
}
5055

5156
export type GenerationResult =
@@ -100,6 +105,7 @@ export async function generateDemosDataFromGithub({
100105
allMarkdown: MarkdownPageProps['allMarkdown']
101106
faviconLink: string | null
102107
logo: GenerateLogoLinkResponse
108+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
103109
}
104110
| { result: 'error'; reason: 'no demos' }
105111
| { result: 'error'; reason: 'demo not found' }
@@ -124,6 +130,7 @@ export async function generateDemosDataFromGithub({
124130
mainBranch,
125131
organization,
126132
portal,
133+
cta: fetchResult.cta,
127134
googleAnalyticsId: fetchResult.googleAnalyticsId,
128135
customSnippet: fetchResult.customSnippet,
129136
demo,
@@ -245,6 +252,7 @@ async function _fetch({
245252
primaryColor: konfigYaml.content.portal.primaryColor,
246253
mainBranch: repository.data.default_branch,
247254
logo: logoLink,
255+
cta: konfigYaml.content.portal?.cta ?? null,
248256
faviconLink,
249257
...(konfigYaml.content.portal.socials
250258
? { socials: konfigYaml.content.portal.socials }

generator/konfig-next-app/src/utils/generate-props-for-markdown-page.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
DocumentationConfig,
3+
KonfigYamlCommonType,
34
KonfigYamlType,
45
OperationObject,
56
getOperations,
@@ -58,6 +59,7 @@ export type MarkdownPageProps = {
5859
omitOwnerAndRepo: boolean
5960
faviconLink: string | null
6061
logo: GenerateLogoLinkResponse
62+
cta: NonNullable<KonfigYamlCommonType['portal']>['cta'] | null
6163
}
6264

6365
export async function generatePropsForMarkdownPage({
@@ -235,6 +237,7 @@ export async function generatePropsForMarkdownPage({
235237
breadcrumb,
236238
allMarkdown,
237239
operations,
240+
cta: konfigYaml.content.portal?.cta ?? null,
238241
defaultBranch,
239242
idToLabel,
240243
demos:

0 commit comments

Comments
 (0)