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

External link support in header #276

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion example/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ const stories2 = [
</p>
</div>
),
header: {externalLink: "https://github.com/mohitk05", profileImage: "https://picsum.photos/360/480", heading: "Mohit Karekar", subheading: "mohitk05"}
},
{
url:
Expand Down
26 changes: 18 additions & 8 deletions src/components/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import React from "react";
import { HeaderProps } from "./../interfaces";

const Header = ({ profileImage, heading, subheading }: HeaderProps) => (
<div style={styles.main}>
{profileImage && <img style={styles.img} src={profileImage} />}
<span style={styles.text}>
<p style={styles.heading}>{heading}</p>
<p style={styles.subheading}>{subheading}</p>
</span>
</div>
const Header = ({
externalLink,
profileImage,
heading,
subheading,
}: HeaderProps) => (
<a style={styles.link} href={externalLink} target="_blank" rel="noreferrer">
<div style={styles.main}>
{profileImage && <img style={styles.img} src={profileImage} />}
<span style={styles.text}>
<p style={styles.heading}>{heading}</p>
<p style={styles.subheading}>{subheading}</p>
</span>
</div>
</a>
);

const styles = {
main: {
display: "flex",
alignItems: "center",
},
link: {
textDecoration: "none",
},
img: {
width: 40,
height: 40,
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface Header {
heading: string;
subheading: string;
profileImage: string;
externalLink?: string;
}

export interface SeeMoreProps {
Expand All @@ -135,6 +136,7 @@ export interface HeaderProps {
profileImage: string;
heading: string;
subheading: string;
externalLink?: string;
}

export interface ProgressProps {
Expand Down
13 changes: 8 additions & 5 deletions src/renderers/wrappers/withHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ import React from "react";
import { Story } from "../../interfaces";
import Header from "./../../components/Header";

const withHeader: React.FC<React.PropsWithChildren<{
story: Story;
globalHeader: Function;
}>> = ({ story, globalHeader, children }) => {
const withHeader: React.FC<
React.PropsWithChildren<{
story: Story;
globalHeader: Function;
}>
> = ({ story, globalHeader, children }) => {
return (
<>
{children}
{story.header && (
<div style={{ position: "absolute", left: 12, top: 20, zIndex: 19 }}>
<div style={{ position: "absolute", left: 12, top: 20, zIndex: 1001 }}>
{typeof story === "object" ? (
globalHeader ? (
globalHeader(story.header)
) : (
<Header
externalLink={story.header.externalLink}
heading={story.header.heading}
subheading={story.header.subheading}
profileImage={story.header.profileImage}
Expand Down