From 45e496385fe3e82604641c2c067cf43da4241123 Mon Sep 17 00:00:00 2001 From: Innei Date: Thu, 20 Jun 2024 15:55:51 +0800 Subject: [PATCH] fix: `tab` to switch element focus (#76) Signed-off-by: Innei --- .../src/components/ui/button/variants.tsx | 2 +- src/renderer/src/components/ui/checkbox.tsx | 35 ++++---- src/renderer/src/components/ui/switch.tsx | 2 +- src/renderer/src/components/ui/tabs.tsx | 4 +- src/renderer/src/components/user-button.tsx | 2 +- .../src/modules/entry-column/index.tsx | 2 +- .../src/modules/feed-column/index.tsx | 2 +- .../src/pages/(external)/redirect.tsx | 26 ++++-- src/renderer/src/styles/base.css | 4 + src/renderer/src/styles/tailwind-extend.css | 82 +++++++++++++++++++ 10 files changed, 127 insertions(+), 34 deletions(-) diff --git a/src/renderer/src/components/ui/button/variants.tsx b/src/renderer/src/components/ui/button/variants.tsx index c3ffc1699..b4b453dbe 100644 --- a/src/renderer/src/components/ui/button/variants.tsx +++ b/src/renderer/src/components/ui/button/variants.tsx @@ -2,7 +2,7 @@ import { cn } from "@renderer/lib/utils" import { cva } from "class-variance-authority" export const buttonVariants = cva( - "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50", + "inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors disabled:pointer-events-none disabled:opacity-50", { variants: { size: { diff --git a/src/renderer/src/components/ui/checkbox.tsx b/src/renderer/src/components/ui/checkbox.tsx index 4e94fd48f..db4fd91e9 100644 --- a/src/renderer/src/components/ui/checkbox.tsx +++ b/src/renderer/src/components/ui/checkbox.tsx @@ -1,27 +1,24 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox" import { cn } from "@renderer/lib/utils" -import { Check } from "lucide-react" import * as React from "react" const Checkbox = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - - - - -)) + HTMLInputElement, + React.ComponentPropsWithoutRef<"input"> & { + onCheckedChange?: (checked: boolean) => void + } +>(({ className, onCheckedChange, ...props }, ref) => ( + { + onCheckedChange?.(event.target.checked) + props.onChange?.(event) + }} + /> + )) Checkbox.displayName = CheckboxPrimitive.Root.displayName export { Checkbox } diff --git a/src/renderer/src/components/ui/switch.tsx b/src/renderer/src/components/ui/switch.tsx index c6d945da1..f4499b82d 100644 --- a/src/renderer/src/components/ui/switch.tsx +++ b/src/renderer/src/components/ui/switch.tsx @@ -8,7 +8,7 @@ const Switch = React.forwardRef< >(({ className, ...props }, ref) => ( = memo((props) => { return } return ( - + diff --git a/src/renderer/src/modules/entry-column/index.tsx b/src/renderer/src/modules/entry-column/index.tsx index 33df36ffa..a9521259b 100644 --- a/src/renderer/src/modules/entry-column/index.tsx +++ b/src/renderer/src/modules/entry-column/index.tsx @@ -288,7 +288,7 @@ const ListHeader: FC<{ )} - + - + diff --git a/src/renderer/src/pages/(external)/redirect.tsx b/src/renderer/src/pages/(external)/redirect.tsx index 5184c5510..8da320eaa 100644 --- a/src/renderer/src/pages/(external)/redirect.tsx +++ b/src/renderer/src/pages/(external)/redirect.tsx @@ -49,14 +49,24 @@ export function Component() { {" "} and safely close this page. - window.open(await getCallbackUrl())} - > - Open - {" "} - {APP_NAME} - +
+ navigate("/")} + > + Continue in Browser + + + window.open(await getCallbackUrl())} + > + Open + {" "} + {APP_NAME} + +
) } diff --git a/src/renderer/src/styles/base.css b/src/renderer/src/styles/base.css index c844846a3..d8720bc7b 100644 --- a/src/renderer/src/styles/base.css +++ b/src/renderer/src/styles/base.css @@ -9,6 +9,10 @@ body, @apply font-theme; } +:focus-visible { + outline: theme(colors.theme.accent.DEFAULT) auto 1px; +} + button, a { @apply cursor-default; diff --git a/src/renderer/src/styles/tailwind-extend.css b/src/renderer/src/styles/tailwind-extend.css index 93756f174..a5c8dd48c 100644 --- a/src/renderer/src/styles/tailwind-extend.css +++ b/src/renderer/src/styles/tailwind-extend.css @@ -53,6 +53,12 @@ .shadow-modal { @apply shadow-2xl shadow-stone-300 dark:shadow-stone-800; } + /* Utils */ + .no-animation { + --btn-focus-scale: 1; + --animation-btn: 0; + --animation-input: 0; + } } /* Radio styling */ @@ -139,3 +145,79 @@ background-color: oklch(0.232607 0.013807 253.101); } } + +/* Checkbox */ +@layer components { + .checkbox { + --chkbg: theme(colors.theme.accent.DEFAULT); + --chkfg: theme(colors.zinc.100); + + flex-shrink: 0; + height: 0.9em; + width: 0.9em; + cursor: pointer; + appearance: none; + border-radius: 5px; + border-width: 1px; + border-color: theme(colors.zinc.500); + --tw-border-opacity: 0.2; + } + + .checkbox:focus { + box-shadow: none; + } + + .checkbox:focus-visible { + outline-style: solid; + outline-width: 2px; + outline-offset: 2px; + outline-color: theme(colors.theme.accent.DEFAULT); + border-color: theme(colors.theme.accent.DEFAULT); + } + + .checkbox:disabled { + border-width: 0; + cursor: not-allowed; + border-color: transparent; + --tw-bg-opacity: 1; + background-color: var(--chkbg); + opacity: 0.2; + } + + .checkbox:checked, + .checkbox[aria-checked="true"] { + background-repeat: no-repeat; + animation: checkmark var(--animation-input, 0.2s) ease-out; + border-color: theme(colors.theme.accent.DEFAULT); + background-color: var(--chkbg); + background-image: linear-gradient( + -45deg, + transparent 65%, + var(--chkbg) 65.99% + ), + linear-gradient(45deg, transparent 75%, var(--chkbg) 75.99%), + linear-gradient(-45deg, var(--chkbg) 40%, transparent 40.99%), + linear-gradient( + 45deg, + var(--chkbg) 30%, + var(--chkfg) 30.99%, + var(--chkfg) 40%, + transparent 40.99% + ), + linear-gradient(-45deg, var(--chkfg) 50%, var(--chkbg) 50.99%); + } + + @keyframes checkmark { + 0% { + background-position-y: 5px; + } + + 50% { + background-position-y: -2px; + } + + to { + background-position-y: 0; + } + } +}