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

Closed

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.

Copy link
Author

Choose a reason for hiding this comment

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

By the way, just noticed that Radix Primitives has an example of Custom hotkey prop for Toast component 🙂

image

Copy link
Member

Choose a reason for hiding this comment

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

FWIW Radix Primitives is designed to be more flexible, where Themes is a more opinionated starter. I could be convinced on this, however. I agree it can be annoying to deal with potential conflicts.

@chaance
Copy link
Member

chaance commented Oct 4, 2024

Hi! Just wanted to weigh in here since we've had a little maintainer shuffle since this PR was opened.

Any chance we could break this into two separate, stacked PRs? I'd like to consider each new feature independently since there's a little unresolved feedback. Specifically it'd be nice to see it broken into three:

  • Making ThemePanel use controllable state
  • New useHotKey hook
  • Allow for customizing/disabling hotkeys (and hiding the hotkey button accordingly)

I know it's been a while, so totally understand if you've moved on. Happy to take this as a feature request and re-implement if we decide to move forward.

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.

3 participants