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

[C] improvements to slideout and share buttons #124

Merged
merged 1 commit into from
Nov 29, 2023
Merged
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
8 changes: 8 additions & 0 deletions packages/epo-react-lib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,11 @@

- add signature overloads to `token`
- export `ImageShape`, `Option`, and `ListBoxOption` from their modules

## 2.0.10

- add `showText` to share buttons to optionally display labels
- add links as a valid `menuitem` in Slideout
- add `InfoCircle` icon
- reset all icons to stroke-width: 0
- minor refactor to use CSS variables for backgrounds and hovers.
2 changes: 1 addition & 1 deletion packages/epo-react-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@rubin-epo/epo-react-lib",
"description": "Rubin Observatory Education & Public Outreach team React UI library.",
"version": "2.0.9",
"version": "2.0.10",
"author": "Rubin EPO",
"license": "MIT",
"homepage": "https://lsst-epo.github.io/epo-react-lib",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ interface BaseButtonProps {
label: string;
icon: string;
iconSize?: number;
bgColor?: string;
bgHoverColor?: string;
showText?: boolean;
}

const BaseButton: FunctionComponent<BaseButtonProps> = ({
label,
icon,
iconSize,
bgColor = "#000",
bgHoverColor = "#000",
showText = false,
}) => {
return (
<Styled.Wrapper $bgColor={bgColor} $bgHoverColor={bgHoverColor}>
<IconComposer icon={icon} size={iconSize} />
<Styled.SrText>{label}</Styled.SrText>
</Styled.Wrapper>
<>
{showText && label}
<Styled.Wrapper>
<IconComposer icon={icon} size={iconSize} />
{!showText && <Styled.SrText>{label}</Styled.SrText>}
</Styled.Wrapper>
</>
);
};

Expand Down
20 changes: 4 additions & 16 deletions packages/epo-react-lib/src/atomic/Share/BaseButton/styles.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
import { ScreenreaderText } from "@/styles/utils";
import styled from "styled-components";

interface WrapperProps {
$bgColor: string;
$bgHoverColor: string;
}

export const Wrapper = styled.div<WrapperProps>`
export const Wrapper = styled.div`
background-color: var(--share-background-color, #000);
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
width: var(--share-size, 40px);
height: var(--share-size, 40px);
border: transparent solid 2px;
border-radius: 50%;
color: var(--white);
transition: background-color 0.2s, border-color 0.2s;

${({ $bgColor, $bgHoverColor }) => `
background-color: ${$bgColor};

&:hover {
background-color: ${$bgHoverColor};
}
`}
`;

export const SrText = ScreenreaderText;
15 changes: 12 additions & 3 deletions packages/epo-react-lib/src/atomic/Share/CopyUrlButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentMeta, ComponentStoryObj } from "@storybook/react";
import { Meta, StoryObj } from "@storybook/react";

import CopyUrlButton from "./CopyUrlButton";

const meta: ComponentMeta<typeof CopyUrlButton> = {
const meta: Meta<typeof CopyUrlButton> = {
component: CopyUrlButton,
argTypes: {
url: {
Expand All @@ -18,11 +18,20 @@ const meta: ComponentMeta<typeof CopyUrlButton> = {
},
},
},
showText: {
description: "Shows the share button's label",
control: "boolean",
table: {
type: {
summary: "boolean",
},
},
},
},
};
export default meta;

export const Primary: ComponentStoryObj<typeof CopyUrlButton> = {
export const Primary: StoryObj<typeof CopyUrlButton> = {
args: {
url: "https://rubinobservatory.org/",
},
Expand Down
11 changes: 5 additions & 6 deletions packages/epo-react-lib/src/atomic/Share/CopyUrlButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { useTranslation } from "react-i18next";
import * as Styled from "./styles";
import BaseButton from "./BaseButton/BaseButton";

const CopyUrlButton: FunctionComponent<Omit<ShareButtonProps, "title">> = ({
url,
}) => {
const CopyUrlButton: FunctionComponent<
Pick<ShareButtonProps, "url" | "className" | "showText">
> = ({ url, className, showText }) => {
const { t } = useTranslation();

function onClick() {
Expand All @@ -16,13 +16,12 @@ const CopyUrlButton: FunctionComponent<Omit<ShareButtonProps, "title">> = ({
}

return (
<Styled.CopyUrlButton onClick={onClick}>
<Styled.CopyUrlButton {...{ className, onClick }}>
<BaseButton
label={t("share.copy_url")}
icon="shareCopyUrl"
iconSize={20}
bgColor="var(--turquoise70)"
bgHoverColor="#7ac1c2"
showText={showText}
/>
</Styled.CopyUrlButton>
);
Expand Down
15 changes: 12 additions & 3 deletions packages/epo-react-lib/src/atomic/Share/EmailButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentMeta, ComponentStoryObj } from "@storybook/react";
import { Meta, StoryObj } from "@storybook/react";

import EmailButton from "./EmailButton";

const meta: ComponentMeta<typeof EmailButton> = {
const meta: Meta<typeof EmailButton> = {
component: EmailButton,
argTypes: {
url: {
Expand Down Expand Up @@ -30,11 +30,20 @@ const meta: ComponentMeta<typeof EmailButton> = {
},
},
},
showText: {
description: "Shows the share button's label",
control: "boolean",
table: {
type: {
summary: "boolean",
},
},
},
},
};
export default meta;

export const Primary: ComponentStoryObj<typeof EmailButton> = {
export const Primary: StoryObj<typeof EmailButton> = {
args: {
url: "https://rubinobservatory.org/",
title: "New image gallery posts!",
Expand Down
19 changes: 12 additions & 7 deletions packages/epo-react-lib/src/atomic/Share/EmailButton.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
import { EmailShareButton } from "react-share";
import { useTranslation } from "react-i18next";
import BaseButton from "./BaseButton/BaseButton";
import { FunctionComponent } from "react";
import { ShareButtonProps } from "@/types/share-button";
import * as Styled from "./styles";

const EmailButton: FunctionComponent<ShareButtonProps> = ({ title, url }) => {
const EmailButton: FunctionComponent<ShareButtonProps> = ({
title,
url,
className,
showText,
...shareProps
}) => {
const { t } = useTranslation();

return (
<EmailShareButton
url={url}
<Styled.EmailShareButton
subject={t("share.email_subject", {
title,
})}
body={url}
{...{ ...shareProps, className, url }}
>
<BaseButton
label={t("share.email")}
icon="shareEmail"
iconSize={40}
bgColor="var(--turquoise85)"
bgHoverColor="#7fb3b1"
showText={showText}
/>
</EmailShareButton>
</Styled.EmailShareButton>
);
};

Expand Down
15 changes: 12 additions & 3 deletions packages/epo-react-lib/src/atomic/Share/FacebookButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentMeta, ComponentStoryObj } from "@storybook/react";
import { Meta, StoryObj } from "@storybook/react";

import FacebookButton from "./FacebookButton";

const meta: ComponentMeta<typeof FacebookButton> = {
const meta: Meta<typeof FacebookButton> = {
component: FacebookButton,
argTypes: {
url: {
Expand Down Expand Up @@ -30,11 +30,20 @@ const meta: ComponentMeta<typeof FacebookButton> = {
},
},
},
showText: {
description: "Shows the share button's label",
control: "boolean",
table: {
type: {
summary: "boolean",
},
},
},
},
};
export default meta;

export const Primary: ComponentStoryObj<typeof FacebookButton> = {
export const Primary: StoryObj<typeof FacebookButton> = {
args: {
url: "https://rubinobservatory.org/",
title: "New image gallery posts!",
Expand Down
14 changes: 8 additions & 6 deletions packages/epo-react-lib/src/atomic/Share/FacebookButton.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import { FacebookShareButton } from "react-share";
import { useTranslation } from "react-i18next";
import BaseButton from "./BaseButton/BaseButton";
import { FunctionComponent } from "react";
import { ShareButtonProps } from "@/types/share-button";
import * as Styled from "./styles";

const FacebookButton: FunctionComponent<ShareButtonProps> = ({
url,
title,
className,
showText,
...shareProps
}) => {
const { t } = useTranslation();

return (
<FacebookShareButton
url={url}
<Styled.FacebookShareButton
quote={t("share.facebook_quote", { title })}
hashtag="#RubinObs"
{...{ ...shareProps, className, url }}
>
<BaseButton
label="Facebook"
icon="shareFacebook"
iconSize={32}
bgColor="#3d5a99"
bgHoverColor="#98a5cb"
showText={showText}
/>
</FacebookShareButton>
</Styled.FacebookShareButton>
);
};

Expand Down
15 changes: 12 additions & 3 deletions packages/epo-react-lib/src/atomic/Share/TwitterButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ComponentMeta, ComponentStoryObj } from "@storybook/react";
import { Meta, StoryObj } from "@storybook/react";

import TwitterButton from "./TwitterButton";

const meta: ComponentMeta<typeof TwitterButton> = {
const meta: Meta<typeof TwitterButton> = {
component: TwitterButton,
argTypes: {
url: {
Expand Down Expand Up @@ -30,11 +30,20 @@ const meta: ComponentMeta<typeof TwitterButton> = {
},
},
},
showText: {
description: "Shows the share button's label",
control: "boolean",
table: {
type: {
summary: "boolean",
},
},
},
},
};
export default meta;

export const Primary: ComponentStoryObj<typeof TwitterButton> = {
export const Primary: StoryObj<typeof TwitterButton> = {
args: {
url: "https://rubinobservatory.org/",
title: "New image gallery posts!",
Expand Down
20 changes: 12 additions & 8 deletions packages/epo-react-lib/src/atomic/Share/TwitterButton.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
import { FunctionComponent } from "react";
import { ShareButtonProps } from "@/types/share-button";

import { TwitterShareButton } from "react-share";
import { useTranslation } from "react-i18next";
import BaseButton from "./BaseButton/BaseButton";
import * as Styled from "./styles";

const TwitterButton: FunctionComponent<ShareButtonProps> = ({ url, title }) => {
const TwitterButton: FunctionComponent<ShareButtonProps> = ({
url,
title,
className,
showText,
...shareProps
}) => {
const { t } = useTranslation();

return (
<TwitterShareButton
url={url}
<Styled.TwitterShareButton
title={t("share.twitter_title", { title })}
hashtags={["RubinObs"]}
{...{ ...shareProps, url, className }}
>
<BaseButton
label="Twitter"
icon="shareTwitter"
iconSize={44}
bgColor="#38a8e0"
bgHoverColor="#98d0f1"
showText={showText}
/>
</TwitterShareButton>
</Styled.TwitterShareButton>
);
};

Expand Down
Loading