diff --git a/.yarn/cache/@reach-checkbox-npm-0.18.0-817b08c2c9-6f40bfb546.zip b/.yarn/cache/@reach-checkbox-npm-0.18.0-817b08c2c9-6f40bfb546.zip deleted file mode 100644 index 7f1ad7811..000000000 Binary files a/.yarn/cache/@reach-checkbox-npm-0.18.0-817b08c2c9-6f40bfb546.zip and /dev/null differ diff --git a/packages/web/package.json b/packages/web/package.json index 8b8b04824..e2cfc8347 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -30,7 +30,6 @@ "@babel/preset-typescript": "^7.18.6", "@lexical/react": "0.9.2", "@pmmmwh/react-refresh-webpack-plugin": "^0.5.10", - "@reach/checkbox": "^0.18.0", "@reach/disclosure": "^0.18.0", "@reach/listbox": "^0.18.0", "@simplewebauthn/browser": "^7.1.0", diff --git a/packages/web/src/javascripts/Components/LinkedItems/LinkedFileMenuOptions.tsx b/packages/web/src/javascripts/Components/LinkedItems/LinkedFileMenuOptions.tsx index 37fd99ea0..6c364a172 100644 --- a/packages/web/src/javascripts/Components/LinkedItems/LinkedFileMenuOptions.tsx +++ b/packages/web/src/javascripts/Components/LinkedItems/LinkedFileMenuOptions.tsx @@ -1,4 +1,3 @@ -import { FOCUSABLE_BUT_NOT_TABBABLE } from '@/Constants/Constants' import { FilesController } from '@/Controllers/FilesController' import { FileItem } from '@standardnotes/snjs' import { useState } from 'react' @@ -6,8 +5,8 @@ import { FileItemActionType } from '../AttachedFilesPopover/PopoverFileItemActio import { FileContextMenuBackupOption } from '../FileContextMenu/FileContextMenuBackupOption' import Icon from '../Icon/Icon' import MenuItem from '../Menu/MenuItem' +import MenuSwitchButtonItem from '../Menu/MenuSwitchButtonItem' import HorizontalSeparator from '../Shared/HorizontalSeparator' -import Switch from '../Switch/Switch' type Props = { file: FileItem @@ -37,9 +36,10 @@ const LinkedFileMenuOptions = ({ file, closeMenu, handleFileAction, setIsRenamin Preview file - { + checked={isFileProtected} + onChange={() => { handleFileAction({ type: FileItemActionType.ToggleFileProtection, payload: { file }, @@ -49,12 +49,9 @@ const LinkedFileMenuOptions = ({ file, closeMenu, handleFileAction, setIsRenamin }).catch(console.error) }} > - - - Password protect - - - + + Password protect + { diff --git a/packages/web/src/javascripts/Components/Menu/MenuSwitchButtonItem.tsx b/packages/web/src/javascripts/Components/Menu/MenuSwitchButtonItem.tsx index 5b781d150..4658e410f 100644 --- a/packages/web/src/javascripts/Components/Menu/MenuSwitchButtonItem.tsx +++ b/packages/web/src/javascripts/Components/Menu/MenuSwitchButtonItem.tsx @@ -4,13 +4,12 @@ import { PlatformedKeyboardShortcut } from '@standardnotes/ui-services' import { ComponentPropsWithoutRef, ForwardedRef, forwardRef, ReactNode } from 'react' import { KeyboardShortcutIndicator } from '../KeyboardShortcutIndicator/KeyboardShortcutIndicator' import Switch from '../Switch/Switch' -import { SwitchProps } from '../Switch/SwitchProps' import MenuListItem from './MenuListItem' type Props = { checked: boolean children: ReactNode - onChange: NonNullable + onChange: (checked: boolean) => void shortcut?: PlatformedKeyboardShortcut } & Omit, 'onChange'> @@ -42,7 +41,7 @@ const MenuSwitchButtonItem = forwardRef( {children}
{shortcut && } - +
diff --git a/packages/web/src/javascripts/Components/QuickSettingsMenu/FocusModeSwitch.tsx b/packages/web/src/javascripts/Components/QuickSettingsMenu/FocusModeSwitch.tsx index ee7c16bfa..17a3ff5f1 100644 --- a/packages/web/src/javascripts/Components/QuickSettingsMenu/FocusModeSwitch.tsx +++ b/packages/web/src/javascripts/Components/QuickSettingsMenu/FocusModeSwitch.tsx @@ -1,10 +1,8 @@ import { WebApplication } from '@/Application/Application' -import { FunctionComponent, MouseEventHandler, useCallback, useMemo } from 'react' -import Switch from '@/Components/Switch/Switch' +import { FunctionComponent, useCallback, useMemo } from 'react' import { isMobileScreen } from '@/Utils' import { TOGGLE_FOCUS_MODE_COMMAND } from '@standardnotes/ui-services' -import { KeyboardShortcutIndicator } from '../KeyboardShortcutIndicator/KeyboardShortcutIndicator' -import MenuItem from '../Menu/MenuItem' +import MenuSwitchButtonItem from '../Menu/MenuSwitchButtonItem' type Props = { application: WebApplication @@ -14,15 +12,10 @@ type Props = { } const FocusModeSwitch: FunctionComponent = ({ application, onToggle, onClose, isEnabled }) => { - const toggle: MouseEventHandler = useCallback( - (e) => { - e.preventDefault() - - onToggle(!isEnabled) - onClose() - }, - [onToggle, isEnabled, onClose], - ) + const toggle = useCallback(() => { + onToggle(!isEnabled) + onClose() + }, [onToggle, isEnabled, onClose]) const shortcut = useMemo( () => application.keyboardService.keyboardShortcutForCommand(TOGGLE_FOCUS_MODE_COMMAND), @@ -36,13 +29,9 @@ const FocusModeSwitch: FunctionComponent = ({ application, onToggle, onCl } return ( - -
Focus Mode
-
- {shortcut && } - -
-
+ + Focus Mode + ) } diff --git a/packages/web/src/javascripts/Components/Switch/Switch.tsx b/packages/web/src/javascripts/Components/Switch/Switch.tsx index b394ac715..42974e2c6 100644 --- a/packages/web/src/javascripts/Components/Switch/Switch.tsx +++ b/packages/web/src/javascripts/Components/Switch/Switch.tsx @@ -1,49 +1,46 @@ -import { CustomCheckboxContainer, CustomCheckboxInput, CustomCheckboxInputProps } from '@reach/checkbox' -import { FunctionComponent, useState } from 'react' -import { SwitchProps } from './SwitchProps' +import { Checkbox, VisuallyHidden } from '@ariakit/react' +import { classNames } from '@standardnotes/snjs' -const Switch: FunctionComponent = (props: SwitchProps) => { - const [checkedState, setChecked] = useState(props.checked || false) - const checked = props.checked ?? checkedState - const className = props.className ?? '' - - const isDisabled = !!props.disabled - const isActive = checked && !isDisabled +const Switch = ({ + checked, + onChange, + className, + disabled = false, + tabIndex, +}: { + checked: boolean + onChange: (checked: boolean) => void + className?: string + disabled?: boolean + tabIndex?: number +}) => { + const isActive = checked && !disabled return (