Skip to content

Commit

Permalink
Show loading animation after clicking on bookmark link
Browse files Browse the repository at this point in the history
  • Loading branch information
flaksp committed Aug 16, 2020
1 parent 6716b21 commit 74f1fac
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/components/Bookmark/BookmarkFolder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const BookmarkFolder = (props: BookmarkFolderProps) => {
return (
<li className={s.bookmarkItem}>
<button className={s.bookmark} onClick={handleFolderClick} type="button">
<Chip icon={icon} label={props.bookmark.title} shape={ChipShape.Rounded} />
<Chip icon={icon} label={props.bookmark.title} loading={false} shape={ChipShape.Rounded} />
</button>
</li>
);
Expand Down
13 changes: 11 additions & 2 deletions src/components/Bookmark/BookmarkLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,24 @@ interface BookmarkProps {

export const BookmarkLink = (props: BookmarkProps) => {
const [icon, setIcon] = useState(props.bookmark.favicon);
const [isLoading, setLoading] = useState(false);

const handleFaviconLoadingError = () => {
setIcon(iconPublic);
};

const handleClick = () => {
setLoading(true);

setTimeout(() => {
setLoading(false);
}, 5000);
};

return (
<li className={s.bookmarkItem}>
<a className={s.bookmark} href={props.bookmark.url} rel="noopener" target="_self">
<Chip handleFaviconLoadingError={handleFaviconLoadingError} icon={icon} label={props.bookmark.title} shape={ChipShape.Rounded} />
<a className={s.bookmark} href={props.bookmark.url} onClick={handleClick} rel="noopener" target="_self">
<Chip handleFaviconLoadingError={handleFaviconLoadingError} icon={icon} label={props.bookmark.title} loading={isLoading} shape={ChipShape.Rounded} />
</a>
</li>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const BookmarkManager = () => {
return (
<li className={bookmarkStyles.bookmarkItem}>
<a className={bookmarkStyles.bookmark} href={url} onClick={handleClick} rel="noopener" target="_self">
<Chip icon={iconStar} label={label} shape={ChipShape.Squared} tooltip={tooltip} />
<Chip icon={iconStar} label={label} loading={false} shape={ChipShape.Squared} tooltip={tooltip} />
</a>
</li>
);
Expand Down
23 changes: 23 additions & 0 deletions src/components/Chip/Chip.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,29 @@
transition: background-color 0.2s, transform 0.2s;
}

.chip.loading {
animation: backgroundStripAnimation 1s linear infinite reverse;
background-image:
repeating-linear-gradient(
135deg,
var(--chip-loading-strip-color-1) 25%,
var(--chip-loading-strip-color-1) 50%,
var(--chip-loading-strip-color-2) 50%,
var(--chip-loading-strip-color-2) 75%
);
background-size: var(--chip-loading-strip-size) var(--chip-loading-strip-size);
}

@keyframes backgroundStripAnimation {
0% {
background-position: 0 0;
}

100% {
background-position: calc(var(--chip-loading-strip-size) * -1) 0;
}
}

.chip.chip--rounded {
border-radius: var(--chip-rounded-border-radius);
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/Chip/Chip.css.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
declare namespace ChipCssNamespace {
export interface IChipCss {
backgroundStripAnimation: string;
chip: string;
chipIcon: string;
chipIconInline: string;
chipLabel: string;
chipRounded: string;
chipSquared: string;
loading: string;
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/components/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ interface ChipProps {
handleFaviconLoadingError?: () => void;
icon: string | Favicon;
label: string;
loading: boolean;
shape: ChipShape;
tooltip?: string;
}
Expand All @@ -50,25 +51,29 @@ export const Chip = (props: ChipProps) => {

const tooltip = props.tooltip || props.label;

let shapeClass;
const chipClasses = [s.chip];

switch (props.shape) {
case ChipShape.Rounded:
shapeClass = s.chipRounded;
chipClasses.push(s.chipRounded);

break;

case ChipShape.Squared:
shapeClass = s.chipSquared;
chipClasses.push(s.chipSquared);

break;

default:
throw Error('Unsupported chip shape');
}

if (props.loading) {
chipClasses.push(s.loading);
}

return (
<div className={classnames(s.chip, shapeClass)} title={tooltip}>
<div className={classnames(chipClasses)} title={tooltip}>
{iconElement}

<span className={s.chipLabel}>{props.label}</span>
Expand Down
3 changes: 3 additions & 0 deletions src/components/variables.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
--bookmark-category-title-text-color: #eee;
--bookmark-column-min-width: 235px;
--bookmark-text-color: #eee;
--chip-loading-strip-size: 20px;
--chip-loading-strip-color-1: rgba(238, 238, 238, 0.1);
--chip-loading-strip-color-2: rgba(238, 238, 238, 0.2);
--chip-rounded-border-radius: 1rem;
--chip-squared-border-radius: 0.5rem;
--font-family-sans-serif: -apple-system, blinkmacsystemfont, "Segoe UI", roboto, "Helvetica Neue", arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
Expand Down

0 comments on commit 74f1fac

Please sign in to comment.