Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/382 refactor theme panel component #393

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

snelsi
Copy link

@snelsi snelsi commented Mar 20, 2024

Description

Main changes:

  • Allow passing optional open and onOpenChange props to the ThemePanel component using the useControllableState hook
  • Simplify setup by merging ThemePanel and ThemePanelImpl components. Remove redundant interfaces
  • Move common logic related to hotkeys into a custom useHotKey hook (no external dependencies)
  • Allow overriding default open/appearance hotkeys using optional openHotkey and toogleAppearanceHotkey props
  • Allow passing null or false to disable a hotkey
  • Hide the top-right open hotkey button when openHotkey is null

Things to improve in the future:

  • Allow passing combination of keys like Control + F or Shift + H
  • useHotKey implementation is very barebones. Consider using a library like react-hotkeys-hook

Testing steps

Use cases:

  1. Controlled behaviour:
const [open, setOpen] = useState(false);

return <ThemePanel open={open} onOpenChange={setOpen} />
  1. Custom hotkeys:
return <ThemePanel openHotkey="P" toogleAppearanceHotkey="/" />
  1. Disabling hotkeys:
return <ThemePanel openHotkey={null} toogleAppearanceHotkey={false} />

Relates issues / PRs

Refs #382

Copy link

vercel bot commented Mar 20, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
themes-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 20, 2024 10:24am

Comment on lines +75 to +84
/** A hotkey to quickly show/hide the panel.
* Set to `null` or `false` to disable the hotkey.
* @default "T"
*/
openHotkey?: string | null | false;
/** A hotkey to quickly toggle the appearance.
* Set to `null` or `false` to disable the hotkey.
* @default "D"
* */
toogleAppearanceHotkey?: string | null | false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We wouldn't want to expose a way to customize the shortcut itself – the theme panel should always work the same in different places. Having different shortcuts on different websites is going to feel unpredictable.

Just a boolean prop to disable the shortcuts should be fine, e.g. disableShortcuts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I respectfully disagree with your perspective. Default behavior can indeed remain consistent, but offering customization options allows users to adapt the component to fit seamlessly into their workflows. If a user chooses to change a defined hotkey, it should be within their responsibility, and providing such flexibility enhances the usability and adaptability of the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants