Skip to content

Commit

Permalink
feat: copy button and stiling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mauroerta committed Oct 12, 2021
1 parent 153fdbc commit 91c30ac
Show file tree
Hide file tree
Showing 18 changed files with 157 additions and 82 deletions.
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build
public
4 changes: 1 addition & 3 deletions devtool/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
build
dev
public
dev
2 changes: 1 addition & 1 deletion devtool/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"externally_connectable": {
"ids": ["*"]
},
"permissions": ["storage", "activeTab"],
"permissions": ["storage", "activeTab", "clipboardWrite", "clipboardRead"],
"background": {
"service_worker": "background.bundle.js"
},
Expand Down
1 change: 1 addition & 0 deletions devtool/src/_shared/components/Accordion/style.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.labelContainer {
display: flex;
align-items: center;
cursor: pointer;
}

.toggle {
Expand Down
55 changes: 55 additions & 0 deletions devtool/src/_shared/components/CopyButton/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React, { useCallback, useState } from 'react';
import { Color } from '@morfeo/react';
import clsx from 'clsx';
import { Icon } from '../Icon';
import styles from './style.module.css';

type Props = {
text: string;
};

function copyToClipboard(element: HTMLElement) {
if (window.getSelection && document.createRange) {
const selection = window.getSelection();
const range = document.createRange();
range.selectNodeContents(element);
selection?.removeAllRanges();
selection?.addRange(range);

return document.execCommand('copy', true);
}

return false;
}

export const CopyButton: React.FC<Props> = ({ text }) => {
const [isCopied, setIsCopied] = useState<boolean>(false);
const ref = React.useRef<HTMLSpanElement>(null);

const onClick = useCallback(() => {
const hasBeenCopied = copyToClipboard(ref.current as HTMLSpanElement);
if (hasBeenCopied) {
setTimeout(() => {
setIsCopied(false);
}, 2000);
}
setIsCopied(hasBeenCopied);
}, []);

return (
<>
<div
className={clsx(styles.copyButton, isCopied && styles.copied)}
onClick={onClick}
>
<Icon name="copy" size="s" color={'invertedTextColor' as Color} />
<p className="morfeo-typography-p2">
{isCopied ? 'Copied' : 'Copy alias'}
</p>
</div>
<span ref={ref} className={styles.hiddenText}>
{text}
</span>
</>
);
};
37 changes: 37 additions & 0 deletions devtool/src/_shared/components/CopyButton/style.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.copyButton {
display: flex;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
align-items: center;
width: fit-content;
align-self: flex-end;
max-width: var(--spacings-s);
transition: var(--transitions-medium);
background-color: var(--colors-gray-dark);
padding: calc(var(--spacings-xxs) / 2);
border-top-left-radius: var(--radii-xs);
border-bottom-right-radius: var(--radii-xs);
}

.copyButton p {
display: none;
opacity: 0;
margin-left: var(--spacings-xxs);
color: var(--colors-inverted-text-color) !important;
}

.copyButton:hover, .copyButton.copied {
align-self: flex-end;
max-width: 10rem;
}

.copyButton:hover p, .copyButton.copied p {
opacity: 1;
display: inline-block;
}

.hiddenText {
position: fixed;
opacity: 0;
}
31 changes: 17 additions & 14 deletions devtool/src/_shared/components/SliceCard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
import React from "react";
import { ThemeKey } from "@morfeo/react";
import { Link } from "../Link";
import { RouteName } from "../../../_shared/contexts";
import { useRouter } from "../../hooks";
import React from 'react';
import { ThemeKey } from '@morfeo/react';
import { noCase } from 'change-case';
import { RouteName } from '../../../_shared/contexts';

import styles from "./style.module.css";
import clsx from "clsx";
import styles from './style.module.css';
import clsx from 'clsx';
import { Link } from '../Link';
import { CopyButton } from '../CopyButton';

type Props = {
slice: ThemeKey;
};

export const SliceCard: React.FC<Props> = ({ slice }) => {
const { navigate } = useRouter();
return (
<div
className={clsx("morfeo-card", styles.sliceCard)}
onClick={() => navigate(slice as RouteName)}
>
<Link to={slice as RouteName}>{slice}</Link>
<button className="morfeo-button-round height-l width-l mt-s" />
<div className={clsx('morfeo-card', styles.container)}>
<div className={clsx('morfeo-card', styles.innerCard)}>
<CopyButton text={slice} />
</div>
<div className={styles.bottomContainer}>
<Link to={'slice' as RouteName} className="morfeo-typography-h2">
{noCase(slice)}
</Link>
</div>
</div>
);
};
33 changes: 30 additions & 3 deletions devtool/src/_shared/components/SliceCard/style.module.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
.sliceCard {
.container {
display: flex;
flex-direction: column;
justify-content: flex-start;
align-items: flex-start;
margin: var(--spacings-xs);
width: 7rem;
height: 7rem;
width: 10rem;
height: 15rem;
border: var(--borders-primary);
border-color: var(--colors-primary);
}

.innerCard {
display: flex;
align-items: flex-end;
justify-content: flex-end;
overflow: hidden;
width: 10rem;
height: 10rem;
background-color: var(--colors-primary);
border: var(--borders-primary);
border-color: var(--colors-primary);
border-bottom-width: none;
}

.bottomContainer {
width: 100%;
display: flex;
padding-left: var(--spacings-xs);
justify-content: flex-start;
text-align: left;
border-bottom-left-radius: var(--radii-s);
border-bottom-right-radius: var(--radii-s);
}
1 change: 1 addition & 0 deletions devtool/src/_shared/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './Icon';
export * from './Route';
export * from './SliceCard';
export * from './Accordion';
export * from './CopyButton';
24 changes: 0 additions & 24 deletions devtool/src/_shared/css/dark-components.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,39 @@
color: var(--colors-text-color);
cursor: pointer;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="dark"] .morfeo-card:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="dark"] .morfeo-card-small {
color: var(--colors-text-color);
width: 100px;
cursor: pointer;
height: 100px;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="dark"] .morfeo-card-small:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="dark"] .morfeo-card-medium {
color: var(--colors-text-color);
width: 200px;
cursor: pointer;
height: 200px;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="dark"] .morfeo-card-medium:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="dark"] .morfeo-card-large {
color: var(--colors-text-color);
width: 300px;
cursor: pointer;
height: 300px;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="dark"] .morfeo-card-large:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="dark"] .morfeo-button {
color: var(--colors-inverted-text-color);
Expand Down
2 changes: 1 addition & 1 deletion devtool/src/_shared/css/dark-variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
--spacings-xxl: 56px;
--spacings-none: 0px;
--transitions-slow: 1s ease;
--transitions-medium: .6 ease;
--transitions-medium: .6s ease;
--transitions-fast: .3s ease;
--transitions-none: 0s;
--z-indices-none: 0;
Expand Down
24 changes: 0 additions & 24 deletions devtool/src/_shared/css/light-components.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,39 @@
color: var(--colors-text-color);
cursor: pointer;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="light"] .morfeo-card:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="light"] .morfeo-card-small {
color: var(--colors-text-color);
width: 100px;
cursor: pointer;
height: 100px;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="light"] .morfeo-card-small:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="light"] .morfeo-card-medium {
color: var(--colors-text-color);
width: 200px;
cursor: pointer;
height: 200px;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="light"] .morfeo-card-medium:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="light"] .morfeo-card-large {
color: var(--colors-text-color);
width: 300px;
cursor: pointer;
height: 300px;
display: flex;
padding: var(--spacings-xs);
box-shadow: var(--border-widths-none) var(--border-widths-s) var(--radii-xxs) var(--colors-gray);
align-items: center;
border-radius: var(--radii-s);
flex-direction: column;
background-color: var(--colors-background);
}
[data-morfeo-theme="light"] .morfeo-card-large:hover {
box-shadow: var(--border-widths-none) var(--border-widths-m) var(--radii-xs) var(--colors-gray);
}
[data-morfeo-theme="light"] .morfeo-button {
color: var(--colors-inverted-text-color);
Expand Down
2 changes: 1 addition & 1 deletion devtool/src/_shared/css/light-variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
--spacings-xxl: 56px;
--spacings-none: 0px;
--transitions-slow: 1s ease;
--transitions-medium: .6 ease;
--transitions-medium: .6s ease;
--transitions-fast: .3s ease;
--transitions-none: 0s;
--z-indices-none: 0;
Expand Down
6 changes: 0 additions & 6 deletions devtool/src/_shared/styles/components/card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@ import { ComponentConfig } from '@morfeo/react';
export const Card: ComponentConfig = {
tag: 'div',
style: {
p: 'xs',
bg: 'background',
cursor: 'pointer',
color: 'textColor',
shadow: 'light',
corner: 's',
display: 'flex',
alignItems: 'center',
flexDirection: 'column',
'&:hover': {
shadow: 'medium',
},
},
variants: {
small: {
Expand Down
1 change: 1 addition & 0 deletions devtool/src/_shared/template/SideBar/Menus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const MenuItem: React.FC<MenuItemProps> = ({ text, icon, onNavigate }) => {
color: 'var(--color-inverted-text-color)',
marginBottom: 'var(--spacings-none)',
marginLeft: 'var(--spacings-xxs)',
cursor: 'pointer',
}}
>
{text}
Expand Down
Loading

0 comments on commit 91c30ac

Please sign in to comment.