Skip to content
This repository was archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
feat: add toggles to consent options
Browse files Browse the repository at this point in the history
allows setting each consent category separately
  • Loading branch information
Gregor Adams committed Aug 22, 2021
1 parent 1f4c1a4 commit 50dda56
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/molecules/input-field/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const StyledInput = styled("input", {
&:focus {
outline: 0;
box-shadow: inset 0 0 0 1px
box-shadow: inset 0 0 0 ${theme.borders.focusRing}
${invalid
? theme.ui.molecules.inputField.error.border
: theme.ui.colors.focusRing.border};
Expand Down
49 changes: 38 additions & 11 deletions src/pages/legal/cookie-policy/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Button from "@/atoms/button";
import ButtonGroup from "@/atoms/button/button-group";
import Toggle from "@/atoms/toggle";
import { StyledToggleLabel } from "@/atoms/toggle/styled";
import Typography from "@/atoms/typography";
import { useCookieConsentContext } from "@/ions/contexts/cookie-consent";
import { GET_LEGAL_PAGE } from "@/ions/queries/legal-page";
Expand Down Expand Up @@ -41,22 +43,47 @@ const Page: NextPage<PageProps> = props => {
);
const { t } = useTranslation(["cookie-banner"]);

const { consent, acceptAllCookies, declineAllCookies } = useCookieConsentContext();
const { consent, acceptAllCookies, declineAllCookies, acceptCookies } =
useCookieConsentContext();

return (
<WrappedLegalPage data={data} error={error} loading={loading}>
<div>
<Typography variant="h3">{t("cookie-banner:consent-given")}</Typography>
<ol>
{consentKeys.map(key => {
return (
<Typography key={key} raw component="li">
{t(`cookie-banner:${key}`)}:{" "}
{consent[key] ? t("common:yes") : t("common:no")}
</Typography>
);
})}
</ol>
<table>
<tbody>
{consentKeys.map(key => {
return (
<tr key={key}>
<td>
<Typography raw>
{t(`cookie-banner:${key}`)}&nbsp;
</Typography>
</td>
<td>
<label>
<Toggle
checked={consent[key] as boolean}
disabled={key === "necessary"}
onChange={event_ => {
acceptCookies({
...consent,
[key]: (event_.target as HTMLInputElement)
.checked,
});
}}
/>
<StyledToggleLabel>
{consent[key] ? t("common:yes") : t("common:no")}
</StyledToggleLabel>
</label>
</td>
</tr>
);
})}
</tbody>
</table>
<br />
</div>
<ButtonGroup>
<Button
Expand Down
9 changes: 6 additions & 3 deletions src/templates/design-system/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,25 @@ const DesignSystem = () => {
<Column>
<ul>
<li>
<I18nLink href="/design-system/typography">Typography</I18nLink>
<I18nLink href="/design-system/accordion">Accordion</I18nLink>
</li>
<li>
<I18nLink href="/design-system/button">Button</I18nLink>
</li>
<li>
<I18nLink href="/design-system/grid">Grid</I18nLink>
</li>
<li>
<I18nLink href="/design-system/space">Space</I18nLink>
</li>
<li>
<I18nLink href="/design-system/spinner">Spinner</I18nLink>
</li>
<li>
<I18nLink href="/design-system/accordion">Accordion</I18nLink>
<I18nLink href="/design-system/toggle">Toggle</I18nLink>
</li>
<li>
<I18nLink href="/design-system/grid">Grid</I18nLink>
<I18nLink href="/design-system/typography">Typography</I18nLink>
</li>
</ul>
</Column>
Expand Down

0 comments on commit 50dda56

Please sign in to comment.