Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: migrate buttons folder #2672

Merged
merged 25 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
9b674cc
feat: migrate Button
Shurtu-gal Feb 19, 2024
ecda68b
feat: migrate ApplyJob
Shurtu-gal Feb 19, 2024
0320b45
feat: migrate ChapterSuggestions and add icons
Shurtu-gal Feb 19, 2024
d0bf7b0
chore: rename folder
Shurtu-gal Feb 19, 2024
17246ef
feat: migrate icons
Shurtu-gal Feb 19, 2024
a7ffbc0
feat: migrate Docs and GitHUb buttons
Shurtu-gal Feb 19, 2024
6fcef9d
feat: migrate rest of the buttons
Shurtu-gal Feb 19, 2024
6ca5cc2
Trigger Netlify
akshatnema Feb 19, 2024
2f25e94
fix: types in some icons
Shurtu-gal Feb 19, 2024
3bfc66d
Merge remote-tracking branch 'upstream/migrate-ts' into feat/migrate-…
Shurtu-gal Feb 21, 2024
45b6c1f
chore: add blank line
Shurtu-gal Feb 22, 2024
60b639c
chore: run eslint over the code
Shurtu-gal Feb 23, 2024
ab685fc
chore: remove uneeded jobs buttons
Shurtu-gal Feb 23, 2024
27f68d6
feat: fix components and add styles to _app
Shurtu-gal Feb 23, 2024
c88263e
chore: add preview
Shurtu-gal Feb 23, 2024
df5f690
chore: remove preview
Shurtu-gal Feb 24, 2024
30c76f9
chore: add JSDoc comments in icons
Shurtu-gal Feb 24, 2024
b096ce0
chore: format the code
Shurtu-gal Feb 24, 2024
850ba7d
chore: add JSDoc comments in buttons
Shurtu-gal Feb 24, 2024
127d347
Merge branch 'migrate-ts' into feat/migrate-buttons
Shurtu-gal Feb 24, 2024
b0bccb3
Merge branch 'migrate-ts' into feat/migrate-buttons
akshatnema Feb 26, 2024
41ba98b
Merge branch 'migrate-ts' into feat/migrate-buttons
akshatnema Feb 27, 2024
8486e71
chore: change post from hardcode to import
Shurtu-gal Feb 28, 2024
46cb9c3
chore: add IDocs type for docs posts
Shurtu-gal Feb 28, 2024
3bda3a2
chore: add scripts in build script
Shurtu-gal Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions components/buttons/ApplyJob.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IJob } from '@/types/job';
Shurtu-gal marked this conversation as resolved.
Show resolved Hide resolved
import Button from './Button'

interface IApplyJobButtonProps {
job: IJob
className?: string
}

export default function ApplyJobButton({ job, className = '' }: IApplyJobButtonProps) {
const getHref = (contact: string) => {
try {
new URL(contact);
} catch (_) {
return `mailto:${contact}`;
}

return contact;
}

return (
<Button
href={getHref(job.contact)}
target="_blank"
text="Apply for this job"
className={className}
/>
)
}
Shurtu-gal marked this conversation as resolved.
Show resolved Hide resolved
77 changes: 77 additions & 0 deletions components/buttons/Button.tsx
Shurtu-gal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { twMerge } from "tailwind-merge";
import Link from 'next/link'

type IButtonProps = {
text: string;
icon?: React.ReactNode;
iconPosition?: 'left' | 'right';
target?: string;
bgClassName?: string;
textClassName?: string;
buttonSize?: 'small' | 'default';
type?: 'submit' | 'reset' | 'button';
} &
({
href: string;
} & React.AnchorHTMLAttributes<HTMLAnchorElement> | {
href: undefined | null;
} & React.ButtonHTMLAttributes<HTMLButtonElement>)


/**
* @description The Button component is a reusable button component that can be used to render a button or an anchor tag. It accepts a variety of props to customize the button's appearance and behavior.
* @description The component accepts button or anchor tag props based on the presence of the href prop. If the href prop is present, the component will render an anchor tag, otherwise it will render a button tag.
*/
Shurtu-gal marked this conversation as resolved.
Show resolved Hide resolved
export default function Button({
text,
type = 'button',
target = '_self',
icon,
iconPosition = 'right',
className,
bgClassName = twMerge(`bg-primary-500 hover:bg-primary-400`),
textClassName = twMerge(`text-white`),
buttonSize,
...props
}: IButtonProps) : React.ReactElement {

const smallButtonClasses = twMerge(`${bgClassName} ${textClassName} transition-all duration-500 ease-in-out rounded-md px-3 py-2 text-sm font-medium tracking-heading ${className || ''}`)
const classNames = twMerge(`${bgClassName} ${textClassName} transition-all duration-500 ease-in-out rounded-md px-4 py-3 text-md font-semibold tracking-heading ${className || ''}`)

if (!props.href) {
return (
<button {...props as React.ButtonHTMLAttributes<HTMLButtonElement>} type={type} className={buttonSize === 'small' ? smallButtonClasses : classNames} data-testid="Button-main" >
{
icon && iconPosition === 'left' && (
<span className="inline-block mr-2" data-testid="Button-icon-left">{icon}</span>
)
}
<span className="inline-block">{text}</span>
{
icon && iconPosition === 'right' && (
<span className="inline-block ml-2" data-testid="Button-icon-right">{icon}</span>
)
}
</button>
)
}

return (
<Link href={props.href} passHref>
<a {...props} target={target} rel="noopener noreferrer" className={buttonSize === 'small' ? smallButtonClasses : classNames} data-testid="Button-link">
{
icon && iconPosition === 'left' && (
<span className="inline-block mr-2">{icon}</span>
)
}
<span className="inline-block">{text}</span>
{
icon && iconPosition === 'right' && (
<span className="inline-block ml-2">{icon}</span>
)
}
</a>
</Link>
)
}

51 changes: 51 additions & 0 deletions components/buttons/ChapterSuggestion.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { HTMLAttributeAnchorTarget } from 'react'
import IconArrowRight from '../icons/ArrowRight'
import Link from 'next/link'
import { Url } from 'url'

export interface IChapterSuggestionProps {
href: Url
target?: HTMLAttributeAnchorTarget
title: string
description: string
linkText: string
className?: string
}

/**
*
* @param {Object} props - The props of the component
* @param {string} props.href - The URL of the chapter
* @param {string} props.target - The target of the link
* @param {string} props.title - The title of the chapter
* @param {string} props.description - The description of the chapter
* @param {string} props.linkText - The text of the link
* @param {string} props.className - The class name of the component
*/
export default function ChapterSuggestion({
href,
target = '_self',
title,
description,
linkText,
className,
}: IChapterSuggestionProps) {
return (
<Link href={href}>
<a
target={target}
rel="noopener noreferrer"
title={description}
className={`${className} flex flex-col mt-4 p-6 max-w-lg rounded shadow-md border border-gray-200 text-gray-900 transition-all duration-300 ease-in-out hover:shadow-lg hover:border-gray-300`}
data-testid="ChapterSuggestion-link"
>
<h5 className="text-lg font-medium font-sans antialiased mb-2">{title}</h5>
<p className="flex-1 mb-2 font-normal text-gray-600 font-sans antialiased">{description}</p>
<p className="text-primary-500 font-medium font-sans antialiased">
{linkText}
<IconArrowRight className="inline-block h-4" />
</p>
</a>
</Link>
)
}
31 changes: 31 additions & 0 deletions components/buttons/ChapterSuggestions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ChapterSuggestion, { IChapterSuggestionProps } from "./ChapterSuggestion";

interface IChapterSuggestionsProps {
suggestions: IChapterSuggestionProps[]
className?: string
}

/**
*
* @param {Object} props - The props of the component
* @param {Array} props.suggestions - The suggestions of the chapter
* @param {string} props.className - The class name of the component
*/
export default function ChapterSuggestions({ suggestions = [], className = '' }: IChapterSuggestionsProps) {
return (
<div className={`${className} grid grid-cols-1 gap-4 sm:grid-cols-2`}>
{
suggestions.map((suggestion, index) => (
<ChapterSuggestion
key={index}
href={suggestion.href}
title={suggestion.title}
description={suggestion.description}
linkText={suggestion.linkText}
className={suggestion.className}
/>
))
}
</div>
)
}
72 changes: 72 additions & 0 deletions components/buttons/DocsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { IPost } from '@/types/post';
import Link from 'next/link';

export interface IDocsButtonProps {
post: IPost
className?: string
}

export default function DocsButton({ post, className = '' }: IDocsButtonProps) {
return (
<div className={`flex flex-row gap-4 mb-4 h-full ${className}`}>
<div className="w-1/2 h-auto">
{ post?.prevPage && <Link href={post.prevPage.href} passHref>
<a>
<div className="p-4 rounded shadow-md border border-gray-200 transition-all duration-300 ease-in-out hover:shadow-lg hover:border-gray-300 text-center lg:text-left cursor-pointer">
<div className="text-secondary-500" data-testid="DocsButton-Prevdiv">
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 inline mr-1"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M11 15l-3-3m0 0l3-3m-3 3h8M3 12a9 9 0 1118 0 9 9 0 01-18 0z"
/>
</svg>
<div className="my-auto font-bold text-sm inline uppercase">
Go Back
</div>
</div>
<div className="font-medium text-base my-2" data-testid="DocsButton-PrevPage" >{post.prevPage.title}</div>
</div>
</a>
</Link>
}
</div>
<div className="w-1/2 h-auto">
{ post?.nextPage && <Link href={post.nextPage.href} className='h-auto' passHref>
<a>
<div className="p-4 rounded shadow-md border border-gray-200 transition-all duration-300 ease-in-out hover:shadow-lg hover:border-gray-300 text-center lg:text-right cursor-pointer h-full">
<div className="text-secondary-500" data-testid="DocsButton-Nextdiv">
<div className="font-bold my-auto text-sm inline uppercase">
Up Next
</div>
<svg
xmlns="http://www.w3.org/2000/svg"
className="h-6 w-6 inline ml-1"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M13 9l3 3m0 0l-3 3m3-3H8m13 0a9 9 0 11-18 0 9 9 0 0118 0z"
/>
</svg>
</div>
<div className="font-medium text-base my-2" data-testid="DocsButton-NextPage">{post.nextPage.title}</div>
</div>
</a>
</Link>
}
</div>
</div>
);
}
10 changes: 10 additions & 0 deletions components/buttons/GitHubIssue.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'

export default function GitHubIssue({ className = '' }) {
return (
<a className={`bg-black text-white flex flex-row lg:w-6/12 shadow-md hover:shadow-lg transition-all duration-500 ease-in-out py-2 rounded justify-center ${className}`} href='https://github.com/asyncapi/website/issues/new?assignees=alequetzalli+-&labels=%F0%9F%93%91+docs&template=docs.yml&title=%5B%F0%9F%93%91+Docs%5D%3A+' target='_blank' rel='noopener noreferrer' data-testid="GithubIssue-Link">
<img src='/img/logos/github-fill.svg' className='mr-2' alt="Github:AsyncAPI" />
Create Issue on GitHub
</a>
)
}
39 changes: 39 additions & 0 deletions components/buttons/GithubButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Button from './Button'
import IconGithub from '../icons/Github'
import { IButtonDefaultProps } from './types';
// TODO: add this again when we have i18n
// import { useTranslation } from '../../lib/i18n'

interface IGithubButtonProps extends IButtonDefaultProps {
inNav?: boolean;
}

export default function GithubButton({
text = 'githubButton',
href = 'https://github.com/asyncapi',
target = '_blank',
iconPosition = 'left',
className,
inNav
}: IGithubButtonProps) {

// TODO: add this again when we have i18n
// const { t } = useTranslation("common");

return (
<Button
// TODO: add this again when we have i18n
// text={t(text)}
text={text}
icon={<IconGithub className="inline-block -mt-1 w-6 h-6" />}
href={href}
iconPosition={iconPosition}
target={target}
className={className}
data-testid="Github-button"
bgClassName="bg-gray-800 hover:bg-gray-700"
buttonSize={ inNav ? "small" : "default" }
/>
)
}

34 changes: 34 additions & 0 deletions components/buttons/GoogleCalendarButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Button from './Button';
import IconGoogleCalendar from '../icons/GoogleCalendar';
import { IButtonDefaultProps } from './types';
// TODO: add this again when we have i18n
// import { useTranslation } from '../../lib/i18n';

interface IGoogleCalendarButtonProps extends IButtonDefaultProps {}

export default function GoogleCalendarButton({
text = 'googleCalendarBtn',
href,
target = '_blank',
iconPosition = 'left',
className,
}: IGoogleCalendarButtonProps) {

// TODO: add this again when we have i18n
// const { t } = useTranslation('common');

return (
<Button
// TODO: add this again when we have i18n
// text={t(text)}
text={text}
icon={<IconGoogleCalendar />}
href={href}
iconPosition={iconPosition}
target={target}
className={`text-center block mt-2 md:mt-0 md:inline-block text-gray-900 ${className}`}
bgClassName="bg-gray-200 hover:bg-gray-100"
/>
)
}

34 changes: 34 additions & 0 deletions components/buttons/ICSFileButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Button from './Button';
import IconCalendar from '../icons/Calendar';
// TODO: add this again when we have i18n
// import { useTranslation } from '../../lib/i18n';
import { IButtonDefaultProps } from './types';

interface IICSFButtonProps extends IButtonDefaultProps {}

export default function ICSFButton({
text = 'icsFileBtn',
href,
target = '_blank',
iconPosition = 'left',
className,
}: IICSFButtonProps) {

// TODO: add this again when we have i18n
// const { t } = useTranslation('common');

return (
<Button
// TODO: add this again when we have i18n
// text={t(text)}
text={text}
icon={<IconCalendar />}
href={href}
iconPosition={iconPosition}
target={target}
className={`text-center block mt-2 md:mt-0 md:inline-block text-gray-900 ${className}`}
bgClassName="bg-gray-200 hover:bg-gray-100"
/>
)
}

Loading
Loading