Skip to content

Commit

Permalink
fix: simplify toggles
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardocasares committed Oct 30, 2020
1 parent 5265099 commit 5c2966a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 35 deletions.
24 changes: 5 additions & 19 deletions src/components/Card/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { FC } from "react";
import { PlayCircle, Heart, HeartFill } from "@geist-ui/react-icons";
import { PlayCircle } from "@geist-ui/react-icons";
import { HeartToggle } from "@/components/Toggles";
import { Container, Cover, Button, Title, Subtitle, Body } from "./style";

export const HeartToggle: FC<{ active: boolean }> = ({ active }) => {
if (active) {
return <HeartFill color="var(--highlight-magenta)" />;
}

return <Heart color="var(--accents-3)" />;
};

const DEFAULT_SUBTITLE = "Global";

export type Card = {
Expand Down Expand Up @@ -42,16 +35,9 @@ export const Card: FC<Card> = ({
<Title>{title}</Title>
<Subtitle>{subtitle || DEFAULT_SUBTITLE}</Subtitle>
</div>
{!isFaved && (
<Button onClick={onFaved}>
<HeartToggle active={false} />
</Button>
)}
{isFaved && (
<Button onClick={onUnFaved}>
<HeartToggle active={true} />
</Button>
)}
<Button onClick={!isFaved ? onFaved : onUnFaved}>
<HeartToggle active={isFaved} />
</Button>
</Body>
</Container>
);
14 changes: 0 additions & 14 deletions src/components/Toggle/index.tsx

This file was deleted.

43 changes: 43 additions & 0 deletions src/components/Toggles/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { FC, ReactElement } from "react";
import {
Heart,
HeartFill,
ToggleLeft,
ToggleRight,
} from "@geist-ui/react-icons";

export { ToggleItem } from "./style";

export type Toggable = {
on: ReactElement;
off: ReactElement;
};

export type Activable = {
active: boolean;
};

export type Toggle = Toggable & Activable;

export const Toggle: FC<Toggle> = ({ on, off, active }) => (
<>
{active && on}
{!active && off}
</>
);

export const HeartToggle: FC<Activable> = (props) => (
<Toggle
on={<HeartFill color="var(--highlight-magenta)" />}
off={<Heart color="var(--accents-5)" />}
{...props}
/>
);

export const RightLeftToggle: FC<Activable> = (props) => (
<Toggle
on={<ToggleRight color="var(--cyan)" />}
off={<ToggleLeft color="var(--accents-5)" />}
{...props}
/>
);
File renamed without changes.
4 changes: 2 additions & 2 deletions src/pages/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Link from "next/link";
import { Box } from "@/components/Box";
import { Stack } from "@/components/Stack";
import { Toggle, ToggleItem } from "@/components/Toggle";
import { RightLeftToggle, ToggleItem } from "@/components/Toggles";
import { Heading } from "@/components/Typography";
import { useTranslation } from "@/lib/hooks/useTranslation";
import { localesMap } from "@/lib/utils";
Expand All @@ -25,7 +25,7 @@ export const Index = () => {
<Link href="/settings" locale={lang}>
<a>
<ToggleItem>
{localesMap[lang]} <Toggle active={locale == lang} />
{localesMap[lang]} <RightLeftToggle active={locale == lang} />
</ToggleItem>
</a>
</Link>
Expand Down

0 comments on commit 5c2966a

Please sign in to comment.